Skip to content

Commit 2ced474

Browse files
committed
Check that trait is exported or public before adding intercrate ambiguity hint
1 parent 4b65a86 commit 2ced474

11 files changed

+6
-22
lines changed

src/librustc/traits/specialize/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,12 @@ pub(super) fn specialization_graph_provider(
366366
}
367367
}
368368

369-
for cause in &overlap.intercrate_ambiguity_causes {
370-
cause.add_intercrate_ambiguity_hint(&mut err);
369+
let access_levels = tcx.privacy_access_levels(impl_def_id.krate);
370+
let id = tcx.hir().as_local_hir_id(impl_def_id).unwrap();
371+
if access_levels.is_exported(id) || access_levels.is_public(id) {
372+
for cause in &overlap.intercrate_ambiguity_causes {
373+
cause.add_intercrate_ambiguity_hint(&mut err);
374+
}
371375
}
372376

373377
if overlap.involves_placeholder {

src/test/ui/coherence/coherence-overlap-upstream.old.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ LL | impl<T> Foo for T where T: Remote {}
55
| --------------------------------- first implementation here
66
LL | impl Foo for i16 {}
77
| ^^^^^^^^^^^^^^^^ conflicting implementation for `i16`
8-
|
9-
= note: upstream crates may add new impl of trait `coherence_lib::Remote` for type `i16` in future versions
108

119
error: aborting due to previous error
1210

src/test/ui/coherence/coherence-overlap-upstream.re.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ LL | impl<T> Foo for T where T: Remote {}
55
| --------------------------------- first implementation here
66
LL | impl Foo for i16 {}
77
| ^^^^^^^^^^^^^^^^ conflicting implementation for `i16`
8-
|
9-
= note: upstream crates may add new impl of trait `coherence_lib::Remote` for type `i16` in future versions
108

119
error: aborting due to previous error
1210

src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.old.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | impl<T: lib::MyCopy> MyTrait for T { }
66
...
77
LL | impl MyTrait for lib::MyFundamentalStruct<(MyType,)> { }
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyFundamentalStruct<(MyType,)>`
9-
|
10-
= note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyFundamentalStruct<(MyType,)>` in future versions
119

1210
error: aborting due to previous error
1311

src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.re.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | impl<T: lib::MyCopy> MyTrait for T { }
66
...
77
LL | impl MyTrait for lib::MyFundamentalStruct<(MyType,)> { }
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyFundamentalStruct<(MyType,)>`
9-
|
10-
= note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyFundamentalStruct<(MyType,)>` in future versions
119

1210
error: aborting due to previous error
1311

src/test/ui/coherence/coherence_copy_like_err_struct.old.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | impl<T: lib::MyCopy> MyTrait for T { }
66
...
77
LL | impl MyTrait for lib::MyStruct<MyType> { }
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyStruct<MyType>`
9-
|
10-
= note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyStruct<MyType>` in future versions
119

1210
error: aborting due to previous error
1311

src/test/ui/coherence/coherence_copy_like_err_struct.re.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | impl<T: lib::MyCopy> MyTrait for T { }
66
...
77
LL | impl MyTrait for lib::MyStruct<MyType> { }
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyStruct<MyType>`
9-
|
10-
= note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyStruct<MyType>` in future versions
119

1210
error: aborting due to previous error
1311

src/test/ui/coherence/coherence_copy_like_err_tuple.old.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | impl<T: lib::MyCopy> MyTrait for T { }
66
...
77
LL | impl MyTrait for (MyType,) { }
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(MyType,)`
9-
|
10-
= note: upstream crates may add new impl of trait `lib::MyCopy` for type `(MyType,)` in future versions
119

1210
error: aborting due to previous error
1311

src/test/ui/coherence/coherence_copy_like_err_tuple.re.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | impl<T: lib::MyCopy> MyTrait for T { }
66
...
77
LL | impl MyTrait for (MyType,) { }
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(MyType,)`
9-
|
10-
= note: upstream crates may add new impl of trait `lib::MyCopy` for type `(MyType,)` in future versions
119

1210
error: aborting due to previous error
1311

src/test/ui/issues/issue-48728.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | #[derive(Clone)]
66
...
77
LL | impl<T: Clone + ?Sized> Clone for Node<[T]> {
88
| ------------------------------------------- first implementation here
9-
|
10-
= note: upstream crates may add new impl of trait `std::clone::Clone` for type `[_]` in future versions
119

1210
error: aborting due to previous error
1311

src/test/ui/specialization/issue-52050.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ LL | | }
1010
LL |
1111
LL | impl IntoPyDictPointer for ()
1212
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`
13-
|
14-
= note: upstream crates may add new impl of trait `std::iter::Iterator` for type `()` in future versions
1513

1614
error: aborting due to previous error
1715

0 commit comments

Comments
 (0)