Skip to content

Commit f3e56de

Browse files
committed
Avoid follow-up errors and ICEs after missing lifetime errors on data structures
1 parent 486bc27 commit f3e56de

21 files changed

+45
-204
lines changed

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
}

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

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
}

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/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<{

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

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() {}

0 commit comments

Comments
 (0)