Skip to content

Commit

Permalink
Unrolled build for rust-lang#117570
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#117570 - bvanjoi:fix-117547, r=cjgillot

fallback for `construct_generic_bound_failure`

Fixes rust-lang#117547

This case regressed at rust-lang#115882.

In this context, `generic_param_scope` is produced by `RPITVisitor` and not included by `hir_owner`. Therefore, I've added a fallback to address this.
  • Loading branch information
rust-timer committed Nov 4, 2023
2 parents a42d94e + a4768fe commit 541d676
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
20 changes: 12 additions & 8 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2444,18 +2444,22 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let suggestion =
if has_lifetimes { format!(" + {lt_name}") } else { format!(": {lt_name}") };
suggs.push((sp, suggestion))
} else {
let generics = self.tcx.hir().get_generics(suggestion_scope).unwrap();
} else if let Some(generics) = self.tcx.hir().get_generics(suggestion_scope) {
let pred = format!("{bound_kind}: {lt_name}");
let suggestion = format!("{} {}", generics.add_where_or_trailing_comma(), pred,);
let suggestion = format!("{} {}", generics.add_where_or_trailing_comma(), pred);
suggs.push((generics.tail_span_for_predicate_suggestion(), suggestion))
} else {
let consider = format!("{msg} `{bound_kind}: {sub}`...");
err.help(consider);
}

err.multipart_suggestion_verbose(
format!("{msg}"),
suggs,
Applicability::MaybeIncorrect, // Issue #41966
);
if !suggs.is_empty() {
err.multipart_suggestion_verbose(
format!("{msg}"),
suggs,
Applicability::MaybeIncorrect, // Issue #41966
);
}
}

err
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/impl-trait/in-trait/async-and-ret-ref.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// edition:2021
// https://github.com/rust-lang/rust/issues/117547

trait T {}

trait MyTrait {
async fn foo() -> &'static impl T;
//~^ ERROR the associated type `<Self as MyTrait>::{opaque#0}` may not live long enough
}

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0310]: the associated type `<Self as MyTrait>::{opaque#0}` may not live long enough
--> $DIR/async-and-ret-ref.rs:7:5
|
LL | async fn foo() -> &'static impl T;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| the associated type `<Self as MyTrait>::{opaque#0}` must be valid for the static lifetime...
| ...so that the reference type `&'static impl T` does not outlive the data it points at
|
= help: consider adding an explicit lifetime bound `<Self as MyTrait>::{opaque#0}: 'static`...

error: aborting due to previous error

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

0 comments on commit 541d676

Please sign in to comment.