Skip to content

Commit a6d38a1

Browse files
authored
Rollup merge of #135083 - compiler-errors:invalid-predicate-source, r=camelid
Do not ICE when encountering predicates from other items in method error reporting See the comments I left in the code and the test file. Fixes #124350
2 parents 9e24b6b + e4193e2 commit a6d38a1

File tree

3 files changed

+79
-3
lines changed

3 files changed

+79
-3
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10961096
)
10971097
) {
10981098
continue;
1099-
};
1099+
}
11001100

11011101
match self.tcx.hir().get_if_local(item_def_id) {
11021102
// Unmet obligation comes from a `derive` macro, point at it once to
@@ -1210,8 +1210,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12101210
entry.1.insert((cause_span, "unsatisfied trait bound introduced here"));
12111211
entry.2.push(p);
12121212
}
1213-
Some(node) => unreachable!("encountered `{node:?}` due to `{cause:#?}`"),
1214-
None => (),
1213+
_ => {
1214+
// It's possible to use well-formedness clauses to get obligations
1215+
// which point arbitrary items like ADTs, so there's no use in ICEing
1216+
// here if we find that the obligation originates from some other
1217+
// node that we don't handle.
1218+
}
12151219
}
12161220
}
12171221
let mut spanned_predicates: Vec<_> = spanned_predicates.into_iter().collect();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
trait Wf {
2+
type Assoc;
3+
}
4+
5+
struct Wrapper<T: Wf<Assoc = U>, U>(T);
6+
7+
trait Trait {
8+
fn needs_sized(self);
9+
}
10+
11+
fn test<T>(t: T) {
12+
Wrapper(t).needs_sized();
13+
//~^ ERROR the trait bound `T: Wf` is not satisfied
14+
//~| ERROR the trait bound `T: Wf` is not satisfied
15+
//~| the method `needs_sized` exists for struct `Wrapper<T, _>`, but its trait bounds were not satisfied
16+
}
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error[E0277]: the trait bound `T: Wf` is not satisfied
2+
--> $DIR/bad-wf-when-selecting-method.rs:12:13
3+
|
4+
LL | Wrapper(t).needs_sized();
5+
| ------- ^ the trait `Wf` is not implemented for `T`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
note: required by a bound in `Wrapper`
10+
--> $DIR/bad-wf-when-selecting-method.rs:5:19
11+
|
12+
LL | struct Wrapper<T: Wf<Assoc = U>, U>(T);
13+
| ^^^^^^^^^^^^^ required by this bound in `Wrapper`
14+
help: consider restricting type parameter `T` with trait `Wf`
15+
|
16+
LL | fn test<T: Wf>(t: T) {
17+
| ++++
18+
19+
error[E0277]: the trait bound `T: Wf` is not satisfied
20+
--> $DIR/bad-wf-when-selecting-method.rs:12:5
21+
|
22+
LL | Wrapper(t).needs_sized();
23+
| ^^^^^^^^^^ the trait `Wf` is not implemented for `T`
24+
|
25+
note: required by a bound in `Wrapper`
26+
--> $DIR/bad-wf-when-selecting-method.rs:5:19
27+
|
28+
LL | struct Wrapper<T: Wf<Assoc = U>, U>(T);
29+
| ^^^^^^^^^^^^^ required by this bound in `Wrapper`
30+
help: consider restricting type parameter `T` with trait `Wf`
31+
|
32+
LL | fn test<T: Wf>(t: T) {
33+
| ++++
34+
35+
error[E0599]: the method `needs_sized` exists for struct `Wrapper<T, _>`, but its trait bounds were not satisfied
36+
--> $DIR/bad-wf-when-selecting-method.rs:12:16
37+
|
38+
LL | struct Wrapper<T: Wf<Assoc = U>, U>(T);
39+
| ----------------------------------- method `needs_sized` not found for this struct
40+
...
41+
LL | Wrapper(t).needs_sized();
42+
| ^^^^^^^^^^^ method cannot be called on `Wrapper<T, _>` due to unsatisfied trait bounds
43+
|
44+
= note: the following trait bounds were not satisfied:
45+
`T: Wf`
46+
help: consider restricting the type parameter to satisfy the trait bound
47+
|
48+
LL | fn test<T>(t: T) where T: Wf {
49+
| +++++++++++
50+
51+
error: aborting due to 3 previous errors
52+
53+
Some errors have detailed explanations: E0277, E0599.
54+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)