Skip to content

Commit

Permalink
Do not emit note for projected derived obligations
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Apr 18, 2020
1 parent 6bc55c7 commit ce936e9
Show file tree
Hide file tree
Showing 29 changed files with 22 additions and 48 deletions.
7 changes: 6 additions & 1 deletion src/librustc_middle/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ pub enum ObligationCauseCode<'tcx> {

ImplDerivedObligation(DerivedObligationCause<'tcx>),

DerivedObligation(DerivedObligationCause<'tcx>),

/// Error derived when matching traits/impls; see ObligationCause for more details
CompareImplMethodObligation {
item_name: ast::Name,
Expand Down Expand Up @@ -263,7 +265,10 @@ impl ObligationCauseCode<'_> {
// Return the base obligation, ignoring derived obligations.
pub fn peel_derives(&self) -> &Self {
let mut base_cause = self;
while let BuiltinDerivedObligation(cause) | ImplDerivedObligation(cause) = base_cause {
while let BuiltinDerivedObligation(cause)
| ImplDerivedObligation(cause)
| DerivedObligation(cause) = base_cause
{
base_cause = &cause.parent_code;
}
base_cause
Expand Down
1 change: 1 addition & 0 deletions src/librustc_middle/traits/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
super::ImplDerivedObligation(ref cause) => {
tcx.lift(cause).map(super::ImplDerivedObligation)
}
super::DerivedObligation(ref cause) => tcx.lift(cause).map(super::DerivedObligation),
super::CompareImplMethodObligation {
item_name,
impl_item_def_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {

match obligation.cause.code {
ObligationCauseCode::BuiltinDerivedObligation(..)
| ObligationCauseCode::ImplDerivedObligation(..) => {}
| ObligationCauseCode::ImplDerivedObligation(..)
| ObligationCauseCode::DerivedObligation(..) => {}
_ => {
// this is a "direct", user-specified, rather than derived,
// obligation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
while let Some(code) = next_code {
debug!("maybe_note_obligation_cause_for_async_await: code={:?}", code);
match code {
ObligationCauseCode::BuiltinDerivedObligation(derived_obligation)
ObligationCauseCode::DerivedObligation(derived_obligation)
| ObligationCauseCode::BuiltinDerivedObligation(derived_obligation)
| ObligationCauseCode::ImplDerivedObligation(derived_obligation) => {
let ty = derived_obligation.parent_trait_ref.self_ty();
debug!(
Expand Down Expand Up @@ -1661,6 +1662,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
obligated_types,
);
}
ObligationCauseCode::DerivedObligation(ref data) => {
let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
let parent_predicate = parent_trait_ref.without_const().to_predicate();
self.note_obligation_cause_code(
err,
&parent_predicate,
&data.parent_code,
obligated_types,
);
}
ObligationCauseCode::CompareImplMethodObligation { .. } => {
err.note(&format!(
"the requirement `{}` appears on the impl method \
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trait_selection/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
parent_trait_ref,
parent_code: Rc::new(obligation.cause.code.clone()),
};
cause.code = traits::ObligationCauseCode::ImplDerivedObligation(derived_cause);
cause.code = traits::ObligationCauseCode::DerivedObligation(derived_cause);
}
extend_cause_with_original_assoc_item_obligation(
tcx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ LL | impl Case1 for S1 {
| ^^^^^ `<L1 as Lam<&'a u8>>::App` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
= help: the trait `for<'a> std::fmt::Debug` is not implemented for `<L1 as Lam<&'a u8>>::App`
= note: required because of the requirements on the impl of `for<'a> std::fmt::Debug` for `<<<<S1 as Case1>::C as std::iter::Iterator>::Item as std::iter::Iterator>::Item as Lam<&'a u8>>::App`

error[E0277]: `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterator
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/associated-types/defaults-unsound-62211-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ LL | impl<T> UncheckedCopy for T {}
|
= help: the trait `std::fmt::Display` is not implemented for `T`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: required because of the requirements on the impl of `std::fmt::Display` for `<T as UncheckedCopy>::Output`
help: consider restricting type parameter `T`
|
LL | impl<T: std::fmt::Display> UncheckedCopy for T {}
Expand All @@ -71,7 +70,6 @@ LL | + Deref<Target = str>
LL | impl<T> UncheckedCopy for T {}
| ^^^^^^^^^^^^^ the trait `std::ops::Deref` is not implemented for `T`
|
= note: required because of the requirements on the impl of `std::ops::Deref` for `<T as UncheckedCopy>::Output`
help: consider restricting type parameter `T`
|
LL | impl<T: std::ops::Deref> UncheckedCopy for T {}
Expand All @@ -90,7 +88,6 @@ LL | impl<T> UncheckedCopy for T {}
| ^^^^^^^^^^^^^ no implementation for `T += &'static str`
|
= help: the trait `std::ops::AddAssign<&'static str>` is not implemented for `T`
= note: required because of the requirements on the impl of `std::ops::AddAssign<&'static str>` for `<T as UncheckedCopy>::Output`
help: consider restricting type parameter `T`
|
LL | impl<T: std::ops::AddAssign<&'static str>> UncheckedCopy for T {}
Expand All @@ -108,7 +105,6 @@ LL | type Output: Copy
LL | impl<T> UncheckedCopy for T {}
| ^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
|
= note: required because of the requirements on the impl of `std::marker::Copy` for `<T as UncheckedCopy>::Output`
help: consider restricting type parameter `T`
|
LL | impl<T: std::marker::Copy> UncheckedCopy for T {}
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/associated-types/defaults-unsound-62211-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ LL | impl<T> UncheckedCopy for T {}
|
= help: the trait `std::fmt::Display` is not implemented for `T`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: required because of the requirements on the impl of `std::fmt::Display` for `<T as UncheckedCopy>::Output`
help: consider restricting type parameter `T`
|
LL | impl<T: std::fmt::Display> UncheckedCopy for T {}
Expand All @@ -71,7 +70,6 @@ LL | + Deref<Target = str>
LL | impl<T> UncheckedCopy for T {}
| ^^^^^^^^^^^^^ the trait `std::ops::Deref` is not implemented for `T`
|
= note: required because of the requirements on the impl of `std::ops::Deref` for `<T as UncheckedCopy>::Output`
help: consider restricting type parameter `T`
|
LL | impl<T: std::ops::Deref> UncheckedCopy for T {}
Expand All @@ -90,7 +88,6 @@ LL | impl<T> UncheckedCopy for T {}
| ^^^^^^^^^^^^^ no implementation for `T += &'static str`
|
= help: the trait `std::ops::AddAssign<&'static str>` is not implemented for `T`
= note: required because of the requirements on the impl of `std::ops::AddAssign<&'static str>` for `<T as UncheckedCopy>::Output`
help: consider restricting type parameter `T`
|
LL | impl<T: std::ops::AddAssign<&'static str>> UncheckedCopy for T {}
Expand All @@ -108,7 +105,6 @@ LL | type Output: Copy
LL | impl<T> UncheckedCopy for T {}
| ^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
|
= note: required because of the requirements on the impl of `std::marker::Copy` for `<T as UncheckedCopy>::Output`
help: consider restricting type parameter `T`
|
LL | impl<T: std::marker::Copy> UncheckedCopy for T {}
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/associated-types/issue-43924.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ LL | type Out: Default + ToString + ?Sized = dyn ToString;
...
LL | impl Foo<u32> for () {}
| ^^^^^^^^ the trait `std::default::Default` is not implemented for `(dyn std::string::ToString + 'static)`
|
= note: required because of the requirements on the impl of `std::default::Default` for `<() as Foo<u32>>::Out`

error[E0277]: the trait bound `(dyn std::string::ToString + 'static): std::default::Default` is not satisfied
--> $DIR/issue-43924.rs:11:6
Expand All @@ -29,8 +27,6 @@ LL | type Out: Default + ToString + ?Sized = dyn ToString;
...
LL | impl Foo<u64> for () {}
| ^^^^^^^^ the trait `std::default::Default` is not implemented for `(dyn std::string::ToString + 'static)`
|
= note: required because of the requirements on the impl of `std::default::Default` for `<() as Foo<u64>>::Out`

error: aborting due to 3 previous errors

Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/associated-types/issue-65774-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ LL | type MpuConfig: MyDisplay = T;
...
LL | impl MPU for S { }
| ^^^ the trait `MyDisplay` is not implemented for `T`
|
= note: required because of the requirements on the impl of `MyDisplay` for `<S as MPU>::MpuConfig`

error: aborting due to 2 previous errors

Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/associated-types/issue-65774-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ LL | type MpuConfig: MyDisplay = T;
...
LL | impl MPU for S { }
| ^^^ the trait `MyDisplay` is not implemented for `T`
|
= note: required because of the requirements on the impl of `MyDisplay` for `<S as MPU>::MpuConfig`

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ LL | type Assoc: Bar;
...
LL | type Assoc = bool;
| ^^^^ the trait `Bar` is not implemented for `bool`
|
= note: required because of the requirements on the impl of `Bar` for `<() as Foo>::Assoc`

error[E0277]: the trait bound `bool: Bar` is not satisfied
--> $DIR/point-at-type-on-obligation-failure-2.rs:16:18
Expand All @@ -19,8 +17,6 @@ LL | trait Baz where Self::Assoc: Bar {
...
LL | type Assoc = bool;
| ^^^^ the trait `Bar` is not implemented for `bool`
|
= note: required because of the requirements on the impl of `Bar` for `<() as Baz>::Assoc`

error[E0277]: the trait bound `bool: Bar` is not satisfied
--> $DIR/point-at-type-on-obligation-failure-2.rs:24:18
Expand All @@ -30,8 +26,6 @@ LL | trait Bat where <Self as Bat>::Assoc: Bar {
...
LL | type Assoc = bool;
| ^^^^ the trait `Bar` is not implemented for `bool`
|
= note: required because of the requirements on the impl of `Bar` for `<() as Bat>::Assoc`

error: aborting due to 3 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ LL | impl <T: Sync+'static> Foo for (T,) { }
|
= help: within `(T,)`, the trait `std::marker::Send` is not implemented for `T`
= note: required because it appears within the type `(T,)`
= note: required because of the requirements on the impl of `std::marker::Send` for `(T,)`
help: consider further restricting this bound
|
LL | impl <T: Sync+'static + std::marker::Send> Foo for (T,) { }
Expand All @@ -26,7 +25,6 @@ LL | impl <T: Send> Foo for (T,T) { }
|
= help: within `(T, T)`, the trait `std::marker::Sync` is not implemented for `T`
= note: required because it appears within the type `(T, T)`
= note: required because of the requirements on the impl of `std::marker::Sync` for `(T, T)`
help: consider further restricting this bound
|
LL | impl <T: Send + std::marker::Sync> Foo for (T,T) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ LL | pub trait RequiresRequiresShareAndSend : RequiresShare + Send { }
|
= help: within `X<T>`, the trait `std::marker::Send` is not implemented for `T`
= note: required because it appears within the type `X<T>`
= note: required because of the requirements on the impl of `std::marker::Send` for `X<T>`
help: consider further restricting this bound
|
LL | impl <T:Sync+'static + std::marker::Send> RequiresRequiresShareAndSend for X<T> { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ LL | impl Foo for std::rc::Rc<i8> { }
| ^^^ `std::rc::Rc<i8>` cannot be sent between threads safely
|
= help: the trait `std::marker::Send` is not implemented for `std::rc::Rc<i8>`
= note: required because of the requirements on the impl of `std::marker::Send` for `std::rc::Rc<i8>`

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ LL | impl <T: Sync+'static> Foo for T { }
| ^^^ `T` cannot be sent between threads safely
|
= help: the trait `std::marker::Send` is not implemented for `T`
= note: required because of the requirements on the impl of `std::marker::Send` for `T`
help: consider further restricting this bound
|
LL | impl <T: Sync+'static + std::marker::Send> Foo for T { }
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/dst/dst-sized-trait-param.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ LL | impl Foo<[isize]> for usize { }
|
= help: the trait `std::marker::Sized` is not implemented for `[isize]`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required because of the requirements on the impl of `std::marker::Sized` for `[isize]`

error[E0277]: the size for values of type `[usize]` cannot be known at compilation time
--> $DIR/dst-sized-trait-param.rs:10:6
Expand All @@ -22,7 +21,6 @@ LL | impl Foo<isize> for [usize] { }
|
= help: the trait `std::marker::Sized` is not implemented for `[usize]`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required because of the requirements on the impl of `std::marker::Sized` for `[usize]`

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ LL | impl Tsized for () {}
|
= help: the trait `std::marker::Sized` is not implemented for `[()]`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required because of the requirements on the impl of `std::marker::Sized` for `[()]`

error: aborting due to previous error

Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/impl-bounds-checking.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ LL | trait Getter<T: Clone2> {
...
LL | impl Getter<isize> for isize {
| ^^^^^^^^^^^^^ the trait `Clone2` is not implemented for `isize`
|
= note: required because of the requirements on the impl of `Clone2` for `isize`

error: aborting due to previous error

Expand Down
1 change: 0 additions & 1 deletion src/test/ui/issues/issue-10412.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ LL | impl<'self> Serializable<str> for &'self str {
|
= help: the trait `std::marker::Sized` is not implemented for `str`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required because of the requirements on the impl of `std::marker::Sized` for `str`

error: aborting due to 9 previous errors

Expand Down
1 change: 0 additions & 1 deletion src/test/ui/issues/issue-43784-associated-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
LL | type Assoc = T;
| ^ the trait `std::marker::Copy` is not implemented for `T`
|
= note: required because of the requirements on the impl of `std::marker::Copy` for `<T as Complete>::Assoc`
help: consider restricting type parameter `T`
|
LL | impl<T: std::marker::Copy> Complete for T {
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/issues/issue-43784-supertrait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
LL | impl<T> Complete for T {}
| ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
|
= note: required because of the requirements on the impl of `std::marker::Copy` for `T`
help: consider restricting type parameter `T`
|
LL | impl<T: std::marker::Copy> Complete for T {}
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/issues/issue-65673.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ LL | type Ctx = dyn Alias<T>;
|
= help: the trait `std::marker::Sized` is not implemented for `(dyn Trait + 'static)`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required because of the requirements on the impl of `std::marker::Sized` for `<T as WithType>::Ctx`

error: aborting due to previous error

Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/malformed/malformed-derive-entry.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ LL | #[derive(Copy(Bad))]
LL | pub trait Copy: Clone {
| ----- required by this bound in `std::marker::Copy`
|
= note: required because of the requirements on the impl of `std::clone::Clone` for `Test1`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Test2: std::clone::Clone` is not satisfied
Expand All @@ -41,7 +40,6 @@ LL | #[derive(Copy="bad")]
LL | pub trait Copy: Clone {
| ----- required by this bound in `std::marker::Copy`
|
= note: required because of the requirements on the impl of `std::clone::Clone` for `Test2`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 5 previous errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ LL |
LL | default impl<U> Foo<'static, U> for () {}
| ^^^^^^^^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `U`
|
= note: required because of the requirements on the impl of `std::cmp::Eq` for `U`
help: consider restricting type parameter `U`
|
LL | default impl<U: std::cmp::Eq> Foo<'static, U> for () {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ LL | type Assoc = ChildWrapper<T::Assoc>;
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `Child<A>` is not implemented for `<T as Parent>::Assoc`
|
= note: required because of the requirements on the impl of `Child<A>` for `ChildWrapper<<T as Parent>::Assoc>`
= note: required because of the requirements on the impl of `Child<<ParentWrapper<T> as Parent>::Ty>` for `<ParentWrapper<T> as Parent>::Assoc`

error[E0277]: the trait bound `<T as Parent>::Assoc: Child<A>` is not satisfied
--> $DIR/missing-assoc-type-bound-restriction.rs:20:5
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/traits/cycle-cache-err-60010.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ LL | type Storage = SalsaStorage;
= note: required because of the requirements on the impl of `SourceDatabase` for `RootDatabase`
= note: required because of the requirements on the impl of `Query<RootDatabase>` for `ParseQuery`
= note: required because it appears within the type `SalsaStorage`
= note: required because of the requirements on the impl of `std::marker::Sized` for `<RootDatabase as Database>::Storage`

error: aborting due to 2 previous errors

Expand Down
1 change: 0 additions & 1 deletion src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ LL | impl<X: ?Sized> T2<X> for S4<X> {
|
= help: the trait `std::marker::Sized` is not implemented for `X`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required because of the requirements on the impl of `std::marker::Sized` for `X`

error: aborting due to previous error

Expand Down
1 change: 0 additions & 1 deletion src/test/ui/unsized7.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ LL | impl<X: ?Sized + T> T1<X> for S3<X> {
|
= help: the trait `std::marker::Sized` is not implemented for `X`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required because of the requirements on the impl of `std::marker::Sized` for `X`

error: aborting due to previous error

Expand Down

0 comments on commit ce936e9

Please sign in to comment.