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
16 changes: 6 additions & 10 deletions compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,16 @@ impl<'tcx> BestObligation<'tcx> {
// We always handle rigid alias candidates separately as we may not add them for
// aliases whose trait bound doesn't hold.
candidates.retain(|c| !matches!(c.kind(), inspect::ProbeKind::RigidAlias { .. }));
// If we have >1 candidate, one may still be due to "boring" reasons, like
// an alias-relate that failed to hold when deeply evaluated. We really
// don't care about reasons like this.
// If there are multiple candidates, we can still recurse into a single one if all
// others fail due to boring reasons. Currently that's if we fail to normalize
// while considering the candidate.
if candidates.len() > 1 {
candidates.retain(|candidate| {
goal.infcx().probe(|_| {
candidate.instantiate_nested_goals(self.span()).iter().any(
!candidate.instantiate_nested_goals(self.span()).iter().any(
|nested_goal| {
matches!(
nested_goal.source(),
GoalSource::ImplWhereBound
| GoalSource::AliasBoundConstCondition
| GoalSource::AliasWellFormed
) && nested_goal.result().is_err()
nested_goal.source() == GoalSource::Normalization
&& nested_goal.result().is_err()
Comment thread
LorrensP-2158466 marked this conversation as resolved.
},
)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//@compile-flags: -Znext-solver=globally
//@check-fail

// See issue https://github.com/rust-lang/rust/issues/161882, test makes sure we don't report
// irrelevant and not implemented bounds when we can't proof an obligation.

struct MyError;

trait MaybeFallible {
type Error: MaybeError; //~ ERROR: the trait bound `MyError: From<<Self as MaybeFallible>::Error>` is not satisfied
}

trait MaybeError: Sized
where
MyError: From<Self>,
{
type ComposeWithOther: MaybeError; //~ ERROR: the trait bound `MyError: From<<Self as MaybeError>::ComposeWithOther>` is not satisfied
}

fn compose<A: MaybeFallible, B>() -> Result<(), ()>
where
<A::Error as MaybeError>::ComposeWithOther: From<B>, //~ ERROR: the trait bound `MyError: From<<A as MaybeFallible>::Error>` is not satisfied
{
todo!()
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
error[E0277]: the trait bound `MyError: From<<A as MaybeFallible>::Error>` is not satisfied
--> $DIR/confusing-diagnostic-due-to-best-obligation-visitor.rs:22:49
|
LL | <A::Error as MaybeError>::ComposeWithOther: From<B>,
| ^^^^^^^ unsatisfied trait bound
|
help: the trait `From<<A as MaybeFallible>::Error>` is not implemented for `MyError`
--> $DIR/confusing-diagnostic-due-to-best-obligation-visitor.rs:7:1
|
LL | struct MyError;
| ^^^^^^^^^^^^^^
note: required by a bound in `MaybeError`
--> $DIR/confusing-diagnostic-due-to-best-obligation-visitor.rs:15:14
|
LL | trait MaybeError: Sized
LL | where
LL | MyError: From<Self>,
| ^^^^^^^^^^ required by this bound in `MaybeError`
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
|
LL | <A::Error as MaybeError>::ComposeWithOther: From<B>, MyError: From<<A as MaybeFallible>::Error>
| ++++++++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `MyError: From<<Self as MaybeFallible>::Error>` is not satisfied
--> $DIR/confusing-diagnostic-due-to-best-obligation-visitor.rs:10:17
|
LL | type Error: MaybeError;
| ^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `From<<Self as MaybeFallible>::Error>` is not implemented for `MyError`
--> $DIR/confusing-diagnostic-due-to-best-obligation-visitor.rs:7:1
|
LL | struct MyError;
| ^^^^^^^^^^^^^^
note: required by a bound in `MaybeError`
--> $DIR/confusing-diagnostic-due-to-best-obligation-visitor.rs:15:14
|
LL | trait MaybeError: Sized
LL | where
LL | MyError: From<Self>,
| ^^^^^^^^^^ required by this bound in `MaybeError`

error[E0277]: the trait bound `MyError: From<<Self as MaybeError>::ComposeWithOther>` is not satisfied
--> $DIR/confusing-diagnostic-due-to-best-obligation-visitor.rs:17:28
|
LL | type ComposeWithOther: MaybeError;
| ^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `From<<Self as MaybeError>::ComposeWithOther>` is not implemented for `MyError`
--> $DIR/confusing-diagnostic-due-to-best-obligation-visitor.rs:7:1
|
LL | struct MyError;
| ^^^^^^^^^^^^^^
note: required by a bound in `MaybeError`
--> $DIR/confusing-diagnostic-due-to-best-obligation-visitor.rs:15:14
|
LL | trait MaybeError: Sized
LL | where
LL | MyError: From<Self>,
| ^^^^^^^^^^ required by this bound in `MaybeError`

error: aborting due to 3 previous errors

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