Fixes after rebase

This commit is contained in:
Aaron Turon 2016-03-11 15:51:35 -08:00
parent e36620dd9c
commit e5753b4605
11 changed files with 47 additions and 29 deletions

View file

@ -11,7 +11,6 @@
//! See `README.md` for high-level documentation
use super::{SelectionContext, Obligation, ObligationCause};
use super::util;
use middle::cstore::LOCAL_CRATE;
use middle::def_id::DefId;

View file

@ -433,7 +433,10 @@ pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvi
let elaborated_env = unnormalized_env.with_caller_bounds(predicates);
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(elaborated_env), ProjectionMode::AnyFinal);
let infcx = infer::new_infer_ctxt(tcx,
&tcx.tables,
Some(elaborated_env),
ProjectionMode::AnyFinal);
let predicates = match fully_normalize(&infcx,
cause,
&infcx.parameter_environment.caller_bounds) {

View file

@ -1121,7 +1121,7 @@ fn confirm_impl_candidate<'cx,'tcx>(
tcx.types.err
});
let substs = translate_substs(selcx.infcx(), impl_def_id, substs, node_item.node);
(ty.subst(tcx, &substs), nested)
(ty.subst(tcx, substs), nested)
}
None => {
tcx.sess.span_bug(obligation.cause.span,
@ -1135,7 +1135,9 @@ fn confirm_impl_candidate<'cx,'tcx>(
///
/// Based on the "projection mode", this lookup may in fact only examine the
/// topmost impl. See the comments for `ProjectionMode` for more details.
fn assoc_ty_def<'cx, 'tcx>(selcx: &SelectionContext<'cx, 'tcx>, impl_def_id: DefId, assoc_ty_name: ast::Name)
fn assoc_ty_def<'cx, 'tcx>(selcx: &SelectionContext<'cx, 'tcx>,
impl_def_id: DefId,
assoc_ty_name: ast::Name)
-> Option<specialization_graph::NodeItem<Rc<ty::AssociatedType<'tcx>>>>
{
let trait_def_id = selcx.tcx().impl_trait_ref(impl_def_id).unwrap().def_id;

View file

@ -75,9 +75,9 @@ pub struct Overlap<'a, 'tcx: 'a> {
/// resolved.
pub fn translate_substs<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
source_impl: DefId,
source_substs: Substs<'tcx>,
source_substs: &'tcx Substs<'tcx>,
target_node: specialization_graph::Node)
-> Substs<'tcx> {
-> &'tcx Substs<'tcx> {
let source_trait_ref = infcx.tcx
.impl_trait_ref(source_impl)
.unwrap()
@ -111,7 +111,7 @@ pub fn translate_substs<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
};
// directly inherent the method generics, since those do not vary across impls
target_substs.with_method_from_subst(&source_substs)
infcx.tcx.mk_substs(target_substs.with_method_from_subst(source_substs))
}
/// Is impl1 a specialization of impl2?
@ -164,7 +164,7 @@ pub fn specializes(tcx: &TyCtxt, impl1_def_id: DefId, impl2_def_id: DefId) -> bo
};
penv.caller_bounds.extend(normalization_obligations.into_iter().map(|o| o.predicate));
// Install the parameter environment, which means we take the predicates of impl1 as assumptions:
// Install the parameter environment, taking the predicates of impl1 as assumptions:
infcx.parameter_environment = penv;
// Attempt to prove that impl2 applies, given all of the above.
@ -217,7 +217,7 @@ fn fulfill_implication<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
infcx.parameter_environment.caller_bounds);
Err(())
} else {
debug!("fulfill_implication: an impl for {:?} specializes {:?} (`where` clauses elided)",
debug!("fulfill_implication: an impl for {:?} specializes {:?}",
source_trait_ref,
target_trait_ref);

View file

@ -97,7 +97,7 @@ impl Graph {
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, ProjectionMode::Topmost);
let overlap = traits::overlapping_impls(&infcx, possible_sibling, impl_def_id);
if let Some(trait_ref) = overlap {
if let Some(impl_header) = overlap {
let le = specializes(tcx, impl_def_id, possible_sibling);
let ge = specializes(tcx, possible_sibling, impl_def_id);
@ -124,7 +124,7 @@ impl Graph {
// overlap, but no specialization; error out
return Err(Overlap {
with_impl: possible_sibling,
on_trait_ref: trait_ref,
on_trait_ref: impl_header.trait_ref.unwrap(),
in_context: infcx,
});
}

View file

@ -22,6 +22,7 @@ use rustc_typeck::middle::resolve_lifetime;
use rustc_typeck::middle::stability;
use rustc_typeck::middle::subst;
use rustc_typeck::middle::subst::Subst;
use rustc_typeck::middle::traits::ProjectionMode;
use rustc_typeck::middle::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc_typeck::middle::ty::relate::TypeRelation;
use rustc_typeck::middle::infer::{self, TypeOrigin};
@ -143,7 +144,10 @@ fn test_env<F>(source_string: &str,
lang_items,
index,
|tcx| {
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
let infcx = infer::new_infer_ctxt(tcx,
&tcx.tables,
None,
ProjectionMode::AnyFinal);
body(Env { infcx: &infcx });
let free_regions = FreeRegionMap::new();
infcx.resolve_regions_and_report_errors(&free_regions,

View file

@ -13,7 +13,7 @@
use rustc::dep_graph::DepNode;
use rustc::middle::infer::{self, InferCtxt};
use rustc::middle::traits;
use rustc::middle::traits::{self, ProjectionMode};
use rustc::middle::ty::fold::TypeFoldable;
use rustc::middle::ty::{self, Ty, TyCtxt};
use rustc::mir::repr::*;
@ -582,7 +582,10 @@ impl<'tcx> MirPass<'tcx> for TypeckMir {
}
let _task = tcx.dep_graph.in_task(DepNode::MirTypeck(id));
let param_env = ty::ParameterEnvironment::for_item(tcx, id);
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(param_env));
let infcx = infer::new_infer_ctxt(tcx,
&tcx.tables,
Some(param_env),
ProjectionMode::AnyFinal);
let mut checker = TypeChecker::new(&infcx);
{
let mut verifier = TypeVerifier::new(&mut checker, mir);

View file

@ -823,7 +823,7 @@ fn do_static_trait_method_dispatch<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
impl_did,
tcx.mk_substs(callee_substs),
trait_method.name);
Some((impl_method.method.def_id, impl_method.substs))
Some((impl_method.method.def_id, &impl_method.substs))
}
// If we have a closure or a function pointer, we will also encounter
// the concrete closure/function somewhere else (during closure or fn
@ -983,7 +983,7 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
if can_have_local_instance(ccx, impl_method.method.def_id) {
Some(create_fn_trans_item(ccx,
impl_method.method.def_id,
impl_method.substs,
&impl_method.substs,
&Substs::trans_empty()))
} else {
None
@ -1163,12 +1163,12 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// the method type from the impl to substitute into.
let mth = meth::get_impl_method(tcx,
impl_def_id,
callee_substs.clone(),
callee_substs,
default_impl.name);
assert!(mth.is_provided);
let predicates = mth.method.predicates.predicates.subst(tcx, mth.substs);
let predicates = mth.method.predicates.predicates.subst(tcx, &mth.substs);
if !normalize_and_test_predicates(ccx, predicates.into_vec()) {
continue;
}

View file

@ -34,7 +34,6 @@ use trans::machine;
use trans::type_::Type;
use trans::type_of::*;
use middle::ty::{self, Ty, TyCtxt, TypeFoldable};
use middle::ty::MethodCall;
use syntax::ast::{self, Name};
use syntax::attr;
@ -110,7 +109,7 @@ pub fn callee_for_trait_impl<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// those from the impl and those from the method:
let impl_substs = vtable_impl.substs.with_method_from(&substs);
let substs = ccx.tcx().mk_substs(impl_substs);
let mth = get_impl_method(ccx.tcx(), impl_did, impl_substs, mname);
let mth = get_impl_method(ccx.tcx(), impl_did, substs, mname);
// Translate the function, bypassing Callee::def.
// That is because default methods have the same ID as the
@ -318,7 +317,7 @@ pub fn get_vtable<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
trans_fn_ref_with_substs(ccx,
mth.method.def_id,
None,
mth.substs).val
&mth.substs).val
}
None => nullptr
}
@ -431,7 +430,7 @@ pub fn get_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// The substitutions we have are on the impl, so we grab
// the method type from the impl to substitute into.
let mth = get_impl_method(tcx, impl_id, substs.clone(), name);
let mth = get_impl_method(tcx, impl_id, substs, name);
debug!("get_vtable_methods: mth={:?}", mth);
@ -441,7 +440,7 @@ pub fn get_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// method could then never be called, so we do not want to
// try and trans it, in that case. Issue #23435.
if mth.is_provided {
let predicates = mth.method.predicates.predicates.subst(tcx, mth.substs);
let predicates = mth.method.predicates.predicates.subst(tcx, &mth.substs);
if !normalize_and_test_predicates(ccx, predicates.into_vec()) {
debug!("get_vtable_methods: predicates do not hold");
return None;
@ -473,14 +472,14 @@ fn opaque_method_ty<'tcx>(tcx: &TyCtxt<'tcx>, method_ty: &ty::BareFnTy<'tcx>)
#[derive(Debug)]
pub struct ImplMethod<'tcx> {
pub method: Rc<ty::Method<'tcx>>,
pub substs: Substs<'tcx>,
pub substs: &'tcx Substs<'tcx>,
pub is_provided: bool
}
/// Locates the applicable definition of a method, given its name.
pub fn get_impl_method<'tcx>(tcx: &TyCtxt<'tcx>,
impl_def_id: DefId,
substs: Substs<'tcx>,
substs: &'tcx Substs<'tcx>,
name: Name)
-> ImplMethod<'tcx>
{

View file

@ -13,9 +13,12 @@
//! constructor provide a method with the same name.
use middle::cstore::CrateStore;
use middle::traits;
use middle::def_id::DefId;
use middle::traits::{self, ProjectionMode};
use middle::infer;
use middle::ty::{self, TyCtxt};
use syntax::ast;
use syntax::codemap::Span;
use rustc::dep_graph::DepNode;
use rustc_front::hir;
use rustc_front::intravisit;
@ -86,7 +89,10 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
for (i, &impl1_def_id) in impls.iter().enumerate() {
for &impl2_def_id in &impls[(i+1)..] {
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, None);
let infcx = infer::new_infer_ctxt(self.tcx,
&self.tcx.tables,
None,
ProjectionMode::Topmost);
if traits::overlapping_impls(&infcx, impl1_def_id, impl2_def_id).is_some() {
self.check_for_common_items_in_impls(impl1_def_id, impl2_def_id)
}
@ -117,7 +123,8 @@ impl<'cx, 'tcx,'v> intravisit::Visitor<'v> for OverlapChecker<'cx, 'tcx> {
self.tcx.span_of_impl(impl_def_id).unwrap(), E0519,
"redundant default implementations of trait `{}`:",
trait_ref);
err.span_note(self.tcx.span_of_impl(self.tcx.map.local_def_id(prev_id)).unwrap(),
err.span_note(self.tcx.span_of_impl(self.tcx.map.local_def_id(prev_id))
.unwrap(),
"redundant implementation is here:");
err.emit();
}

View file

@ -804,7 +804,8 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
convert_method(ccx, ImplContainer(def_id),
impl_item.name, impl_item.id, method_vis,
sig, impl_item.defaultness, selfty, &ty_generics, &ty_predicates);
sig, impl_item.defaultness, selfty, &ty_generics,
&ty_predicates);
}
}