Skip to content

Commit 3c0c140

Browse files
authored
Rollup merge of #96679 - ricked-twice:issue-96223-fix, r=jackh726
Quick fix for #96223. This PR is a quick fix regarding #96223. As mentioned in the issue, others modification could be added to not elide types with bound vars from suggestions. Special thanks to `@jackh726` for mentoring and `@Manishearth` for minimal test case. r? `@jackh726`
2 parents b47fb3b + 574bee3 commit 3c0c140

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
866866
return false;
867867
}
868868

869-
let orig_ty = old_pred.self_ty().skip_binder();
869+
// This is a quick fix to resolve an ICE (#96223).
870+
// This change should probably be deeper.
871+
// As suggested by @jackh726, `mk_trait_obligation_with_new_self_ty` could take a `Binder<(TraitRef, Ty)>
872+
// instead of `Binder<Ty>` leading to some changes to its call places.
873+
let Some(orig_ty) = old_pred.self_ty().no_bound_vars() else {
874+
return false;
875+
};
870876
let mk_result = |new_ty| {
871877
let obligation =
872878
self.mk_trait_obligation_with_new_self_ty(param_env, old_pred, new_ty);
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Previously ICEd because we didn't properly track binders in suggestions
2+
// check-fail
3+
4+
pub trait Foo<'de>: Sized {}
5+
6+
pub trait Bar<'a>: 'static {
7+
type Inner: 'a;
8+
}
9+
10+
pub trait Fubar {
11+
type Bar: for<'a> Bar<'a>;
12+
}
13+
14+
pub struct Baz<T>(pub T);
15+
16+
impl<'de, T> Foo<'de> for Baz<T> where T: Foo<'de> {}
17+
18+
struct Empty;
19+
20+
impl<M> Dummy<M> for Empty
21+
where
22+
M: Fubar,
23+
for<'de> Baz<<M::Bar as Bar<'de>>::Inner>: Foo<'de>,
24+
{
25+
}
26+
27+
pub trait Dummy<M>
28+
where
29+
M: Fubar,
30+
{
31+
}
32+
33+
pub struct EmptyBis<'a>(&'a [u8]);
34+
35+
impl<'a> Bar<'a> for EmptyBis<'static> {
36+
type Inner = EmptyBis<'a>;
37+
}
38+
39+
pub struct EmptyMarker;
40+
41+
impl Fubar for EmptyMarker {
42+
type Bar = EmptyBis<'static>;
43+
}
44+
45+
fn icey_bounds<D: Dummy<EmptyMarker>>(p: &D) {}
46+
47+
fn trigger_ice() {
48+
let p = Empty;
49+
icey_bounds(&p); //~ERROR the trait bound
50+
}
51+
52+
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:49: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:16: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:20: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:45: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)