Skip to content
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 @@ -282,23 +282,31 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
if self.tcx.is_diagnostic_item(sym::From, trait_def_id)
|| self.tcx.is_diagnostic_item(sym::TryFrom, trait_def_id)
{
let found_ty = leaf_trait_predicate.skip_binder().trait_ref.args.type_at(1);
let ty = main_trait_predicate.skip_binder().self_ty();
if let Some(cast_ty) = self.find_explicit_cast_type(
obligation.param_env,
found_ty,
ty,
) {
let found_ty_str = self.tcx.short_string(found_ty, &mut long_ty_file);
let cast_ty_str = self.tcx.short_string(cast_ty, &mut long_ty_file);
err.help(
format!(
let trait_ref = leaf_trait_predicate.skip_binder().trait_ref;

// Defensive: next-solver may produce fewer args than expected.
if trait_ref.args.len() > 1 {
Comment on lines +287 to +288
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't. There's a more involved underlying bug here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though actually, this whole diagnostics looks somewhat non-sensical. If the DefId of the root goal is From or TryFrom, this doesn't tell you anything about the leaf_trait_predicate. It could be an arbitrary trait goal?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not the next-solver that produces fewer args.
The problem is that obligation, i.e. its trait def just has the fewer args(=1) here and it is ZeroablePrimitive in this case.
I'll look into why we are trying to report a fulfillment error on it.

let found_ty = trait_ref.args.type_at(1);
let ty = main_trait_predicate.skip_binder().self_ty();

if let Some(cast_ty) = self.find_explicit_cast_type(
obligation.param_env,
found_ty,
ty,
) {
let found_ty_str =
self.tcx.short_string(found_ty, &mut long_ty_file);
let cast_ty_str =
self.tcx.short_string(cast_ty, &mut long_ty_file);

err.help(format!(
"consider casting the `{found_ty_str}` value to `{cast_ty_str}`",
),
);
));
}
}
}


*err.long_ty_path() = long_ty_file;

let mut suggested = false;
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/traits/next-solver-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@compile-flags: -Znext-solver=globally
//@check-fail

fn check<T: Iterator>() {
<f32 as From<<T as Iterator>::Item>>::from;
//~^ ERROR the trait bound `f32: From<<T as Iterator>::Item>` is not satisfied
}

fn main() {}
21 changes: 21 additions & 0 deletions tests/ui/traits/next-solver-ice.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0277]: the trait bound `f32: From<<T as Iterator>::Item>` is not satisfied
--> $DIR/next-solver-ice.rs:5:6
|
LL | <f32 as From<<T as Iterator>::Item>>::from;
| ^^^ the nightly-only, unstable trait `ZeroablePrimitive` is not implemented for `f32`
|
= help: the following other types implement trait `ZeroablePrimitive`:
i128
i16
i32
i64
i8
isize
u128
u16
and 4 others
= note: required for `f32` to implement `From<<T as Iterator>::Item>`

error: aborting due to 1 previous error

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