Commit Graph

175 Commits

Author SHA1 Message Date
Matthias Krüger 3121a5ca3b
Rollup merge of #126045 - olafes:master, r=compiler-errors
check_expr_struct_fields: taint context with errors if struct definit…

Taint errors while checking `struct { field: 1 }` below if struct definition has duplicated fields so that we don't pass it to const eval.

fixes #125842, fixes #124464, fixes #124552
```rust
struct Struct {
    field: Option<u8>,
    field: u8,
}

static STATIC: Struct = Struct {
    field: 1,
};

pub fn main() {}
```
(This was #125947 but i messed something up, sorry)
r? ``@compiler-errors``
2024-06-06 04:17:27 +02:00
Boxy f74119a2e4 Bless tests and handle tests/crashes 2024-06-05 22:25:42 +01:00
Olaf Siwiński 743c41757c
check_expr_struct_fields: taint context with errors if struct definition is malformed 2024-06-05 21:54:22 +02:00
Matthias Krüger 69a8c139f1
Rollup merge of #124840 - bvanjoi:fix-124490, r=petrochenkov
resolve: mark it undetermined if single import is not has any bindings

- Fixes #124490
- Fixes #125013

This issue arises from incorrect resolution updates, for example:

```rust
mod a {
    pub mod b {
        pub mod c {}
    }
}

use a::*;

use b::c;
use c as b;

fn main() {}
```

1. In the first loop, binding `(root, b)` is refer to `root:🅰️:b` due to `use a::*`.
    1. However, binding `(root, c)` isn't defined by `use b::c` during this stage because `use c as b` falls under the `single_imports` of `(root, b)`, where the `imported_module` hasn't been computed yet. This results in marking the `path_res` for `b` as `Indeterminate`.
    2. Then, the `imported_module` for `use c as b` will be recorded.
2. In the second loop, `use b::c` will be processed again:
    1. Firstly, it attempts to find the `path_res` for `(root, b)`.
    2. It will iterate through the `single_imports` of `use b::c`, encounter `use c as b`, attempt to resolve `c` in `root`, and ultimately return `Err(Undetermined)`, thus passing the iterator.
    3. Use the binding `(root, b)` -> `root:🅰️:b` introduced by `use a::*` and ultimately return `root:🅰️:b` as the `path_res` of `b`.
    4. Then define the binding `(root, c)` -> `root:🅰️🅱️:c`.
3. Then process `use c as b`, update the resolution for `(root, b)` to refer to `root:🅰️🅱️:c`, ultimately causing inconsistency.

In my view, step `2.2` has an issue where it should exit early, similar to the behavior when there's no `imported_module`. Therefore, I've added an attribute called `indeterminate` to `ImportData`. This will help us handle only those single imports that have at least one determined binding.

r? ``@petrochenkov``
2024-06-05 18:21:11 +02:00
Michael Goulet 7699da4858
Rollup merge of #125865 - ajwock:ice_not_fully_resolved, r=fee1-dead
Fix ICE caused by ignoring EffectVars in type inference

Fixes #119830
​r? ```@matthiaskrgr```
2024-06-04 08:52:13 -04:00
bohan f67a0eb2b7 resolve: mark it undetermined if single import is not has any bindings 2024-06-04 12:40:41 +08:00
Oli Scherer adb2ac0165 Mark all extraneous generic args as errors 2024-06-03 13:21:17 +00:00
Oli Scherer 2e3842b6d0 Mark all missing generic args as errors 2024-06-03 13:16:56 +00:00
Andrew Wock 66a13861ae Fix ICE caused by ignoring EffectVars in type inference
Signed-off-by: Andrew Wock <ajwock@gmail.com>
2024-06-03 07:18:24 -04:00
Luv-Ray d3c8e6788c check index `value <= 0xFFFF_FF00` 2024-06-01 09:40:46 +08:00
Adrian Taylor 8c1777750b Remove duplicative test.
I think that this test is supposed to be a treereduced version of
122903-1.rs, but is actually identical.
2024-05-31 11:05:32 +00:00
Adrian Taylor 6287c94fa1 Adjust crash bug to still reproduce.
This test reproduces a rustc ICE. Unfortunately, the changes to lifetime
elision mask the original ICE bug by making this function signature
illegal. However, by simplifying the signature we can regain the
original ICE.
2024-05-31 11:04:32 +00:00
Boxy d5bd4e233d Partially implement `ConstArgHasType` 2024-05-29 17:06:54 +01:00
Jubilee 01aa2e8511
Rollup merge of #125640 - fmease:plz-no-stringify, r=estebank
Don't suggest turning non-char-literal exprs of ty `char` into string literals

Fixes #125595.
Fixes #125081.

r? estebank (#122217) or compiler
2024-05-28 02:07:48 -07:00
León Orell Valerian Liehr 27cdc0df4e
Don't suggest turning non-char-literal exprs of ty `char` into string literals 2024-05-28 09:40:02 +02:00
Matthias Krüger bae945201f remove fixed crashes, add fixed crashes to tests, add new cashed found in the meantime 2024-05-27 20:41:09 +02:00
Matthias Krüger e5d100363a crashes: increment the number of tracked ones 2024-05-27 17:32:56 +02:00
Matthias Krüger 7ea507e041
Rollup merge of #125451 - oli-obk:const_type_mismatch, r=compiler-errors
Fail relating constants of different types

fixes #121585
fixes #121858
fixes #124151

I gave this several attempts before, but we lost too many important diagnostics until I managed to make compilation never bail out early. We have reached this point, so now we can finally fix all those ICEs by bubbling up an error instead of continueing when we encounter a bug.
2024-05-25 12:54:34 +02:00
Matthias Krüger 104e1a4bf2
Rollup merge of #125501 - compiler-errors:opaque-opaque-anon-ct, r=BoxyUwU
Resolve anon const's parent predicates to direct parent instead of opaque's parent

When an anon const is inside of an opaque, #99801 added a hack to resolve the anon const's parent predicates *not* to the opaque's predicates, but to the opaque's *parent's* predicates. This is insufficient when considering nested opaques.

This means that the `predicates_of` an anon const might reference duplicated lifetimes (installed by `compute_bidirectional_outlives_predicates`) when computing known outlives in MIR borrowck, leading to these ICEs:
Fixes #121574
Fixes #118403

~~Instead, we should be using the `OpaqueTypeOrigin` to acquire the owner item (fn/type alias/etc) of the opaque, whose predicates we're fine to mention.~~

~~I think it's a bit sketchy that we're doing this at all, tbh; I think it *should* be fine for the anon const to inherit the predicates of the opaque it's located inside. However, that would also mean that we need to make sure the `generics_of` that anon const line up in the same way.~~

~~None of this is important to solve right now; I just want to fix these ICEs so we can land #125468, which accidentally fixes these issues in a different and unrelated way.~~

edit: We don't need this special case anyways because we install the right parent item in `generics_of` anyways:
213ad10c8f/compiler/rustc_hir_analysis/src/collect/generics_of.rs (L150)

r? `@BoxyUwU`
2024-05-24 23:01:11 +02:00
Michael Goulet de517b79bc Actually just remove the special case altogether 2024-05-24 13:16:06 -04:00
Oli Scherer 526090b901 Add regression tests 2024-05-24 14:01:49 +00:00
Oli Scherer d5eb7a71b3 Use regular type equating instead of a custom query 2024-05-24 09:15:43 +00:00
Oli Scherer 9dc76207ff Fail relating constants of different types 2024-05-24 09:15:43 +00:00
bors 7c547894c7 Auto merge of #125457 - fmease:gacs-diag-infer-plac-missing-ty, r=compiler-errors
Properly deal with missing/placeholder types inside GACs

Fixes #124833.

r? oli-obk (#123130)
2024-05-24 06:45:40 +00:00
León Orell Valerian Liehr 39d9b840bb
Handle trait/impl GAC mismatches when inferring missing/placeholder types 2024-05-24 00:42:32 +02:00
Oli Scherer 4cf34cb752 Allow const eval failures if the cause is a type layout issue 2024-05-23 10:51:52 +00:00
bors f0038a7c8f Auto merge of #124227 - compiler-errors:hack-check-method-res, r=estebank
Make sure that the method resolution matches in `note_source_of_type_mismatch_constraint`

`note_source_of_type_mismatch_constraint` is a pile of hacks that I implemented to cover up another pile of hacks.

It does a bunch of re-confirming methods, but it wasn't previously checking that the methods it was looking (back) up were equal to the methods we previously had. This PR adds those checks.

Fixes #118185
2024-05-22 10:57:59 +00:00
Matthias Krüger 734e216b35 crashes: add more 2024-05-18 23:56:57 +02:00
Michael Goulet c697ec41f4 Propagate errors rather than using return_if_err 2024-05-12 12:50:18 -04:00
bohan f70f900036 ignore generics args in attribute paths 2024-05-11 00:13:27 +08:00
lcnr feff7520df update crashes 2024-05-09 17:51:05 +00:00
Matthias Krüger 812fb24e79
Rollup merge of #124775 - matthiaskrgr:boom, r=jieyouxu
crashes: add lastest batch of crash tests
2024-05-08 23:33:25 +02:00
Matthias Krüger e997508ecb
Rollup merge of #124548 - gurry:113272-ice-failed-to-normalize, r=compiler-errors
Handle normalization failure in `struct_tail_erasing_lifetimes`

Fixes #113272

The ICE occurred because the struct being normalized had an error. This PR adds some defensive code to guard against that.
2024-05-08 17:03:08 +02:00
bors faefc618cf Auto merge of #124219 - gurry:122989-ice-unexpected-anon-const, r=compiler-errors
Do not ICE on `AnonConst`s in `diagnostic_hir_wf_check`

Fixes #122989

Below is the snippet from #122989 that ICEs:
```rust
trait Traitor<const N: N<2> = 1, const N: N<2> = N> {
    fn N(&N) -> N<2> {
        M
    }
}

trait N<const N: Traitor<2> = 12> {}
```

The `AnonConst` that triggers the ICE is the `2` in the param `const N: N<2> = 1`. The currently existing code in `diagnostic_hir_wf_check` deals only with `AnonConst`s that are default values of some param, but  the `2` is not a default value. It is just an `AnonConst` HIR node inside a `TraitRef` HIR node corresponding to `N<2>`. Therefore the existing code cannot handle it and this PR ensures that it does.
2024-05-07 20:01:18 +00:00
Matthias Krüger 397a35d081 crashes: add lastest batch of crash tests 2024-05-05 23:41:08 +02:00
Nadrieril 57e8aebb6c Lower never patterns to Unreachable in mir 2024-05-04 16:30:01 +02:00
bors d2d24e395a Auto merge of #123602 - cjgillot:gvn-borrowed, r=oli-obk
Account for immutably borrowed locals in MIR copy-prop and GVN

For the most part, we consider that immutably borrowed `Freeze` locals still fulfill SSA conditions. As the borrow is immutable, any use of the local will have the value given by the single assignment, and there can be no surprise.

This allows copy-prop to merge a non-borrowed local with a borrowed local. We chose to keep copy-classes heads unborrowed, as those may be easier to optimize in later passes.

This also allows to GVN the value behind an immutable borrow. If a SSA local is borrowed, dereferencing that borrow is equivalent to copying the local's value: re-executing the assignment between the borrow and the dereference would be UB.

r? `@ghost` for perf
2024-05-03 21:50:13 +00:00
Gurinder Singh 0c71c9d74b Handle normalization failure in `struct_tail_erasing_lifetimes`
Fixes an ICE that occurred when the struct in question has an error
2024-05-01 09:29:33 +05:30
许杰友 Jieyou Xu (Joe) 43265f5721
Rollup merge of #124504 - gurry:123710-union-ICE, r=oli-obk
Mark unions non-const-propagatable in `KnownPanicsLint` without calling layout

Fixes #123710

The ICE occurs during the layout calculation of the union `InvalidTag` in #123710 because the following assert fails:5fe8b697e7/compiler/rustc_abi/src/layout.rs (L289-L292)

The layout calculation is invoked by `KnownPanicsLint` when it is trying to figure out which locals it can const prop. Since `KnownPanicsLint` is never actually going to const props unions thanks to PR https://github.com/rust-lang/rust/pull/121628 there's no point calling layout to check if it can. So in this fix I skip the call to layout and just mark the local non-const propagatable if it is a union.
2024-04-29 18:03:24 +01:00
Gurinder Singh 254a9fbe86 Prohibit const prop of unions in `KnownPanicsLint`
as they have a potential to ICE during layout calculation
2024-04-29 08:16:26 +05:30
Matthias Krüger c32e2fe179 add test for https://github.com/rust-lang/rust/issues/109812 2024-04-28 10:23:10 +02:00
Matthias Krüger aeb4c0413c
Rollup merge of #124394 - gurry:123863-ice-unexpected-region, r=lcnr
Fix ICE on invalid const param types

Fixes ICE #123863 which occurs because the const param has a type which is not a `bool`, `char` or an integral type.

The ICEing code path begins here in `typeck_with_fallback`: cb3752d20e/compiler/rustc_hir_typeck/src/lib.rs (L167)

The `fallback` invokes the `type_of` query and that eventually ends up calling `ct_infer` from the lowering code over here:
cb3752d20e/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs (L561) and `ct_infer` ICEs at this location: cb3752d20e/compiler/rustc_hir_analysis/src/collect.rs (L392)

To fix the ICE it I'm triggering a `span_delayed_bug` before we hit `ct_infer` if the type of the const param is not one of the supported types

### Edit
On `@lcnr's` suggestion I've changed the approach to not let `ReStatic` region hit the `bug!` in `ct_infer` instead of triggering a `span_delayed_bug`.
2024-04-27 20:46:08 +02:00
Gurinder Singh c62bc31b16 Fix ICE on invalid const param types 2024-04-27 09:36:38 +05:30
Matthias Krüger 60c0fa1285 crashes: add more tests 2024-04-26 17:20:16 +02:00
Michael Goulet 870ed4bfa2 Add test 2024-04-25 10:51:54 -04:00
León Orell Valerian Liehr e15d6f9d85
Rollup merge of #123993 - compiler-errors:coroutine-obl, r=lcnr
Do `check_coroutine_obligations` once per typeck root

We only need to do `check_coroutine_obligations` once per typeck root, especially since the new solver can't really (easily) associate which obligations correspond to which coroutines.

This requires us to move the checks for sized coroutine fields into `mir_coroutine_witnesses`, but that's fine imo.

r? lcnr
2024-04-23 17:25:16 +02:00
Matthias Krüger 8859631b40
Rollup merge of #124057 - gurry:124031-ice-layout-errored, r=compiler-errors
Fix ICE when ADT tail has type error

Fixes #124031
2024-04-23 06:24:55 +02:00
Gurinder Singh 446f78d051 Do not ICE on `AnonConst`s in `diagnostic_hir_wf_check` 2024-04-22 10:31:32 +05:30
Gurinder Singh 06cd79bb5b Fix ICE when ADT tail has type error 2024-04-22 09:12:36 +05:30
Matthias Krüger 6774801563 crashes: add a couple more ICE tests 2024-04-21 21:04:32 +02:00
Michael Goulet 483f13ce91 Make sure that the method resolution matches in note_source_of_type_mismatch_constraint 2024-04-21 11:11:31 -04:00
Camille GILLOT c19866f335 Remove no_core ICE test. 2024-04-20 19:28:48 +00:00
bors f1bff1f323 Auto merge of #124176 - matthiaskrgr:tests_are_the_best, r=jieyouxu
add more known crashes tests

r? `@jieyouxu`
2024-04-20 06:36:58 +00:00
Matthias Krüger b015f61488 add more known-crashes tests 2024-04-19 23:09:37 +02:00
Maybe Waffle e5a6d8d0cd Remove old ICE tests that no longer ICE (yay!) 2024-04-19 11:34:37 +00:00
bors fa0068b541 Auto merge of #124038 - matthiaskrgr:one_or_two_more_tests, r=jieyouxu
crashes: add a couple more ice tests
2024-04-19 01:02:44 +00:00
Matthias Krüger 1d45b7adaf crashes: add a couple more tests 2024-04-18 18:55:20 +02:00
Scott McMurray 20cf59549f The ICE in 121127 needs debuginfo 2024-04-18 09:42:26 -07:00
bors b1248bc60d Auto merge of #124046 - matthiaskrgr:one_or_two_more_tests____some_on_top, r=jieyouxu
crashes: add even more tests?!?

adds more tests that were not already added with https://github.com/rust-lang/rust/pull/124038 from the past 10 months or so.
Need a couple more passes through the tracker to filter out more missing ice /fixed tests but we're slowly getting there.
2024-04-18 05:23:09 +00:00
Matthias Krüger 06335c6532 crashes: add even more tests?!? 2024-04-18 06:13:47 +02:00
Oli Scherer 8c9cba2be7 Validate nested static items 2024-04-17 09:50:15 +00:00
Guillaume Gomez 4885ddfa92
Rollup merge of #123675 - oli-obk:static_wf_ice, r=compiler-errors
Taint const qualifs if a static is referenced that didn't pass wfcheck

It is correct to only check the signature here, as the ICE is caused by `USE_WITH_ERROR` trying to allocate memory to store the result of `WITH_ERROR` before evaluating it.

fixes #123153
2024-04-17 00:00:22 +02:00
Oli Scherer 801413ecd1 Taint const qualifs if a static is referenced that didn't pass wfcheck 2024-04-16 10:43:41 +00:00
Gurinder Singh c30e15aded Fail candidate assembly for erroneous types
Trait predicates for types which have errors may still
evaluate to OK leading to downstream ICEs. Now we return
a selection error for such types in candidate assembly and
thereby prevent such issues
2024-04-16 12:42:48 +05:30
Michael Goulet a8c9a0bd81 crash -> test 2024-04-15 22:21:50 -04:00
Matthias Krüger 83d73e4929 crashes: readme: add reminder to add Fixes #abcde to prs to automatically close issues. 2024-04-15 21:44:04 +02:00
Matthias Krüger 2ce487c45c crashes: limit a couple tests to only run on x86_64 and/or not on windows 2024-04-14 23:53:39 +02:00
Matthias Krüger 37df49059d update README and add COMPILETEST_VERBOSE_CRASHES env var which when set print stdout, stderr and exit code of "crashes" tests, useful for debugging or adding new tests 2024-04-14 11:30:29 +02:00
Matthias Krüger 6d9175f98e crashes: fix ice detection which did not trigger if code compiled without error by accident 2024-04-14 11:21:58 +02:00
Matthias Krüger 7d826ae43e tests/crashes: add ICEs from matthiaskrgr/glacier2 2024-04-14 11:21:51 +02:00
Matthias Krüger 98dd566033 add .rs crashes from https://github.com/rust-lang/glacier 2024-04-14 11:18:23 +02:00
Matthias Krüger 7048ce7e8f tidy: add tidy check agains \.rs files inside tests/crashes that are missing "//@ known-bug: " 2024-04-14 11:16:26 +02:00
Matthias Krüger d6e70df1a2 crashes: add another test showing that everything works fine when we need compile-flags to repro an ice and add README 2024-04-14 11:16:15 +02:00
Matthias Krüger 7b05360a1e bootstrap/compiletest: implement "crashes" tests that fail if no ice is reproduced 2024-04-14 11:14:45 +02:00
Matthias Krüger 65ca71815a add initial ice as test 2024-04-14 11:04:27 +02:00