Skip to content

Commit ce936e9

Browse files
committed
Do not emit note for projected derived obligations
1 parent 6bc55c7 commit ce936e9

29 files changed

+22
-48
lines changed

src/librustc_middle/traits/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ pub enum ObligationCauseCode<'tcx> {
191191

192192
ImplDerivedObligation(DerivedObligationCause<'tcx>),
193193

194+
DerivedObligation(DerivedObligationCause<'tcx>),
195+
194196
/// Error derived when matching traits/impls; see ObligationCause for more details
195197
CompareImplMethodObligation {
196198
item_name: ast::Name,
@@ -263,7 +265,10 @@ impl ObligationCauseCode<'_> {
263265
// Return the base obligation, ignoring derived obligations.
264266
pub fn peel_derives(&self) -> &Self {
265267
let mut base_cause = self;
266-
while let BuiltinDerivedObligation(cause) | ImplDerivedObligation(cause) = base_cause {
268+
while let BuiltinDerivedObligation(cause)
269+
| ImplDerivedObligation(cause)
270+
| DerivedObligation(cause) = base_cause
271+
{
267272
base_cause = &cause.parent_code;
268273
}
269274
base_cause

src/librustc_middle/traits/structural_impls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
456456
super::ImplDerivedObligation(ref cause) => {
457457
tcx.lift(cause).map(super::ImplDerivedObligation)
458458
}
459+
super::DerivedObligation(ref cause) => tcx.lift(cause).map(super::DerivedObligation),
459460
super::CompareImplMethodObligation {
460461
item_name,
461462
impl_item_def_id,

src/librustc_trait_selection/traits/error_reporting/on_unimplemented.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
134134

135135
match obligation.cause.code {
136136
ObligationCauseCode::BuiltinDerivedObligation(..)
137-
| ObligationCauseCode::ImplDerivedObligation(..) => {}
137+
| ObligationCauseCode::ImplDerivedObligation(..)
138+
| ObligationCauseCode::DerivedObligation(..) => {}
138139
_ => {
139140
// this is a "direct", user-specified, rather than derived,
140141
// obligation.

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
11351135
while let Some(code) = next_code {
11361136
debug!("maybe_note_obligation_cause_for_async_await: code={:?}", code);
11371137
match code {
1138-
ObligationCauseCode::BuiltinDerivedObligation(derived_obligation)
1138+
ObligationCauseCode::DerivedObligation(derived_obligation)
1139+
| ObligationCauseCode::BuiltinDerivedObligation(derived_obligation)
11391140
| ObligationCauseCode::ImplDerivedObligation(derived_obligation) => {
11401141
let ty = derived_obligation.parent_trait_ref.self_ty();
11411142
debug!(
@@ -1661,6 +1662,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
16611662
obligated_types,
16621663
);
16631664
}
1665+
ObligationCauseCode::DerivedObligation(ref data) => {
1666+
let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
1667+
let parent_predicate = parent_trait_ref.without_const().to_predicate();
1668+
self.note_obligation_cause_code(
1669+
err,
1670+
&parent_predicate,
1671+
&data.parent_code,
1672+
obligated_types,
1673+
);
1674+
}
16641675
ObligationCauseCode::CompareImplMethodObligation { .. } => {
16651676
err.note(&format!(
16661677
"the requirement `{}` appears on the impl method \

src/librustc_trait_selection/traits/wf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
243243
parent_trait_ref,
244244
parent_code: Rc::new(obligation.cause.code.clone()),
245245
};
246-
cause.code = traits::ObligationCauseCode::ImplDerivedObligation(derived_cause);
246+
cause.code = traits::ObligationCauseCode::DerivedObligation(derived_cause);
247247
}
248248
extend_cause_with_original_assoc_item_obligation(
249249
tcx,

src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ LL | impl Case1 for S1 {
1111
| ^^^^^ `<L1 as Lam<&'a u8>>::App` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
1212
|
1313
= help: the trait `for<'a> std::fmt::Debug` is not implemented for `<L1 as Lam<&'a u8>>::App`
14-
= 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`
1514

1615
error[E0277]: `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterator
1716
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20

src/test/ui/associated-types/defaults-unsound-62211-1.stderr

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ LL | impl<T> UncheckedCopy for T {}
5353
|
5454
= help: the trait `std::fmt::Display` is not implemented for `T`
5555
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
56-
= note: required because of the requirements on the impl of `std::fmt::Display` for `<T as UncheckedCopy>::Output`
5756
help: consider restricting type parameter `T`
5857
|
5958
LL | impl<T: std::fmt::Display> UncheckedCopy for T {}
@@ -71,7 +70,6 @@ LL | + Deref<Target = str>
7170
LL | impl<T> UncheckedCopy for T {}
7271
| ^^^^^^^^^^^^^ the trait `std::ops::Deref` is not implemented for `T`
7372
|
74-
= note: required because of the requirements on the impl of `std::ops::Deref` for `<T as UncheckedCopy>::Output`
7573
help: consider restricting type parameter `T`
7674
|
7775
LL | impl<T: std::ops::Deref> UncheckedCopy for T {}
@@ -90,7 +88,6 @@ LL | impl<T> UncheckedCopy for T {}
9088
| ^^^^^^^^^^^^^ no implementation for `T += &'static str`
9189
|
9290
= help: the trait `std::ops::AddAssign<&'static str>` is not implemented for `T`
93-
= note: required because of the requirements on the impl of `std::ops::AddAssign<&'static str>` for `<T as UncheckedCopy>::Output`
9491
help: consider restricting type parameter `T`
9592
|
9693
LL | impl<T: std::ops::AddAssign<&'static str>> UncheckedCopy for T {}
@@ -108,7 +105,6 @@ LL | type Output: Copy
108105
LL | impl<T> UncheckedCopy for T {}
109106
| ^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
110107
|
111-
= note: required because of the requirements on the impl of `std::marker::Copy` for `<T as UncheckedCopy>::Output`
112108
help: consider restricting type parameter `T`
113109
|
114110
LL | impl<T: std::marker::Copy> UncheckedCopy for T {}

src/test/ui/associated-types/defaults-unsound-62211-2.stderr

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ LL | impl<T> UncheckedCopy for T {}
5353
|
5454
= help: the trait `std::fmt::Display` is not implemented for `T`
5555
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
56-
= note: required because of the requirements on the impl of `std::fmt::Display` for `<T as UncheckedCopy>::Output`
5756
help: consider restricting type parameter `T`
5857
|
5958
LL | impl<T: std::fmt::Display> UncheckedCopy for T {}
@@ -71,7 +70,6 @@ LL | + Deref<Target = str>
7170
LL | impl<T> UncheckedCopy for T {}
7271
| ^^^^^^^^^^^^^ the trait `std::ops::Deref` is not implemented for `T`
7372
|
74-
= note: required because of the requirements on the impl of `std::ops::Deref` for `<T as UncheckedCopy>::Output`
7573
help: consider restricting type parameter `T`
7674
|
7775
LL | impl<T: std::ops::Deref> UncheckedCopy for T {}
@@ -90,7 +88,6 @@ LL | impl<T> UncheckedCopy for T {}
9088
| ^^^^^^^^^^^^^ no implementation for `T += &'static str`
9189
|
9290
= help: the trait `std::ops::AddAssign<&'static str>` is not implemented for `T`
93-
= note: required because of the requirements on the impl of `std::ops::AddAssign<&'static str>` for `<T as UncheckedCopy>::Output`
9491
help: consider restricting type parameter `T`
9592
|
9693
LL | impl<T: std::ops::AddAssign<&'static str>> UncheckedCopy for T {}
@@ -108,7 +105,6 @@ LL | type Output: Copy
108105
LL | impl<T> UncheckedCopy for T {}
109106
| ^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
110107
|
111-
= note: required because of the requirements on the impl of `std::marker::Copy` for `<T as UncheckedCopy>::Output`
112108
help: consider restricting type parameter `T`
113109
|
114110
LL | impl<T: std::marker::Copy> UncheckedCopy for T {}

src/test/ui/associated-types/issue-43924.stderr

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ LL | type Out: Default + ToString + ?Sized = dyn ToString;
1616
...
1717
LL | impl Foo<u32> for () {}
1818
| ^^^^^^^^ the trait `std::default::Default` is not implemented for `(dyn std::string::ToString + 'static)`
19-
|
20-
= note: required because of the requirements on the impl of `std::default::Default` for `<() as Foo<u32>>::Out`
2119

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

3531
error: aborting due to 3 previous errors
3632

src/test/ui/associated-types/issue-65774-1.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ LL | type MpuConfig: MyDisplay = T;
1616
...
1717
LL | impl MPU for S { }
1818
| ^^^ the trait `MyDisplay` is not implemented for `T`
19-
|
20-
= note: required because of the requirements on the impl of `MyDisplay` for `<S as MPU>::MpuConfig`
2119

2220
error: aborting due to 2 previous errors
2321

0 commit comments

Comments
 (0)