Unify intercrate ambiguity emitters into a function.
This commit is contained in:
parent
043786dcdf
commit
84bfc33fac
3 changed files with 22 additions and 23 deletions
|
@ -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>,
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue