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
Original file line number Diff line number Diff line change
Expand Up @@ -3962,21 +3962,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let short_item_name = with_forced_trimmed_paths!(tcx.def_path_str(item_def_id));
let mut multispan = MultiSpan::from(span);
let sm = tcx.sess.source_map();
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy =
tcx.def_kind(item_def_id)
{
let span = tcx.def_span(tcx.parent(item_def_id)).shrink_to_lo();
multispan.push_span_context(span);
}
if let Some(ident) = tcx.opt_item_ident(item_def_id) {
let same_line =
match (sm.lookup_line(ident.span.hi()), sm.lookup_line(span.lo())) {
(Ok(l), Ok(r)) => l.line == r.line,
_ => true,
};
if ident.span.is_visible(sm) && !ident.span.overlaps(span) && !same_line {
multispan.push_span_label(
ident.span,
format!(
"required by a bound in this {}",
tcx.def_kind(item_def_id).descr(item_def_id)
),
);
}
multispan.push_span_context(ident.span);
}
let mut a = "a";
let mut this = "this bound";
Expand Down
2 changes: 2 additions & 0 deletions tests/ui-fulldeps/rustc-dev-remap.remap-unremap.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ LL | impl<E> VisitorResult for Result<(), E> {
note: required by a bound in `rustc_ast::visit::Visitor::Result`
--> $COMPILER_DIR_REAL/rustc_ast/src/visit.rs:LL:COL
|
LL | pub trait $Visitor<$($lt)?>: Sized $(${ignore($mut)} + MutVisitorResult<Result = ()>)? {
...
LL | type Result: VisitorResult = ();
| ^^^^^^^^^^^^^ required by this bound in `Visitor::Result`
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LL | const _: Ty::Pr<String> = String::new();
note: required by a bound in `Ty::Pr`
--> $DIR/generic-associated-types-bad.rs:10:16
|
LL | impl Ty {
LL | type Pr<T: Copy> = T;
| ^^^^ required by this bound in `Ty::Pr`

Expand All @@ -19,6 +20,7 @@ LL | const _: Ty::Pr<String> = String::new();
note: required by a bound in `Ty::Pr`
--> $DIR/generic-associated-types-bad.rs:10:16
|
LL | impl Ty {
LL | type Pr<T: Copy> = T;
| ^^^^ required by this bound in `Ty::Pr`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LL | let _: Ty::Pr<Vec<()>>;
note: required by a bound in `Ty::Pr`
--> $DIR/generic-associated-types-bad.rs:10:16
|
LL | impl Ty {
LL | type Pr<T: Copy> = T;
| ^^^^ required by this bound in `Ty::Pr`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ note: required by a bound in `S<T>::T`
LL | impl<T: Copy> S<T> {
| ^^^^ required by this bound in `S<T>::T`
LL | type T = T;
| - required by a bound in this associated type
|

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ LL | let _: S::<String>::X;
note: required by a bound in `S<T>::X`
--> $DIR/unsatisfied-bounds-where-clause-on-assoc-ty.rs:9:12
|
LL | impl<T> S<T> {
LL | type X = ()
| - required by a bound in this associated type
LL | where
LL | T: Copy;
| ^^^^ required by this bound in `S<T>::X`
Expand Down
1 change: 1 addition & 0 deletions tests/ui/associated-type-bounds/duplicate-bound-err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ LL | fn foo() -> impl Iterator<Item = i32, Item = u32> {
note: required by a bound in `Trait3::foo::{anon_assoc#0}`
--> $DIR/duplicate-bound-err.rs:99:31
|
LL | trait Trait3 {
LL | fn foo() -> impl Iterator<Item = i32, Item = u32>;
| ^^^^^^^^^^ required by this bound in `Trait3::foo::{anon_assoc#0}`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ note: required by a bound in `test`
--> $DIR/path-unsatisfied.rs:17:20
|
LL | fn test<T: Trait>()
| ---- required by a bound in this function
LL | where
LL | T::method(..): Send,
| ^^^^ required by this bound in `test`
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/associated-types/associated-types-eq-hr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ note: required by a bound in `foo`
--> $DIR/associated-types-eq-hr.rs:45:36
|
LL | fn foo<T>()
| --- required by a bound in this function
LL | where
LL | T: for<'x> TheTrait<&'x isize, A = &'x isize>,
| ^^^^^^^^^^^^^ required by this bound in `foo`
Expand All @@ -37,7 +36,6 @@ note: required by a bound in `bar`
--> $DIR/associated-types-eq-hr.rs:52:36
|
LL | fn bar<T>()
| --- required by a bound in this function
LL | where
LL | T: for<'x> TheTrait<&'x isize, A = &'x usize>,
| ^^^^^^^^^^^^^ required by this bound in `bar`
Expand Down
18 changes: 15 additions & 3 deletions tests/ui/associated-types/defaults-suitability.current.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LL | type Ty: Clone = NotClone;
note: required by a bound in `Tr::Ty`
--> $DIR/defaults-suitability.rs:16:14
|
LL | trait Tr {
LL | type Ty: Clone = NotClone;
| ^^^^^ required by this bound in `Tr::Ty`
help: consider annotating `NotClone` with `#[derive(Clone)]`
Expand All @@ -24,11 +25,13 @@ LL | type Ty = NotClone;
note: required by a bound in `Tr2::Ty`
--> $DIR/defaults-suitability.rs:23:15
|
LL | trait Tr2
LL | where
LL | Self::Ty: Clone,
| ^^^^^ required by this bound in `Tr2::Ty`
LL | {
LL | type Ty = NotClone;
| -- required by a bound in this associated type
|
help: consider annotating `NotClone` with `#[derive(Clone)]`
|
LL + #[derive(Clone)]
Expand All @@ -45,6 +48,7 @@ LL | type Bar: Clone = Vec<T>;
note: required by a bound in `Foo::Bar`
--> $DIR/defaults-suitability.rs:31:15
|
LL | trait Foo<T> {
LL | type Bar: Clone = Vec<T>;
| ^^^^^ required by this bound in `Foo::Bar`
help: consider restricting type parameter `T` with trait `Clone`
Expand All @@ -66,6 +70,8 @@ LL | trait Foo<T> {
note: required by a bound in `Bar::Assoc`
--> $DIR/defaults-suitability.rs:37:17
|
LL | trait Bar: Sized {
LL | // `(): Foo<Self>` might hold for some possible impls but not all.
LL | type Assoc: Foo<Self> = ();
| ^^^^^^^^^ required by this bound in `Bar::Assoc`

Expand All @@ -83,11 +89,13 @@ LL | struct NotClone;
note: required by a bound in `D::Assoc`
--> $DIR/defaults-suitability.rs:56:18
|
LL | trait D where
LL | Vec<Self::Assoc>: Clone,
LL | Self::Assoc: IsU8<Self::Assoc>,
| ^^^^^^^^^^^^^^^^^ required by this bound in `D::Assoc`
...
LL | type Assoc = NotClone;
| ----- required by a bound in this associated type
|

error[E0277]: the trait bound `<Self as Foo2<T>>::Baz: Clone` is not satisfied
--> $DIR/defaults-suitability.rs:68:23
Expand All @@ -99,6 +107,7 @@ LL | type Bar: Clone = Vec<Self::Baz>;
note: required by a bound in `Foo2::Bar`
--> $DIR/defaults-suitability.rs:68:15
|
LL | trait Foo2<T> {
LL | type Bar: Clone = Vec<Self::Baz>;
| ^^^^^ required by this bound in `Foo2::Bar`
help: consider further restricting the associated type
Expand All @@ -116,6 +125,7 @@ LL | type Bar: Clone = Vec<Self::Baz>;
note: required by a bound in `Foo25::Bar`
--> $DIR/defaults-suitability.rs:77:15
|
LL | trait Foo25<T: Clone> {
LL | type Bar: Clone = Vec<Self::Baz>;
| ^^^^^ required by this bound in `Foo25::Bar`
help: consider further restricting the associated type
Expand All @@ -132,11 +142,13 @@ LL | type Baz = T;
note: required by a bound in `Foo3::Baz`
--> $DIR/defaults-suitability.rs:87:16
|
LL | trait Foo3<T>
...
LL | Self::Baz: Clone,
| ^^^^^ required by this bound in `Foo3::Baz`
...
LL | type Baz = T;
| --- required by a bound in this associated type
|
help: consider further restricting type parameter `T` with trait `Clone`
|
LL | Self::Baz: Clone, T: std::clone::Clone
Expand Down
18 changes: 15 additions & 3 deletions tests/ui/associated-types/defaults-suitability.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LL | type Ty: Clone = NotClone;
note: required by a bound in `Tr::Ty`
--> $DIR/defaults-suitability.rs:16:14
|
LL | trait Tr {
LL | type Ty: Clone = NotClone;
| ^^^^^ required by this bound in `Tr::Ty`
help: consider annotating `NotClone` with `#[derive(Clone)]`
Expand All @@ -24,11 +25,13 @@ LL | type Ty = NotClone;
note: required by a bound in `Tr2::Ty`
--> $DIR/defaults-suitability.rs:23:15
|
LL | trait Tr2
LL | where
LL | Self::Ty: Clone,
| ^^^^^ required by this bound in `Tr2::Ty`
LL | {
LL | type Ty = NotClone;
| -- required by a bound in this associated type
|
help: consider annotating `NotClone` with `#[derive(Clone)]`
|
LL + #[derive(Clone)]
Expand All @@ -45,6 +48,7 @@ LL | type Bar: Clone = Vec<T>;
note: required by a bound in `Foo::Bar`
--> $DIR/defaults-suitability.rs:31:15
|
LL | trait Foo<T> {
LL | type Bar: Clone = Vec<T>;
| ^^^^^ required by this bound in `Foo::Bar`
help: consider restricting type parameter `T` with trait `Clone`
Expand All @@ -66,6 +70,8 @@ LL | trait Foo<T> {
note: required by a bound in `Bar::Assoc`
--> $DIR/defaults-suitability.rs:37:17
|
LL | trait Bar: Sized {
LL | // `(): Foo<Self>` might hold for some possible impls but not all.
LL | type Assoc: Foo<Self> = ();
| ^^^^^^^^^ required by this bound in `Bar::Assoc`

Expand All @@ -83,11 +89,13 @@ LL | struct NotClone;
note: required by a bound in `D::Assoc`
--> $DIR/defaults-suitability.rs:56:18
|
LL | trait D where
LL | Vec<Self::Assoc>: Clone,
LL | Self::Assoc: IsU8<Self::Assoc>,
| ^^^^^^^^^^^^^^^^^ required by this bound in `D::Assoc`
...
LL | type Assoc = NotClone;
| ----- required by a bound in this associated type
|

error[E0277]: the trait bound `<Self as Foo2<T>>::Baz: Clone` is not satisfied
--> $DIR/defaults-suitability.rs:68:23
Expand All @@ -99,6 +107,7 @@ LL | type Bar: Clone = Vec<Self::Baz>;
note: required by a bound in `Foo2::Bar`
--> $DIR/defaults-suitability.rs:68:15
|
LL | trait Foo2<T> {
LL | type Bar: Clone = Vec<Self::Baz>;
| ^^^^^ required by this bound in `Foo2::Bar`
help: consider further restricting the associated type
Expand All @@ -116,6 +125,7 @@ LL | type Bar: Clone = Vec<Self::Baz>;
note: required by a bound in `Foo25::Bar`
--> $DIR/defaults-suitability.rs:77:15
|
LL | trait Foo25<T: Clone> {
LL | type Bar: Clone = Vec<Self::Baz>;
| ^^^^^ required by this bound in `Foo25::Bar`
help: consider further restricting the associated type
Expand All @@ -132,11 +142,13 @@ LL | type Baz = T;
note: required by a bound in `Foo3::Baz`
--> $DIR/defaults-suitability.rs:87:16
|
LL | trait Foo3<T>
...
LL | Self::Baz: Clone,
| ^^^^^ required by this bound in `Foo3::Baz`
...
LL | type Baz = T;
| --- required by a bound in this associated type
|
help: consider further restricting type parameter `T` with trait `Clone`
|
LL | Self::Baz: Clone, T: std::clone::Clone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + Fro
note: required by a bound in `UncheckedCopy::Output`
--> $DIR/defaults-unsound-62211-1.rs:24:86
|
LL | trait UncheckedCopy: Sized {
...
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
| ^^^^^^^ required by this bound in `UncheckedCopy::Output`
help: consider further restricting `Self`
Expand All @@ -23,6 +25,8 @@ LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + Fro
note: required by a bound in `UncheckedCopy::Output`
--> $DIR/defaults-unsound-62211-1.rs:24:47
|
LL | trait UncheckedCopy: Sized {
...
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `UncheckedCopy::Output`
help: consider further restricting `Self`
Expand All @@ -39,6 +43,8 @@ LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + Fro
note: required by a bound in `UncheckedCopy::Output`
--> $DIR/defaults-unsound-62211-1.rs:24:25
|
LL | trait UncheckedCopy: Sized {
...
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
| ^^^^^^^^^^^^^^^^^^^ required by this bound in `UncheckedCopy::Output`
help: consider further restricting `Self`
Expand All @@ -55,6 +61,8 @@ LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + Fro
note: required by a bound in `UncheckedCopy::Output`
--> $DIR/defaults-unsound-62211-1.rs:24:18
|
LL | trait UncheckedCopy: Sized {
...
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
| ^^^^ required by this bound in `UncheckedCopy::Output`
help: consider further restricting `Self`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + Fro
note: required by a bound in `UncheckedCopy::Output`
--> $DIR/defaults-unsound-62211-1.rs:24:86
|
LL | trait UncheckedCopy: Sized {
...
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
| ^^^^^^^ required by this bound in `UncheckedCopy::Output`
help: consider further restricting `Self`
Expand All @@ -23,6 +25,8 @@ LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + Fro
note: required by a bound in `UncheckedCopy::Output`
--> $DIR/defaults-unsound-62211-1.rs:24:47
|
LL | trait UncheckedCopy: Sized {
...
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `UncheckedCopy::Output`
help: consider further restricting `Self`
Expand All @@ -39,6 +43,8 @@ LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + Fro
note: required by a bound in `UncheckedCopy::Output`
--> $DIR/defaults-unsound-62211-1.rs:24:31
|
LL | trait UncheckedCopy: Sized {
...
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
| ^^^^^^^^^^^^ required by this bound in `UncheckedCopy::Output`
help: consider further restricting `Self`
Expand All @@ -55,6 +61,8 @@ LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + Fro
note: required by a bound in `UncheckedCopy::Output`
--> $DIR/defaults-unsound-62211-1.rs:24:18
|
LL | trait UncheckedCopy: Sized {
...
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
| ^^^^ required by this bound in `UncheckedCopy::Output`
help: consider further restricting `Self`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + Fro
note: required by a bound in `UncheckedCopy::Output`
--> $DIR/defaults-unsound-62211-2.rs:24:86
|
LL | trait UncheckedCopy: Sized {
...
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
| ^^^^^^^ required by this bound in `UncheckedCopy::Output`
help: consider further restricting `Self`
Expand All @@ -23,6 +25,8 @@ LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + Fro
note: required by a bound in `UncheckedCopy::Output`
--> $DIR/defaults-unsound-62211-2.rs:24:47
|
LL | trait UncheckedCopy: Sized {
...
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `UncheckedCopy::Output`
help: consider further restricting `Self`
Expand All @@ -39,6 +43,8 @@ LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + Fro
note: required by a bound in `UncheckedCopy::Output`
--> $DIR/defaults-unsound-62211-2.rs:24:25
|
LL | trait UncheckedCopy: Sized {
...
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
| ^^^^^^^^^^^^^^^^^^^ required by this bound in `UncheckedCopy::Output`
help: consider further restricting `Self`
Expand All @@ -55,6 +61,8 @@ LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + Fro
note: required by a bound in `UncheckedCopy::Output`
--> $DIR/defaults-unsound-62211-2.rs:24:18
|
LL | trait UncheckedCopy: Sized {
...
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
| ^^^^ required by this bound in `UncheckedCopy::Output`
help: consider further restricting `Self`
Expand Down
Loading
Loading