Skip to content

Commit df21a6f

Browse files
Rollup merge of rust-lang#62696 - chocol4te:fix_#62194, r=estebank
Check that trait is exported or public before adding hint Closes rust-lang#62194. This PR checks the `AccessLevels` of a trait to check whether adding the intercrate ambiguity hint is valid or not. I am unsure of both the use of `.unwrap()` as well as removing hints for [downstream *and* [upstream](https://github.com/rust-lang/rust/blob/92b0f52584c9375505ecdefdd7855b93a5919d51/src/librustc/traits/select.rs#L112-L142).
2 parents cc16d04 + 3c11944 commit df21a6f

11 files changed

+7
-22
lines changed

src/librustc/traits/specialize/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,13 @@ 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+
if let Some(id) = tcx.hir().as_local_hir_id(impl_def_id) {
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+
}
375+
}
371376
}
372377

373378
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)