From 2ced474e808d59e4b3bf2c6874e40446a4598f51 Mon Sep 17 00:00:00 2001 From: Ferdia McKeogh Date: Mon, 15 Jul 2019 19:45:51 +0200 Subject: [PATCH 1/2] Check that trait is exported or public before adding intercrate ambiguity hint --- src/librustc/traits/specialize/mod.rs | 8 ++++++-- .../ui/coherence/coherence-overlap-upstream.old.stderr | 2 -- .../ui/coherence/coherence-overlap-upstream.re.stderr | 2 -- ...ence_copy_like_err_fundamental_struct_tuple.old.stderr | 2 -- ...rence_copy_like_err_fundamental_struct_tuple.re.stderr | 2 -- .../coherence/coherence_copy_like_err_struct.old.stderr | 2 -- .../ui/coherence/coherence_copy_like_err_struct.re.stderr | 2 -- .../ui/coherence/coherence_copy_like_err_tuple.old.stderr | 2 -- .../ui/coherence/coherence_copy_like_err_tuple.re.stderr | 2 -- src/test/ui/issues/issue-48728.stderr | 2 -- src/test/ui/specialization/issue-52050.stderr | 2 -- 11 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index f0389bb037ac5..9027d330a90f6 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -366,8 +366,12 @@ pub(super) fn specialization_graph_provider( } } - for cause in &overlap.intercrate_ambiguity_causes { - cause.add_intercrate_ambiguity_hint(&mut err); + let access_levels = tcx.privacy_access_levels(impl_def_id.krate); + let id = tcx.hir().as_local_hir_id(impl_def_id).unwrap(); + if access_levels.is_exported(id) || access_levels.is_public(id) { + for cause in &overlap.intercrate_ambiguity_causes { + cause.add_intercrate_ambiguity_hint(&mut err); + } } if overlap.involves_placeholder { diff --git a/src/test/ui/coherence/coherence-overlap-upstream.old.stderr b/src/test/ui/coherence/coherence-overlap-upstream.old.stderr index 6c3484c2d8c4d..dea948ff8abbb 100644 --- a/src/test/ui/coherence/coherence-overlap-upstream.old.stderr +++ b/src/test/ui/coherence/coherence-overlap-upstream.old.stderr @@ -5,8 +5,6 @@ LL | impl Foo for T where T: Remote {} | --------------------------------- first implementation here LL | impl Foo for i16 {} | ^^^^^^^^^^^^^^^^ conflicting implementation for `i16` - | - = note: upstream crates may add new impl of trait `coherence_lib::Remote` for type `i16` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-overlap-upstream.re.stderr b/src/test/ui/coherence/coherence-overlap-upstream.re.stderr index 6c3484c2d8c4d..dea948ff8abbb 100644 --- a/src/test/ui/coherence/coherence-overlap-upstream.re.stderr +++ b/src/test/ui/coherence/coherence-overlap-upstream.re.stderr @@ -5,8 +5,6 @@ LL | impl Foo for T where T: Remote {} | --------------------------------- first implementation here LL | impl Foo for i16 {} | ^^^^^^^^^^^^^^^^ conflicting implementation for `i16` - | - = note: upstream crates may add new impl of trait `coherence_lib::Remote` for type `i16` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.old.stderr b/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.old.stderr index 12c7a1f977c3f..0ec4f0bb8e74d 100644 --- a/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.old.stderr +++ b/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.old.stderr @@ -6,8 +6,6 @@ LL | impl MyTrait for T { } ... LL | impl MyTrait for lib::MyFundamentalStruct<(MyType,)> { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyFundamentalStruct<(MyType,)>` - | - = note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyFundamentalStruct<(MyType,)>` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.re.stderr b/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.re.stderr index 12c7a1f977c3f..0ec4f0bb8e74d 100644 --- a/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.re.stderr +++ b/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.re.stderr @@ -6,8 +6,6 @@ LL | impl MyTrait for T { } ... LL | impl MyTrait for lib::MyFundamentalStruct<(MyType,)> { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyFundamentalStruct<(MyType,)>` - | - = note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyFundamentalStruct<(MyType,)>` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_copy_like_err_struct.old.stderr b/src/test/ui/coherence/coherence_copy_like_err_struct.old.stderr index 1b6c62e9bf3a8..e5862fdda7c58 100644 --- a/src/test/ui/coherence/coherence_copy_like_err_struct.old.stderr +++ b/src/test/ui/coherence/coherence_copy_like_err_struct.old.stderr @@ -6,8 +6,6 @@ LL | impl MyTrait for T { } ... LL | impl MyTrait for lib::MyStruct { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyStruct` - | - = note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyStruct` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_copy_like_err_struct.re.stderr b/src/test/ui/coherence/coherence_copy_like_err_struct.re.stderr index 1b6c62e9bf3a8..e5862fdda7c58 100644 --- a/src/test/ui/coherence/coherence_copy_like_err_struct.re.stderr +++ b/src/test/ui/coherence/coherence_copy_like_err_struct.re.stderr @@ -6,8 +6,6 @@ LL | impl MyTrait for T { } ... LL | impl MyTrait for lib::MyStruct { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyStruct` - | - = note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyStruct` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_copy_like_err_tuple.old.stderr b/src/test/ui/coherence/coherence_copy_like_err_tuple.old.stderr index 11bd788c76153..a3c4ef8e105a2 100644 --- a/src/test/ui/coherence/coherence_copy_like_err_tuple.old.stderr +++ b/src/test/ui/coherence/coherence_copy_like_err_tuple.old.stderr @@ -6,8 +6,6 @@ LL | impl MyTrait for T { } ... LL | impl MyTrait for (MyType,) { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(MyType,)` - | - = note: upstream crates may add new impl of trait `lib::MyCopy` for type `(MyType,)` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_copy_like_err_tuple.re.stderr b/src/test/ui/coherence/coherence_copy_like_err_tuple.re.stderr index 11bd788c76153..a3c4ef8e105a2 100644 --- a/src/test/ui/coherence/coherence_copy_like_err_tuple.re.stderr +++ b/src/test/ui/coherence/coherence_copy_like_err_tuple.re.stderr @@ -6,8 +6,6 @@ LL | impl MyTrait for T { } ... LL | impl MyTrait for (MyType,) { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(MyType,)` - | - = note: upstream crates may add new impl of trait `lib::MyCopy` for type `(MyType,)` in future versions error: aborting due to previous error diff --git a/src/test/ui/issues/issue-48728.stderr b/src/test/ui/issues/issue-48728.stderr index 99a9bf9903e25..777e1fc9c27ea 100644 --- a/src/test/ui/issues/issue-48728.stderr +++ b/src/test/ui/issues/issue-48728.stderr @@ -6,8 +6,6 @@ LL | #[derive(Clone)] ... LL | impl Clone for Node<[T]> { | ------------------------------------------- first implementation here - | - = note: upstream crates may add new impl of trait `std::clone::Clone` for type `[_]` in future versions error: aborting due to previous error diff --git a/src/test/ui/specialization/issue-52050.stderr b/src/test/ui/specialization/issue-52050.stderr index dcb34f3ad4836..583c580d341ba 100644 --- a/src/test/ui/specialization/issue-52050.stderr +++ b/src/test/ui/specialization/issue-52050.stderr @@ -10,8 +10,6 @@ LL | | } LL | LL | impl IntoPyDictPointer for () | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()` - | - = note: upstream crates may add new impl of trait `std::iter::Iterator` for type `()` in future versions error: aborting due to previous error From 3c119443767553d31c4c028a7c5519750897fc0a Mon Sep 17 00:00:00 2001 From: Ferdia McKeogh Date: Tue, 16 Jul 2019 07:51:13 +0200 Subject: [PATCH 2/2] Suggested change --- src/librustc/traits/specialize/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 9027d330a90f6..8a84fca143809 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -367,10 +367,11 @@ pub(super) fn specialization_graph_provider( } let access_levels = tcx.privacy_access_levels(impl_def_id.krate); - let id = tcx.hir().as_local_hir_id(impl_def_id).unwrap(); - if access_levels.is_exported(id) || access_levels.is_public(id) { - for cause in &overlap.intercrate_ambiguity_causes { - cause.add_intercrate_ambiguity_hint(&mut err); + if let Some(id) = tcx.hir().as_local_hir_id(impl_def_id) { + if access_levels.is_exported(id) || access_levels.is_public(id) { + for cause in &overlap.intercrate_ambiguity_causes { + cause.add_intercrate_ambiguity_hint(&mut err); + } } }