1
Fork 0

Unify intercrate ambiguity emitters into a function.

This commit is contained in:
Masaki Hara 2017-07-25 16:52:36 +09:00 committed by Niko Matsakis
parent 043786dcdf
commit 84bfc33fac
3 changed files with 22 additions and 23 deletions

View file

@ -100,6 +100,26 @@ pub enum IntercrateAmbiguityCause {
UpstreamCrateUpdate(DefId), 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. // A stack that walks back up the stack frame.
struct TraitObligationStack<'prev, 'tcx: 'prev> { struct TraitObligationStack<'prev, 'tcx: 'prev> {
obligation: &'prev TraitObligation<'tcx>, obligation: &'prev TraitObligation<'tcx>,

View file

@ -340,17 +340,7 @@ pub(super) fn specialization_graph_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
} }
for cause in &overlap.intercrate_ambiguity_causes { for cause in &overlap.intercrate_ambiguity_causes {
match cause { cause.add_intercrate_ambiguity_hint(tcx, &mut err);
&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)));
}
}
} }
err.emit(); err.emit();

View file

@ -12,7 +12,6 @@ use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc::hir; use rustc::hir;
use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::itemlikevisit::ItemLikeVisitor;
use rustc::traits; use rustc::traits;
use rustc::traits::IntercrateAmbiguityCause;
use rustc::ty::{self, TyCtxt}; use rustc::ty::{self, TyCtxt};
pub fn crate_inherent_impls_overlap_check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, 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)); format!("other definition for `{}`", name));
for cause in &overlap.intercrate_ambiguity_causes { for cause in &overlap.intercrate_ambiguity_causes {
match cause { cause.add_intercrate_ambiguity_hint(self.tcx, &mut err);
&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)));
}
}
} }
err.emit(); err.emit();