about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMasaki Hara <ackie.h.gmai@gmail.com>2017-07-25 16:52:36 +0900
committerNiko Matsakis <niko@alum.mit.edu>2017-09-05 12:19:35 -0400
commit84bfc33face2cecadace55af6efd1db5fb3aee6f (patch)
tree054429b57971f811e5b41466f12cfac207fac74b /src
parent043786dcdfbb245cb13d54fa0cfb8a198e8a479b (diff)
downloadrust-84bfc33face2cecadace55af6efd1db5fb3aee6f.tar.gz
rust-84bfc33face2cecadace55af6efd1db5fb3aee6f.zip
Unify intercrate ambiguity emitters into a function.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/traits/select.rs20
-rw-r--r--src/librustc/traits/specialize/mod.rs12
-rw-r--r--src/librustc_typeck/coherence/inherent_impls_overlap.rs13
3 files changed, 22 insertions, 23 deletions
diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs
index 6815cb8c55e..366bb6aeb5c 100644
--- a/src/librustc/traits/select.rs
+++ b/src/librustc/traits/select.rs
@@ -100,6 +100,26 @@ pub enum IntercrateAmbiguityCause {
     UpstreamCrateUpdate(DefId),
 }
 
+impl IntercrateAmbiguityCause {
+    /// Emits notes when the overlap is caused by complex intercrate ambiguities.
+    /// See #23980 for details.
+    pub fn add_intercrate_ambiguity_hint<'a, 'tcx>(&self,
+                                                   tcx: TyCtxt<'a, 'tcx, 'tcx>,
+                                                   err: &mut ::errors::DiagnosticBuilder) {
+        match self {
+            &IntercrateAmbiguityCause::DownstreamCrate(def_id) => {
+                err.note(&format!("downstream crates may implement `{}`",
+                                  tcx.item_path_str(def_id)));
+            }
+            &IntercrateAmbiguityCause::UpstreamCrateUpdate(def_id) => {
+                err.note(&format!("upstream crates may add new impl for `{}` \
+                                  in future versions",
+                                  tcx.item_path_str(def_id)));
+            }
+        }
+    }
+}
+
 // A stack that walks back up the stack frame.
 struct TraitObligationStack<'prev, 'tcx: 'prev> {
     obligation: &'prev TraitObligation<'tcx>,
diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs
index 1c79190fd93..98d8c64634c 100644
--- a/src/librustc/traits/specialize/mod.rs
+++ b/src/librustc/traits/specialize/mod.rs
@@ -340,17 +340,7 @@ pub(super) fn specialization_graph_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
                 }
 
                 for cause in &overlap.intercrate_ambiguity_causes {
-                    match cause {
-                        &IntercrateAmbiguityCause::DownstreamCrate(def_id) => {
-                            err.note(&format!("downstream crates may implement `{}`",
-                                              tcx.item_path_str(def_id)));
-                        }
-                        &IntercrateAmbiguityCause::UpstreamCrateUpdate(def_id) => {
-                            err.note(&format!("upstream crates may add new impl for `{}` \
-                                              in future versions",
-                                              tcx.item_path_str(def_id)));
-                        }
-                    }
+                    cause.add_intercrate_ambiguity_hint(tcx, &mut err);
                 }
 
                 err.emit();
diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs
index e733b5328d3..0fad16c9582 100644
--- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs
+++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs
@@ -12,7 +12,6 @@ use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
 use rustc::hir;
 use rustc::hir::itemlikevisit::ItemLikeVisitor;
 use rustc::traits;
-use rustc::traits::IntercrateAmbiguityCause;
 use rustc::ty::{self, TyCtxt};
 
 pub fn crate_inherent_impls_overlap_check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -64,17 +63,7 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {
                                    format!("other definition for `{}`", name));
 
                     for cause in &overlap.intercrate_ambiguity_causes {
-                        match cause {
-                            &IntercrateAmbiguityCause::DownstreamCrate(def_id) => {
-                                err.note(&format!("downstream crates may implement `{}`",
-                                                  self.tcx.item_path_str(def_id)));
-                            }
-                            &IntercrateAmbiguityCause::UpstreamCrateUpdate(def_id) => {
-                                err.note(&format!("upstream crates may add new impl for `{}` \
-                                                  in future versions",
-                                                  self.tcx.item_path_str(def_id)));
-                            }
-                        }
+                        cause.add_intercrate_ambiguity_hint(self.tcx, &mut err);
                     }
 
                     err.emit();