Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Suggest various missing trait bounds on HostEffect clauses not bein…
…g satisfied
  • Loading branch information
oli-obk committed Apr 28, 2026
commit 61e876fe760a983a3d172e812ec1be1b60453cd4
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use rustc_middle::traits::select::OverflowError;
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::print::{
PrintPolyTraitPredicateExt, PrintTraitPredicateExt as _, PrintTraitRefExt as _,
with_forced_trimmed_paths,
PrintPolyTraitPredicateExt, PrintPolyTraitRefExt as _, PrintTraitPredicateExt as _,
PrintTraitRefExt as _, with_forced_trimmed_paths,
};
use rustc_middle::ty::{
self, GenericArgKind, TraitRef, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
Expand Down Expand Up @@ -886,6 +886,23 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
);
}
}
} else if let ty::Param(param) = trait_ref.self_ty().skip_binder().kind()
&& let Some(generics) =
self.tcx.hir_node_by_def_id(main_obligation.cause.body_id).generics()
{
let constraint = ty::print::with_no_trimmed_paths!(format!(
"[const] {}",
trait_ref.map_bound(|tr| tr.trait_ref).print_trait_sugared(),
));
ty::suggest_constraining_type_param(
self.tcx,
generics,
&mut diag,
param.name.as_str(),
&constraint,
Some(trait_ref.def_id()),
None,
);
}
diag
}
Expand Down Expand Up @@ -2708,7 +2725,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
fn predicate_can_apply(
&self,
param_env: ty::ParamEnv<'tcx>,
pred: ty::PolyTraitPredicate<'tcx>,
pred: impl Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>> + TypeFoldable<TyCtxt<'tcx>>,
) -> bool {
struct ParamToVarFolder<'a, 'tcx> {
infcx: &'a InferCtxt<'tcx>,
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/consts/trait_alias.fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ error[E0277]: the trait bound `T: [const] Baz` is not satisfied
|
LL | x.baz();
| ^^^
|
help: consider further restricting type parameter `T` with trait `Baz`
|
LL | const fn foo<T: [const] Foo + [const] Baz>(x: &T) {
| +++++++++++++

error: aborting due to 1 previous error

Expand Down
5 changes: 5 additions & 0 deletions tests/ui/consts/trait_alias.next_fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ error[E0277]: the trait bound `T: [const] Baz` is not satisfied
|
LL | x.baz();
| ^^^
|
help: consider further restricting type parameter `T` with trait `Baz`
|
LL | const fn foo<T: [const] Foo + [const] Baz>(x: &T) {
| +++++++++++++

error: aborting due to 1 previous error

Expand Down
5 changes: 5 additions & 0 deletions tests/ui/traits/const-traits/super-traits-fail-2.yn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ error[E0277]: the trait bound `T: [const] Foo` is not satisfied
|
LL | x.a();
| ^
|
help: consider further restricting type parameter `T` with trait `Foo`
|
LL | const fn foo<T: Bar + [const] Foo>(x: &T) {
| +++++++++++++

error: aborting due to 2 previous errors

Expand Down
5 changes: 5 additions & 0 deletions tests/ui/traits/const-traits/super-traits-fail-2.yy.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ error[E0277]: the trait bound `T: [const] Foo` is not satisfied
|
LL | x.a();
| ^
|
help: consider further restricting type parameter `T` with trait `Foo`
|
LL | const fn foo<T: Bar + [const] Foo>(x: &T) {
| +++++++++++++

error: aborting due to 1 previous error

Expand Down
5 changes: 5 additions & 0 deletions tests/ui/traits/const-traits/super-traits-fail-3.yyn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ error[E0277]: the trait bound `T: [const] Foo` is not satisfied
|
LL | x.a();
| ^
|
help: consider further restricting type parameter `T` with trait `Foo`
|
LL | const fn foo<T: [const] Bar + [const] Foo>(x: &T) {
| +++++++++++++

error: aborting due to 4 previous errors

Expand Down
Loading