Skip to content

Commit c92a8e4

Browse files
committed
Auto merge of #127311 - oli-obk:do_not_count_errors, r=compiler-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 #124262 fixes #124083 fixes #125155 fixes #125888 fixes #125992 fixes #126666 fixes #126648 fixes #127268 fixes #127266 fixes #127304
2 parents fdf7ea6 + dce98c5 commit c92a8e4

22 files changed

+37
-211
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ build/
5050
/target
5151
/src/bootstrap/target
5252
/src/tools/x/target
53+
/inc-fat/
5354
# Created by default with `src/ci/docker/run.sh`
5455
/obj/
5556
/rustc-ice*

compiler/rustc_infer/src/infer/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,9 @@ impl<'tcx> InferCtxt<'tcx> {
12641264
where
12651265
T: TypeFoldable<TyCtxt<'tcx>>,
12661266
{
1267+
if let Err(guar) = value.error_reported() {
1268+
self.set_tainted_by_errors(guar);
1269+
}
12671270
if !value.has_non_region_infer() {
12681271
return value;
12691272
}

tests/crashes/124083.rs

-9
This file was deleted.

tests/crashes/124262.rs

-5
This file was deleted.

tests/crashes/125155.rs

-17
This file was deleted.

tests/crashes/125888.rs

-17
This file was deleted.

tests/crashes/125992.rs

-19
This file was deleted.

tests/crashes/126648.rs

-8
This file was deleted.

tests/crashes/126666.rs

-18
This file was deleted.

tests/crashes/127266.rs

-17
This file was deleted.

tests/crashes/127304.rs

-20
This file was deleted.

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>

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`.

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`.

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`.

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<

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

+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`.

tests/ui/mismatched_types/issue-74918-missing-lifetime.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ impl<T, S: Iterator<Item = T>> Iterator for ChunkingIterator<T, S> {
99
type Item = IteratorChunk<T, S>; //~ ERROR missing lifetime
1010

1111
fn next(&mut self) -> Option<IteratorChunk<T, S>> {
12-
//~^ ERROR `impl` item signature doesn't match `trait` item signature
1312
todo!()
1413
}
1514
}

tests/ui/mismatched_types/issue-74918-missing-lifetime.stderr

+1-15
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,6 @@ help: consider introducing a named lifetime parameter
99
LL | type Item<'a> = IteratorChunk<'a, T, S>;
1010
| ++++ +++
1111

12-
error: `impl` item signature doesn't match `trait` item signature
13-
--> $DIR/issue-74918-missing-lifetime.rs:11:5
14-
|
15-
LL | fn next(&mut self) -> Option<IteratorChunk<T, S>> {
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 mut ChunkingIterator<T, S>) -> Option<IteratorChunk<'1, T, S>>`
17-
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
18-
|
19-
= note: expected `fn(&'1 mut ChunkingIterator<T, S>) -> Option<IteratorChunk<'2, T, S>>`
20-
|
21-
= note: expected signature `fn(&'1 mut ChunkingIterator<T, S>) -> Option<IteratorChunk<'2, T, S>>`
22-
found signature `fn(&'1 mut ChunkingIterator<T, S>) -> Option<IteratorChunk<'1, T, S>>`
23-
= help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
24-
= help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output
25-
26-
error: aborting due to 2 previous errors
12+
error: aborting due to 1 previous error
2713

2814
For more information about this error, try `rustc --explain E0106`.

tests/ui/statics/missing_lifetime.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! This test checks that we taint typeck results when there are
2+
//! error lifetimes, even though typeck doesn't actually care about lifetimes.
3+
4+
struct Slice(&'reborrow [&'static [u8]]);
5+
//~^ ERROR undeclared lifetime
6+
7+
static MAP: Slice = Slice(&[b"" as &'static [u8]]);
8+
9+
fn main() {}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0261]: use of undeclared lifetime name `'reborrow`
2+
--> $DIR/missing_lifetime.rs:4:15
3+
|
4+
LL | struct Slice(&'reborrow [&'static [u8]]);
5+
| - ^^^^^^^^^ undeclared lifetime
6+
| |
7+
| help: consider introducing lifetime `'reborrow` here: `<'reborrow>`
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)