Skip to content

Commit 5ed75a9

Browse files
Rollup merge of #112868 - compiler-errors:liberate-afit-sugg, r=WaffleLapkin
Liberate bound vars properly when suggesting missing async-fn-in-trait Fixes #112848
2 parents a5561eb + 7563909 commit 5ed75a9

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

compiler/rustc_hir_analysis/src/check/mod.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -470,19 +470,16 @@ fn suggestion_signature<'tcx>(
470470
);
471471

472472
match assoc.kind {
473-
ty::AssocKind::Fn => {
474-
// We skip the binder here because the binder would deanonymize all
475-
// late-bound regions, and we don't want method signatures to show up
476-
// `as for<'r> fn(&'r MyType)`. Pretty-printing handles late-bound
477-
// regions just fine, showing `fn(&MyType)`.
478-
fn_sig_suggestion(
479-
tcx,
480-
tcx.fn_sig(assoc.def_id).subst(tcx, substs).skip_binder(),
481-
assoc.ident(tcx),
482-
tcx.predicates_of(assoc.def_id).instantiate_own(tcx, substs),
483-
assoc,
484-
)
485-
}
473+
ty::AssocKind::Fn => fn_sig_suggestion(
474+
tcx,
475+
tcx.liberate_late_bound_regions(
476+
assoc.def_id,
477+
tcx.fn_sig(assoc.def_id).subst(tcx, substs),
478+
),
479+
assoc.ident(tcx),
480+
tcx.predicates_of(assoc.def_id).instantiate_own(tcx, substs),
481+
assoc,
482+
),
486483
ty::AssocKind::Type => {
487484
let (generics, where_clauses) = bounds_from_generic_predicates(
488485
tcx,

tests/ui/impl-trait/in-trait/suggest-missing-item.fixed

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ trait Trait {
99
async fn bar() -> i32;
1010

1111
fn test(&self) -> impl Sized + '_;
12+
13+
async fn baz(&self) -> &i32;
1214
}
1315

1416
struct S;
1517

16-
impl Trait for S {fn test(&self) -> impl Sized + '_ { todo!() }
18+
impl Trait for S {async fn baz(&self) -> &i32 { todo!() }
19+
fn test(&self) -> impl Sized + '_ { todo!() }
1720
async fn bar() -> i32 { todo!() }
1821
async fn foo() { todo!() }
1922
}

tests/ui/impl-trait/in-trait/suggest-missing-item.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ trait Trait {
99
async fn bar() -> i32;
1010

1111
fn test(&self) -> impl Sized + '_;
12+
13+
async fn baz(&self) -> &i32;
1214
}
1315

1416
struct S;

tests/ui/impl-trait/in-trait/suggest-missing-item.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
error[E0046]: not all trait items implemented, missing: `foo`, `bar`, `test`
2-
--> $DIR/suggest-missing-item.rs:16:1
1+
error[E0046]: not all trait items implemented, missing: `foo`, `bar`, `test`, `baz`
2+
--> $DIR/suggest-missing-item.rs:18:1
33
|
44
LL | async fn foo();
55
| --------------- `foo` from trait
@@ -9,9 +9,12 @@ LL | async fn bar() -> i32;
99
LL |
1010
LL | fn test(&self) -> impl Sized + '_;
1111
| ---------------------------------- `test` from trait
12+
LL |
13+
LL | async fn baz(&self) -> &i32;
14+
| ---------------------------- `baz` from trait
1215
...
1316
LL | impl Trait for S {}
14-
| ^^^^^^^^^^^^^^^^ missing `foo`, `bar`, `test` in implementation
17+
| ^^^^^^^^^^^^^^^^ missing `foo`, `bar`, `test`, `baz` in implementation
1518

1619
error: aborting due to previous error
1720

0 commit comments

Comments
 (0)