mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-24 14:32:21 +03:00
Unify intercrate ambiguity emitters into a function.
This commit is contained in:
committed by
Niko Matsakis
parent
043786dcdf
commit
84bfc33fac
@@ -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;
|
||||
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 @@ enum Namespace {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user