Skip to content

Commit 7b804d2

Browse files
committed
Auto merge of #127311 - oli-obk:do_not_count_errors, r=<try>
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 #124262 fixes #124083 fixes #125155 fixes #125888 fixes #125992 fixes #126666 fixes #126648 fixes #127268
2 parents 9ffe52e + 2d5b2d8 commit 7b804d2

23 files changed

+48
-225
lines changed

Diff for: compiler/rustc_infer/src/infer/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,9 @@ impl<'tcx> InferCtxt<'tcx> {
12731273
where
12741274
T: TypeFoldable<TyCtxt<'tcx>>,
12751275
{
1276+
if let Err(guar) = value.error_reported() {
1277+
self.set_tainted_by_errors(guar);
1278+
}
12761279
if !value.has_non_region_infer() {
12771280
return value;
12781281
}

Diff for: tests/crashes/124083.rs

-9
This file was deleted.

Diff for: tests/crashes/124262.rs

-5
This file was deleted.

Diff for: tests/crashes/125155.rs

-17
This file was deleted.

Diff for: tests/crashes/125888.rs

-17
This file was deleted.

Diff for: tests/crashes/125992.rs

-19
This file was deleted.

Diff for: tests/crashes/126648.rs

-8
This file was deleted.

Diff for: tests/crashes/126666.rs

-18
This file was deleted.

Diff for: tests/rustdoc-ui/unable-fulfill-trait.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub struct Foo<'a, 'b, T> {
44
field1: dyn Bar<'a, 'b>,
55
//~^ ERROR
66
//~| ERROR
7-
//~| ERROR
87
}
98

109
pub trait Bar<'x, 's, U>

Diff for: tests/rustdoc-ui/unable-fulfill-trait.stderr

+3-20
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | field1: dyn Bar<'a, 'b>,
55
| ^^^ expected 1 generic argument
66
|
77
note: trait defined here, with 1 generic parameter: `U`
8-
--> $DIR/unable-fulfill-trait.rs:10:11
8+
--> $DIR/unable-fulfill-trait.rs:9:11
99
|
1010
LL | pub trait Bar<'x, 's, U>
1111
| ^^^ -
@@ -20,24 +20,7 @@ error[E0227]: ambiguous lifetime bound, explicit lifetime bound required
2020
LL | field1: dyn Bar<'a, 'b>,
2121
| ^^^^^^^^^^^^^^^
2222

23-
error[E0478]: lifetime bound not satisfied
24-
--> $DIR/unable-fulfill-trait.rs:4:13
25-
|
26-
LL | field1: dyn Bar<'a, 'b>,
27-
| ^^^^^^^^^^^^^^^
28-
|
29-
note: lifetime parameter instantiated with the lifetime `'b` as defined here
30-
--> $DIR/unable-fulfill-trait.rs:3:20
31-
|
32-
LL | pub struct Foo<'a, 'b, T> {
33-
| ^^
34-
note: but lifetime parameter must outlive the lifetime `'a` as defined here
35-
--> $DIR/unable-fulfill-trait.rs:3:16
36-
|
37-
LL | pub struct Foo<'a, 'b, T> {
38-
| ^^
39-
40-
error: aborting due to 3 previous errors
23+
error: aborting due to 2 previous errors
4124

42-
Some errors have detailed explanations: E0107, E0227, E0478.
25+
Some errors have detailed explanations: E0107, E0227.
4326
For more information about an error, try `rustc --explain E0107`.

Diff for: tests/ui/const-generics/issues/issue-62878.min.stderr

+3-27
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,7 @@ help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
3030
LL + #![feature(generic_arg_infer)]
3131
|
3232

33-
error[E0284]: type annotations needed
34-
--> $DIR/issue-62878.rs:10:5
35-
|
36-
LL | foo::<_, { [1] }>();
37-
| ^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `foo`
38-
|
39-
note: required by a const generic parameter in `foo`
40-
--> $DIR/issue-62878.rs:5:8
41-
|
42-
LL | fn foo<const N: usize, const A: [u8; N]>() {}
43-
| ^^^^^^^^^^^^^^ required by this const generic parameter in `foo`
44-
45-
error[E0284]: type annotations needed
46-
--> $DIR/issue-62878.rs:10:5
47-
|
48-
LL | foo::<_, { [1] }>();
49-
| ^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `A` declared on the function `foo`
50-
|
51-
note: required by a const generic parameter in `foo`
52-
--> $DIR/issue-62878.rs:5:24
53-
|
54-
LL | fn foo<const N: usize, const A: [u8; N]>() {}
55-
| ^^^^^^^^^^^^^^^^ required by this const generic parameter in `foo`
56-
57-
error: aborting due to 5 previous errors
33+
error: aborting due to 3 previous errors
5834

59-
Some errors have detailed explanations: E0284, E0747, E0770.
60-
For more information about an error, try `rustc --explain E0284`.
35+
Some errors have detailed explanations: E0747, E0770.
36+
For more information about an error, try `rustc --explain E0747`.

Diff for: tests/ui/const-generics/issues/issue-62878.rs

-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@ fn foo<const N: usize, const A: [u8; N]>() {}
99
fn main() {
1010
foo::<_, { [1] }>();
1111
//[min]~^ ERROR: type provided when a constant was expected
12-
//[min]~| ERROR type annotations needed
13-
//[min]~| ERROR type annotations needed
1412
}

Diff for: tests/ui/const-generics/issues/issue-71381.full.stderr

+3-15
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,13 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
77
= note: type parameters may not be used in the type of const parameters
88

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

17-
error[E0594]: cannot assign to `self.0`, which is behind a `&` reference
18-
--> $DIR/issue-71381.rs:17:9
19-
|
20-
LL | self.0 = Self::trampiline::<Args, IDX, FN> as _
21-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written
22-
|
23-
help: consider changing this to be a mutable reference
24-
|
25-
LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&mut self) {
26-
| ~~~~~~~~~
27-
28-
error: aborting due to 3 previous errors
17+
error: aborting due to 2 previous errors
2918

30-
Some errors have detailed explanations: E0594, E0770.
31-
For more information about an error, try `rustc --explain E0594`.
19+
For more information about this error, try `rustc --explain E0770`.

Diff for: tests/ui/const-generics/issues/issue-71381.min.stderr

+4-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
77
= note: type parameters may not be used in the type of const parameters
88

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

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

33-
error[E0594]: cannot assign to `self.0`, which is behind a `&` reference
34-
--> $DIR/issue-71381.rs:17:9
35-
|
36-
LL | self.0 = Self::trampiline::<Args, IDX, FN> as _
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written
38-
|
39-
help: consider changing this to be a mutable reference
40-
|
41-
LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&mut self) {
42-
| ~~~~~~~~~
43-
44-
error: aborting due to 5 previous errors
33+
error: aborting due to 4 previous errors
4534

46-
Some errors have detailed explanations: E0594, E0770.
47-
For more information about an error, try `rustc --explain E0594`.
35+
For more information about this error, try `rustc --explain E0770`.

Diff for: tests/ui/const-generics/issues/issue-71381.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ impl Test {
1515
//~^ ERROR: the type of const parameters must not depend on other generic parameters
1616
//[min]~^^ ERROR: using function pointers as const generic parameters is forbidden
1717
self.0 = Self::trampiline::<Args, IDX, FN> as _
18-
//~^ ERROR: cannot assign to `self.0`
1918
}
2019

2120
unsafe extern "C" fn trampiline<

Diff for: tests/ui/const-generics/min_const_generics/macro-fail.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ fn make_marker() -> impl Marker<gimme_a_const!(marker)> {
1616
//~| ERROR: type provided when a constant was expected
1717
Example::<gimme_a_const!(marker)>
1818
//~^ ERROR: type provided when a constant was expected
19-
//~| ERROR type annotations needed
2019
}
2120

2221
fn from_marker(_: impl Marker<{

Diff for: tests/ui/const-generics/min_const_generics/macro-fail.stderr

+9-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: expected type, found `{`
2-
--> $DIR/macro-fail.rs:31:27
2+
--> $DIR/macro-fail.rs:30:27
33
|
44
LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> {
55
| ----------------------
@@ -13,7 +13,7 @@ LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }}
1313
= note: this error originates in the macro `gimme_a_const` (in Nightly builds, run with -Z macro-backtrace for more info)
1414

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

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

78-
error[E0284]: type annotations needed
79-
--> $DIR/macro-fail.rs:17:3
80-
|
81-
LL | Example::<gimme_a_const!(marker)>
82-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the struct `Example`
83-
|
84-
note: required by a const generic parameter in `Example`
85-
--> $DIR/macro-fail.rs:1:16
86-
|
87-
LL | struct Example<const N: usize>;
88-
| ^^^^^^^^^^^^^^ required by this const generic parameter in `Example`
89-
9078
error[E0747]: type provided when a constant was expected
91-
--> $DIR/macro-fail.rs:38:25
79+
--> $DIR/macro-fail.rs:37:25
9280
|
9381
LL | let _fail = Example::<external_macro!()>;
9482
| ^^^^^^^^^^^^^^^^^
9583

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

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

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

134-
error: aborting due to 12 previous errors
122+
error: aborting due to 11 previous errors
135123

136124
Some errors have detailed explanations: E0284, E0747.
137125
For more information about an error, try `rustc --explain E0284`.

Diff for: tests/ui/impl-trait/issue-72911.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ fn gather_from_file(dir_entry: &foo::MissingItem) -> impl Iterator<Item = Lint>
1515

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

Diff for: tests/ui/impl-trait/issue-72911.stderr

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
error[E0277]: `()` is not an iterator
2-
--> $DIR/issue-72911.rs:16:20
3-
|
4-
LL | fn lint_files() -> impl Iterator<Item = foo::MissingItem> {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
6-
|
7-
= help: the trait `Iterator` is not implemented for `()`
8-
91
error[E0433]: failed to resolve: use of undeclared crate or module `foo`
102
--> $DIR/issue-72911.rs:11:33
113
|
@@ -18,7 +10,6 @@ error[E0433]: failed to resolve: use of undeclared crate or module `foo`
1810
LL | fn lint_files() -> impl Iterator<Item = foo::MissingItem> {
1911
| ^^^ use of undeclared crate or module `foo`
2012

21-
error: aborting due to 3 previous errors
13+
error: aborting due to 2 previous errors
2214

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

0 commit comments

Comments
 (0)