Skip to content

Commit cafa457

Browse files
uwu
1 parent cd90d5c commit cafa457

File tree

10 files changed

+111
-116
lines changed

10 files changed

+111
-116
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
13981398
self.tcx.predicates_of(impl_def_id).instantiate(self.tcx, impl_args);
13991399
let impl_bounds = ocx.normalize(cause, self.param_env, impl_bounds);
14001400
// Convert the bounds into obligations.
1401-
ocx.register_obligations(traits::predicates_for_generics(
1401+
let predicates: Vec<_> = traits::predicates_for_generics(
14021402
|idx, span| {
14031403
let code = if span.is_dummy() {
14041404
traits::ExprItemObligation(impl_def_id, self.scope_expr_id, idx)
@@ -1414,7 +1414,21 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14141414
},
14151415
self.param_env,
14161416
impl_bounds,
1417-
));
1417+
)
1418+
.collect();
1419+
if let Some(obligation) = predicates.iter().find(|obligation| {
1420+
!self.infcx.next_trait_solver()
1421+
&& !self.infcx.predicate_may_hold(&obligation)
1422+
}) {
1423+
result = ProbeResult::NoMatch;
1424+
possibly_unsatisfied_predicates.push((
1425+
self.resolve_vars_if_possible(obligation.predicate),
1426+
None,
1427+
Some(obligation.cause.clone()),
1428+
));
1429+
} else {
1430+
ocx.register_obligations(predicates);
1431+
}
14181432
}
14191433
TraitCandidate(poly_trait_ref) => {
14201434
// Some trait methods are excluded for arrays before 2021.
@@ -1507,22 +1521,25 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15071521
}
15081522

