Fix misdetection of upstream intercrate ambiguity.

This commit is contained in:
Masaki Hara 2017-08-01 12:37:11 +04:30 committed by Niko Matsakis
parent 4d503b0c74
commit 099bb1ba8a
3 changed files with 15 additions and 10 deletions

View File

@ -31,7 +31,7 @@ use super::{VtableImplData, VtableObjectData, VtableBuiltinData, VtableGenerator
use super::util;
use dep_graph::{DepNodeIndex, DepKind};
use hir::def_id::DefId;
use hir::def_id::{DefId, LOCAL_CRATE};
use infer;
use infer::{InferCtxt, InferOk, TypeFreshener};
use ty::subst::{Kind, Subst, Substs};
@ -1069,13 +1069,18 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
if !candidate_set.ambiguous && candidate_set.vec.is_empty() {
let trait_ref = stack.obligation.predicate.skip_binder().trait_ref;
let self_ty = trait_ref.self_ty();
let cause = IntercrateAmbiguityCause::UpstreamCrateUpdate {
trait_desc: trait_ref.to_string(),
self_desc: if self_ty.has_concrete_skeleton() {
Some(self_ty.to_string())
} else {
None
},
let trait_desc = trait_ref.to_string();
let self_desc = if self_ty.has_concrete_skeleton() {
Some(self_ty.to_string())
} else {
None
};
let cause = if
trait_ref.def_id.krate != LOCAL_CRATE &&
!self.tcx().has_attr(trait_ref.def_id, "fundamental") {
IntercrateAmbiguityCause::UpstreamCrateUpdate { trait_desc, self_desc }
} else {
IntercrateAmbiguityCause::DownstreamCrate { trait_desc, self_desc }
};
self.intercrate_ambiguity_causes.push(cause);
}

View File

@ -19,7 +19,7 @@ struct Cake<X>(X);
impl<T:Sugar> Cake<T> { fn dummy(&self) { } }
//~^ ERROR E0592
//~| NOTE duplicate definitions for `dummy`
//~| NOTE upstream crates may add new impl of trait `Sugar` for type `std::boxed::Box<_>`
//~| NOTE downstream crates may implement trait `Sugar` for type `std::boxed::Box<_>`
impl<U:Sugar> Cake<Box<U>> { fn dummy(&self) { } }
//~^ NOTE other definition for `dummy`

View File

@ -19,6 +19,6 @@ impl<T:Sugar> Sweet for T { }
impl<U:Sugar> Sweet for Box<U> { }
//~^ ERROR E0119
//~| NOTE conflicting implementation for `std::boxed::Box<_>`
//~| NOTE upstream crates may add new impl of trait `Sugar` for type `std::boxed::Box<_>`
//~| NOTE downstream crates may implement trait `Sugar` for type `std::boxed::Box<_>`
fn main() { }