Skip to content

Don't suggest constraining unstable associated types #137635

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

Merged
merged 1 commit into from
Feb 26, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>(
) {
if hir_generics.where_clause_span.from_expansion()
|| hir_generics.where_clause_span.desugaring_kind().is_some()
|| projection.is_some_and(|projection| tcx.is_impl_trait_in_trait(projection.def_id))
|| projection.is_some_and(|projection| {
tcx.is_impl_trait_in_trait(projection.def_id)
|| tcx.lookup_stability(projection.def_id).is_some_and(|stab| stab.is_unstable())
})
{
return;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/async-await/async-fn/suggest-constrain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Ensure that we don't suggest constraining `CallRefFuture` here,
// since that isn't stable.

fn spawn<F: AsyncFn() + Send>(f: F) {
check_send(f());
//~^ ERROR cannot be sent between threads safely
}

fn check_send<T: Send>(_: T) {}

fn main() {}
18 changes: 18 additions & 0 deletions tests/ui/async-await/async-fn/suggest-constrain.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0277]: `<F as AsyncFnMut<()>>::CallRefFuture<'_>` cannot be sent between threads safely
--> $DIR/suggest-constrain.rs:5:16
|
LL | check_send(f());
| ---------- ^^^ `<F as AsyncFnMut<()>>::CallRefFuture<'_>` cannot be sent between threads safely
| |
| required by a bound introduced by this call
|
= help: the trait `Send` is not implemented for `<F as AsyncFnMut<()>>::CallRefFuture<'_>`
note: required by a bound in `check_send`
--> $DIR/suggest-constrain.rs:9:18
|
LL | fn check_send<T: Send>(_: T) {}
| ^^^^ required by this bound in `check_send`

error: aborting due to 1 previous error

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