Fix @nikomatsakis' nits in typeck.
This commit is contained in:
parent
09ad993a25
commit
923616e188
3 changed files with 27 additions and 36 deletions
|
@ -622,7 +622,7 @@ pub fn instantiate_trait_ref<'tcx>(
|
||||||
-> Rc<ty::TraitRef<'tcx>>
|
-> Rc<ty::TraitRef<'tcx>>
|
||||||
{
|
{
|
||||||
let path = &trait_ref.path;
|
let path = &trait_ref.path;
|
||||||
match ::lookup_def_tcx(this.tcx(), path.span, trait_ref.ref_id) {
|
match ::lookup_full_def(this.tcx(), path.span, trait_ref.ref_id) {
|
||||||
def::DefTrait(trait_def_id) => {
|
def::DefTrait(trait_def_id) => {
|
||||||
let trait_ref = ast_path_to_trait_ref(this,
|
let trait_ref = ast_path_to_trait_ref(this,
|
||||||
rscope,
|
rscope,
|
||||||
|
@ -899,7 +899,10 @@ fn ast_ty_to_trait_ref<'tcx>(this: &AstConv<'tcx>,
|
||||||
|
|
||||||
match ty.node {
|
match ty.node {
|
||||||
ast::TyPath(None, ref path) => {
|
ast::TyPath(None, ref path) => {
|
||||||
let def = this.tcx().def_map.borrow().get(&ty.id).map(|d| d.full_def());
|
let def = match this.tcx().def_map.borrow().get(&ty.id) {
|
||||||
|
Some(&def::PathResolution { base_def, depth: 0, .. }) => Some(base_def),
|
||||||
|
_ => None
|
||||||
|
};
|
||||||
match def {
|
match def {
|
||||||
Some(def::DefTrait(trait_def_id)) => {
|
Some(def::DefTrait(trait_def_id)) => {
|
||||||
let mut projection_bounds = Vec::new();
|
let mut projection_bounds = Vec::new();
|
||||||
|
@ -1202,7 +1205,10 @@ pub fn finish_resolving_def_to_ty<'tcx>(this: &AstConv<'tcx>,
|
||||||
segments.last().unwrap())
|
segments.last().unwrap())
|
||||||
}
|
}
|
||||||
def::DefMod(id) => {
|
def::DefMod(id) => {
|
||||||
// Used as sentinel by callers to indicate the `<T>::a::b::c` form.
|
// Used as sentinel by callers to indicate the `<T>::A::B::C` form.
|
||||||
|
// FIXME(#22519) This part of the resolution logic should be
|
||||||
|
// avoided entirely for that form, once we stop needed a Def
|
||||||
|
// for `associated_path_def_to_ty`.
|
||||||
if segments.is_empty() {
|
if segments.is_empty() {
|
||||||
opt_self_ty.expect("missing T in <T>::a::b::c")
|
opt_self_ty.expect("missing T in <T>::a::b::c")
|
||||||
} else {
|
} else {
|
||||||
|
@ -1890,7 +1896,7 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
|
||||||
for ast_bound in ast_bounds {
|
for ast_bound in ast_bounds {
|
||||||
match *ast_bound {
|
match *ast_bound {
|
||||||
ast::TraitTyParamBound(ref b, ast::TraitBoundModifier::None) => {
|
ast::TraitTyParamBound(ref b, ast::TraitBoundModifier::None) => {
|
||||||
match ::lookup_def_tcx(tcx, b.trait_ref.path.span, b.trait_ref.ref_id) {
|
match ::lookup_full_def(tcx, b.trait_ref.path.span, b.trait_ref.ref_id) {
|
||||||
def::DefTrait(trait_did) => {
|
def::DefTrait(trait_did) => {
|
||||||
match trait_def_ids.get(&trait_did) {
|
match trait_def_ids.get(&trait_did) {
|
||||||
// Already seen this trait. We forbid
|
// Already seen this trait. We forbid
|
||||||
|
|
|
@ -103,7 +103,7 @@ use middle::ty::{MethodCall, MethodCallee, MethodMap, ObjectCastMap};
|
||||||
use middle::ty_fold::{TypeFolder, TypeFoldable};
|
use middle::ty_fold::{TypeFolder, TypeFoldable};
|
||||||
use rscope::RegionScope;
|
use rscope::RegionScope;
|
||||||
use session::Session;
|
use session::Session;
|
||||||
use {CrateCtxt, lookup_def_ccx, require_same_types};
|
use {CrateCtxt, lookup_full_def, require_same_types};
|
||||||
use TypeAndSubsts;
|
use TypeAndSubsts;
|
||||||
use lint;
|
use lint;
|
||||||
use util::common::{block_query, indenter, loop_query};
|
use util::common::{block_query, indenter, loop_query};
|
||||||
|
@ -3401,7 +3401,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
|
||||||
ast::ExprPath(None, ref path) => {
|
ast::ExprPath(None, ref path) => {
|
||||||
// FIXME(pcwalton): For now we hardcode the two permissible
|
// FIXME(pcwalton): For now we hardcode the two permissible
|
||||||
// places: the exchange heap and the managed heap.
|
// places: the exchange heap and the managed heap.
|
||||||
let definition = lookup_def(fcx, path.span, place.id);
|
let definition = lookup_full_def(tcx, path.span, place.id);
|
||||||
let def_id = definition.def_id();
|
let def_id = definition.def_id();
|
||||||
let referent_ty = fcx.expr_ty(&**subexpr);
|
let referent_ty = fcx.expr_ty(&**subexpr);
|
||||||
if tcx.lang_items.exchange_heap() == Some(def_id) {
|
if tcx.lang_items.exchange_heap() == Some(def_id) {
|
||||||
|
@ -3884,14 +3884,14 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
|
||||||
}
|
}
|
||||||
ast::ExprStruct(ref path, ref fields, ref base_expr) => {
|
ast::ExprStruct(ref path, ref fields, ref base_expr) => {
|
||||||
// Resolve the path.
|
// Resolve the path.
|
||||||
let def = tcx.def_map.borrow().get(&id).map(|d| d.full_def());
|
let def = lookup_full_def(tcx, path.span, id);
|
||||||
let struct_id = match def {
|
let struct_id = match def {
|
||||||
Some(def::DefVariant(enum_id, variant_id, true)) => {
|
def::DefVariant(enum_id, variant_id, true) => {
|
||||||
check_struct_enum_variant(fcx, id, expr.span, enum_id,
|
check_struct_enum_variant(fcx, id, expr.span, enum_id,
|
||||||
variant_id, &fields[..]);
|
variant_id, &fields[..]);
|
||||||
enum_id
|
enum_id
|
||||||
}
|
}
|
||||||
Some(def::DefTrait(def_id)) => {
|
def::DefTrait(def_id) => {
|
||||||
span_err!(tcx.sess, path.span, E0159,
|
span_err!(tcx.sess, path.span, E0159,
|
||||||
"use of trait `{}` as a struct constructor",
|
"use of trait `{}` as a struct constructor",
|
||||||
pprust::path_to_string(path));
|
pprust::path_to_string(path));
|
||||||
|
@ -3901,7 +3901,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
|
||||||
base_expr);
|
base_expr);
|
||||||
def_id
|
def_id
|
||||||
},
|
},
|
||||||
Some(def) => {
|
def => {
|
||||||
// Verify that this was actually a struct.
|
// Verify that this was actually a struct.
|
||||||
let typ = ty::lookup_item_type(fcx.ccx.tcx, def.def_id());
|
let typ = ty::lookup_item_type(fcx.ccx.tcx, def.def_id());
|
||||||
match typ.ty.sty {
|
match typ.ty.sty {
|
||||||
|
@ -3926,10 +3926,6 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
|
||||||
|
|
||||||
def.def_id()
|
def.def_id()
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
tcx.sess.span_bug(path.span,
|
|
||||||
"structure constructor wasn't resolved")
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Turn the path into a type and verify that that type unifies with
|
// Turn the path into a type and verify that that type unifies with
|
||||||
|
@ -4643,10 +4639,6 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
|
||||||
check_instantiable(ccx.tcx, sp, id);
|
check_instantiable(ccx.tcx, sp, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lookup_def(fcx: &FnCtxt, sp: Span, id: ast::NodeId) -> def::Def {
|
|
||||||
lookup_def_ccx(fcx.ccx, sp, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the type parameter count and the type for the given definition.
|
// Returns the type parameter count and the type for the given definition.
|
||||||
fn type_scheme_and_predicates_for_def<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
fn type_scheme_and_predicates_for_def<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
|
@ -5171,18 +5163,15 @@ pub fn may_break(cx: &ty::ctxt, id: ast::NodeId, b: &ast::Block) -> bool {
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
})) ||
|
})) ||
|
||||||
// Second: is there a labeled break with label
|
// Second: is there a labeled break with label
|
||||||
// <id> nested anywhere inside the loop?
|
// <id> nested anywhere inside the loop?
|
||||||
(block_query(b, |e| {
|
(block_query(b, |e| {
|
||||||
match e.node {
|
if let ast::ExprBreak(Some(_)) = e.node {
|
||||||
ast::ExprBreak(Some(_)) => {
|
lookup_full_def(cx, e.span, e.id) == def::DefLabel(id)
|
||||||
match cx.def_map.borrow().get(&e.id).map(|d| d.full_def()) {
|
} else {
|
||||||
Some(def::DefLabel(loop_id)) if id == loop_id => true,
|
false
|
||||||
_ => false,
|
}
|
||||||
}
|
}))
|
||||||
}
|
|
||||||
_ => false
|
|
||||||
}}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_bounds_are_used<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
pub fn check_bounds_are_used<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
||||||
|
|
|
@ -163,20 +163,16 @@ fn write_substs_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||||
tcx.item_substs.borrow_mut().insert(node_id, item_substs);
|
tcx.item_substs.borrow_mut().insert(node_id, item_substs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def {
|
|
||||||
|
fn lookup_full_def(tcx: &ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def {
|
||||||
match tcx.def_map.borrow().get(&id) {
|
match tcx.def_map.borrow().get(&id) {
|
||||||
Some(x) => x.full_def(),
|
Some(x) => x.full_def(),
|
||||||
_ => {
|
None => {
|
||||||
span_fatal!(tcx.sess, sp, E0242, "internal error looking up a definition")
|
span_fatal!(tcx.sess, sp, E0242, "internal error looking up a definition")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lookup_def_ccx(ccx: &CrateCtxt, sp: Span, id: ast::NodeId)
|
|
||||||
-> def::Def {
|
|
||||||
lookup_def_tcx(ccx.tcx, sp, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn require_same_types<'a, 'tcx, M>(tcx: &ty::ctxt<'tcx>,
|
fn require_same_types<'a, 'tcx, M>(tcx: &ty::ctxt<'tcx>,
|
||||||
maybe_infcx: Option<&infer::InferCtxt<'a, 'tcx>>,
|
maybe_infcx: Option<&infer::InferCtxt<'a, 'tcx>>,
|
||||||
t1_is_expected: bool,
|
t1_is_expected: bool,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue