Skip to content

Commit 51742be

Browse files
committed
specialization_graph: avoid trimmed paths for OverlapError
1 parent c5a6131 commit 51742be

34 files changed

+75
-73
lines changed

compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::OverlapError;
33
use crate::traits;
44
use rustc_hir::def_id::DefId;
55
use rustc_middle::ty::fast_reject::{self, SimplifiedType};
6+
use rustc_middle::ty::print::with_no_trimmed_paths;
67
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
78

89
pub use rustc_middle::traits::specialization_graph::*;
@@ -102,7 +103,8 @@ impl ChildrenExt for Children {
102103
let trait_ref = overlap.impl_header.trait_ref.unwrap();
103104
let self_ty = trait_ref.self_ty();
104105

105-
OverlapError {
106+
// FIXME: should postpone string formatting until we decide to actually emit.
107+
with_no_trimmed_paths(|| OverlapError {
106108
with_impl: possible_sibling,
107109
trait_desc: trait_ref.print_only_trait_path().to_string(),
108110
// Only report the `Self` type if it has at least
@@ -115,7 +117,7 @@ impl ChildrenExt for Children {
115117
},
116118
intercrate_ambiguity_causes: overlap.intercrate_ambiguity_causes,
117119
involves_placeholder: overlap.involves_placeholder,
118-
}
120+
})
119121
};
120122

121123
let report_overlap_error = |overlap: traits::coherence::OverlapResult<'_>,

src/test/ui/coherence/coherence-blanket-conflicts-with-specific-cross-crate.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0119]: conflicting implementations of trait `GoMut` for type `MyThingy`:
1+
error[E0119]: conflicting implementations of trait `go_trait::GoMut` for type `MyThingy`:
22
--> $DIR/coherence-blanket-conflicts-with-specific-cross-crate.rs:15:1
33
|
44
LL | impl GoMut for MyThingy {

src/test/ui/coherence/coherence-conflicting-negative-trait-impl.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0751]: found both positive and negative implementation of trait `Send` for type `TestType<_>`:
1+
error[E0751]: found both positive and negative implementation of trait `std::marker::Send` for type `TestType<_>`:
22
--> $DIR/coherence-conflicting-negative-trait-impl.rs:11:1
33
|
44
LL | unsafe impl<T: MyTrait + 'static> Send for TestType<T> {}
@@ -7,7 +7,7 @@ LL |
77
LL | impl<T: MyTrait> !Send for TestType<T> {}
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ negative implementation here
99

10-
error[E0119]: conflicting implementations of trait `Send` for type `TestType<_>`:
10+
error[E0119]: conflicting implementations of trait `std::marker::Send` for type `TestType<_>`:
1111
--> $DIR/coherence-conflicting-negative-trait-impl.rs:13:1
1212
|
1313
LL | unsafe impl<T: MyTrait + 'static> Send for TestType<T> {}

src/test/ui/coherence/coherence-cross-crate-conflict.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0119]: conflicting implementations of trait `Foo` for type `isize`:
1+
error[E0119]: conflicting implementations of trait `trait_impl_conflict::Foo` for type `isize`:
22
--> $DIR/coherence-cross-crate-conflict.rs:9:1
33
|
44
LL | impl<A> Foo for A {

src/test/ui/coherence/coherence-impls-copy.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0119]: conflicting implementations of trait `Copy` for type `i32`:
1+
error[E0119]: conflicting implementations of trait `std::marker::Copy` for type `i32`:
22
--> $DIR/coherence-impls-copy.rs:5:1
33
|
44
LL | impl Copy for i32 {}
@@ -7,7 +7,7 @@ LL | impl Copy for i32 {}
77
= note: conflicting implementation in crate `core`:
88
- impl Copy for i32;
99

10-
error[E0119]: conflicting implementations of trait `Copy` for type `&NotSync`:
10+
error[E0119]: conflicting implementations of trait `std::marker::Copy` for type `&NotSync`:
1111
--> $DIR/coherence-impls-copy.rs:29:1
1212
|
1313
LL | impl Copy for &'static NotSync {}
@@ -17,7 +17,7 @@ LL | impl Copy for &'static NotSync {}
1717
- impl<T> Copy for &T
1818
where T: ?Sized;
1919