15091523
// Evaluate those obligations to see if they might possibly hold.
1510-
for error in ocx.select_where_possible() {
1511-
result = ProbeResult::NoMatch;
1512-
let nested_predicate = self.resolve_vars_if_possible(error.obligation.predicate);
1513-
if let Some(trait_predicate) = trait_predicate
1514-
&& nested_predicate == self.resolve_vars_if_possible(trait_predicate)
1515-
{
1516-
// Don't report possibly unsatisfied predicates if the root
1517-
// trait obligation from a `TraitCandidate` is unsatisfied.
1518-
// That just means the candidate doesn't hold.
1519-
} else {
1520-
possibly_unsatisfied_predicates.push((
1521-
nested_predicate,
1522-
Some(self.resolve_vars_if_possible(error.root_obligation.predicate))
1523-
.filter(|root_predicate| *root_predicate != nested_predicate),
1524-
Some(error.obligation.cause),
1525-
));
1524+
if let ProbeResult::Match = result {
1525+
for error in ocx.select_where_possible() {
1526+
result = ProbeResult::NoMatch;
1527+
let nested_predicate =
1528+
self.resolve_vars_if_possible(error.obligation.predicate);
1529+
if let Some(trait_predicate) = trait_predicate
1530+
&& nested_predicate == self.resolve_vars_if_possible(trait_predicate)
1531+
{
1532+
// Don't report possibly unsatisfied predicates if the root
1533+
// trait obligation from a `TraitCandidate` is unsatisfied.
1534+
// That just means the candidate doesn't hold.
1535+
} else {
1536+
possibly_unsatisfied_predicates.push((
1537+
nested_predicate,
1538+
Some(self.resolve_vars_if_possible(error.root_obligation.predicate))
1539+
.filter(|root_predicate| *root_predicate != nested_predicate),
1540+
Some(error.obligation.cause),
1541+
));
1542+
}
15261543
}
15271544
}
15281545

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
1+
error[E0599]: the function or associated item `new` exists for struct `Inline<dyn Debug>`, but its trait bounds were not satisfied
2+
--> $DIR/issue-80742.rs:36:36
3+
|
4+
LL | struct Inline<T>
5+
| ---------------- function or associated item `new` not found for this struct
6+
...
7+
LL | let dst = Inline::<dyn Debug>::new(0);
8+
| ^^^ function or associated item cannot be called on `Inline<dyn Debug>` due to unsatisfied trait bounds
9+
|
10+
note: if you're trying to build a new `Inline<dyn Debug>`, consider using `Inline::<T>::new` which returns `Inline<_>`
11+
--> $DIR/issue-80742.rs:30:5
12+
|
13+
LL | pub fn new(val: T) -> Inline<T> {
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
note: trait bound `dyn Debug: Sized` was not satisfied
16+
--> $DIR/issue-80742.rs:26:6
17+
|
18+
LL | impl<T> Inline<T>
19+
| ^ ---------
20+
| |
21+
| unsatisfied trait bound introduced here
22+
help: consider relaxing the type parameter's implicit `Sized` bound
23+
|
24+
LL | impl<T: ?Sized> Inline<T>
25+
| ++++++++
26+
127
error: internal compiler error: compiler/rustc_const_eval/src/interpret/step.rs:LL:CC: SizeOf MIR operator called for unsized type dyn Debug
228
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
329

430
Box<dyn Any>
531
query stack during panic:
6-
#0 [eval_to_allocation_raw] const-evaluating + checking `<impl at $DIR/issue-80742.rs:26:1: 28:32>::{constant#0}`
32+
#0 [eval_to_allocation_raw] const-evaluating + checking `Inline::{constant#0}`
733
#1 [eval_to_valtree] evaluating type-level constant
834
end of query stack
9-
error: aborting due to 1 previous error
35+
error: aborting due to 2 previous errors
1036

37+
For more information about this error, try `rustc --explain E0599`.

tests/ui/derives/issue-91550.stderr

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ error[E0599]: the method `insert` exists for struct `HashSet<Value>`, but its tr
22
--> $DIR/issue-91550.rs:8:8
33
|
44
LL | struct Value(u32);
5-
| ------------ doesn't satisfy `Value: Eq` or `Value: Hash`
5+
| ------------ doesn't satisfy `Value: Eq`
66
...
77
LL | hs.insert(Value(0));
88
| ^^^^^^
99
|
1010
= note: the following trait bounds were not satisfied:
1111
`Value: Eq`
12-
`Value: Hash`
13-
help: consider annotating `Value` with `#[derive(Eq, Hash, PartialEq)]`
12+
help: consider annotating `Value` with `#[derive(Eq, PartialEq)]`
1413
|
15-
LL + #[derive(Eq, Hash, PartialEq)]
14+
LL + #[derive(Eq, PartialEq)]
1615
LL | struct Value(u32);
1716
|
1817

@@ -70,23 +69,20 @@ error[E0599]: the method `use_ord_and_partial_ord` exists for struct `Object<NoD
7069
--> $DIR/issue-91550.rs:28:9
7170
|
7271
LL | pub struct NoDerives;
73-
| -------------------- doesn't satisfy `NoDerives: Ord` or `NoDerives: PartialOrd`
72+
| -------------------- doesn't satisfy `NoDerives: Ord`
7473
LL |
7574
LL | struct Object<T>(T);
7675
| ---------------- method `use_ord_and_partial_ord` not found for this struct
7776
...
7877
LL | foo.use_ord_and_partial_ord();
7978
| ^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `Object<NoDerives>` due to unsatisfied trait bounds
8079
|
81-
note: the following trait bounds were not satisfied:
82-
`NoDerives: Ord`
83-
`NoDerives: PartialOrd`
80+
note: trait bound `NoDerives: Ord` was not satisfied
8481
--> $DIR/issue-91550.rs:21:9
8582
|
8683
LL | impl<T: Ord + PartialOrd> Object<T> {
87-
| ^^^ ^^^^^^^^^^ ---------
88-
| | |
89-
| | unsatisfied trait bound introduced here
84+
| ^^^ ---------
85+
| |
9086
| unsatisfied trait bound introduced here
9187
help: consider annotating `NoDerives` with `#[derive(Eq, Ord, PartialEq, PartialOrd)]`
9288
|

tests/ui/methods/method-not-found-generic-arg-elision.stderr

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,12 @@ LL | struct Struct<T> {
8888
LL | s.method();
8989
| ^^^^^^ method cannot be called on `Struct<f64>` due to unsatisfied trait bounds
9090
|
91-
note: the following trait bounds were not satisfied:
92-
`f64: Eq`
93-
`f64: Ord`
91+
note: trait bound `f64: Eq` was not satisfied
9492
--> $DIR/method-not-found-generic-arg-elision.rs:74:36
9593
|
9694
LL | impl<T: Clone + Copy + PartialEq + Eq + PartialOrd + Ord> Struct<T> {
97-
| ^^ ^^^ ---------
98-
| | |
99-
| | unsatisfied trait bound introduced here
95+
| ^^ ---------
96+
| |
10097
| unsatisfied trait bound introduced here
10198

10299
error: aborting due to 9 previous errors

tests/ui/missing-trait-bounds/issue-35677.fixed

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/ui/missing-trait-bounds/issue-35677.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ run-rustfix
21
#![allow(dead_code)]
32
use std::collections::HashSet;
43
use std::hash::Hash;

tests/ui/missing-trait-bounds/issue-35677.stderr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
error[E0599]: the method `is_subset` exists for reference `&HashSet<T>`, but its trait bounds were not satisfied
2-
--> $DIR/issue-35677.rs:7:10
2+
--> $DIR/issue-35677.rs:6:10
33
|
44
LL | this.is_subset(other)
55
| ^^^^^^^^^ method cannot be called on `&HashSet<T>` due to unsatisfied trait bounds
66
|
77
= note: the following trait bounds were not satisfied:
88
`T: Eq`
9-
`T: Hash`
10-
help: consider restricting the type parameters to satisfy the trait bounds
9+
help: consider restricting the type parameter to satisfy the trait bound
1110
|
12-
LL | fn is_subset<T>(this: &HashSet<T>, other: &HashSet<T>) -> bool where T: Eq, T: Hash {
13-
| ++++++++++++++++++++
11+
LL | fn is_subset<T>(this: &HashSet<T>, other: &HashSet<T>) -> bool where T: Eq {
12+
| +++++++++++
1413

1514
error: aborting due to 1 previous error
1615

tests/ui/suggestions/derive-trait-for-method-call.stderr

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,21 @@ error[E0599]: the method `test` exists for struct `Foo<Enum, CloneEnum>`, but it
22
--> $DIR/derive-trait-for-method-call.rs:28:15
33
|
44
LL | enum Enum {
5-
| --------- doesn't satisfy `Enum: Clone` or `Enum: Default`
6-
...
7-
LL | enum CloneEnum {
8-
| -------------- doesn't satisfy `CloneEnum: Default`
5+
| --------- doesn't satisfy `Enum: Clone`
96
...
107
LL | struct Foo<X, Y> (X, Y);
118
| ---------------- method `test` not found for this struct
129
...
1310
LL | let y = x.test();
1411
| ^^^^ method cannot be called on `Foo<Enum, CloneEnum>` due to unsatisfied trait bounds
1512
|
16-
note: the following trait bounds were not satisfied:
17-
`CloneEnum: Default`
18-
`Enum: Clone`
19-
`Enum: Default`
13+
note: trait bound `Enum: Clone` was not satisfied
2014
--> $DIR/derive-trait-for-method-call.rs:20:9
2115
|
2216
LL | impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> {
23-
| ^^^^^ ^^^^^^^ ^^^^^^^ ---------
24-
| | | |
25-
| | | unsatisfied trait bound introduced here
26-
| | unsatisfied trait bound introduced here
17+
| ^^^^^ ---------
18+
| |
2719
| unsatisfied trait bound introduced here
28-
note: the trait `Default` must be implemented
29-
--> $SRC_DIR/core/src/default.rs:LL:COL
3020
help: consider annotating `Enum` with `#[derive(Clone)]`
3121
|
3222
LL + #[derive(Clone)]
@@ -37,67 +27,43 @@ error[E0599]: the method `test` exists for struct `Foo<Struct, CloneStruct>`, bu
3727
--> $DIR/derive-trait-for-method-call.rs:34:15
3828
|
3929
LL | struct Struct {
40-
| ------------- doesn't satisfy `Struct: Clone` or `Struct: Default`
41-
...
42-
LL | struct CloneStruct {
43-
| ------------------ doesn't satisfy `CloneStruct: Default`
30+
| ------------- doesn't satisfy `Struct: Clone`
4431
...
4532
LL | struct Foo<X, Y> (X, Y);
4633
| ---------------- method `test` not found for this struct
4734
...
4835
LL | let y = x.test();
4936
| ^^^^ method cannot be called on `Foo<Struct, CloneStruct>` due to unsatisfied trait bounds
5037
|
51-
note: the following trait bounds were not satisfied:
52-
`CloneStruct: Default`
53-
`Struct: Clone`
54-
`Struct: Default`
38+
note: trait bound `Struct: Clone` was not satisfied
5539
--> $DIR/derive-trait-for-method-call.rs:20:9
5640
|
5741
LL | impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> {
58-
| ^^^^^ ^^^^^^^ ^^^^^^^ ---------
59-
| | | |
60-
| | | unsatisfied trait bound introduced here
61-
| | unsatisfied trait bound introduced here
42+
| ^^^^^ ---------
43+
| |
6244
| unsatisfied trait bound introduced here
63-
help: consider annotating `CloneStruct` with `#[derive(Default)]`
64-
|
65-
LL + #[derive(Default)]
66-
LL | struct CloneStruct {
45+
help: consider annotating `Struct` with `#[derive(Clone)]`
6746
|
68-
help: consider annotating `Struct` with `#[derive(Clone, Default)]`
69-
|
70-
LL + #[derive(Clone, Default)]
47+
LL + #[derive(Clone)]
7148
LL | struct Struct {
7249
|
7350

7451
error[E0599]: the method `test` exists for struct `Foo<Vec<Enum>, Instant>`, but its trait bounds were not satisfied
7552
--> $DIR/derive-trait-for-method-call.rs:40:15
7653
|
77-
LL | enum Enum {
78-
| --------- doesn't satisfy `Enum: Clone`
79-
...
8054
LL | struct Foo<X, Y> (X, Y);
8155
| ---------------- method `test` not found for this struct
8256
...
8357
LL | let y = x.test();
8458
| ^^^^ method cannot be called on `Foo<Vec<Enum>, Instant>` due to unsatisfied trait bounds
8559
|
86-
note: trait bound `Instant: Default` was not satisfied
87-
--> $DIR/derive-trait-for-method-call.rs:20:40
60+
note: trait bound `Vec<Enum>: Clone` was not satisfied
61+
--> $DIR/derive-trait-for-method-call.rs:20:9
8862
|
8963
LL | impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> {
90-
| ^^^^^^^ ---------
91-
| |
92-
| unsatisfied trait bound introduced here
93-
= note: the following trait bounds were not satisfied:
94-
`Enum: Clone`
95-
which is required by `Vec<Enum>: Clone`
96-
help: consider annotating `Enum` with `#[derive(Clone)]`
97-
|
98-
LL + #[derive(Clone)]
99-
LL | enum Enum {
100-
|
64+
| ^^^^^ ---------
65+
| |
66+
| unsatisfied trait bound introduced here
10167

10268
error: aborting due to 3 previous errors
10369

tests/ui/traits/alias/issue-108132-unmet-trait-alias-bound-on-generic-impl.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ LL | struct Foo<I>(I);
77
LL | Foo::<()>::f()
88
| ^ function or associated item cannot be called on `Foo<()>` due to unsatisfied trait bounds
99
|
10-
note: trait bound `(): Iterator` was not satisfied
11-
--> $DIR/issue-108132-unmet-trait-alias-bound-on-generic-impl.rs:5:23
10+
note: trait bound `(): IteratorAlias` was not satisfied
11+
--> $DIR/issue-108132-unmet-trait-alias-bound-on-generic-impl.rs:9:9
1212
|
13-
LL | trait IteratorAlias = Iterator;
14-
| ------------- ^^^^^^^^ unsatisfied trait bound introduced here
13+
LL | impl<I: IteratorAlias> Foo<I> {
14+
| ^^^^^^^^^^^^^ ------
15+
| |
16+
| unsatisfied trait bound introduced here
1517

1618
error: aborting due to 1 previous error
1719

tests/ui/traits/track-obligations.stderr

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@ error[E0599]: the method `check` exists for struct `Client<()>`, but its trait b
44
LL | struct ALayer<C>(C);
55
| ---------------- doesn't satisfy `ALayer<()>: ParticularServiceLayer<()>`
66
...
7-
LL | struct AService;
8-
| --------------- doesn't satisfy `<AService as Service<Req>>::Response = Res`
9-
...
107
LL | struct Client<C>(C);
118
| ---------------- method `check` not found for this struct
129
...
1310
LL | Client(()).check();
1411
| ^^^^^ method cannot be called on `Client<()>` due to unsatisfied trait bounds
1512
|
16-
note: trait bound `<AService as Service<Req>>::Response = Res` was not satisfied
17-
--> $DIR/track-obligations.rs:24:21
13+
note: trait bound `ALayer<()>: ParticularServiceLayer<()>` was not satisfied
14+
--> $DIR/track-obligations.rs:71:16
1815
|
19-
LL | impl<T> ParticularService for T
20-
| ----------------- -
16+
LL | impl<C> Client<C>
17+
| ---------
2118
LL | where
22-
LL | T: Service<Req, Response = Res>,
23-
| ^^^^^^^^^^^^^^ unsatisfied trait bound introduced here
19+
LL | ALayer<C>: ParticularServiceLayer<C>,
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced here
21+
note: the trait `ParticularServiceLayer` must be implemented
22+
--> $DIR/track-obligations.rs:34:1
23+
|
24+
LL | / pub trait ParticularServiceLayer<C>:
25+
LL | | Layer<C, Service = <Self as ParticularServiceLayer<C>>::Service>
26+
| |____________________________________________________________________^
2427

2528
error[E0271]: type mismatch resolving `<AService as Service<Req>>::Response == Res`
2629
--> $DIR/track-obligations.rs:87:11

0 commit comments

Comments
 (0)