Skip to content

Commit

Permalink
Auto merge of rust-lang#127311 - oli-obk:do_not_count_errors, r=compi…
Browse files Browse the repository at this point in the history
…ler-errors

Avoid follow-up errors and ICEs after missing lifetime errors on data structures

Tuple struct constructors are functions, so when we call them typeck will use the signature tuple struct constructor function to provide type hints. Since typeck mostly ignores and erases lifetimes, we end up never seeing the error lifetime in writeback, thus not tainting the typeck result.

Now, we eagerly taint typeck results by tainting from `resolve_vars_if_possible`, which is called all over the place.

I did not carry over all the `crashes` test suite tests, as they are really all the same cause (missing or unknown lifetime names in tuple struct definitions or generic arg lists).

fixes rust-lang#124262
fixes rust-lang#124083
fixes rust-lang#125155
fixes rust-lang#125888
fixes rust-lang#125992
fixes rust-lang#126666
fixes rust-lang#126648
fixes rust-lang#127268
  • Loading branch information
bors committed Jul 9, 2024
2 parents 6be96e3 + 2d5b2d8 commit 567809d
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 225 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,9 @@ impl<'tcx> InferCtxt<'tcx> {
where
T: TypeFoldable<TyCtxt<'tcx>>,
{
if let Err(guar) = value.error_reported() {
self.set_tainted_by_errors(guar);
}
if !value.has_non_region_infer() {
return value;
}
Expand Down
9 changes: 0 additions & 9 deletions tests/crashes/124083.rs

This file was deleted.

5 changes: 0 additions & 5 deletions tests/crashes/124262.rs

This file was deleted.

17 changes: 0 additions & 17 deletions tests/crashes/125155.rs

This file was deleted.

17 changes: 0 additions & 17 deletions tests/crashes/125888.rs

This file was deleted.

19 changes: 0 additions & 19 deletions tests/crashes/125992.rs

This file was deleted.

8 changes: 0 additions & 8 deletions tests/crashes/126648.rs

This file was deleted.

18 changes: 0 additions & 18 deletions tests/crashes/126666.rs

This file was deleted.

1 change: 0 additions & 1 deletion tests/rustdoc-ui/unable-fulfill-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub struct Foo<'a, 'b, T> {
field1: dyn Bar<'a, 'b>,
//~^ ERROR
//~| ERROR
//~| ERROR
}

pub trait Bar<'x, 's, U>
Expand Down
23 changes: 3 additions & 20 deletions tests/rustdoc-ui/unable-fulfill-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | field1: dyn Bar<'a, 'b>,
| ^^^ expected 1 generic argument
|
note: trait defined here, with 1 generic parameter: `U`
--> $DIR/unable-fulfill-trait.rs:10:11
--> $DIR/unable-fulfill-trait.rs:9:11
|
LL | pub trait Bar<'x, 's, U>
| ^^^ -
Expand All @@ -20,24 +20,7 @@ error[E0227]: ambiguous lifetime bound, explicit lifetime bound required
LL | field1: dyn Bar<'a, 'b>,
| ^^^^^^^^^^^^^^^

error[E0478]: lifetime bound not satisfied
--> $DIR/unable-fulfill-trait.rs:4:13
|
LL | field1: dyn Bar<'a, 'b>,
| ^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'b` as defined here
--> $DIR/unable-fulfill-trait.rs:3:20
|
LL | pub struct Foo<'a, 'b, T> {
| ^^
note: but lifetime parameter must outlive the lifetime `'a` as defined here
--> $DIR/unable-fulfill-trait.rs:3:16
|
LL | pub struct Foo<'a, 'b, T> {
| ^^

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0107, E0227, E0478.
Some errors have detailed explanations: E0107, E0227.
For more information about an error, try `rustc --explain E0107`.
30 changes: 3 additions & 27 deletions tests/ui/const-generics/issues/issue-62878.min.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,7 @@ help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
LL + #![feature(generic_arg_infer)]
|

error[E0284]: type annotations needed
--> $DIR/issue-62878.rs:10:5
|
LL | foo::<_, { [1] }>();
| ^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `foo`
|
note: required by a const generic parameter in `foo`
--> $DIR/issue-62878.rs:5:8
|
LL | fn foo<const N: usize, const A: [u8; N]>() {}
| ^^^^^^^^^^^^^^ required by this const generic parameter in `foo`

error[E0284]: type annotations needed
--> $DIR/issue-62878.rs:10:5
|
LL | foo::<_, { [1] }>();
| ^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `A` declared on the function `foo`
|
note: required by a const generic parameter in `foo`
--> $DIR/issue-62878.rs:5:24
|
LL | fn foo<const N: usize, const A: [u8; N]>() {}
| ^^^^^^^^^^^^^^^^ required by this const generic parameter in `foo`

error: aborting due to 5 previous errors
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0284, E0747, E0770.
For more information about an error, try `rustc --explain E0284`.
Some errors have detailed explanations: E0747, E0770.
For more information about an error, try `rustc --explain E0747`.
2 changes: 0 additions & 2 deletions tests/ui/const-generics/issues/issue-62878.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ fn foo<const N: usize, const A: [u8; N]>() {}
fn main() {
foo::<_, { [1] }>();
//[min]~^ ERROR: type provided when a constant was expected
//[min]~| ERROR type annotations needed
//[min]~| ERROR type annotations needed
}
18 changes: 3 additions & 15 deletions tests/ui/const-generics/issues/issue-71381.full.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,13 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
= note: type parameters may not be used in the type of const parameters

error[E0770]: the type of const parameters must not depend on other generic parameters
--> $DIR/issue-71381.rs:24:40
--> $DIR/issue-71381.rs:23:40
|
LL | const FN: unsafe extern "C" fn(Args),
| ^^^^ the type must not depend on the parameter `Args`
|
= note: type parameters may not be used in the type of const parameters

error[E0594]: cannot assign to `self.0`, which is behind a `&` reference
--> $DIR/issue-71381.rs:17:9
|
LL | self.0 = Self::trampiline::<Args, IDX, FN> as _
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written
|
help: consider changing this to be a mutable reference
|
LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&mut self) {
| ~~~~~~~~~

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0594, E0770.
For more information about an error, try `rustc --explain E0594`.
For more information about this error, try `rustc --explain E0770`.
20 changes: 4 additions & 16 deletions tests/ui/const-generics/issues/issue-71381.min.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
= note: type parameters may not be used in the type of const parameters

error[E0770]: the type of const parameters must not depend on other generic parameters
--> $DIR/issue-71381.rs:24:40
--> $DIR/issue-71381.rs:23:40
|
LL | const FN: unsafe extern "C" fn(Args),
| ^^^^ the type must not depend on the parameter `Args`
Expand All @@ -23,25 +23,13 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
= note: the only supported types are integers, `bool` and `char`

error: using function pointers as const generic parameters is forbidden
--> $DIR/issue-71381.rs:24:19
--> $DIR/issue-71381.rs:23:19
|
LL | const FN: unsafe extern "C" fn(Args),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`

error[E0594]: cannot assign to `self.0`, which is behind a `&` reference
--> $DIR/issue-71381.rs:17:9
|
LL | self.0 = Self::trampiline::<Args, IDX, FN> as _
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written
|
help: consider changing this to be a mutable reference
|
LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&mut self) {
| ~~~~~~~~~

error: aborting due to 5 previous errors
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0594, E0770.
For more information about an error, try `rustc --explain E0594`.
For more information about this error, try `rustc --explain E0770`.
1 change: 0 additions & 1 deletion tests/ui/const-generics/issues/issue-71381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ impl Test {
//~^ ERROR: the type of const parameters must not depend on other generic parameters
//[min]~^^ ERROR: using function pointers as const generic parameters is forbidden
self.0 = Self::trampiline::<Args, IDX, FN> as _
//~^ ERROR: cannot assign to `self.0`
}

unsafe extern "C" fn trampiline<
Expand Down
1 change: 0 additions & 1 deletion tests/ui/const-generics/min_const_generics/macro-fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ fn make_marker() -> impl Marker<gimme_a_const!(marker)> {
//~| ERROR: type provided when a constant was expected
Example::<gimme_a_const!(marker)>
//~^ ERROR: type provided when a constant was expected
//~| ERROR type annotations needed
}

fn from_marker(_: impl Marker<{
Expand Down
30 changes: 9 additions & 21 deletions tests/ui/const-generics/min_const_generics/macro-fail.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: expected type, found `{`
--> $DIR/macro-fail.rs:31:27
--> $DIR/macro-fail.rs:30:27
|
LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> {
| ----------------------
Expand All @@ -13,7 +13,7 @@ LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }}
= note: this error originates in the macro `gimme_a_const` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected type, found `{`
--> $DIR/macro-fail.rs:31:27
--> $DIR/macro-fail.rs:30:27
|
LL | Example::<gimme_a_const!(marker)>
| ----------------------
Expand Down Expand Up @@ -41,7 +41,7 @@ LL | let _fail = Example::<external_macro!()>;
= note: this error originates in the macro `external_macro` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unexpected end of macro invocation
--> $DIR/macro-fail.rs:42:25
--> $DIR/macro-fail.rs:41:25
|
LL | macro_rules! gimme_a_const {
| -------------------------- when calling this macro
Expand All @@ -50,7 +50,7 @@ LL | let _fail = Example::<gimme_a_const!()>;
| ^^^^^^^^^^^^^^^^ missing tokens in macro arguments
|
note: while trying to match meta-variable `$rusty:ident`
--> $DIR/macro-fail.rs:31:8
--> $DIR/macro-fail.rs:30:8
|
LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }}
| ^^^^^^^^^^^^^
Expand All @@ -75,32 +75,20 @@ error[E0747]: type provided when a constant was expected
LL | Example::<gimme_a_const!(marker)>
| ^^^^^^^^^^^^^^^^^^^^^^

error[E0284]: type annotations needed
--> $DIR/macro-fail.rs:17:3
|
LL | Example::<gimme_a_const!(marker)>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the struct `Example`
|
note: required by a const generic parameter in `Example`
--> $DIR/macro-fail.rs:1:16
|
LL | struct Example<const N: usize>;
| ^^^^^^^^^^^^^^ required by this const generic parameter in `Example`

error[E0747]: type provided when a constant was expected
--> $DIR/macro-fail.rs:38:25
--> $DIR/macro-fail.rs:37:25
|
LL | let _fail = Example::<external_macro!()>;
| ^^^^^^^^^^^^^^^^^

error[E0747]: type provided when a constant was expected
--> $DIR/macro-fail.rs:42:25
--> $DIR/macro-fail.rs:41:25
|
LL | let _fail = Example::<gimme_a_const!()>;
| ^^^^^^^^^^^^^^^^

error[E0284]: type annotations needed for `Example<_>`
--> $DIR/macro-fail.rs:38:7
--> $DIR/macro-fail.rs:37:7
|
LL | let _fail = Example::<external_macro!()>;
| ^^^^^ ---------------------------- type must be known at this point
Expand All @@ -116,7 +104,7 @@ LL | let _fail: Example<N> = Example::<external_macro!()>;
| ++++++++++++

error[E0284]: type annotations needed for `Example<_>`
--> $DIR/macro-fail.rs:42:7
--> $DIR/macro-fail.rs:41:7
|
LL | let _fail = Example::<gimme_a_const!()>;
| ^^^^^ --------------------------- type must be known at this point
Expand All @@ -131,7 +119,7 @@ help: consider giving `_fail` an explicit type, where the value of const paramet
LL | let _fail: Example<N> = Example::<gimme_a_const!()>;
| ++++++++++++

error: aborting due to 12 previous errors
error: aborting due to 11 previous errors

Some errors have detailed explanations: E0284, E0747.
For more information about an error, try `rustc --explain E0284`.
1 change: 0 additions & 1 deletion tests/ui/impl-trait/issue-72911.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ fn gather_from_file(dir_entry: &foo::MissingItem) -> impl Iterator<Item = Lint>

fn lint_files() -> impl Iterator<Item = foo::MissingItem> {
//~^ ERROR: failed to resolve
//~| ERROR: `()` is not an iterator
unimplemented!()
}

Expand Down
13 changes: 2 additions & 11 deletions tests/ui/impl-trait/issue-72911.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
error[E0277]: `()` is not an iterator
--> $DIR/issue-72911.rs:16:20
|
LL | fn lint_files() -> impl Iterator<Item = foo::MissingItem> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
|
= help: the trait `Iterator` is not implemented for `()`

error[E0433]: failed to resolve: use of undeclared crate or module `foo`
--> $DIR/issue-72911.rs:11:33
|
Expand All @@ -18,7 +10,6 @@ error[E0433]: failed to resolve: use of undeclared crate or module `foo`
LL | fn lint_files() -> impl Iterator<Item = foo::MissingItem> {
| ^^^ use of undeclared crate or module `foo`

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0277, E0433.
For more information about an error, try `rustc --explain E0277`.
For more information about this error, try `rustc --explain E0433`.
Loading

0 comments on commit 567809d

Please sign in to comment.