20-
error[E0119]: conflicting implementations of trait `Copy` for type `&[NotSync]`:
20+
error[E0119]: conflicting implementations of trait `std::marker::Copy` for type `&[NotSync]`:
2121
--> $DIR/coherence-impls-copy.rs:34:1
2222
|
2323
LL | impl Copy for &'static [NotSync] {}

src/test/ui/coherence/coherence-impls-send.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0119]: conflicting implementations of trait `Send` for type `&[NotSync]`:
1+
error[E0119]: conflicting implementations of trait `std::marker::Send` for type `&[NotSync]`:
22
--> $DIR/coherence-impls-send.rs:25:1
33
|
44
LL | unsafe impl Send for &'static [NotSync] {}

src/test/ui/coherence/coherence-overlap-issue-23516.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0119]: conflicting implementations of trait `Sweet` for type `Box<_>`:
1+
error[E0119]: conflicting implementations of trait `Sweet` for type `std::boxed::Box<_>`:
22
--> $DIR/coherence-overlap-issue-23516.rs:8:1
33
|
44
LL | impl<T:Sugar> Sweet for T { }
55
| ------------------------- first implementation here
66
LL | impl<U:Sugar> Sweet for Box<U> { }
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Box<_>`
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::boxed::Box<_>`
88
|
99
= note: downstream crates may implement trait `Sugar` for type `std::boxed::Box<_>`
1010

src/test/ui/coherence/coherence-projection-conflict-ty-param.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0119]: conflicting implementations of trait `Foo<_>` for type `Option<_>`:
1+
error[E0119]: conflicting implementations of trait `Foo<_>` for type `std::option::Option<_>`:
22
--> $DIR/coherence-projection-conflict-ty-param.rs:10:1
33
|
44
LL | impl <P, T: Foo<P>> Foo<P> for Option<T> {}
55
| ---------------------------------------- first implementation here
66
LL |
77
LL | impl<T, U> Foo<T> for Option<U> { }
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Option<_>`
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::option::Option<_>`
99

1010
error: aborting due to previous error
1111

src/test/ui/coherence/coherence-wasm-bindgen.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: conflicting implementations of trait `IntoWasmAbi` for type `&dyn Fn(&_) -> _`:
1+
error: conflicting implementations of trait `IntoWasmAbi` for type `&dyn std::ops::Fn(&_) -> _`:
22
--> $DIR/coherence-wasm-bindgen.rs:28:1
33
|
44
LL | / impl<'a, 'b, A, R> IntoWasmAbi for &'a (dyn Fn(A) -> R + 'b)
@@ -16,7 +16,7 @@ LL | | R: ReturnWasmAbi,
1616
... |
1717
LL | |
1818
LL | | }
19-
| |_^ conflicting implementation for `&dyn Fn(&_) -> _`
19+
| |_^ conflicting implementation for `&dyn std::ops::Fn(&_) -> _`
2020
|
2121
note: the lint level is defined here
2222
--> $DIR/coherence-wasm-bindgen.rs:10:9

src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0119]: conflicting implementations of trait `MyTrait` for type `MyFundamentalStruct<(MyType,)>`:
1+
error[E0119]: conflicting implementations of trait `MyTrait` for type `lib::MyFundamentalStruct<(MyType,)>`:
22
--> $DIR/coherence_copy_like_err_fundamental_struct_tuple.rs:16:1
33
|
44
LL | impl<T: lib::MyCopy> MyTrait for T { }
55
| ---------------------------------- first implementation here
66
...
77
LL | impl MyTrait for lib::MyFundamentalStruct<(MyType,)> { }
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyFundamentalStruct<(MyType,)>`
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyFundamentalStruct<(MyType,)>`
99
|
1010
= note: upstream crates may add a new impl of trait `lib::MyCopy` for type `lib::MyFundamentalStruct<(MyType,)>` in future versions
1111

0 commit comments

Comments
 (0)