Skip to content

Commit 1cc76f5

Browse files
authored
Unrolled build for rust-lang#130137
Rollup merge of rust-lang#130137 - gurry:master, r=cjgillot Fix ICE caused by missing span in a region error Fixes rust-lang#130012 The ICE occurs on line 634 in this error handling code: https://github.com/rust-lang/rust/blob/085744b7ad8b227239bcee0a44cd78dcd0310ab9/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs#L617-L637 It is caused by the span being a dummy span and `!span.is_dummy()` on line 628 evaluating to `false`. A dummy span, however, is expected here thanks to the `Self: Trait` predicate from `predicates_of` (see line 61): https://github.com/rust-lang/rust/blob/085744b7ad8b227239bcee0a44cd78dcd0310ab9/compiler/rustc_hir_analysis/src/collect/predicates_of.rs#L61-L69 This PR changes the error handling code to omit the note which needed the span instead of ICE'ing in the presence of a dummy span.
2 parents d7522d8 + 0f8efb3 commit 1cc76f5

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

Diff for: compiler/rustc_trait_selection/src/error_reporting/infer/region.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,19 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
625625
if let ObligationCauseCode::WhereClause(_, span)
626626
| ObligationCauseCode::WhereClauseInExpr(_, span, ..) =
627627
&trace.cause.code().peel_derives()
628-
&& !span.is_dummy()
629628
{
630629
let span = *span;
631-
self.report_concrete_failure(generic_param_scope, placeholder_origin, sub, sup)
632-
.with_span_note(span, "the lifetime requirement is introduced here")
630+
let mut err = self.report_concrete_failure(
631+
generic_param_scope,
632+
placeholder_origin,
633+
sub,
634+
sup,
635+
);
636+
if !span.is_dummy() {
637+
err =
638+
err.with_span_note(span, "the lifetime requirement is introduced here");
639+
}
640+
err
633641
} else {
634642
unreachable!(
635643
"control flow ensures we have a `BindingObligation` or `WhereClauseInExpr` here..."

Diff for: tests/ui/wf/ice-wf-missing-span-in-error-130012.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Regression test for ICE #130012
2+
// Checks that we do not ICE while reporting
3+
// lifetime mistmatch error
4+
5+
trait Fun {
6+
type Assoc;
7+
}
8+
9+
trait MyTrait: for<'a> Fun<Assoc = &'a ()> {}
10+
//~^ ERROR binding for associated type `Assoc` references lifetime `'a`, which does not appear in the trait input types
11+
//~| ERROR binding for associated type `Assoc` references lifetime `'a`, which does not appear in the trait input types
12+
//~| ERROR binding for associated type `Assoc` references lifetime `'a`, which does not appear in the trait input types
13+
14+
impl<F: for<'b> Fun<Assoc = &'b ()>> MyTrait for F {}
15+
//~^ ERROR binding for associated type `Assoc` references lifetime `'b`, which does not appear in the trait input types
16+
//~| ERROR mismatched types
17+
18+
fn main() {}
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
error[E0582]: binding for associated type `Assoc` references lifetime `'a`, which does not appear in the trait input types
2+
--> $DIR/ice-wf-missing-span-in-error-130012.rs:9:28
3+
|
4+
LL | trait MyTrait: for<'a> Fun<Assoc = &'a ()> {}
5+
| ^^^^^^^^^^^^^^
6+
7+
error[E0582]: binding for associated type `Assoc` references lifetime `'a`, which does not appear in the trait input types
8+
--> $DIR/ice-wf-missing-span-in-error-130012.rs:9:28
9+
|
10+
LL | trait MyTrait: for<'a> Fun<Assoc = &'a ()> {}
11+
| ^^^^^^^^^^^^^^
12+
|
13+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14+
15+
error[E0582]: binding for associated type `Assoc` references lifetime `'a`, which does not appear in the trait input types
16+
--> $DIR/ice-wf-missing-span-in-error-130012.rs:9:28
17+
|
18+
LL | trait MyTrait: for<'a> Fun<Assoc = &'a ()> {}
19+
| ^^^^^^^^^^^^^^
20+
|
21+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
22+
23+
error[E0582]: binding for associated type `Assoc` references lifetime `'b`, which does not appear in the trait input types
24+
--> $DIR/ice-wf-missing-span-in-error-130012.rs:14:21
25+
|
26+
LL | impl<F: for<'b> Fun<Assoc = &'b ()>> MyTrait for F {}
27+
| ^^^^^^^^^^^^^^
28+
29+
error[E0308]: mismatched types
30+
--> $DIR/ice-wf-missing-span-in-error-130012.rs:14:50
31+
|
32+
LL | impl<F: for<'b> Fun<Assoc = &'b ()>> MyTrait for F {}
33+
| ^ lifetime mismatch
34+
|
35+
= note: expected reference `&()`
36+
found reference `&'b ()`
37+
38+
error: aborting due to 5 previous errors
39+
40+
Some errors have detailed explanations: E0308, E0582.
41+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)