Skip to content

Commit 84bfc33

Browse files
qnighynikomatsakis
authored andcommitted
Unify intercrate ambiguity emitters into a function.
1 parent 043786d commit 84bfc33

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

src/librustc/traits/select.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ pub enum IntercrateAmbiguityCause {
100100
UpstreamCrateUpdate(DefId),
101101
}
102102

103+
impl IntercrateAmbiguityCause {
104+
/// Emits notes when the overlap is caused by complex intercrate ambiguities.
105+
/// See #23980 for details.
106+
pub fn add_intercrate_ambiguity_hint<'a, 'tcx>(&self,
107+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
108+
err: &mut ::errors::DiagnosticBuilder) {
109+
match self {
110+
&IntercrateAmbiguityCause::DownstreamCrate(def_id) => {
111+
err.note(&format!("downstream crates may implement `{}`",
112+
tcx.item_path_str(def_id)));
113+
}
114+
&IntercrateAmbiguityCause::UpstreamCrateUpdate(def_id) => {
115+
err.note(&format!("upstream crates may add new impl for `{}` \
116+
in future versions",
117+
tcx.item_path_str(def_id)));
118+
}
119+
}
120+
}
121+
}
122+
103123
// A stack that walks back up the stack frame.
104124
struct TraitObligationStack<'prev, 'tcx: 'prev> {
105125
obligation: &'prev TraitObligation<'tcx>,

src/librustc/traits/specialize/mod.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -340,17 +340,7 @@ pub(super) fn specialization_graph_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
340340
}
341341

342342
for cause in &overlap.intercrate_ambiguity_causes {
343-
match cause {
344-
&IntercrateAmbiguityCause::DownstreamCrate(def_id) => {
345-
err.note(&format!("downstream crates may implement `{}`",
346-
tcx.item_path_str(def_id)));
347-
}
348-
&IntercrateAmbiguityCause::UpstreamCrateUpdate(def_id) => {
349-
err.note(&format!("upstream crates may add new impl for `{}` \
350-
in future versions",
351-
tcx.item_path_str(def_id)));
352-
}
353-
}
343+
cause.add_intercrate_ambiguity_hint(tcx, &mut err);
354344
}
355345

356346
err.emit();

src/librustc_typeck/coherence/inherent_impls_overlap.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
1212
use rustc::hir;
1313
use rustc::hir::itemlikevisit::ItemLikeVisitor;
1414
use rustc::traits;
15-
use rustc::traits::IntercrateAmbiguityCause;
1615
use rustc::ty::{self, TyCtxt};
1716

1817
pub fn crate_inherent_impls_overlap_check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -64,17 +63,7 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {
6463
format!("other definition for `{}`", name));
6564

6665
for cause in &overlap.intercrate_ambiguity_causes {
67-
match cause {
68-
&IntercrateAmbiguityCause::DownstreamCrate(def_id) => {
69-
err.note(&format!("downstream crates may implement `{}`",
70-
self.tcx.item_path_str(def_id)));
71-
}
72-
&IntercrateAmbiguityCause::UpstreamCrateUpdate(def_id) => {
73-
err.note(&format!("upstream crates may add new impl for `{}` \
74-
in future versions",
75-
self.tcx.item_path_str(def_id)));
76-
}
77-
}
66+
cause.add_intercrate_ambiguity_hint(self.tcx, &mut err);
7867
}
7968

8069
err.emit();

0 commit comments

Comments
 (0)