Skip to content

Commit

Permalink
Rollup merge of #112868 - compiler-errors:liberate-afit-sugg, r=Waffl…
Browse files Browse the repository at this point in the history
…eLapkin

Liberate bound vars properly when suggesting missing async-fn-in-trait

Fixes #112848
  • Loading branch information
GuillaumeGomez authored Jun 21, 2023
2 parents a5561eb + 7563909 commit 5ed75a9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
23 changes: 10 additions & 13 deletions compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,19 +470,16 @@ fn suggestion_signature<'tcx>(
);

match assoc.kind {
ty::AssocKind::Fn => {
// We skip the binder here because the binder would deanonymize all
// late-bound regions, and we don't want method signatures to show up
// `as for<'r> fn(&'r MyType)`. Pretty-printing handles late-bound
// regions just fine, showing `fn(&MyType)`.
fn_sig_suggestion(
tcx,
tcx.fn_sig(assoc.def_id).subst(tcx, substs).skip_binder(),
assoc.ident(tcx),
tcx.predicates_of(assoc.def_id).instantiate_own(tcx, substs),
assoc,
)
}
ty::AssocKind::Fn => fn_sig_suggestion(
tcx,
tcx.liberate_late_bound_regions(
assoc.def_id,
tcx.fn_sig(assoc.def_id).subst(tcx, substs),
),
assoc.ident(tcx),
tcx.predicates_of(assoc.def_id).instantiate_own(tcx, substs),
assoc,
),
ty::AssocKind::Type => {
let (generics, where_clauses) = bounds_from_generic_predicates(
tcx,
Expand Down
5 changes: 4 additions & 1 deletion tests/ui/impl-trait/in-trait/suggest-missing-item.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ trait Trait {
async fn bar() -> i32;

fn test(&self) -> impl Sized + '_;

async fn baz(&self) -> &i32;
}

struct S;

impl Trait for S {fn test(&self) -> impl Sized + '_ { todo!() }
impl Trait for S {async fn baz(&self) -> &i32 { todo!() }
fn test(&self) -> impl Sized + '_ { todo!() }
async fn bar() -> i32 { todo!() }
async fn foo() { todo!() }
}
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/impl-trait/in-trait/suggest-missing-item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ trait Trait {
async fn bar() -> i32;

fn test(&self) -> impl Sized + '_;

async fn baz(&self) -> &i32;
}

struct S;
Expand Down
9 changes: 6 additions & 3 deletions tests/ui/impl-trait/in-trait/suggest-missing-item.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0046]: not all trait items implemented, missing: `foo`, `bar`, `test`
--> $DIR/suggest-missing-item.rs:16:1
error[E0046]: not all trait items implemented, missing: `foo`, `bar`, `test`, `baz`
--> $DIR/suggest-missing-item.rs:18:1
|
LL | async fn foo();
| --------------- `foo` from trait
Expand All @@ -9,9 +9,12 @@ LL | async fn bar() -> i32;
LL |
LL | fn test(&self) -> impl Sized + '_;
| ---------------------------------- `test` from trait
LL |
LL | async fn baz(&self) -> &i32;
| ---------------------------- `baz` from trait
...
LL | impl Trait for S {}
| ^^^^^^^^^^^^^^^^ missing `foo`, `bar`, `test` in implementation
| ^^^^^^^^^^^^^^^^ missing `foo`, `bar`, `test`, `baz` in implementation

error: aborting due to previous error

Expand Down

0 comments on commit 5ed75a9

Please sign in to comment.