Skip to content

Commit c6bdec4

Browse files
committed
fallback for construct_generic_bound_failure
1 parent 2db26d3 commit c6bdec4

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -2444,18 +2444,22 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
24442444
let suggestion =
24452445
if has_lifetimes { format!(" + {lt_name}") } else { format!(": {lt_name}") };
24462446
suggs.push((sp, suggestion))
2447-
} else {
2448-
let generics = self.tcx.hir().get_generics(suggestion_scope).unwrap();
2447+
} else if let Some(generics) = self.tcx.hir().get_generics(suggestion_scope) {
24492448
let pred = format!("{bound_kind}: {lt_name}");
2450-
let suggestion = format!("{} {}", generics.add_where_or_trailing_comma(), pred,);
2449+
let suggestion = format!("{} {}", generics.add_where_or_trailing_comma(), pred);
24512450
suggs.push((generics.tail_span_for_predicate_suggestion(), suggestion))
2451+
} else {
2452+
let consider = format!("{msg} `{bound_kind}: {sub}`...");
2453+
err.help(consider);
24522454
}
24532455

2454-
err.multipart_suggestion_verbose(
2455-
format!("{msg}"),
2456-
suggs,
2457-
Applicability::MaybeIncorrect, // Issue #41966
2458-
);
2456+
if !suggs.is_empty() {
2457+
err.multipart_suggestion_verbose(
2458+
format!("{msg}"),
2459+
suggs,
2460+
Applicability::MaybeIncorrect, // Issue #41966
2461+
);
2462+
}
24592463
}
24602464

24612465
err

tests/ui/impl-trait/issue-117547.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// edition:2021
2+
3+
trait T {}
4+
5+
trait MyTrait {
6+
async fn foo() -> &'static impl T;
7+
//~^ ERROR the associated type `<Self as MyTrait>::{opaque#0}` may not live long enough
8+
}
9+
10+
fn main() {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0310]: the associated type `<Self as MyTrait>::{opaque#0}` may not live long enough
2+
--> $DIR/issue-117547.rs:6:5
3+
|
4+
LL | async fn foo() -> &'static impl T;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| the associated type `<Self as MyTrait>::{opaque#0}` must be valid for the static lifetime...
8+
| ...so that the reference type `&'static impl T` does not outlive the data it points at
9+
|
10+
= help: consider adding an explicit lifetime bound `<Self as MyTrait>::{opaque#0}: 'static`...
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0310`.

0 commit comments

Comments
 (0)