Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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