Skip to content

Commit 6c30dd3

Browse files
ricked-twiceMabezDev
authored andcommitted
Quick fix for rust-lang#96223.
1 parent e097602 commit 6c30dd3

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
713713
return false;
714714
}
715715

716-
let orig_ty = old_pred.self_ty().skip_binder();
716+
// This is a quick fix to resolve an ICE ([issue#96223](https://github.com/rust-lang/rust/issues/96223)).
717+
// This change should probably be deeper.
718+
// As suggested by @jackh726, `mk_trait_obligation_with_new_self_ty` could take a `Binder<(TraitRef, Ty)>
719+
// instead of `Binder<Ty>` leading to some changes to its call places.
720+
let Some(orig_ty) = old_pred.self_ty().no_bound_vars() else {
721+
return false;
722+
};
717723
let mk_result = |new_ty| {
718724
let obligation =
719725
self.mk_trait_obligation_with_new_self_ty(param_env, old_pred, new_ty);
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Test case for #96223.
2+
// An ICE was triggered because of a failed assertion.
3+
// Thanks to @Manishearth for the minimal test case.
4+
5+
pub trait Foo<'de>: Sized {}
6+
7+
pub trait Bar<'a>: 'static {
8+
type Inner: 'a;
9+
}
10+
11+
pub trait Fubar {
12+
type Bar: for<'a> Bar<'a>;
13+
}
14+
15+
pub struct Baz<T>(pub T);
16+
17+
impl<'de, T> Foo<'de> for Baz<T> where T: Foo<'de> {}
18+
19+
struct Empty;
20+
21+
impl<M> Dummy<M> for Empty
22+
where
23+
M: Fubar,
24+
for<'de> Baz<<M::Bar as Bar<'de>>::Inner>: Foo<'de>,
25+
{
26+
}
27+
28+
pub trait Dummy<M>
29+
where
30+
M: Fubar,
31+
{
32+
}
33+
34+
pub struct EmptyBis<'a>(&'a [u8]);
35+
36+
impl<'a> Bar<'a> for EmptyBis<'static> {
37+
type Inner = EmptyBis<'a>;
38+
}
39+
40+
pub struct EmptyMarker;
41+
42+
impl Fubar for EmptyMarker {
43+
type Bar = EmptyBis<'static>;
44+
}
45+
46+
fn icey_bounds<D: Dummy<EmptyMarker>>(p: &D) {}
47+
48+
fn trigger_ice() {
49+
let p = Empty;
50+
icey_bounds(&p); //~ERROR
51+
}
52+
53+
fn main() {}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error[E0277]: the trait bound `for<'de> EmptyBis<'de>: Foo<'_>` is not satisfied
2+
--> $DIR/issue-96223.rs:50:17
3+
|
4+
LL | icey_bounds(&p);
5+
| ----------- ^^ the trait `for<'de> Foo<'_>` is not implemented for `EmptyBis<'de>`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= help: the trait `Foo<'de>` is implemented for `Baz<T>`
10+
note: required because of the requirements on the impl of `for<'de> Foo<'de>` for `Baz<EmptyBis<'de>>`
11+
--> $DIR/issue-96223.rs:17:14
12+
|
13+
LL | impl<'de, T> Foo<'de> for Baz<T> where T: Foo<'de> {}
14+
| ^^^^^^^^ ^^^^^^
15+
note: required because of the requirements on the impl of `Dummy<EmptyMarker>` for `Empty`
16+
--> $DIR/issue-96223.rs:21:9
17+
|
18+
LL | impl<M> Dummy<M> for Empty
19+
| ^^^^^^^^ ^^^^^
20+
note: required by a bound in `icey_bounds`
21+
--> $DIR/issue-96223.rs:46:19
22+
|
23+
LL | fn icey_bounds<D: Dummy<EmptyMarker>>(p: &D) {}
24+
| ^^^^^^^^^^^^^^^^^^ required by this bound in `icey_bounds`
25+
26+
error: aborting due to previous error
27+
28+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)