Add an intital HIR and lowering step
This commit is contained in:
parent
cfd76b364c
commit
facdf2ebb1
160 changed files with 13917 additions and 4451 deletions
|
|
@ -72,7 +72,10 @@ use syntax::{abi, ast};
|
|||
use syntax::codemap::{Span, Pos};
|
||||
use syntax::feature_gate::emit_feature_err;
|
||||
use syntax::parse::token;
|
||||
use syntax::print::pprust;
|
||||
|
||||
use rustc_front::print::pprust;
|
||||
use rustc_front::hir;
|
||||
|
||||
|
||||
pub trait AstConv<'tcx> {
|
||||
fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx>;
|
||||
|
|
@ -152,7 +155,7 @@ pub trait AstConv<'tcx> {
|
|||
-> Ty<'tcx>;
|
||||
}
|
||||
|
||||
pub fn ast_region_to_region(tcx: &ty::ctxt, lifetime: &ast::Lifetime)
|
||||
pub fn ast_region_to_region(tcx: &ty::ctxt, lifetime: &hir::Lifetime)
|
||||
-> ty::Region {
|
||||
let r = match tcx.named_region_map.get(&lifetime.id) {
|
||||
None => {
|
||||
|
|
@ -250,7 +253,7 @@ pub fn opt_ast_region_to_region<'tcx>(
|
|||
this: &AstConv<'tcx>,
|
||||
rscope: &RegionScope,
|
||||
default_span: Span,
|
||||
opt_lifetime: &Option<ast::Lifetime>) -> ty::Region
|
||||
opt_lifetime: &Option<hir::Lifetime>) -> ty::Region
|
||||
{
|
||||
let r = match *opt_lifetime {
|
||||
Some(ref lifetime) => {
|
||||
|
|
@ -285,7 +288,7 @@ pub fn ast_path_substs_for_ty<'tcx>(
|
|||
span: Span,
|
||||
param_mode: PathParamMode,
|
||||
decl_generics: &ty::Generics<'tcx>,
|
||||
item_segment: &ast::PathSegment)
|
||||
item_segment: &hir::PathSegment)
|
||||
-> Substs<'tcx>
|
||||
{
|
||||
let tcx = this.tcx();
|
||||
|
|
@ -302,10 +305,10 @@ pub fn ast_path_substs_for_ty<'tcx>(
|
|||
assert!(decl_generics.types.all(|d| d.space != FnSpace));
|
||||
|
||||
let (regions, types, assoc_bindings) = match item_segment.parameters {
|
||||
ast::AngleBracketedParameters(ref data) => {
|
||||
hir::AngleBracketedParameters(ref data) => {
|
||||
convert_angle_bracketed_parameters(this, rscope, span, decl_generics, data)
|
||||
}
|
||||
ast::ParenthesizedParameters(..) => {
|
||||
hir::ParenthesizedParameters(..) => {
|
||||
span_err!(tcx.sess, span, E0214,
|
||||
"parenthesized parameters may only be used with a trait");
|
||||
let ty_param_defs = decl_generics.types.get_slice(TypeSpace);
|
||||
|
|
@ -490,7 +493,7 @@ fn convert_angle_bracketed_parameters<'tcx>(this: &AstConv<'tcx>,
|
|||
rscope: &RegionScope,
|
||||
span: Span,
|
||||
decl_generics: &ty::Generics<'tcx>,
|
||||
data: &ast::AngleBracketedParameterData)
|
||||
data: &hir::AngleBracketedParameterData)
|
||||
-> (Substs<'tcx>,
|
||||
Vec<Ty<'tcx>>,
|
||||
Vec<ConvertedBinding<'tcx>>)
|
||||
|
|
@ -562,7 +565,7 @@ fn find_implied_output_region<'tcx>(tcx: &ty::ctxt<'tcx>,
|
|||
|
||||
fn convert_ty_with_lifetime_elision<'tcx>(this: &AstConv<'tcx>,
|
||||
elided_lifetime: ElidedLifetime,
|
||||
ty: &ast::Ty)
|
||||
ty: &hir::Ty)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
match elided_lifetime {
|
||||
|
|
@ -584,7 +587,7 @@ fn convert_parenthesized_parameters<'tcx>(this: &AstConv<'tcx>,
|
|||
rscope: &RegionScope,
|
||||
span: Span,
|
||||
decl_generics: &ty::Generics<'tcx>,
|
||||
data: &ast::ParenthesizedParameterData)
|
||||
data: &hir::ParenthesizedParameterData)
|
||||
-> (Substs<'tcx>,
|
||||
Vec<Ty<'tcx>>,
|
||||
Vec<ConvertedBinding<'tcx>>)
|
||||
|
|
@ -628,7 +631,7 @@ fn convert_parenthesized_parameters<'tcx>(this: &AstConv<'tcx>,
|
|||
pub fn instantiate_poly_trait_ref<'tcx>(
|
||||
this: &AstConv<'tcx>,
|
||||
rscope: &RegionScope,
|
||||
ast_trait_ref: &ast::PolyTraitRef,
|
||||
ast_trait_ref: &hir::PolyTraitRef,
|
||||
self_ty: Option<Ty<'tcx>>,
|
||||
poly_projections: &mut Vec<ty::PolyProjectionPredicate<'tcx>>)
|
||||
-> ty::PolyTraitRef<'tcx>
|
||||
|
|
@ -654,7 +657,7 @@ pub fn instantiate_poly_trait_ref<'tcx>(
|
|||
pub fn instantiate_mono_trait_ref<'tcx>(
|
||||
this: &AstConv<'tcx>,
|
||||
rscope: &RegionScope,
|
||||
trait_ref: &ast::TraitRef,
|
||||
trait_ref: &hir::TraitRef,
|
||||
self_ty: Option<Ty<'tcx>>)
|
||||
-> ty::TraitRef<'tcx>
|
||||
{
|
||||
|
|
@ -668,7 +671,7 @@ pub fn instantiate_mono_trait_ref<'tcx>(
|
|||
trait_ref.path.segments.last().unwrap())
|
||||
}
|
||||
|
||||
fn trait_def_id<'tcx>(this: &AstConv<'tcx>, trait_ref: &ast::TraitRef) -> DefId {
|
||||
fn trait_def_id<'tcx>(this: &AstConv<'tcx>, trait_ref: &hir::TraitRef) -> DefId {
|
||||
let path = &trait_ref.path;
|
||||
match ::lookup_full_def(this.tcx(), path.span, trait_ref.ref_id) {
|
||||
def::DefTrait(trait_def_id) => trait_def_id,
|
||||
|
|
@ -685,7 +688,7 @@ fn object_path_to_poly_trait_ref<'a,'tcx>(
|
|||
span: Span,
|
||||
param_mode: PathParamMode,
|
||||
trait_def_id: DefId,
|
||||
trait_segment: &ast::PathSegment,
|
||||
trait_segment: &hir::PathSegment,
|
||||
mut projections: &mut Vec<ty::PolyProjectionPredicate<'tcx>>)
|
||||
-> ty::PolyTraitRef<'tcx>
|
||||
{
|
||||
|
|
@ -706,7 +709,7 @@ fn ast_path_to_poly_trait_ref<'a,'tcx>(
|
|||
param_mode: PathParamMode,
|
||||
trait_def_id: DefId,
|
||||
self_ty: Option<Ty<'tcx>>,
|
||||
trait_segment: &ast::PathSegment,
|
||||
trait_segment: &hir::PathSegment,
|
||||
poly_projections: &mut Vec<ty::PolyProjectionPredicate<'tcx>>)
|
||||
-> ty::PolyTraitRef<'tcx>
|
||||
{
|
||||
|
|
@ -752,7 +755,7 @@ fn ast_path_to_mono_trait_ref<'a,'tcx>(this: &AstConv<'tcx>,
|
|||
param_mode: PathParamMode,
|
||||
trait_def_id: DefId,
|
||||
self_ty: Option<Ty<'tcx>>,
|
||||
trait_segment: &ast::PathSegment)
|
||||
trait_segment: &hir::PathSegment)
|
||||
-> ty::TraitRef<'tcx>
|
||||
{
|
||||
let (substs, assoc_bindings) =
|
||||
|
|
@ -773,7 +776,7 @@ fn create_substs_for_ast_trait_ref<'a,'tcx>(this: &AstConv<'tcx>,
|
|||
param_mode: PathParamMode,
|
||||
trait_def_id: DefId,
|
||||
self_ty: Option<Ty<'tcx>>,
|
||||
trait_segment: &ast::PathSegment)
|
||||
trait_segment: &hir::PathSegment)
|
||||
-> (&'tcx Substs<'tcx>, Vec<ConvertedBinding<'tcx>>)
|
||||
{
|
||||
debug!("create_substs_for_ast_trait_ref(trait_segment={:?})",
|
||||
|
|
@ -789,7 +792,7 @@ fn create_substs_for_ast_trait_ref<'a,'tcx>(this: &AstConv<'tcx>,
|
|||
};
|
||||
|
||||
let (regions, types, assoc_bindings) = match trait_segment.parameters {
|
||||
ast::AngleBracketedParameters(ref data) => {
|
||||
hir::AngleBracketedParameters(ref data) => {
|
||||
// For now, require that parenthetical notation be used
|
||||
// only with `Fn()` etc.
|
||||
if !this.tcx().sess.features.borrow().unboxed_closures && trait_def.paren_sugar {
|
||||
|
|
@ -802,7 +805,7 @@ fn create_substs_for_ast_trait_ref<'a,'tcx>(this: &AstConv<'tcx>,
|
|||
|
||||
convert_angle_bracketed_parameters(this, rscope, span, &trait_def.generics, data)
|
||||
}
|
||||
ast::ParenthesizedParameters(ref data) => {
|
||||
hir::ParenthesizedParameters(ref data) => {
|
||||
// For now, require that parenthetical notation be used
|
||||
// only with `Fn()` etc.
|
||||
if !this.tcx().sess.features.borrow().unboxed_closures && !trait_def.paren_sugar {
|
||||
|
|
@ -920,7 +923,7 @@ fn ast_path_to_ty<'tcx>(
|
|||
span: Span,
|
||||
param_mode: PathParamMode,
|
||||
did: DefId,
|
||||
item_segment: &ast::PathSegment)
|
||||
item_segment: &hir::PathSegment)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
let tcx = this.tcx();
|
||||
|
|
@ -953,8 +956,8 @@ type TraitAndProjections<'tcx> = (ty::PolyTraitRef<'tcx>, Vec<ty::PolyProjection
|
|||
|
||||
fn ast_ty_to_trait_ref<'tcx>(this: &AstConv<'tcx>,
|
||||
rscope: &RegionScope,
|
||||
ty: &ast::Ty,
|
||||
bounds: &[ast::TyParamBound])
|
||||
ty: &hir::Ty,
|
||||
bounds: &[hir::TyParamBound])
|
||||
-> Result<TraitAndProjections<'tcx>, ErrorReported>
|
||||
{
|
||||
/*!
|
||||
|
|
@ -969,7 +972,7 @@ fn ast_ty_to_trait_ref<'tcx>(this: &AstConv<'tcx>,
|
|||
*/
|
||||
|
||||
match ty.node {
|
||||
ast::TyPath(None, ref path) => {
|
||||
hir::TyPath(None, ref path) => {
|
||||
let def = match this.tcx().def_map.borrow().get(&ty.id) {
|
||||
Some(&def::PathResolution { base_def, depth: 0, .. }) => Some(base_def),
|
||||
_ => None
|
||||
|
|
@ -997,8 +1000,8 @@ fn ast_ty_to_trait_ref<'tcx>(this: &AstConv<'tcx>,
|
|||
"expected a path on the left-hand side of `+`, not `{}`",
|
||||
pprust::ty_to_string(ty));
|
||||
let hi = bounds.iter().map(|x| match *x {
|
||||
ast::TraitTyParamBound(ref tr, _) => tr.span.hi,
|
||||
ast::RegionTyParamBound(ref r) => r.span.hi,
|
||||
hir::TraitTyParamBound(ref tr, _) => tr.span.hi,
|
||||
hir::RegionTyParamBound(ref r) => r.span.hi,
|
||||
}).max_by(|x| x.to_usize());
|
||||
let full_span = hi.map(|hi| Span {
|
||||
lo: ty.span.lo,
|
||||
|
|
@ -1006,8 +1009,8 @@ fn ast_ty_to_trait_ref<'tcx>(this: &AstConv<'tcx>,
|
|||
expn_id: ty.span.expn_id,
|
||||
});
|
||||
match (&ty.node, full_span) {
|
||||
(&ast::TyRptr(None, ref mut_ty), Some(full_span)) => {
|
||||
let mutbl_str = if mut_ty.mutbl == ast::MutMutable { "mut " } else { "" };
|
||||
(&hir::TyRptr(None, ref mut_ty), Some(full_span)) => {
|
||||
let mutbl_str = if mut_ty.mutbl == hir::MutMutable { "mut " } else { "" };
|
||||
this.tcx().sess
|
||||
.span_suggestion(full_span, "try adding parentheses (per RFC 438):",
|
||||
format!("&{}({} +{})",
|
||||
|
|
@ -1015,8 +1018,8 @@ fn ast_ty_to_trait_ref<'tcx>(this: &AstConv<'tcx>,
|
|||
pprust::ty_to_string(&*mut_ty.ty),
|
||||
pprust::bounds_to_string(bounds)));
|
||||
}
|
||||
(&ast::TyRptr(Some(ref lt), ref mut_ty), Some(full_span)) => {
|
||||
let mutbl_str = if mut_ty.mutbl == ast::MutMutable { "mut " } else { "" };
|
||||
(&hir::TyRptr(Some(ref lt), ref mut_ty), Some(full_span)) => {
|
||||
let mutbl_str = if mut_ty.mutbl == hir::MutMutable { "mut " } else { "" };
|
||||
this.tcx().sess
|
||||
.span_suggestion(full_span, "try adding parentheses (per RFC 438):",
|
||||
format!("&{} {}({} +{})",
|
||||
|
|
@ -1041,7 +1044,7 @@ fn trait_ref_to_object_type<'tcx>(this: &AstConv<'tcx>,
|
|||
span: Span,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
projection_bounds: Vec<ty::PolyProjectionPredicate<'tcx>>,
|
||||
bounds: &[ast::TyParamBound])
|
||||
bounds: &[hir::TyParamBound])
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
let existential_bounds = conv_existential_bounds(this,
|
||||
|
|
@ -1199,7 +1202,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
span: Span,
|
||||
ty: Ty<'tcx>,
|
||||
ty_path_def: def::Def,
|
||||
item_segment: &ast::PathSegment)
|
||||
item_segment: &hir::PathSegment)
|
||||
-> (Ty<'tcx>, def::Def)
|
||||
{
|
||||
let tcx = this.tcx();
|
||||
|
|
@ -1280,7 +1283,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
// `ty::trait_items` used below requires information generated
|
||||
// by type collection, which may be in progress at this point.
|
||||
match tcx.map.expect_item(trait_did.node).node {
|
||||
ast::ItemTrait(_, _, _, ref trait_items) => {
|
||||
hir::ItemTrait(_, _, _, ref trait_items) => {
|
||||
let item = trait_items.iter()
|
||||
.find(|i| i.ident.name == assoc_name)
|
||||
.expect("missing associated type");
|
||||
|
|
@ -1303,8 +1306,8 @@ fn qpath_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
param_mode: PathParamMode,
|
||||
opt_self_ty: Option<Ty<'tcx>>,
|
||||
trait_def_id: DefId,
|
||||
trait_segment: &ast::PathSegment,
|
||||
item_segment: &ast::PathSegment)
|
||||
trait_segment: &hir::PathSegment,
|
||||
item_segment: &hir::PathSegment)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
let tcx = this.tcx();
|
||||
|
|
@ -1357,7 +1360,7 @@ pub fn ast_ty_arg_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
decl_generics: &ty::Generics<'tcx>,
|
||||
index: usize,
|
||||
region_substs: &Substs<'tcx>,
|
||||
ast_ty: &ast::Ty)
|
||||
ast_ty: &hir::Ty)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
let tcx = this.tcx();
|
||||
|
|
@ -1380,7 +1383,7 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
param_mode: PathParamMode,
|
||||
def: &def::Def,
|
||||
opt_self_ty: Option<Ty<'tcx>>,
|
||||
base_segments: &[ast::PathSegment])
|
||||
base_segments: &[hir::PathSegment])
|
||||
-> Ty<'tcx> {
|
||||
let tcx = this.tcx();
|
||||
|
||||
|
|
@ -1489,8 +1492,8 @@ pub fn finish_resolving_def_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
param_mode: PathParamMode,
|
||||
def: &def::Def,
|
||||
opt_self_ty: Option<Ty<'tcx>>,
|
||||
base_segments: &[ast::PathSegment],
|
||||
assoc_segments: &[ast::PathSegment])
|
||||
base_segments: &[hir::PathSegment],
|
||||
assoc_segments: &[hir::PathSegment])
|
||||
-> Ty<'tcx> {
|
||||
let mut ty = base_def_to_ty(this,
|
||||
rscope,
|
||||
|
|
@ -1521,7 +1524,7 @@ pub fn finish_resolving_def_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
/// internal notion of a type.
|
||||
pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
|
||||
rscope: &RegionScope,
|
||||
ast_ty: &ast::Ty)
|
||||
ast_ty: &hir::Ty)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
debug!("ast_ty_to_ty(id={:?}, ast_ty={:?})",
|
||||
|
|
@ -1535,10 +1538,10 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
}
|
||||
|
||||
let typ = match ast_ty.node {
|
||||
ast::TyVec(ref ty) => {
|
||||
hir::TyVec(ref ty) => {
|
||||
tcx.mk_slice(ast_ty_to_ty(this, rscope, &**ty))
|
||||
}
|
||||
ast::TyObjectSum(ref ty, ref bounds) => {
|
||||
hir::TyObjectSum(ref ty, ref bounds) => {
|
||||
match ast_ty_to_trait_ref(this, rscope, &**ty, bounds) {
|
||||
Ok((trait_ref, projection_bounds)) => {
|
||||
trait_ref_to_object_type(this,
|
||||
|
|
@ -1553,13 +1556,13 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
}
|
||||
}
|
||||
}
|
||||
ast::TyPtr(ref mt) => {
|
||||
hir::TyPtr(ref mt) => {
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: ast_ty_to_ty(this, rscope, &*mt.ty),
|
||||
mutbl: mt.mutbl
|
||||
})
|
||||
}
|
||||
ast::TyRptr(ref region, ref mt) => {
|
||||
hir::TyRptr(ref region, ref mt) => {
|
||||
let r = opt_ast_region_to_region(this, rscope, ast_ty.span, region);
|
||||
debug!("TyRef r={:?}", r);
|
||||
let rscope1 =
|
||||
|
|
@ -1569,25 +1572,25 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
let t = ast_ty_to_ty(this, rscope1, &*mt.ty);
|
||||
tcx.mk_ref(tcx.mk_region(r), ty::TypeAndMut {ty: t, mutbl: mt.mutbl})
|
||||
}
|
||||
ast::TyTup(ref fields) => {
|
||||
hir::TyTup(ref fields) => {
|
||||
let flds = fields.iter()
|
||||
.map(|t| ast_ty_to_ty(this, rscope, &**t))
|
||||
.collect();
|
||||
tcx.mk_tup(flds)
|
||||
}
|
||||
ast::TyParen(ref typ) => ast_ty_to_ty(this, rscope, &**typ),
|
||||
ast::TyBareFn(ref bf) => {
|
||||
hir::TyParen(ref typ) => ast_ty_to_ty(this, rscope, &**typ),
|
||||
hir::TyBareFn(ref bf) => {
|
||||
require_c_abi_if_variadic(tcx, &bf.decl, bf.abi, ast_ty.span);
|
||||
let bare_fn = ty_of_bare_fn(this, bf.unsafety, bf.abi, &*bf.decl);
|
||||
tcx.mk_fn(None, tcx.mk_bare_fn(bare_fn))
|
||||
}
|
||||
ast::TyPolyTraitRef(ref bounds) => {
|
||||
hir::TyPolyTraitRef(ref bounds) => {
|
||||
conv_ty_poly_trait_ref(this, rscope, ast_ty.span, bounds)
|
||||
}
|
||||
ast::TyPath(ref maybe_qself, ref path) => {
|
||||
hir::TyPath(ref maybe_qself, ref path) => {
|
||||
let path_res = if let Some(&d) = tcx.def_map.borrow().get(&ast_ty.id) {
|
||||
d
|
||||
} else if let Some(ast::QSelf { position: 0, .. }) = *maybe_qself {
|
||||
} else if let Some(hir::QSelf { position: 0, .. }) = *maybe_qself {
|
||||
// Create some fake resolution that can't possibly be a type.
|
||||
def::PathResolution {
|
||||
base_def: def::DefMod(DefId::local(ast::CRATE_NODE_ID)),
|
||||
|
|
@ -1622,7 +1625,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
|
||||
ty
|
||||
}
|
||||
ast::TyFixedLengthVec(ref ty, ref e) => {
|
||||
hir::TyFixedLengthVec(ref ty, ref e) => {
|
||||
let hint = UncheckedExprHint(tcx.types.usize);
|
||||
match const_eval::eval_const_expr_partial(tcx, &e, hint) {
|
||||
Ok(r) => {
|
||||
|
|
@ -1654,19 +1657,16 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
}
|
||||
}
|
||||
}
|
||||
ast::TyTypeof(ref _e) => {
|
||||
hir::TyTypeof(ref _e) => {
|
||||
tcx.sess.span_bug(ast_ty.span, "typeof is reserved but unimplemented");
|
||||
}
|
||||
ast::TyInfer => {
|
||||
hir::TyInfer => {
|
||||
// TyInfer also appears as the type of arguments or return
|
||||
// values in a ExprClosure, or as
|
||||
// the type of local variables. Both of these cases are
|
||||
// handled specially and will not descend into this routine.
|
||||
this.ty_infer(None, None, None, ast_ty.span)
|
||||
}
|
||||
ast::TyMac(_) => {
|
||||
tcx.sess.span_bug(ast_ty.span, "unexpanded type macro found conversion")
|
||||
}
|
||||
};
|
||||
|
||||
debug!("ast_ty_to_ty: id={:?} ty={:?}", ast_ty.id, typ);
|
||||
|
|
@ -1676,24 +1676,24 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
|
||||
pub fn ty_of_arg<'tcx>(this: &AstConv<'tcx>,
|
||||
rscope: &RegionScope,
|
||||
a: &ast::Arg,
|
||||
a: &hir::Arg,
|
||||
expected_ty: Option<Ty<'tcx>>)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
match a.ty.node {
|
||||
ast::TyInfer if expected_ty.is_some() => expected_ty.unwrap(),
|
||||
ast::TyInfer => this.ty_infer(None, None, None, a.ty.span),
|
||||
hir::TyInfer if expected_ty.is_some() => expected_ty.unwrap(),
|
||||
hir::TyInfer => this.ty_infer(None, None, None, a.ty.span),
|
||||
_ => ast_ty_to_ty(this, rscope, &*a.ty),
|
||||
}
|
||||
}
|
||||
|
||||
struct SelfInfo<'a, 'tcx> {
|
||||
untransformed_self_ty: Ty<'tcx>,
|
||||
explicit_self: &'a ast::ExplicitSelf,
|
||||
explicit_self: &'a hir::ExplicitSelf,
|
||||
}
|
||||
|
||||
pub fn ty_of_method<'tcx>(this: &AstConv<'tcx>,
|
||||
sig: &ast::MethodSig,
|
||||
sig: &hir::MethodSig,
|
||||
untransformed_self_ty: Ty<'tcx>)
|
||||
-> (ty::BareFnTy<'tcx>, ty::ExplicitSelfCategory) {
|
||||
let self_info = Some(SelfInfo {
|
||||
|
|
@ -1709,17 +1709,17 @@ pub fn ty_of_method<'tcx>(this: &AstConv<'tcx>,
|
|||
(bare_fn_ty, optional_explicit_self_category.unwrap())
|
||||
}
|
||||
|
||||
pub fn ty_of_bare_fn<'tcx>(this: &AstConv<'tcx>, unsafety: ast::Unsafety, abi: abi::Abi,
|
||||
decl: &ast::FnDecl) -> ty::BareFnTy<'tcx> {
|
||||
pub fn ty_of_bare_fn<'tcx>(this: &AstConv<'tcx>, unsafety: hir::Unsafety, abi: abi::Abi,
|
||||
decl: &hir::FnDecl) -> ty::BareFnTy<'tcx> {
|
||||
let (bare_fn_ty, _) = ty_of_method_or_bare_fn(this, unsafety, abi, None, decl);
|
||||
bare_fn_ty
|
||||
}
|
||||
|
||||
fn ty_of_method_or_bare_fn<'a, 'tcx>(this: &AstConv<'tcx>,
|
||||
unsafety: ast::Unsafety,
|
||||
unsafety: hir::Unsafety,
|
||||
abi: abi::Abi,
|
||||
opt_self_info: Option<SelfInfo<'a, 'tcx>>,
|
||||
decl: &ast::FnDecl)
|
||||
decl: &hir::FnDecl)
|
||||
-> (ty::BareFnTy<'tcx>, Option<ty::ExplicitSelfCategory>)
|
||||
{
|
||||
debug!("ty_of_method_or_bare_fn");
|
||||
|
|
@ -1800,14 +1800,14 @@ fn ty_of_method_or_bare_fn<'a, 'tcx>(this: &AstConv<'tcx>,
|
|||
};
|
||||
|
||||
let output_ty = match decl.output {
|
||||
ast::Return(ref output) if output.node == ast::TyInfer =>
|
||||
hir::Return(ref output) if output.node == hir::TyInfer =>
|
||||
ty::FnConverging(this.ty_infer(None, None, None, output.span)),
|
||||
ast::Return(ref output) =>
|
||||
hir::Return(ref output) =>
|
||||
ty::FnConverging(convert_ty_with_lifetime_elision(this,
|
||||
implied_output_region,
|
||||
&output)),
|
||||
ast::DefaultReturn(..) => ty::FnConverging(this.tcx().mk_nil()),
|
||||
ast::NoReturn(..) => ty::FnDiverging
|
||||
hir::DefaultReturn(..) => ty::FnConverging(this.tcx().mk_nil()),
|
||||
hir::NoReturn(..) => ty::FnDiverging
|
||||
};
|
||||
|
||||
(ty::BareFnTy {
|
||||
|
|
@ -1827,9 +1827,9 @@ fn determine_explicit_self_category<'a, 'tcx>(this: &AstConv<'tcx>,
|
|||
-> ty::ExplicitSelfCategory
|
||||
{
|
||||
return match self_info.explicit_self.node {
|
||||
ast::SelfStatic => ty::StaticExplicitSelfCategory,
|
||||
ast::SelfValue(_) => ty::ByValueExplicitSelfCategory,
|
||||
ast::SelfRegion(ref lifetime, mutability, _) => {
|
||||
hir::SelfStatic => ty::StaticExplicitSelfCategory,
|
||||
hir::SelfValue(_) => ty::ByValueExplicitSelfCategory,
|
||||
hir::SelfRegion(ref lifetime, mutability, _) => {
|
||||
let region =
|
||||
opt_ast_region_to_region(this,
|
||||
rscope,
|
||||
|
|
@ -1837,7 +1837,7 @@ fn determine_explicit_self_category<'a, 'tcx>(this: &AstConv<'tcx>,
|
|||
lifetime);
|
||||
ty::ByReferenceExplicitSelfCategory(region, mutability)
|
||||
}
|
||||
ast::SelfExplicit(ref ast_type, _) => {
|
||||
hir::SelfExplicit(ref ast_type, _) => {
|
||||
let explicit_type = ast_ty_to_ty(this, rscope, &**ast_type);
|
||||
|
||||
// We wish to (for now) categorize an explicit self
|
||||
|
|
@ -1903,8 +1903,8 @@ fn determine_explicit_self_category<'a, 'tcx>(this: &AstConv<'tcx>,
|
|||
|
||||
pub fn ty_of_closure<'tcx>(
|
||||
this: &AstConv<'tcx>,
|
||||
unsafety: ast::Unsafety,
|
||||
decl: &ast::FnDecl,
|
||||
unsafety: hir::Unsafety,
|
||||
decl: &hir::FnDecl,
|
||||
abi: abi::Abi,
|
||||
expected_sig: Option<ty::FnSig<'tcx>>)
|
||||
-> ty::ClosureTy<'tcx>
|
||||
|
|
@ -1932,8 +1932,8 @@ pub fn ty_of_closure<'tcx>(
|
|||
let expected_ret_ty = expected_sig.map(|e| e.output);
|
||||
|
||||
let is_infer = match decl.output {
|
||||
ast::Return(ref output) if output.node == ast::TyInfer => true,
|
||||
ast::DefaultReturn(..) => true,
|
||||
hir::Return(ref output) if output.node == hir::TyInfer => true,
|
||||
hir::DefaultReturn(..) => true,
|
||||
_ => false
|
||||
};
|
||||
|
||||
|
|
@ -1942,10 +1942,10 @@ pub fn ty_of_closure<'tcx>(
|
|||
expected_ret_ty.unwrap(),
|
||||
_ if is_infer =>
|
||||
ty::FnConverging(this.ty_infer(None, None, None, decl.output.span())),
|
||||
ast::Return(ref output) =>
|
||||
hir::Return(ref output) =>
|
||||
ty::FnConverging(ast_ty_to_ty(this, &rb, &**output)),
|
||||
ast::DefaultReturn(..) => unreachable!(),
|
||||
ast::NoReturn(..) => ty::FnDiverging
|
||||
hir::DefaultReturn(..) => unreachable!(),
|
||||
hir::NoReturn(..) => ty::FnDiverging
|
||||
};
|
||||
|
||||
debug!("ty_of_closure: input_tys={:?}", input_tys);
|
||||
|
|
@ -1970,7 +1970,7 @@ fn conv_existential_bounds<'tcx>(
|
|||
span: Span,
|
||||
principal_trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
projection_bounds: Vec<ty::PolyProjectionPredicate<'tcx>>,
|
||||
ast_bounds: &[ast::TyParamBound])
|
||||
ast_bounds: &[hir::TyParamBound])
|
||||
-> ty::ExistentialBounds<'tcx>
|
||||
{
|
||||
let partitioned_bounds =
|
||||
|
|
@ -1984,7 +1984,7 @@ fn conv_ty_poly_trait_ref<'tcx>(
|
|||
this: &AstConv<'tcx>,
|
||||
rscope: &RegionScope,
|
||||
span: Span,
|
||||
ast_bounds: &[ast::TyParamBound])
|
||||
ast_bounds: &[hir::TyParamBound])
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
let mut partitioned_bounds = partition_bounds(this.tcx(), span, &ast_bounds[..]);
|
||||
|
|
@ -2074,7 +2074,7 @@ pub fn conv_existential_bounds_from_partitioned_bounds<'tcx>(
|
|||
fn compute_object_lifetime_bound<'tcx>(
|
||||
this: &AstConv<'tcx>,
|
||||
span: Span,
|
||||
explicit_region_bounds: &[&ast::Lifetime],
|
||||
explicit_region_bounds: &[&hir::Lifetime],
|
||||
principal_trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
builtin_bounds: ty::BuiltinBounds)
|
||||
-> Option<ty::Region> // if None, use the default
|
||||
|
|
@ -2132,15 +2132,15 @@ fn compute_object_lifetime_bound<'tcx>(
|
|||
|
||||
pub struct PartitionedBounds<'a> {
|
||||
pub builtin_bounds: ty::BuiltinBounds,
|
||||
pub trait_bounds: Vec<&'a ast::PolyTraitRef>,
|
||||
pub region_bounds: Vec<&'a ast::Lifetime>,
|
||||
pub trait_bounds: Vec<&'a hir::PolyTraitRef>,
|
||||
pub region_bounds: Vec<&'a hir::Lifetime>,
|
||||
}
|
||||
|
||||
/// Divides a list of bounds from the AST into three groups: builtin bounds (Copy, Sized etc),
|
||||
/// general trait bounds, and region bounds.
|
||||
pub fn partition_bounds<'a>(tcx: &ty::ctxt,
|
||||
_span: Span,
|
||||
ast_bounds: &'a [ast::TyParamBound])
|
||||
ast_bounds: &'a [hir::TyParamBound])
|
||||
-> PartitionedBounds<'a>
|
||||
{
|
||||
let mut builtin_bounds = ty::BuiltinBounds::empty();
|
||||
|
|
@ -2148,7 +2148,7 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
|
|||
let mut trait_bounds = Vec::new();
|
||||
for ast_bound in ast_bounds {
|
||||
match *ast_bound {
|
||||
ast::TraitTyParamBound(ref b, ast::TraitBoundModifier::None) => {
|
||||
hir::TraitTyParamBound(ref b, hir::TraitBoundModifier::None) => {
|
||||
match ::lookup_full_def(tcx, b.trait_ref.path.span, b.trait_ref.ref_id) {
|
||||
def::DefTrait(trait_did) => {
|
||||
if tcx.try_add_builtin_trait(trait_did,
|
||||
|
|
@ -2173,8 +2173,8 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
|
|||
}
|
||||
trait_bounds.push(b);
|
||||
}
|
||||
ast::TraitTyParamBound(_, ast::TraitBoundModifier::Maybe) => {}
|
||||
ast::RegionTyParamBound(ref l) => {
|
||||
hir::TraitTyParamBound(_, hir::TraitBoundModifier::Maybe) => {}
|
||||
hir::RegionTyParamBound(ref l) => {
|
||||
region_bounds.push(l);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,13 +26,15 @@ use util::nodemap::FnvHashMap;
|
|||
use std::cmp;
|
||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||
use syntax::ast;
|
||||
use syntax::ast_util;
|
||||
use syntax::codemap::{Span, Spanned};
|
||||
use syntax::print::pprust;
|
||||
use syntax::ptr::P;
|
||||
|
||||
use rustc_front::hir;
|
||||
use rustc_front::print::pprust;
|
||||
use rustc_front::util as hir_util;
|
||||
|
||||
pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
||||
pat: &'tcx ast::Pat,
|
||||
pat: &'tcx hir::Pat,
|
||||
expected: Ty<'tcx>)
|
||||
{
|
||||
let fcx = pcx.fcx;
|
||||
|
|
@ -43,18 +45,18 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
expected);
|
||||
|
||||
match pat.node {
|
||||
ast::PatWild(_) => {
|
||||
hir::PatWild(_) => {
|
||||
fcx.write_ty(pat.id, expected);
|
||||
}
|
||||
ast::PatLit(ref lt) => {
|
||||
hir::PatLit(ref lt) => {
|
||||
check_expr(fcx, &**lt);
|
||||
let expr_ty = fcx.expr_ty(&**lt);
|
||||
|
||||
// Byte string patterns behave the same way as array patterns
|
||||
// They can denote both statically and dynamically sized byte arrays
|
||||
let mut pat_ty = expr_ty;
|
||||
if let ast::ExprLit(ref lt) = lt.node {
|
||||
if let ast::LitBinary(_) = lt.node {
|
||||
if let hir::ExprLit(ref lt) = lt.node {
|
||||
if let hir::LitBinary(_) = lt.node {
|
||||
let expected_ty = structurally_resolved_type(fcx, pat.span, expected);
|
||||
if let ty::TyRef(_, mt) = expected_ty.sty {
|
||||
if let ty::TySlice(_) = mt.ty.sty {
|
||||
|
|
@ -81,7 +83,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
// that's equivalent to there existing a LUB.
|
||||
demand::suptype(fcx, pat.span, expected, pat_ty);
|
||||
}
|
||||
ast::PatRange(ref begin, ref end) => {
|
||||
hir::PatRange(ref begin, ref end) => {
|
||||
check_expr(fcx, begin);
|
||||
check_expr(fcx, end);
|
||||
|
||||
|
|
@ -132,7 +134,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
// subtyping doesn't matter here, as the value is some kind of scalar
|
||||
demand::eqtype(fcx, pat.span, expected, lhs_ty);
|
||||
}
|
||||
ast::PatEnum(..) | ast::PatIdent(..) if pat_is_resolved_const(&tcx.def_map, pat) => {
|
||||
hir::PatEnum(..) | hir::PatIdent(..) if pat_is_resolved_const(&tcx.def_map, pat) => {
|
||||
let const_did = tcx.def_map.borrow().get(&pat.id).unwrap().def_id();
|
||||
let const_scheme = tcx.lookup_item_type(const_did);
|
||||
assert!(const_scheme.generics.is_empty());
|
||||
|
|
@ -148,10 +150,10 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
// is good enough.
|
||||
demand::suptype(fcx, pat.span, expected, const_ty);
|
||||
}
|
||||
ast::PatIdent(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map, pat) => {
|
||||
hir::PatIdent(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map, pat) => {
|
||||
let typ = fcx.local_ty(pat.span, pat.id);
|
||||
match bm {
|
||||
ast::BindByRef(mutbl) => {
|
||||
hir::BindByRef(mutbl) => {
|
||||
// if the binding is like
|
||||
// ref x | ref const x | ref mut x
|
||||
// then `x` is assigned a value of type `&M T` where M is the mutability
|
||||
|
|
@ -166,7 +168,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
demand::eqtype(fcx, pat.span, region_ty, typ);
|
||||
}
|
||||
// otherwise the type of x is the expected type T
|
||||
ast::BindByValue(_) => {
|
||||
hir::BindByValue(_) => {
|
||||
// As above, `T <: typeof(x)` is required but we
|
||||
// use equality, see (*) below.
|
||||
demand::eqtype(fcx, pat.span, expected, typ);
|
||||
|
|
@ -187,15 +189,15 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
check_pat(pcx, &**p, expected);
|
||||
}
|
||||
}
|
||||
ast::PatIdent(_, ref path, _) => {
|
||||
let path = ast_util::ident_to_path(path.span, path.node);
|
||||
hir::PatIdent(_, ref path, _) => {
|
||||
let path = hir_util::ident_to_path(path.span, path.node);
|
||||
check_pat_enum(pcx, pat, &path, Some(&[]), expected);
|
||||
}
|
||||
ast::PatEnum(ref path, ref subpats) => {
|
||||
hir::PatEnum(ref path, ref subpats) => {
|
||||
let subpats = subpats.as_ref().map(|v| &v[..]);
|
||||
check_pat_enum(pcx, pat, path, subpats, expected);
|
||||
}
|
||||
ast::PatQPath(ref qself, ref path) => {
|
||||
hir::PatQPath(ref qself, ref path) => {
|
||||
let self_ty = fcx.to_ty(&qself.ty);
|
||||
let path_res = if let Some(&d) = tcx.def_map.borrow().get(&pat.id) {
|
||||
d
|
||||
|
|
@ -226,10 +228,10 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
}
|
||||
}
|
||||
}
|
||||
ast::PatStruct(ref path, ref fields, etc) => {
|
||||
hir::PatStruct(ref path, ref fields, etc) => {
|
||||
check_pat_struct(pcx, pat, path, fields, etc, expected);
|
||||
}
|
||||
ast::PatTup(ref elements) => {
|
||||
hir::PatTup(ref elements) => {
|
||||
let element_tys: Vec<_> =
|
||||
(0..elements.len()).map(|_| fcx.infcx().next_ty_var())
|
||||
.collect();
|
||||
|
|
@ -240,7 +242,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
check_pat(pcx, &**element_pat, element_ty);
|
||||
}
|
||||
}
|
||||
ast::PatBox(ref inner) => {
|
||||
hir::PatBox(ref inner) => {
|
||||
let inner_ty = fcx.infcx().next_ty_var();
|
||||
let uniq_ty = tcx.mk_box(inner_ty);
|
||||
|
||||
|
|
@ -256,7 +258,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
check_pat(pcx, &**inner, tcx.types.err);
|
||||
}
|
||||
}
|
||||
ast::PatRegion(ref inner, mutbl) => {
|
||||
hir::PatRegion(ref inner, mutbl) => {
|
||||
let inner_ty = fcx.infcx().next_ty_var();
|
||||
|
||||
let mt = ty::TypeAndMut { ty: inner_ty, mutbl: mutbl };
|
||||
|
|
@ -275,7 +277,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
check_pat(pcx, &**inner, tcx.types.err);
|
||||
}
|
||||
}
|
||||
ast::PatVec(ref before, ref slice, ref after) => {
|
||||
hir::PatVec(ref before, ref slice, ref after) => {
|
||||
let expected_ty = structurally_resolved_type(fcx, pat.span, expected);
|
||||
let inner_ty = fcx.infcx().next_ty_var();
|
||||
let pat_ty = match expected_ty.sty {
|
||||
|
|
@ -291,7 +293,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
tcx.mk_ref(tcx.mk_region(region), ty::TypeAndMut {
|
||||
ty: tcx.mk_slice(inner_ty),
|
||||
mutbl: expected_ty.builtin_deref(true).map(|mt| mt.mutbl)
|
||||
.unwrap_or(ast::MutImmutable)
|
||||
.unwrap_or(hir::MutImmutable)
|
||||
})
|
||||
}
|
||||
};
|
||||
|
|
@ -309,7 +311,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
if let Some(ref slice) = *slice {
|
||||
let region = fcx.infcx().next_region_var(infer::PatternRegion(pat.span));
|
||||
let mutbl = expected_ty.builtin_deref(true)
|
||||
.map_or(ast::MutImmutable, |mt| mt.mutbl);
|
||||
.map_or(hir::MutImmutable, |mt| mt.mutbl);
|
||||
|
||||
let slice_ty = tcx.mk_ref(tcx.mk_region(region), ty::TypeAndMut {
|
||||
ty: tcx.mk_slice(inner_ty),
|
||||
|
|
@ -321,7 +323,6 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
check_pat(pcx, &**elt, inner_ty);
|
||||
}
|
||||
}
|
||||
ast::PatMac(_) => tcx.sess.bug("unexpanded macro")
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -393,7 +394,7 @@ fn check_assoc_item_is_const(pcx: &pat_ctxt, def: def::Def, span: Span) -> bool
|
|||
|
||||
pub fn check_dereferencable<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
||||
span: Span, expected: Ty<'tcx>,
|
||||
inner: &ast::Pat) -> bool {
|
||||
inner: &hir::Pat) -> bool {
|
||||
let fcx = pcx.fcx;
|
||||
let tcx = pcx.fcx.ccx.tcx;
|
||||
if pat_is_binding(&tcx.def_map, inner) {
|
||||
|
|
@ -415,11 +416,11 @@ pub fn check_dereferencable<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
}
|
||||
|
||||
pub fn check_match<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
expr: &'tcx ast::Expr,
|
||||
discrim: &'tcx ast::Expr,
|
||||
arms: &'tcx [ast::Arm],
|
||||
expr: &'tcx hir::Expr,
|
||||
discrim: &'tcx hir::Expr,
|
||||
arms: &'tcx [hir::Arm],
|
||||
expected: Expectation<'tcx>,
|
||||
match_src: ast::MatchSource) {
|
||||
match_src: hir::MatchSource) {
|
||||
let tcx = fcx.ccx.tcx;
|
||||
|
||||
// Not entirely obvious: if matches may create ref bindings, we
|
||||
|
|
@ -428,8 +429,8 @@ pub fn check_match<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
let contains_ref_bindings = arms.iter()
|
||||
.filter_map(|a| tcx.arm_contains_ref_binding(a))
|
||||
.max_by(|m| match *m {
|
||||
ast::MutMutable => 1,
|
||||
ast::MutImmutable => 0,
|
||||
hir::MutMutable => 1,
|
||||
hir::MutImmutable => 0,
|
||||
});
|
||||
let discrim_ty;
|
||||
if let Some(m) = contains_ref_bindings {
|
||||
|
|
@ -491,7 +492,7 @@ pub fn check_match<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
} else {
|
||||
let (origin, expected, found) = match match_src {
|
||||
/* if-let construct without an else block */
|
||||
ast::MatchSource::IfLetDesugar { contains_else_clause }
|
||||
hir::MatchSource::IfLetDesugar { contains_else_clause }
|
||||
if !contains_else_clause => (
|
||||
infer::IfExpressionWithNoElse(expr.span),
|
||||
bty,
|
||||
|
|
@ -522,8 +523,8 @@ pub struct pat_ctxt<'a, 'tcx: 'a> {
|
|||
pub map: PatIdMap,
|
||||
}
|
||||
|
||||
pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx ast::Pat,
|
||||
path: &ast::Path, fields: &'tcx [Spanned<ast::FieldPat>],
|
||||
pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx hir::Pat,
|
||||
path: &hir::Path, fields: &'tcx [Spanned<hir::FieldPat>],
|
||||
etc: bool, expected: Ty<'tcx>) {
|
||||
let fcx = pcx.fcx;
|
||||
let tcx = pcx.fcx.ccx.tcx;
|
||||
|
|
@ -557,9 +558,9 @@ pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx ast::Pat,
|
|||
}
|
||||
|
||||
pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
||||
pat: &ast::Pat,
|
||||
path: &ast::Path,
|
||||
subpats: Option<&'tcx [P<ast::Pat>]>,
|
||||
pat: &hir::Pat,
|
||||
path: &hir::Path,
|
||||
subpats: Option<&'tcx [P<hir::Pat>]>,
|
||||
expected: Ty<'tcx>)
|
||||
{
|
||||
// Typecheck the path.
|
||||
|
|
@ -688,7 +689,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
/// `etc` is true if the pattern said '...' and false otherwise.
|
||||
pub fn check_struct_pat_fields<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
||||
span: Span,
|
||||
fields: &'tcx [Spanned<ast::FieldPat>],
|
||||
fields: &'tcx [Spanned<hir::FieldPat>],
|
||||
variant: ty::VariantDef<'tcx>,
|
||||
substs: &Substs<'tcx>,
|
||||
etc: bool) {
|
||||
|
|
|
|||
|
|
@ -29,11 +29,12 @@ use CrateCtxt;
|
|||
use middle::def_id::{DefId, LOCAL_CRATE};
|
||||
use middle::infer;
|
||||
use middle::ty::{self, Ty};
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token;
|
||||
use syntax::ptr::P;
|
||||
|
||||
use rustc_front::hir;
|
||||
|
||||
/// Check that it is legal to call methods of the trait corresponding
|
||||
/// to `trait_id` (this only cares about the trait, not the specific
|
||||
/// method that is called)
|
||||
|
|
@ -68,9 +69,9 @@ pub fn check_legal_trait_for_method_call(ccx: &CrateCtxt, span: Span, trait_id:
|
|||
}
|
||||
|
||||
pub fn check_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
call_expr: &'tcx ast::Expr,
|
||||
callee_expr: &'tcx ast::Expr,
|
||||
arg_exprs: &'tcx [P<ast::Expr>],
|
||||
call_expr: &'tcx hir::Expr,
|
||||
callee_expr: &'tcx hir::Expr,
|
||||
arg_exprs: &'tcx [P<hir::Expr>],
|
||||
expected: Expectation<'tcx>)
|
||||
{
|
||||
check_expr(fcx, callee_expr);
|
||||
|
|
@ -114,8 +115,8 @@ enum CallStep<'tcx> {
|
|||
}
|
||||
|
||||
fn try_overloaded_call_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
call_expr: &'tcx ast::Expr,
|
||||
callee_expr: &'tcx ast::Expr,
|
||||
call_expr: &'tcx hir::Expr,
|
||||
callee_expr: &'tcx hir::Expr,
|
||||
adjusted_ty: Ty<'tcx>,
|
||||
autoderefs: usize)
|
||||
-> Option<CallStep<'tcx>>
|
||||
|
|
@ -177,8 +178,8 @@ fn try_overloaded_call_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
}
|
||||
|
||||
fn try_overloaded_call_traits<'a,'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
call_expr: &ast::Expr,
|
||||
callee_expr: &ast::Expr,
|
||||
call_expr: &hir::Expr,
|
||||
callee_expr: &hir::Expr,
|
||||
adjusted_ty: Ty<'tcx>,
|
||||
autoderefs: usize)
|
||||
-> Option<ty::MethodCallee<'tcx>>
|
||||
|
|
@ -214,9 +215,9 @@ fn try_overloaded_call_traits<'a,'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
}
|
||||
|
||||
fn confirm_builtin_call<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
||||
call_expr: &ast::Expr,
|
||||
call_expr: &hir::Expr,
|
||||
callee_ty: Ty<'tcx>,
|
||||
arg_exprs: &'tcx [P<ast::Expr>],
|
||||
arg_exprs: &'tcx [P<hir::Expr>],
|
||||
expected: Expectation<'tcx>)
|
||||
{
|
||||
let error_fn_sig;
|
||||
|
|
@ -273,8 +274,8 @@ fn confirm_builtin_call<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
|||
}
|
||||
|
||||
fn confirm_deferred_closure_call<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
||||
call_expr: &ast::Expr,
|
||||
arg_exprs: &'tcx [P<ast::Expr>],
|
||||
call_expr: &hir::Expr,
|
||||
arg_exprs: &'tcx [P<hir::Expr>],
|
||||
expected: Expectation<'tcx>,
|
||||
fn_sig: ty::FnSig<'tcx>)
|
||||
{
|
||||
|
|
@ -302,9 +303,9 @@ fn confirm_deferred_closure_call<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
|||
}
|
||||
|
||||
fn confirm_overloaded_call<'a,'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
call_expr: &ast::Expr,
|
||||
callee_expr: &'tcx ast::Expr,
|
||||
arg_exprs: &'tcx [P<ast::Expr>],
|
||||
call_expr: &hir::Expr,
|
||||
callee_expr: &'tcx hir::Expr,
|
||||
arg_exprs: &'tcx [P<hir::Expr>],
|
||||
expected: Expectation<'tcx>,
|
||||
method_callee: ty::MethodCallee<'tcx>)
|
||||
{
|
||||
|
|
@ -322,7 +323,7 @@ fn confirm_overloaded_call<'a,'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
}
|
||||
|
||||
fn write_overloaded_call_method_map<'a,'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
call_expr: &ast::Expr,
|
||||
call_expr: &hir::Expr,
|
||||
method_callee: ty::MethodCallee<'tcx>) {
|
||||
let method_call = ty::MethodCall::expr(call_expr.id);
|
||||
fcx.inh.tables.borrow_mut().method_map.insert(method_call, method_callee);
|
||||
|
|
@ -330,8 +331,8 @@ fn write_overloaded_call_method_map<'a,'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
|
||||
#[derive(Debug)]
|
||||
struct CallResolution<'tcx> {
|
||||
call_expr: &'tcx ast::Expr,
|
||||
callee_expr: &'tcx ast::Expr,
|
||||
call_expr: &'tcx hir::Expr,
|
||||
callee_expr: &'tcx hir::Expr,
|
||||
adjusted_ty: Ty<'tcx>,
|
||||
autoderefs: usize,
|
||||
fn_sig: ty::FnSig<'tcx>,
|
||||
|
|
|
|||
|
|
@ -47,14 +47,15 @@ use lint;
|
|||
use middle::cast::{CastKind, CastTy};
|
||||
use middle::def_id::DefId;
|
||||
use middle::ty::{self, Ty, HasTypeFlags};
|
||||
use syntax::ast;
|
||||
use syntax::ast::UintTy::{TyU8};
|
||||
use syntax::codemap::Span;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::hir::UintTy::TyU8;
|
||||
|
||||
|
||||
/// Reifies a cast check to be checked once we have full type information for
|
||||
/// a function context.
|
||||
pub struct CastCheck<'tcx> {
|
||||
expr: ast::Expr,
|
||||
expr: hir::Expr,
|
||||
expr_ty: Ty<'tcx>,
|
||||
cast_ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
|
|
@ -108,7 +109,7 @@ enum CastError {
|
|||
}
|
||||
|
||||
impl<'tcx> CastCheck<'tcx> {
|
||||
pub fn new(expr: ast::Expr, expr_ty: Ty<'tcx>, cast_ty: Ty<'tcx>, span: Span)
|
||||
pub fn new(expr: hir::Expr, expr_ty: Ty<'tcx>, cast_ty: Ty<'tcx>, span: Span)
|
||||
-> CastCheck<'tcx> {
|
||||
CastCheck {
|
||||
expr: expr,
|
||||
|
|
@ -244,7 +245,7 @@ impl<'tcx> CastCheck<'tcx> {
|
|||
(_, Int(Bool)) => Err(CastError::CastToBool),
|
||||
|
||||
// * -> Char
|
||||
(Int(U(ast::TyU8)), Int(Char)) => Ok(CastKind::U8CharCast), // u8-char-cast
|
||||
(Int(U(hir::TyU8)), Int(Char)) => Ok(CastKind::U8CharCast), // u8-char-cast
|
||||
(_, Int(Char)) => Err(CastError::CastToChar),
|
||||
|
||||
// prim -> float,ptr
|
||||
|
|
@ -340,7 +341,7 @@ impl<'tcx> CastCheck<'tcx> {
|
|||
{
|
||||
// array-ptr-cast.
|
||||
|
||||
if m_expr.mutbl == ast::MutImmutable && m_cast.mutbl == ast::MutImmutable {
|
||||
if m_expr.mutbl == hir::MutImmutable && m_cast.mutbl == hir::MutImmutable {
|
||||
if let ty::TyArray(ety, _) = m_expr.ty.sty {
|
||||
// Due to the limitations of LLVM global constants,
|
||||
// region pointers end up pointing at copies of
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ use middle::subst;
|
|||
use middle::ty::{self, ToPolyTraitRef, Ty};
|
||||
use std::cmp;
|
||||
use syntax::abi;
|
||||
use syntax::ast;
|
||||
use rustc_front::hir;
|
||||
|
||||
pub fn check_expr_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
||||
expr: &ast::Expr,
|
||||
_capture: ast::CaptureClause,
|
||||
decl: &'tcx ast::FnDecl,
|
||||
body: &'tcx ast::Block,
|
||||
expr: &hir::Expr,
|
||||
_capture: hir::CaptureClause,
|
||||
decl: &'tcx hir::FnDecl,
|
||||
body: &'tcx hir::Block,
|
||||
expected: Expectation<'tcx>) {
|
||||
debug!("check_expr_closure(expr={:?},expected={:?})",
|
||||
expr,
|
||||
|
|
@ -41,10 +41,10 @@ pub fn check_expr_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
|||
}
|
||||
|
||||
fn check_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
||||
expr: &ast::Expr,
|
||||
expr: &hir::Expr,
|
||||
opt_kind: Option<ty::ClosureKind>,
|
||||
decl: &'tcx ast::FnDecl,
|
||||
body: &'tcx ast::Block,
|
||||
decl: &'tcx hir::FnDecl,
|
||||
body: &'tcx hir::Block,
|
||||
expected_sig: Option<ty::FnSig<'tcx>>) {
|
||||
let expr_def_id = DefId::local(expr.id);
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ fn check_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
|||
expected_sig);
|
||||
|
||||
let mut fn_ty = astconv::ty_of_closure(fcx,
|
||||
ast::Unsafety::Normal,
|
||||
hir::Unsafety::Normal,
|
||||
decl,
|
||||
abi::RustCall,
|
||||
expected_sig);
|
||||
|
|
@ -79,7 +79,7 @@ fn check_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
|||
fcx.tcx().region_maps.item_extent(body.id), &fn_ty.sig);
|
||||
|
||||
check_fn(fcx.ccx,
|
||||
ast::Unsafety::Normal,
|
||||
hir::Unsafety::Normal,
|
||||
expr.id,
|
||||
&fn_sig,
|
||||
decl,
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ use util::common::indent;
|
|||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::VecDeque;
|
||||
use syntax::ast;
|
||||
use rustc_front::hir;
|
||||
|
||||
struct Coerce<'a, 'tcx: 'a> {
|
||||
fcx: &'a FnCtxt<'a, 'tcx>,
|
||||
|
|
@ -99,7 +99,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
}
|
||||
|
||||
fn coerce(&self,
|
||||
expr_a: &ast::Expr,
|
||||
expr_a: &hir::Expr,
|
||||
a: Ty<'tcx>,
|
||||
b: Ty<'tcx>)
|
||||
-> CoerceResult<'tcx> {
|
||||
|
|
@ -160,10 +160,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
/// To match `A` with `B`, autoderef will be performed,
|
||||
/// calling `deref`/`deref_mut` where necessary.
|
||||
fn coerce_borrowed_pointer(&self,
|
||||
expr_a: &ast::Expr,
|
||||
expr_a: &hir::Expr,
|
||||
a: Ty<'tcx>,
|
||||
b: Ty<'tcx>,
|
||||
mutbl_b: ast::Mutability)
|
||||
mutbl_b: hir::Mutability)
|
||||
-> CoerceResult<'tcx> {
|
||||
debug!("coerce_borrowed_pointer(a={:?}, b={:?})",
|
||||
a,
|
||||
|
|
@ -356,7 +356,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
|
||||
if let ty::TyBareFn(None, fn_ty_b) = b.sty {
|
||||
match (fn_ty_a.unsafety, fn_ty_b.unsafety) {
|
||||
(ast::Unsafety::Normal, ast::Unsafety::Unsafe) => {
|
||||
(hir::Unsafety::Normal, hir::Unsafety::Unsafe) => {
|
||||
let unsafe_a = self.tcx().safe_to_unsafe_fn_ty(fn_ty_a);
|
||||
try!(self.subtype(unsafe_a, b));
|
||||
return Ok(Some(ty::AdjustUnsafeFnPointer));
|
||||
|
|
@ -396,7 +396,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
fn coerce_unsafe_ptr(&self,
|
||||
a: Ty<'tcx>,
|
||||
b: Ty<'tcx>,
|
||||
mutbl_b: ast::Mutability)
|
||||
mutbl_b: hir::Mutability)
|
||||
-> CoerceResult<'tcx> {
|
||||
debug!("coerce_unsafe_ptr(a={:?}, b={:?})",
|
||||
a,
|
||||
|
|
@ -431,7 +431,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
}
|
||||
|
||||
pub fn mk_assignty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
expr: &ast::Expr,
|
||||
expr: &hir::Expr,
|
||||
a: Ty<'tcx>,
|
||||
b: Ty<'tcx>)
|
||||
-> RelateResult<'tcx, ()> {
|
||||
|
|
@ -465,13 +465,13 @@ pub fn mk_assignty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn coerce_mutbls<'tcx>(from_mutbl: ast::Mutability,
|
||||
to_mutbl: ast::Mutability)
|
||||
fn coerce_mutbls<'tcx>(from_mutbl: hir::Mutability,
|
||||
to_mutbl: hir::Mutability)
|
||||
-> CoerceResult<'tcx> {
|
||||
match (from_mutbl, to_mutbl) {
|
||||
(ast::MutMutable, ast::MutMutable) |
|
||||
(ast::MutImmutable, ast::MutImmutable) |
|
||||
(ast::MutMutable, ast::MutImmutable) => Ok(None),
|
||||
(ast::MutImmutable, ast::MutMutable) => Err(TypeError::Mutability)
|
||||
(hir::MutMutable, hir::MutMutable) |
|
||||
(hir::MutImmutable, hir::MutImmutable) |
|
||||
(hir::MutMutable, hir::MutImmutable) => Ok(None),
|
||||
(hir::MutImmutable, hir::MutMutable) => Err(TypeError::Mutability)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ use middle::ty::{self, Ty};
|
|||
use middle::infer;
|
||||
|
||||
use std::result::Result::{Err, Ok};
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use rustc_front::hir;
|
||||
|
||||
// Requires that the two types unify, and prints an error message if
|
||||
// they don't.
|
||||
|
|
@ -56,7 +56,7 @@ pub fn eqtype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
|
|||
pub fn coerce<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
sp: Span,
|
||||
expected: Ty<'tcx>,
|
||||
expr: &ast::Expr) {
|
||||
expr: &hir::Expr) {
|
||||
let expr_ty = fcx.expr_ty(expr);
|
||||
debug!("demand::coerce(expected = {:?}, expr_ty = {:?})",
|
||||
expected,
|
||||
|
|
|
|||
|
|
@ -23,17 +23,18 @@ use {CrateCtxt, require_same_types};
|
|||
use std::collections::{HashMap};
|
||||
use syntax::abi;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token;
|
||||
|
||||
fn equate_intrinsic_type<'a, 'tcx>(tcx: &ty::ctxt<'tcx>, it: &ast::ForeignItem,
|
||||
use rustc_front::hir;
|
||||
|
||||
fn equate_intrinsic_type<'a, 'tcx>(tcx: &ty::ctxt<'tcx>, it: &hir::ForeignItem,
|
||||
n_tps: usize,
|
||||
abi: abi::Abi,
|
||||
inputs: Vec<ty::Ty<'tcx>>,
|
||||
output: ty::FnOutput<'tcx>) {
|
||||
let fty = tcx.mk_fn(None, tcx.mk_bare_fn(ty::BareFnTy {
|
||||
unsafety: ast::Unsafety::Unsafe,
|
||||
unsafety: hir::Unsafety::Unsafe,
|
||||
abi: abi,
|
||||
sig: ty::Binder(FnSig {
|
||||
inputs: inputs,
|
||||
|
|
@ -64,7 +65,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: &ty::ctxt<'tcx>, it: &ast::ForeignItem,
|
|||
|
||||
/// Remember to add all intrinsics here, in librustc_trans/trans/intrinsic.rs,
|
||||
/// and in libcore/intrinsics.rs
|
||||
pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
|
||||
pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &hir::ForeignItem) {
|
||||
fn param<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, n: u32) -> Ty<'tcx> {
|
||||
let name = token::intern(&format!("P{}", n));
|
||||
ccx.tcx.mk_param(subst::FnSpace, n, name)
|
||||
|
|
@ -140,13 +141,13 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
|
|||
vec!(
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(ccx, 0),
|
||||
mutbl: ast::MutImmutable
|
||||
mutbl: hir::MutImmutable
|
||||
}),
|
||||
ccx.tcx.types.isize
|
||||
),
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(ccx, 0),
|
||||
mutbl: ast::MutImmutable
|
||||
mutbl: hir::MutImmutable
|
||||
}))
|
||||
}
|
||||
"copy" | "copy_nonoverlapping" => {
|
||||
|
|
@ -154,11 +155,11 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
|
|||
vec!(
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(ccx, 0),
|
||||
mutbl: ast::MutImmutable
|
||||
mutbl: hir::MutImmutable
|
||||
}),
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(ccx, 0),
|
||||
mutbl: ast::MutMutable
|
||||
mutbl: hir::MutMutable
|
||||
}),
|
||||
tcx.types.usize,
|
||||
),
|
||||
|
|
@ -169,11 +170,11 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
|
|||
vec!(
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(ccx, 0),
|
||||
mutbl: ast::MutMutable
|
||||
mutbl: hir::MutMutable
|
||||
}),
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(ccx, 0),
|
||||
mutbl: ast::MutImmutable
|
||||
mutbl: hir::MutImmutable
|
||||
}),
|
||||
tcx.types.usize,
|
||||
),
|
||||
|
|
@ -184,7 +185,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
|
|||
vec!(
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(ccx, 0),
|
||||
mutbl: ast::MutMutable
|
||||
mutbl: hir::MutMutable
|
||||
}),
|
||||
tcx.types.u8,
|
||||
tcx.types.usize,
|
||||
|
|
@ -324,7 +325,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
|
|||
"try" => {
|
||||
let mut_u8 = tcx.mk_mut_ptr(tcx.types.u8);
|
||||
let fn_ty = ty::BareFnTy {
|
||||
unsafety: ast::Unsafety::Normal,
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
abi: abi::Rust,
|
||||
sig: ty::Binder(FnSig {
|
||||
inputs: vec![mut_u8],
|
||||
|
|
@ -356,7 +357,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
|
|||
|
||||
/// Type-check `extern "platform-intrinsic" { ... }` functions.
|
||||
pub fn check_platform_intrinsic_type(ccx: &CrateCtxt,
|
||||
it: &ast::ForeignItem) {
|
||||
it: &hir::ForeignItem) {
|
||||
let param = |n| {
|
||||
let name = token::intern(&format!("P{}", n));
|
||||
ccx.tcx.mk_param(subst::FnSpace, n, name)
|
||||
|
|
@ -465,18 +466,22 @@ fn match_intrinsic_type_to_type<'tcx, 'a>(
|
|||
match *expected {
|
||||
// (The width we pass to LLVM doesn't concern the type checker.)
|
||||
Integer(signed, bits, _llvm_width) => match (signed, bits, &t.sty) {
|
||||
(true, 8, &ty::TyInt(ast::TyI8)) | (false, 8, &ty::TyUint(ast::TyU8)) |
|
||||
(true, 16, &ty::TyInt(ast::TyI16)) | (false, 16, &ty::TyUint(ast::TyU16)) |
|
||||
(true, 32, &ty::TyInt(ast::TyI32)) | (false, 32, &ty::TyUint(ast::TyU32)) |
|
||||
(true, 64, &ty::TyInt(ast::TyI64)) | (false, 64, &ty::TyUint(ast::TyU64)) => {},
|
||||
(true, 8, &ty::TyInt(hir::IntTy::TyI8)) |
|
||||
(false, 8, &ty::TyUint(hir::UintTy::TyU8)) |
|
||||
(true, 16, &ty::TyInt(hir::IntTy::TyI16)) |
|
||||
(false, 16, &ty::TyUint(hir::UintTy::TyU16)) |
|
||||
(true, 32, &ty::TyInt(hir::IntTy::TyI32)) |
|
||||
(false, 32, &ty::TyUint(hir::UintTy::TyU32)) |
|
||||
(true, 64, &ty::TyInt(hir::IntTy::TyI64)) |
|
||||
(false, 64, &ty::TyUint(hir::UintTy::TyU64)) => {},
|
||||
_ => simple_error(&format!("`{}`", t),
|
||||
&format!("`{}{n}`",
|
||||
if signed {"i"} else {"u"},
|
||||
n = bits)),
|
||||
},
|
||||
Float(bits) => match (bits, &t.sty) {
|
||||
(32, &ty::TyFloat(ast::TyF32)) |
|
||||
(64, &ty::TyFloat(ast::TyF64)) => {},
|
||||
(32, &ty::TyFloat(hir::FloatTy::TyF32)) |
|
||||
(64, &ty::TyFloat(hir::FloatTy::TyF64)) => {},
|
||||
_ => simple_error(&format!("`{}`", t),
|
||||
&format!("`f{n}`", n = bits)),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -19,14 +19,14 @@ use middle::ty::{self, Ty};
|
|||
use middle::ty_fold::TypeFoldable;
|
||||
use middle::infer;
|
||||
use middle::infer::InferCtxt;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use rustc_front::hir;
|
||||
|
||||
struct ConfirmContext<'a, 'tcx:'a> {
|
||||
fcx: &'a FnCtxt<'a, 'tcx>,
|
||||
span: Span,
|
||||
self_expr: &'tcx ast::Expr,
|
||||
call_expr: &'tcx ast::Expr,
|
||||
self_expr: &'tcx hir::Expr,
|
||||
call_expr: &'tcx hir::Expr,
|
||||
}
|
||||
|
||||
struct InstantiatedMethodSig<'tcx> {
|
||||
|
|
@ -45,8 +45,8 @@ struct InstantiatedMethodSig<'tcx> {
|
|||
|
||||
pub fn confirm<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
span: Span,
|
||||
self_expr: &'tcx ast::Expr,
|
||||
call_expr: &'tcx ast::Expr,
|
||||
self_expr: &'tcx hir::Expr,
|
||||
call_expr: &'tcx hir::Expr,
|
||||
unadjusted_self_ty: Ty<'tcx>,
|
||||
pick: probe::Pick<'tcx>,
|
||||
supplied_method_types: Vec<Ty<'tcx>>)
|
||||
|
|
@ -64,8 +64,8 @@ pub fn confirm<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
impl<'a,'tcx> ConfirmContext<'a,'tcx> {
|
||||
fn new(fcx: &'a FnCtxt<'a, 'tcx>,
|
||||
span: Span,
|
||||
self_expr: &'tcx ast::Expr,
|
||||
call_expr: &'tcx ast::Expr)
|
||||
self_expr: &'tcx hir::Expr,
|
||||
call_expr: &'tcx hir::Expr)
|
||||
-> ConfirmContext<'a, 'tcx>
|
||||
{
|
||||
ConfirmContext { fcx: fcx, span: span, self_expr: self_expr, call_expr: call_expr }
|
||||
|
|
@ -456,7 +456,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
|
|||
match sig.0.inputs[0].sty {
|
||||
ty::TyRef(_, ty::TypeAndMut {
|
||||
ty: _,
|
||||
mutbl: ast::MutMutable,
|
||||
mutbl: hir::MutMutable,
|
||||
}) => {}
|
||||
_ => return,
|
||||
}
|
||||
|
|
@ -467,11 +467,11 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
|
|||
loop {
|
||||
let last = exprs[exprs.len() - 1];
|
||||
match last.node {
|
||||
ast::ExprParen(ref expr) |
|
||||
ast::ExprField(ref expr, _) |
|
||||
ast::ExprTupField(ref expr, _) |
|
||||
ast::ExprIndex(ref expr, _) |
|
||||
ast::ExprUnary(ast::UnDeref, ref expr) => exprs.push(&**expr),
|
||||
hir::ExprParen(ref expr) |
|
||||
hir::ExprField(ref expr, _) |
|
||||
hir::ExprTupField(ref expr, _) |
|
||||
hir::ExprIndex(ref expr, _) |
|
||||
hir::ExprUnary(hir::UnDeref, ref expr) => exprs.push(&**expr),
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
|
|
@ -515,7 +515,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
|
|||
// Don't retry the first one or we might infinite loop!
|
||||
if i != 0 {
|
||||
match expr.node {
|
||||
ast::ExprIndex(ref base_expr, ref index_expr) => {
|
||||
hir::ExprIndex(ref base_expr, ref index_expr) => {
|
||||
// If this is an overloaded index, the
|
||||
// adjustment will include an extra layer of
|
||||
// autoref because the method is an &self/&mut
|
||||
|
|
@ -583,7 +583,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
|
|||
demand::suptype(self.fcx, expr.span, expr_ty, return_ty);
|
||||
}
|
||||
}
|
||||
ast::ExprUnary(ast::UnDeref, ref base_expr) => {
|
||||
hir::ExprUnary(hir::UnDeref, ref base_expr) => {
|
||||
// if this is an overloaded deref, then re-evaluate with
|
||||
// a preference for mut
|
||||
let method_call = ty::MethodCall::expr(expr.id);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ use middle::infer;
|
|||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
|
||||
use rustc_front::hir;
|
||||
|
||||
pub use self::MethodError::*;
|
||||
pub use self::CandidateSource::*;
|
||||
|
||||
|
|
@ -110,8 +112,8 @@ pub fn lookup<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
method_name: ast::Name,
|
||||
self_ty: ty::Ty<'tcx>,
|
||||
supplied_method_types: Vec<ty::Ty<'tcx>>,
|
||||
call_expr: &'tcx ast::Expr,
|
||||
self_expr: &'tcx ast::Expr)
|
||||
call_expr: &'tcx hir::Expr,
|
||||
self_expr: &'tcx hir::Expr)
|
||||
-> Result<ty::MethodCallee<'tcx>, MethodError<'tcx>>
|
||||
{
|
||||
debug!("lookup(method_name={}, self_ty={:?}, call_expr={:?}, self_expr={:?})",
|
||||
|
|
@ -128,7 +130,7 @@ pub fn lookup<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
|
||||
pub fn lookup_in_trait<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
span: Span,
|
||||
self_expr: Option<&ast::Expr>,
|
||||
self_expr: Option<&hir::Expr>,
|
||||
m_name: ast::Name,
|
||||
trait_def_id: DefId,
|
||||
self_ty: ty::Ty<'tcx>,
|
||||
|
|
@ -150,7 +152,7 @@ pub fn lookup_in_trait<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
/// this method is basically the same as confirmation.
|
||||
pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
span: Span,
|
||||
self_expr: Option<&ast::Expr>,
|
||||
self_expr: Option<&hir::Expr>,
|
||||
m_name: ast::Name,
|
||||
trait_def_id: DefId,
|
||||
autoderefs: usize,
|
||||
|
|
@ -335,7 +337,7 @@ pub fn resolve_ufcs<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
let def_id = pick.item.def_id();
|
||||
let mut lp = LastMod(AllPublic);
|
||||
if let probe::InherentImplPick = pick.kind {
|
||||
if pick.item.vis() != ast::Public {
|
||||
if pick.item.vis() != hir::Public {
|
||||
lp = LastMod(DependsOn(def_id));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use middle::infer;
|
|||
use middle::infer::InferCtxt;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::{Span, DUMMY_SP};
|
||||
use rustc_front::hir;
|
||||
use std::collections::HashSet;
|
||||
use std::mem;
|
||||
use std::rc::Rc;
|
||||
|
|
@ -92,7 +93,7 @@ pub struct Pick<'tcx> {
|
|||
// Indicates that an autoref is applied after the optional autoderefs
|
||||
//
|
||||
// B = A | &A | &mut A
|
||||
pub autoref: Option<ast::Mutability>,
|
||||
pub autoref: Option<hir::Mutability>,
|
||||
|
||||
// Indicates that the source expression should be "unsized" to a
|
||||
// target type. This should probably eventually go away in favor
|
||||
|
|
@ -311,59 +312,59 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
|
|||
let lang_def_id = self.tcx().lang_items.slice_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: ast::MutImmutable }) => {
|
||||
ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: hir::MutImmutable }) => {
|
||||
let lang_def_id = self.tcx().lang_items.const_ptr_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: ast::MutMutable }) => {
|
||||
ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: hir::MutMutable }) => {
|
||||
let lang_def_id = self.tcx().lang_items.mut_ptr_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyInt(ast::TyI8) => {
|
||||
ty::TyInt(hir::TyI8) => {
|
||||
let lang_def_id = self.tcx().lang_items.i8_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyInt(ast::TyI16) => {
|
||||
ty::TyInt(hir::TyI16) => {
|
||||
let lang_def_id = self.tcx().lang_items.i16_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyInt(ast::TyI32) => {
|
||||
ty::TyInt(hir::TyI32) => {
|
||||
let lang_def_id = self.tcx().lang_items.i32_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyInt(ast::TyI64) => {
|
||||
ty::TyInt(hir::TyI64) => {
|
||||
let lang_def_id = self.tcx().lang_items.i64_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyInt(ast::TyIs) => {
|
||||
ty::TyInt(hir::TyIs) => {
|
||||
let lang_def_id = self.tcx().lang_items.isize_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyUint(ast::TyU8) => {
|
||||
ty::TyUint(hir::TyU8) => {
|
||||
let lang_def_id = self.tcx().lang_items.u8_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyUint(ast::TyU16) => {
|
||||
ty::TyUint(hir::TyU16) => {
|
||||
let lang_def_id = self.tcx().lang_items.u16_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyUint(ast::TyU32) => {
|
||||
ty::TyUint(hir::TyU32) => {
|
||||
let lang_def_id = self.tcx().lang_items.u32_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyUint(ast::TyU64) => {
|
||||
ty::TyUint(hir::TyU64) => {
|
||||
let lang_def_id = self.tcx().lang_items.u64_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyUint(ast::TyUs) => {
|
||||
ty::TyUint(hir::TyUs) => {
|
||||
let lang_def_id = self.tcx().lang_items.usize_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyFloat(ast::TyF32) => {
|
||||
ty::TyFloat(hir::TyF32) => {
|
||||
let lang_def_id = self.tcx().lang_items.f32_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyFloat(ast::TyF64) => {
|
||||
ty::TyFloat(hir::TyF64) => {
|
||||
let lang_def_id = self.tcx().lang_items.f64_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
|
|
@ -952,7 +953,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
|
|||
let region = tcx.mk_region(ty::ReStatic);
|
||||
|
||||
// Search through mutabilities in order to find one where pick works:
|
||||
[ast::MutImmutable, ast::MutMutable].iter().filter_map(|&m| {
|
||||
[hir::MutImmutable, hir::MutMutable].iter().filter_map(|&m| {
|
||||
let autoref_ty = tcx.mk_ref(region, ty::TypeAndMut {
|
||||
ty: step.self_ty,
|
||||
mutbl: m
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ use metadata::{csearch, cstore, decoder};
|
|||
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::print::pprust;
|
||||
use rustc_front::print::pprust;
|
||||
use rustc_front::hir;
|
||||
|
||||
use std::cell;
|
||||
use std::cmp::Ordering;
|
||||
|
|
@ -37,7 +38,7 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
span: Span,
|
||||
rcvr_ty: Ty<'tcx>,
|
||||
item_name: ast::Name,
|
||||
rcvr_expr: Option<&ast::Expr>,
|
||||
rcvr_expr: Option<&hir::Expr>,
|
||||
error: MethodError<'tcx>)
|
||||
{
|
||||
// avoid suggestions when we don't know what's going on.
|
||||
|
|
@ -221,7 +222,7 @@ fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
span: Span,
|
||||
rcvr_ty: Ty<'tcx>,
|
||||
item_name: ast::Name,
|
||||
rcvr_expr: Option<&ast::Expr>,
|
||||
rcvr_expr: Option<&hir::Expr>,
|
||||
valid_out_of_scope_traits: Vec<DefId>)
|
||||
{
|
||||
let tcx = fcx.tcx();
|
||||
|
|
@ -299,7 +300,7 @@ fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
fn type_derefs_to_local<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
span: Span,
|
||||
rcvr_ty: Ty<'tcx>,
|
||||
rcvr_expr: Option<&ast::Expr>) -> bool {
|
||||
rcvr_expr: Option<&hir::Expr>) -> bool {
|
||||
fn is_local(ty: Ty) -> bool {
|
||||
match ty.sty {
|
||||
ty::TyEnum(def, _) | ty::TyStruct(def, _) => def.did.is_local(),
|
||||
|
|
@ -370,7 +371,7 @@ impl Ord for TraitInfo {
|
|||
/// Retrieve all traits in this crate and any dependent crates.
|
||||
pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> {
|
||||
if ccx.all_traits.borrow().is_none() {
|
||||
use syntax::visit;
|
||||
use rustc_front::visit;
|
||||
|
||||
let mut traits = vec![];
|
||||
|
||||
|
|
@ -381,9 +382,9 @@ pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> {
|
|||
traits: &'a mut AllTraitsVec,
|
||||
}
|
||||
impl<'v, 'a> visit::Visitor<'v> for Visitor<'a> {
|
||||
fn visit_item(&mut self, i: &'v ast::Item) {
|
||||
fn visit_item(&mut self, i: &'v hir::Item) {
|
||||
match i.node {
|
||||
ast::ItemTrait(..) => {
|
||||
hir::ItemTrait(..) => {
|
||||
self.traits.push(TraitInfo::new(DefId::local(i.id)));
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -24,15 +24,16 @@ use middle::def_id::DefId;
|
|||
use middle::traits;
|
||||
use middle::ty::{Ty, HasTypeFlags};
|
||||
use syntax::ast;
|
||||
use syntax::ast_util;
|
||||
use syntax::parse::token;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::util as hir_util;
|
||||
|
||||
/// Check a `a <op>= b`
|
||||
pub fn check_binop_assign<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
||||
expr: &'tcx ast::Expr,
|
||||
op: ast::BinOp,
|
||||
lhs_expr: &'tcx ast::Expr,
|
||||
rhs_expr: &'tcx ast::Expr)
|
||||
expr: &'tcx hir::Expr,
|
||||
op: hir::BinOp,
|
||||
lhs_expr: &'tcx hir::Expr,
|
||||
rhs_expr: &'tcx hir::Expr)
|
||||
{
|
||||
let tcx = fcx.ccx.tcx;
|
||||
|
||||
|
|
@ -50,7 +51,7 @@ pub fn check_binop_assign<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
|||
assert!(!lhs_ty.references_error() || !rhs_ty.references_error());
|
||||
span_err!(tcx.sess, lhs_expr.span, E0368,
|
||||
"binary assignment operation `{}=` cannot be applied to types `{}` and `{}`",
|
||||
ast_util::binop_to_string(op.node),
|
||||
hir_util::binop_to_string(op.node),
|
||||
lhs_ty,
|
||||
rhs_ty);
|
||||
fcx.write_error(expr.id);
|
||||
|
|
@ -66,10 +67,10 @@ pub fn check_binop_assign<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
|||
|
||||
/// Check a potentially overloaded binary operator.
|
||||
pub fn check_binop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
expr: &'tcx ast::Expr,
|
||||
op: ast::BinOp,
|
||||
lhs_expr: &'tcx ast::Expr,
|
||||
rhs_expr: &'tcx ast::Expr)
|
||||
expr: &'tcx hir::Expr,
|
||||
op: hir::BinOp,
|
||||
lhs_expr: &'tcx hir::Expr,
|
||||
rhs_expr: &'tcx hir::Expr)
|
||||
{
|
||||
let tcx = fcx.ccx.tcx;
|
||||
|
||||
|
|
@ -125,11 +126,11 @@ pub fn check_binop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
}
|
||||
|
||||
fn enforce_builtin_binop_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
lhs_expr: &'tcx ast::Expr,
|
||||
lhs_expr: &'tcx hir::Expr,
|
||||
lhs_ty: Ty<'tcx>,
|
||||
rhs_expr: &'tcx ast::Expr,
|
||||
rhs_expr: &'tcx hir::Expr,
|
||||
rhs_ty: Ty<'tcx>,
|
||||
op: ast::BinOp)
|
||||
op: hir::BinOp)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
debug_assert!(is_builtin_binop(lhs_ty, rhs_ty, op));
|
||||
|
|
@ -163,11 +164,11 @@ fn enforce_builtin_binop_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
}
|
||||
|
||||
fn check_overloaded_binop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
expr: &'tcx ast::Expr,
|
||||
lhs_expr: &'tcx ast::Expr,
|
||||
expr: &'tcx hir::Expr,
|
||||
lhs_expr: &'tcx hir::Expr,
|
||||
lhs_ty: Ty<'tcx>,
|
||||
rhs_expr: &'tcx ast::Expr,
|
||||
op: ast::BinOp)
|
||||
rhs_expr: &'tcx hir::Expr,
|
||||
op: hir::BinOp)
|
||||
-> (Ty<'tcx>, Ty<'tcx>)
|
||||
{
|
||||
debug!("check_overloaded_binop(expr.id={}, lhs_ty={:?})",
|
||||
|
|
@ -193,7 +194,7 @@ fn check_overloaded_binop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
if !lhs_ty.references_error() {
|
||||
span_err!(fcx.tcx().sess, lhs_expr.span, E0369,
|
||||
"binary operation `{}` cannot be applied to type `{}`",
|
||||
ast_util::binop_to_string(op.node),
|
||||
hir_util::binop_to_string(op.node),
|
||||
lhs_ty);
|
||||
}
|
||||
fcx.tcx().types.err
|
||||
|
|
@ -210,13 +211,13 @@ pub fn check_user_unop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
op_str: &str,
|
||||
mname: &str,
|
||||
trait_did: Option<DefId>,
|
||||
ex: &'tcx ast::Expr,
|
||||
operand_expr: &'tcx ast::Expr,
|
||||
ex: &'tcx hir::Expr,
|
||||
operand_expr: &'tcx hir::Expr,
|
||||
operand_ty: Ty<'tcx>,
|
||||
op: ast::UnOp)
|
||||
op: hir::UnOp)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
assert!(ast_util::is_by_value_unop(op));
|
||||
assert!(hir_util::is_by_value_unop(op));
|
||||
match lookup_op_method(fcx, ex, operand_ty, vec![],
|
||||
token::intern(mname), trait_did,
|
||||
operand_expr) {
|
||||
|
|
@ -231,38 +232,38 @@ pub fn check_user_unop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
}
|
||||
}
|
||||
|
||||
fn name_and_trait_def_id(fcx: &FnCtxt, op: ast::BinOp) -> (&'static str, Option<DefId>) {
|
||||
fn name_and_trait_def_id(fcx: &FnCtxt, op: hir::BinOp) -> (&'static str, Option<DefId>) {
|
||||
let lang = &fcx.tcx().lang_items;
|
||||
match op.node {
|
||||
ast::BiAdd => ("add", lang.add_trait()),
|
||||
ast::BiSub => ("sub", lang.sub_trait()),
|
||||
ast::BiMul => ("mul", lang.mul_trait()),
|
||||
ast::BiDiv => ("div", lang.div_trait()),
|
||||
ast::BiRem => ("rem", lang.rem_trait()),
|
||||
ast::BiBitXor => ("bitxor", lang.bitxor_trait()),
|
||||
ast::BiBitAnd => ("bitand", lang.bitand_trait()),
|
||||
ast::BiBitOr => ("bitor", lang.bitor_trait()),
|
||||
ast::BiShl => ("shl", lang.shl_trait()),
|
||||
ast::BiShr => ("shr", lang.shr_trait()),
|
||||
ast::BiLt => ("lt", lang.ord_trait()),
|
||||
ast::BiLe => ("le", lang.ord_trait()),
|
||||
ast::BiGe => ("ge", lang.ord_trait()),
|
||||
ast::BiGt => ("gt", lang.ord_trait()),
|
||||
ast::BiEq => ("eq", lang.eq_trait()),
|
||||
ast::BiNe => ("ne", lang.eq_trait()),
|
||||
ast::BiAnd | ast::BiOr => {
|
||||
hir::BiAdd => ("add", lang.add_trait()),
|
||||
hir::BiSub => ("sub", lang.sub_trait()),
|
||||
hir::BiMul => ("mul", lang.mul_trait()),
|
||||
hir::BiDiv => ("div", lang.div_trait()),
|
||||
hir::BiRem => ("rem", lang.rem_trait()),
|
||||
hir::BiBitXor => ("bitxor", lang.bitxor_trait()),
|
||||
hir::BiBitAnd => ("bitand", lang.bitand_trait()),
|
||||
hir::BiBitOr => ("bitor", lang.bitor_trait()),
|
||||
hir::BiShl => ("shl", lang.shl_trait()),
|
||||
hir::BiShr => ("shr", lang.shr_trait()),
|
||||
hir::BiLt => ("lt", lang.ord_trait()),
|
||||
hir::BiLe => ("le", lang.ord_trait()),
|
||||
hir::BiGe => ("ge", lang.ord_trait()),
|
||||
hir::BiGt => ("gt", lang.ord_trait()),
|
||||
hir::BiEq => ("eq", lang.eq_trait()),
|
||||
hir::BiNe => ("ne", lang.eq_trait()),
|
||||
hir::BiAnd | hir::BiOr => {
|
||||
fcx.tcx().sess.span_bug(op.span, "&& and || are not overloadable")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lookup_op_method<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>,
|
||||
expr: &'tcx ast::Expr,
|
||||
expr: &'tcx hir::Expr,
|
||||
lhs_ty: Ty<'tcx>,
|
||||
other_tys: Vec<Ty<'tcx>>,
|
||||
opname: ast::Name,
|
||||
trait_did: Option<DefId>,
|
||||
lhs_expr: &'a ast::Expr)
|
||||
lhs_expr: &'a hir::Expr)
|
||||
-> Result<Ty<'tcx>,()>
|
||||
{
|
||||
debug!("lookup_op_method(expr={:?}, lhs_ty={:?}, opname={:?}, trait_did={:?}, lhs_expr={:?})",
|
||||
|
|
@ -330,33 +331,33 @@ enum BinOpCategory {
|
|||
}
|
||||
|
||||
impl BinOpCategory {
|
||||
fn from(op: ast::BinOp) -> BinOpCategory {
|
||||
fn from(op: hir::BinOp) -> BinOpCategory {
|
||||
match op.node {
|
||||
ast::BiShl | ast::BiShr =>
|
||||
hir::BiShl | hir::BiShr =>
|
||||
BinOpCategory::Shift,
|
||||
|
||||
ast::BiAdd |
|
||||
ast::BiSub |
|
||||
ast::BiMul |
|
||||
ast::BiDiv |
|
||||
ast::BiRem =>
|
||||
hir::BiAdd |
|
||||
hir::BiSub |
|
||||
hir::BiMul |
|
||||
hir::BiDiv |
|
||||
hir::BiRem =>
|
||||
BinOpCategory::Math,
|
||||
|
||||
ast::BiBitXor |
|
||||
ast::BiBitAnd |
|
||||
ast::BiBitOr =>
|
||||
hir::BiBitXor |
|
||||
hir::BiBitAnd |
|
||||
hir::BiBitOr =>
|
||||
BinOpCategory::Bitwise,
|
||||
|
||||
ast::BiEq |
|
||||
ast::BiNe |
|
||||
ast::BiLt |
|
||||
ast::BiLe |
|
||||
ast::BiGe |
|
||||
ast::BiGt =>
|
||||
hir::BiEq |
|
||||
hir::BiNe |
|
||||
hir::BiLt |
|
||||
hir::BiLe |
|
||||
hir::BiGe |
|
||||
hir::BiGt =>
|
||||
BinOpCategory::Comparison,
|
||||
|
||||
ast::BiAnd |
|
||||
ast::BiOr =>
|
||||
hir::BiAnd |
|
||||
hir::BiOr =>
|
||||
BinOpCategory::Shortcircuit,
|
||||
}
|
||||
}
|
||||
|
|
@ -380,7 +381,7 @@ impl BinOpCategory {
|
|||
/// the fact, and it worked fine, except for SIMD types. -nmatsakis
|
||||
fn is_builtin_binop<'tcx>(lhs: Ty<'tcx>,
|
||||
rhs: Ty<'tcx>,
|
||||
op: ast::BinOp)
|
||||
op: hir::BinOp)
|
||||
-> bool
|
||||
{
|
||||
match BinOpCategory::from(op) {
|
||||
|
|
|
|||
|
|
@ -99,10 +99,12 @@ use middle::wf::{self, ImpliedBound};
|
|||
|
||||
use std::mem;
|
||||
use std::rc::Rc;
|
||||
use syntax::{ast, ast_util};
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::visit;
|
||||
use syntax::visit::Visitor;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::visit::Visitor;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::util as hir_util;
|
||||
|
||||
use self::SubjectNode::Subject;
|
||||
|
||||
|
|
@ -114,7 +116,7 @@ macro_rules! ignore_err {
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC ENTRY POINTS
|
||||
|
||||
pub fn regionck_expr(fcx: &FnCtxt, e: &ast::Expr) {
|
||||
pub fn regionck_expr(fcx: &FnCtxt, e: &hir::Expr) {
|
||||
let mut rcx = Rcx::new(fcx, RepeatingScope(e.id), e.id, Subject(e.id));
|
||||
if fcx.err_count_since_creation() == 0 {
|
||||
// regionck assumes typeck succeeded
|
||||
|
|
@ -143,8 +145,8 @@ pub fn regionck_item<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
|||
pub fn regionck_fn(fcx: &FnCtxt,
|
||||
fn_id: ast::NodeId,
|
||||
fn_span: Span,
|
||||
decl: &ast::FnDecl,
|
||||
blk: &ast::Block) {
|
||||
decl: &hir::FnDecl,
|
||||
blk: &hir::Block) {
|
||||
debug!("regionck_fn(id={})", fn_id);
|
||||
let mut rcx = Rcx::new(fcx, RepeatingScope(blk.id), blk.id, Subject(fn_id));
|
||||
|
||||
|
|
@ -260,7 +262,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// Try to resolve the type for the given node.
|
||||
pub fn resolve_expr_type_adjusted(&mut self, expr: &ast::Expr) -> Ty<'tcx> {
|
||||
pub fn resolve_expr_type_adjusted(&mut self, expr: &hir::Expr) -> Ty<'tcx> {
|
||||
let ty_unadjusted = self.resolve_node_type(expr.id);
|
||||
if ty_unadjusted.references_error() {
|
||||
ty_unadjusted
|
||||
|
|
@ -274,8 +276,8 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
|
|||
|
||||
fn visit_fn_body(&mut self,
|
||||
id: ast::NodeId,
|
||||
fn_decl: &ast::FnDecl,
|
||||
body: &ast::Block,
|
||||
fn_decl: &hir::FnDecl,
|
||||
body: &hir::Block,
|
||||
span: Span)
|
||||
{
|
||||
// When we enter a function, we can derive
|
||||
|
|
@ -480,33 +482,33 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Rcx<'a, 'tcx> {
|
|||
// hierarchy, and in particular the relationships between free
|
||||
// regions, until regionck, as described in #3238.
|
||||
|
||||
fn visit_fn(&mut self, _fk: visit::FnKind<'v>, fd: &'v ast::FnDecl,
|
||||
b: &'v ast::Block, span: Span, id: ast::NodeId) {
|
||||
fn visit_fn(&mut self, _fk: visit::FnKind<'v>, fd: &'v hir::FnDecl,
|
||||
b: &'v hir::Block, span: Span, id: ast::NodeId) {
|
||||
self.visit_fn_body(id, fd, b, span)
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, i: &ast::Item) { visit_item(self, i); }
|
||||
fn visit_item(&mut self, i: &hir::Item) { visit_item(self, i); }
|
||||
|
||||
fn visit_expr(&mut self, ex: &ast::Expr) { visit_expr(self, ex); }
|
||||
fn visit_expr(&mut self, ex: &hir::Expr) { visit_expr(self, ex); }
|
||||
|
||||
//visit_pat: visit_pat, // (..) see above
|
||||
|
||||
fn visit_arm(&mut self, a: &ast::Arm) { visit_arm(self, a); }
|
||||
fn visit_arm(&mut self, a: &hir::Arm) { visit_arm(self, a); }
|
||||
|
||||
fn visit_local(&mut self, l: &ast::Local) { visit_local(self, l); }
|
||||
fn visit_local(&mut self, l: &hir::Local) { visit_local(self, l); }
|
||||
|
||||
fn visit_block(&mut self, b: &ast::Block) { visit_block(self, b); }
|
||||
fn visit_block(&mut self, b: &hir::Block) { visit_block(self, b); }
|
||||
}
|
||||
|
||||
fn visit_item(_rcx: &mut Rcx, _item: &ast::Item) {
|
||||
fn visit_item(_rcx: &mut Rcx, _item: &hir::Item) {
|
||||
// Ignore items
|
||||
}
|
||||
|
||||
fn visit_block(rcx: &mut Rcx, b: &ast::Block) {
|
||||
fn visit_block(rcx: &mut Rcx, b: &hir::Block) {
|
||||
visit::walk_block(rcx, b);
|
||||
}
|
||||
|
||||
fn visit_arm(rcx: &mut Rcx, arm: &ast::Arm) {
|
||||
fn visit_arm(rcx: &mut Rcx, arm: &hir::Arm) {
|
||||
// see above
|
||||
for p in &arm.pats {
|
||||
constrain_bindings_in_pat(&**p, rcx);
|
||||
|
|
@ -515,14 +517,14 @@ fn visit_arm(rcx: &mut Rcx, arm: &ast::Arm) {
|
|||
visit::walk_arm(rcx, arm);
|
||||
}
|
||||
|
||||
fn visit_local(rcx: &mut Rcx, l: &ast::Local) {
|
||||
fn visit_local(rcx: &mut Rcx, l: &hir::Local) {
|
||||
// see above
|
||||
constrain_bindings_in_pat(&*l.pat, rcx);
|
||||
link_local(rcx, l);
|
||||
visit::walk_local(rcx, l);
|
||||
}
|
||||
|
||||
fn constrain_bindings_in_pat(pat: &ast::Pat, rcx: &mut Rcx) {
|
||||
fn constrain_bindings_in_pat(pat: &hir::Pat, rcx: &mut Rcx) {
|
||||
let tcx = rcx.fcx.tcx();
|
||||
debug!("regionck::visit_pat(pat={:?})", pat);
|
||||
pat_util::pat_bindings(&tcx.def_map, pat, |_, id, span, _| {
|
||||
|
|
@ -559,7 +561,7 @@ fn constrain_bindings_in_pat(pat: &ast::Pat, rcx: &mut Rcx) {
|
|||
})
|
||||
}
|
||||
|
||||
fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
||||
fn visit_expr(rcx: &mut Rcx, expr: &hir::Expr) {
|
||||
debug!("regionck::visit_expr(e={:?}, repeating_scope={})",
|
||||
expr, rcx.repeating_scope);
|
||||
|
||||
|
|
@ -581,9 +583,9 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
|||
// provided as arguments outlive the call.
|
||||
if let Some(callee) = opt_method_callee {
|
||||
let origin = match expr.node {
|
||||
ast::ExprMethodCall(..) =>
|
||||
hir::ExprMethodCall(..) =>
|
||||
infer::ParameterOrigin::MethodCall,
|
||||
ast::ExprUnary(op, _) if op == ast::UnDeref =>
|
||||
hir::ExprUnary(op, _) if op == hir::UnDeref =>
|
||||
infer::ParameterOrigin::OverloadedDeref,
|
||||
_ =>
|
||||
infer::ParameterOrigin::OverloadedOperator
|
||||
|
|
@ -661,14 +663,14 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
|||
}
|
||||
|
||||
match expr.node {
|
||||
ast::ExprPath(..) => {
|
||||
hir::ExprPath(..) => {
|
||||
rcx.fcx.opt_node_ty_substs(expr.id, |item_substs| {
|
||||
let origin = infer::ParameterOrigin::Path;
|
||||
substs_wf_in_scope(rcx, origin, &item_substs.substs, expr.span, expr_region);
|
||||
});
|
||||
}
|
||||
|
||||
ast::ExprCall(ref callee, ref args) => {
|
||||
hir::ExprCall(ref callee, ref args) => {
|
||||
if has_method_map {
|
||||
constrain_call(rcx, expr, Some(&**callee),
|
||||
args.iter().map(|e| &**e), false);
|
||||
|
|
@ -681,14 +683,14 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
|||
visit::walk_expr(rcx, expr);
|
||||
}
|
||||
|
||||
ast::ExprMethodCall(_, _, ref args) => {
|
||||
hir::ExprMethodCall(_, _, ref args) => {
|
||||
constrain_call(rcx, expr, Some(&*args[0]),
|
||||
args[1..].iter().map(|e| &**e), false);
|
||||
|
||||
visit::walk_expr(rcx, expr);
|
||||
}
|
||||
|
||||
ast::ExprAssignOp(_, ref lhs, ref rhs) => {
|
||||
hir::ExprAssignOp(_, ref lhs, ref rhs) => {
|
||||
if has_method_map {
|
||||
constrain_call(rcx, expr, Some(&**lhs),
|
||||
Some(&**rhs).into_iter(), true);
|
||||
|
|
@ -697,15 +699,15 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
|||
visit::walk_expr(rcx, expr);
|
||||
}
|
||||
|
||||
ast::ExprIndex(ref lhs, ref rhs) if has_method_map => {
|
||||
hir::ExprIndex(ref lhs, ref rhs) if has_method_map => {
|
||||
constrain_call(rcx, expr, Some(&**lhs),
|
||||
Some(&**rhs).into_iter(), true);
|
||||
|
||||
visit::walk_expr(rcx, expr);
|
||||
},
|
||||
|
||||
ast::ExprBinary(op, ref lhs, ref rhs) if has_method_map => {
|
||||
let implicitly_ref_args = !ast_util::is_by_value_binop(op.node);
|
||||
hir::ExprBinary(op, ref lhs, ref rhs) if has_method_map => {
|
||||
let implicitly_ref_args = !hir_util::is_by_value_binop(op.node);
|
||||
|
||||
// As `expr_method_call`, but the call is via an
|
||||
// overloaded op. Note that we (sadly) currently use an
|
||||
|
|
@ -717,7 +719,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
|||
visit::walk_expr(rcx, expr);
|
||||
}
|
||||
|
||||
ast::ExprBinary(_, ref lhs, ref rhs) => {
|
||||
hir::ExprBinary(_, ref lhs, ref rhs) => {
|
||||
// If you do `x OP y`, then the types of `x` and `y` must
|
||||
// outlive the operation you are performing.
|
||||
let lhs_ty = rcx.resolve_expr_type_adjusted(&**lhs);
|
||||
|
|
@ -731,23 +733,23 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
|||
visit::walk_expr(rcx, expr);
|
||||
}
|
||||
|
||||
ast::ExprUnary(op, ref lhs) if has_method_map => {
|
||||
let implicitly_ref_args = !ast_util::is_by_value_unop(op);
|
||||
hir::ExprUnary(op, ref lhs) if has_method_map => {
|
||||
let implicitly_ref_args = !hir_util::is_by_value_unop(op);
|
||||
|
||||
// As above.
|
||||
constrain_call(rcx, expr, Some(&**lhs),
|
||||
None::<ast::Expr>.iter(), implicitly_ref_args);
|
||||
None::<hir::Expr>.iter(), implicitly_ref_args);
|
||||
|
||||
visit::walk_expr(rcx, expr);
|
||||
}
|
||||
|
||||
ast::ExprUnary(ast::UnDeref, ref base) => {
|
||||
hir::ExprUnary(hir::UnDeref, ref base) => {
|
||||
// For *a, the lifetime of a must enclose the deref
|
||||
let method_call = MethodCall::expr(expr.id);
|
||||
let base_ty = match rcx.fcx.inh.tables.borrow().method_map.get(&method_call) {
|
||||
Some(method) => {
|
||||
constrain_call(rcx, expr, Some(&**base),
|
||||
None::<ast::Expr>.iter(), true);
|
||||
None::<hir::Expr>.iter(), true);
|
||||
let fn_ret = // late-bound regions in overloaded method calls are instantiated
|
||||
rcx.tcx().no_late_bound_regions(&method.ty.fn_ret()).unwrap();
|
||||
fn_ret.unwrap()
|
||||
|
|
@ -762,7 +764,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
|||
visit::walk_expr(rcx, expr);
|
||||
}
|
||||
|
||||
ast::ExprIndex(ref vec_expr, _) => {
|
||||
hir::ExprIndex(ref vec_expr, _) => {
|
||||
// For a[b], the lifetime of a must enclose the deref
|
||||
let vec_type = rcx.resolve_expr_type_adjusted(&**vec_expr);
|
||||
constrain_index(rcx, expr, vec_type);
|
||||
|
|
@ -770,7 +772,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
|||
visit::walk_expr(rcx, expr);
|
||||
}
|
||||
|
||||
ast::ExprCast(ref source, _) => {
|
||||
hir::ExprCast(ref source, _) => {
|
||||
// Determine if we are casting `source` to a trait
|
||||
// instance. If so, we have to be sure that the type of
|
||||
// the source obeys the trait's region bound.
|
||||
|
|
@ -778,7 +780,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
|||
visit::walk_expr(rcx, expr);
|
||||
}
|
||||
|
||||
ast::ExprAddrOf(m, ref base) => {
|
||||
hir::ExprAddrOf(m, ref base) => {
|
||||
link_addr_of(rcx, expr, m, &**base);
|
||||
|
||||
// Require that when you write a `&expr` expression, the
|
||||
|
|
@ -793,23 +795,23 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
|||
visit::walk_expr(rcx, expr);
|
||||
}
|
||||
|
||||
ast::ExprMatch(ref discr, ref arms, _) => {
|
||||
hir::ExprMatch(ref discr, ref arms, _) => {
|
||||
link_match(rcx, &**discr, &arms[..]);
|
||||
|
||||
visit::walk_expr(rcx, expr);
|
||||
}
|
||||
|
||||
ast::ExprClosure(_, _, ref body) => {
|
||||
hir::ExprClosure(_, _, ref body) => {
|
||||
check_expr_fn_block(rcx, expr, &**body);
|
||||
}
|
||||
|
||||
ast::ExprLoop(ref body, _) => {
|
||||
hir::ExprLoop(ref body, _) => {
|
||||
let repeating_scope = rcx.set_repeating_scope(body.id);
|
||||
visit::walk_expr(rcx, expr);
|
||||
rcx.set_repeating_scope(repeating_scope);
|
||||
}
|
||||
|
||||
ast::ExprWhile(ref cond, ref body, _) => {
|
||||
hir::ExprWhile(ref cond, ref body, _) => {
|
||||
let repeating_scope = rcx.set_repeating_scope(cond.id);
|
||||
rcx.visit_expr(&**cond);
|
||||
|
||||
|
|
@ -826,8 +828,8 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
|||
}
|
||||
|
||||
fn constrain_cast(rcx: &mut Rcx,
|
||||
cast_expr: &ast::Expr,
|
||||
source_expr: &ast::Expr)
|
||||
cast_expr: &hir::Expr,
|
||||
source_expr: &hir::Expr)
|
||||
{
|
||||
debug!("constrain_cast(cast_expr={:?}, source_expr={:?})",
|
||||
cast_expr,
|
||||
|
|
@ -839,7 +841,7 @@ fn constrain_cast(rcx: &mut Rcx,
|
|||
walk_cast(rcx, cast_expr, source_ty, target_ty);
|
||||
|
||||
fn walk_cast<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
|
||||
cast_expr: &ast::Expr,
|
||||
cast_expr: &hir::Expr,
|
||||
from_ty: Ty<'tcx>,
|
||||
to_ty: Ty<'tcx>) {
|
||||
debug!("walk_cast(from_ty={:?}, to_ty={:?})",
|
||||
|
|
@ -872,8 +874,8 @@ fn constrain_cast(rcx: &mut Rcx,
|
|||
}
|
||||
|
||||
fn check_expr_fn_block(rcx: &mut Rcx,
|
||||
expr: &ast::Expr,
|
||||
body: &ast::Block) {
|
||||
expr: &hir::Expr,
|
||||
body: &hir::Block) {
|
||||
let repeating_scope = rcx.set_repeating_scope(body.id);
|
||||
visit::walk_expr(rcx, expr);
|
||||
rcx.set_repeating_scope(repeating_scope);
|
||||
|
|
@ -881,8 +883,8 @@ fn check_expr_fn_block(rcx: &mut Rcx,
|
|||
|
||||
fn constrain_callee(rcx: &mut Rcx,
|
||||
callee_id: ast::NodeId,
|
||||
_call_expr: &ast::Expr,
|
||||
_callee_expr: &ast::Expr) {
|
||||
_call_expr: &hir::Expr,
|
||||
_callee_expr: &hir::Expr) {
|
||||
let callee_ty = rcx.resolve_node_type(callee_id);
|
||||
match callee_ty.sty {
|
||||
ty::TyBareFn(..) => { }
|
||||
|
|
@ -897,9 +899,9 @@ fn constrain_callee(rcx: &mut Rcx,
|
|||
}
|
||||
}
|
||||
|
||||
fn constrain_call<'a, I: Iterator<Item=&'a ast::Expr>>(rcx: &mut Rcx,
|
||||
call_expr: &ast::Expr,
|
||||
receiver: Option<&ast::Expr>,
|
||||
fn constrain_call<'a, I: Iterator<Item=&'a hir::Expr>>(rcx: &mut Rcx,
|
||||
call_expr: &hir::Expr,
|
||||
receiver: Option<&hir::Expr>,
|
||||
arg_exprs: I,
|
||||
implicitly_ref_args: bool) {
|
||||
//! Invoked on every call site (i.e., normal calls, method calls,
|
||||
|
|
@ -956,7 +958,7 @@ fn constrain_call<'a, I: Iterator<Item=&'a ast::Expr>>(rcx: &mut Rcx,
|
|||
/// Invoked on any auto-dereference that occurs. Checks that if this is a region pointer being
|
||||
/// dereferenced, the lifetime of the pointer includes the deref expr.
|
||||
fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
|
||||
deref_expr: &ast::Expr,
|
||||
deref_expr: &hir::Expr,
|
||||
derefs: usize,
|
||||
mut derefd_ty: Ty<'tcx>)
|
||||
{
|
||||
|
|
@ -1077,7 +1079,7 @@ fn check_safety_of_rvalue_destructor_if_necessary<'a, 'tcx>(rcx: &mut Rcx<'a, 't
|
|||
/// Invoked on any index expression that occurs. Checks that if this is a slice being indexed, the
|
||||
/// lifetime of the pointer includes the deref expr.
|
||||
fn constrain_index<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
|
||||
index_expr: &ast::Expr,
|
||||
index_expr: &hir::Expr,
|
||||
indexed_ty: Ty<'tcx>)
|
||||
{
|
||||
debug!("constrain_index(index_expr=?, indexed_ty={}",
|
||||
|
|
@ -1121,8 +1123,8 @@ fn type_of_node_must_outlive<'a, 'tcx>(
|
|||
|
||||
/// Computes the guarantor for an expression `&base` and then ensures that the lifetime of the
|
||||
/// resulting pointer is linked to the lifetime of its guarantor (if any).
|
||||
fn link_addr_of(rcx: &mut Rcx, expr: &ast::Expr,
|
||||
mutability: ast::Mutability, base: &ast::Expr) {
|
||||
fn link_addr_of(rcx: &mut Rcx, expr: &hir::Expr,
|
||||
mutability: hir::Mutability, base: &hir::Expr) {
|
||||
debug!("link_addr_of(expr={:?}, base={:?})", expr, base);
|
||||
|
||||
let cmt = {
|
||||
|
|
@ -1138,7 +1140,7 @@ fn link_addr_of(rcx: &mut Rcx, expr: &ast::Expr,
|
|||
/// Computes the guarantors for any ref bindings in a `let` and
|
||||
/// then ensures that the lifetime of the resulting pointer is
|
||||
/// linked to the lifetime of the initialization expression.
|
||||
fn link_local(rcx: &Rcx, local: &ast::Local) {
|
||||
fn link_local(rcx: &Rcx, local: &hir::Local) {
|
||||
debug!("regionck::for_local()");
|
||||
let init_expr = match local.init {
|
||||
None => { return; }
|
||||
|
|
@ -1152,7 +1154,7 @@ fn link_local(rcx: &Rcx, local: &ast::Local) {
|
|||
/// Computes the guarantors for any ref bindings in a match and
|
||||
/// then ensures that the lifetime of the resulting pointer is
|
||||
/// linked to the lifetime of its guarantor (if any).
|
||||
fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
|
||||
fn link_match(rcx: &Rcx, discr: &hir::Expr, arms: &[hir::Arm]) {
|
||||
debug!("regionck::for_match()");
|
||||
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
|
||||
let discr_cmt = ignore_err!(mc.cat_expr(discr));
|
||||
|
|
@ -1167,7 +1169,7 @@ fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
|
|||
/// Computes the guarantors for any ref bindings in a match and
|
||||
/// then ensures that the lifetime of the resulting pointer is
|
||||
/// linked to the lifetime of its guarantor (if any).
|
||||
fn link_fn_args(rcx: &Rcx, body_scope: CodeExtent, args: &[ast::Arg]) {
|
||||
fn link_fn_args(rcx: &Rcx, body_scope: CodeExtent, args: &[hir::Arg]) {
|
||||
debug!("regionck::link_fn_args(body_scope={:?})", body_scope);
|
||||
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
|
||||
for arg in args {
|
||||
|
|
@ -1186,21 +1188,21 @@ fn link_fn_args(rcx: &Rcx, body_scope: CodeExtent, args: &[ast::Arg]) {
|
|||
fn link_pattern<'t, 'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
|
||||
mc: mc::MemCategorizationContext<'t, 'a, 'tcx>,
|
||||
discr_cmt: mc::cmt<'tcx>,
|
||||
root_pat: &ast::Pat) {
|
||||
root_pat: &hir::Pat) {
|
||||
debug!("link_pattern(discr_cmt={:?}, root_pat={:?})",
|
||||
discr_cmt,
|
||||
root_pat);
|
||||
let _ = mc.cat_pattern(discr_cmt, root_pat, |mc, sub_cmt, sub_pat| {
|
||||
match sub_pat.node {
|
||||
// `ref x` pattern
|
||||
ast::PatIdent(ast::BindByRef(mutbl), _, _) => {
|
||||
hir::PatIdent(hir::BindByRef(mutbl), _, _) => {
|
||||
link_region_from_node_type(
|
||||
rcx, sub_pat.span, sub_pat.id,
|
||||
mutbl, sub_cmt);
|
||||
}
|
||||
|
||||
// `[_, ..slice, _]` pattern
|
||||
ast::PatVec(_, Some(ref slice_pat), _) => {
|
||||
hir::PatVec(_, Some(ref slice_pat), _) => {
|
||||
match mc.cat_slice_pattern(sub_cmt, &**slice_pat) {
|
||||
Ok((slice_cmt, slice_mutbl, slice_r)) => {
|
||||
link_region(rcx, sub_pat.span, &slice_r,
|
||||
|
|
@ -1218,7 +1220,7 @@ fn link_pattern<'t, 'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
|
|||
/// Link lifetime of borrowed pointer resulting from autoref to lifetimes in the value being
|
||||
/// autoref'd.
|
||||
fn link_autoref(rcx: &Rcx,
|
||||
expr: &ast::Expr,
|
||||
expr: &hir::Expr,
|
||||
autoderefs: usize,
|
||||
autoref: &ty::AutoRef)
|
||||
{
|
||||
|
|
@ -1243,7 +1245,7 @@ fn link_autoref(rcx: &Rcx,
|
|||
/// Computes the guarantor for cases where the `expr` is being passed by implicit reference and
|
||||
/// must outlive `callee_scope`.
|
||||
fn link_by_ref(rcx: &Rcx,
|
||||
expr: &ast::Expr,
|
||||
expr: &hir::Expr,
|
||||
callee_scope: CodeExtent) {
|
||||
debug!("link_by_ref(expr={:?}, callee_scope={:?})",
|
||||
expr, callee_scope);
|
||||
|
|
@ -1258,7 +1260,7 @@ fn link_by_ref(rcx: &Rcx,
|
|||
fn link_region_from_node_type<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
|
||||
span: Span,
|
||||
id: ast::NodeId,
|
||||
mutbl: ast::Mutability,
|
||||
mutbl: hir::Mutability,
|
||||
cmt_borrowed: mc::cmt<'tcx>) {
|
||||
debug!("link_region_from_node_type(id={:?}, mutbl={:?}, cmt_borrowed={:?})",
|
||||
id, mutbl, cmt_borrowed);
|
||||
|
|
|
|||
|
|
@ -51,15 +51,16 @@ use middle::infer::{InferCtxt, UpvarRegion};
|
|||
use std::collections::HashSet;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::visit::{self, Visitor};
|
||||
use rustc_front::hir;
|
||||
use rustc_front::visit::{self, Visitor};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC ENTRY POINTS
|
||||
|
||||
pub fn closure_analyze_fn(fcx: &FnCtxt,
|
||||
_id: ast::NodeId,
|
||||
_decl: &ast::FnDecl,
|
||||
body: &ast::Block)
|
||||
_decl: &hir::FnDecl,
|
||||
body: &hir::Block)
|
||||
{
|
||||
let mut seed = SeedBorrowKind::new(fcx);
|
||||
seed.visit_block(body);
|
||||
|
|
@ -81,9 +82,9 @@ struct SeedBorrowKind<'a,'tcx:'a> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for SeedBorrowKind<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &ast::Expr) {
|
||||
fn visit_expr(&mut self, expr: &hir::Expr) {
|
||||
match expr.node {
|
||||
ast::ExprClosure(cc, _, ref body) => {
|
||||
hir::ExprClosure(cc, _, ref body) => {
|
||||
self.check_closure(expr, cc, &**body);
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +95,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for SeedBorrowKind<'a, 'tcx> {
|
|||
}
|
||||
|
||||
// Skip all items; they aren't in the same context.
|
||||
fn visit_item(&mut self, _: &'v ast::Item) { }
|
||||
fn visit_item(&mut self, _: &'v hir::Item) { }
|
||||
}
|
||||
|
||||
impl<'a,'tcx> SeedBorrowKind<'a,'tcx> {
|
||||
|
|
@ -111,9 +112,9 @@ impl<'a,'tcx> SeedBorrowKind<'a,'tcx> {
|
|||
}
|
||||
|
||||
fn check_closure(&mut self,
|
||||
expr: &ast::Expr,
|
||||
capture_clause: ast::CaptureClause,
|
||||
_body: &ast::Block)
|
||||
expr: &hir::Expr,
|
||||
capture_clause: hir::CaptureClause,
|
||||
_body: &hir::Block)
|
||||
{
|
||||
let closure_def_id = DefId::local(expr.id);
|
||||
if !self.fcx.inh.tables.borrow().closure_kinds.contains_key(&closure_def_id) {
|
||||
|
|
@ -132,10 +133,10 @@ impl<'a,'tcx> SeedBorrowKind<'a,'tcx> {
|
|||
debug!("seed upvar_id {:?}", upvar_id);
|
||||
|
||||
let capture_kind = match capture_clause {
|
||||
ast::CaptureByValue => {
|
||||
hir::CaptureByValue => {
|
||||
ty::UpvarCapture::ByValue
|
||||
}
|
||||
ast::CaptureByRef => {
|
||||
hir::CaptureByRef => {
|
||||
let origin = UpvarRegion(upvar_id, expr.span);
|
||||
let freevar_region = self.infcx().next_region_var(origin);
|
||||
let upvar_borrow = ty::UpvarBorrow { kind: ty::ImmBorrow,
|
||||
|
|
@ -168,8 +169,8 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
|
|||
fn analyze_closure(&mut self,
|
||||
id: ast::NodeId,
|
||||
span: Span,
|
||||
decl: &ast::FnDecl,
|
||||
body: &ast::Block) {
|
||||
decl: &hir::FnDecl,
|
||||
body: &hir::Block) {
|
||||
/*!
|
||||
* Analysis starting point.
|
||||
*/
|
||||
|
|
@ -496,8 +497,8 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
|
|||
impl<'a, 'tcx, 'v> Visitor<'v> for AdjustBorrowKind<'a, 'tcx> {
|
||||
fn visit_fn(&mut self,
|
||||
fn_kind: visit::FnKind<'v>,
|
||||
decl: &'v ast::FnDecl,
|
||||
body: &'v ast::Block,
|
||||
decl: &'v hir::FnDecl,
|
||||
body: &'v hir::Block,
|
||||
span: Span,
|
||||
id: ast::NodeId)
|
||||
{
|
||||
|
|
@ -506,7 +507,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for AdjustBorrowKind<'a, 'tcx> {
|
|||
}
|
||||
|
||||
// Skip all items; they aren't in the same context.
|
||||
fn visit_item(&mut self, _: &'v ast::Item) { }
|
||||
fn visit_item(&mut self, _: &'v hir::Item) { }
|
||||
}
|
||||
|
||||
impl<'a,'tcx> euv::Delegate<'tcx> for AdjustBorrowKind<'a,'tcx> {
|
||||
|
|
@ -521,13 +522,13 @@ impl<'a,'tcx> euv::Delegate<'tcx> for AdjustBorrowKind<'a,'tcx> {
|
|||
}
|
||||
|
||||
fn matched_pat(&mut self,
|
||||
_matched_pat: &ast::Pat,
|
||||
_matched_pat: &hir::Pat,
|
||||
_cmt: mc::cmt<'tcx>,
|
||||
_mode: euv::MatchMode)
|
||||
{}
|
||||
|
||||
fn consume_pat(&mut self,
|
||||
_consume_pat: &ast::Pat,
|
||||
_consume_pat: &hir::Pat,
|
||||
cmt: mc::cmt<'tcx>,
|
||||
mode: euv::ConsumeMode)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@ use std::cell::RefCell;
|
|||
use std::collections::HashSet;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::{DUMMY_SP, Span};
|
||||
use syntax::parse::token::{special_idents};
|
||||
use syntax::visit;
|
||||
use syntax::visit::{FnKind, Visitor};
|
||||
use syntax::parse::token::special_idents;
|
||||
|
||||
use rustc_front::visit::{self, Visitor, FnKind};
|
||||
use rustc_front::hir;
|
||||
|
||||
pub struct CheckTypeWellFormedVisitor<'ccx, 'tcx:'ccx> {
|
||||
ccx: &'ccx CrateCtxt<'ccx, 'tcx>,
|
||||
|
|
@ -52,7 +53,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
/// We do this check as a pre-pass before checking fn bodies because if these constraints are
|
||||
/// not included it frequently leads to confusing errors in fn bodies. So it's better to check
|
||||
/// the types first.
|
||||
fn check_item_well_formed(&mut self, item: &ast::Item) {
|
||||
fn check_item_well_formed(&mut self, item: &hir::Item) {
|
||||
let ccx = self.ccx;
|
||||
debug!("check_item_well_formed(it.id={}, it.ident={})",
|
||||
item.id,
|
||||
|
|
@ -76,10 +77,10 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
///
|
||||
/// won't be allowed unless there's an *explicit* implementation of `Send`
|
||||
/// for `T`
|
||||
ast::ItemImpl(_, ast::ImplPolarity::Positive, _, _, _, _) => {
|
||||
hir::ItemImpl(_, hir::ImplPolarity::Positive, _, _, _, _) => {
|
||||
self.check_impl(item);
|
||||
}
|
||||
ast::ItemImpl(_, ast::ImplPolarity::Negative, _, Some(_), _, _) => {
|
||||
hir::ItemImpl(_, hir::ImplPolarity::Negative, _, Some(_), _, _) => {
|
||||
let trait_ref = ccx.tcx.impl_trait_ref(DefId::local(item.id)).unwrap();
|
||||
ccx.tcx.populate_implementations_for_trait_if_necessary(trait_ref.def_id);
|
||||
match ccx.tcx.lang_items.to_builtin_kind(trait_ref.def_id) {
|
||||
|
|
@ -91,30 +92,30 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
ast::ItemFn(..) => {
|
||||
hir::ItemFn(..) => {
|
||||
self.check_item_type(item);
|
||||
}
|
||||
ast::ItemStatic(..) => {
|
||||
hir::ItemStatic(..) => {
|
||||
self.check_item_type(item);
|
||||
}
|
||||
ast::ItemConst(..) => {
|
||||
hir::ItemConst(..) => {
|
||||
self.check_item_type(item);
|
||||
}
|
||||
ast::ItemStruct(ref struct_def, ref ast_generics) => {
|
||||
hir::ItemStruct(ref struct_def, ref ast_generics) => {
|
||||
self.check_type_defn(item, |fcx| {
|
||||
vec![struct_variant(fcx, &**struct_def)]
|
||||
});
|
||||
|
||||
self.check_variances_for_type_defn(item, ast_generics);
|
||||
}
|
||||
ast::ItemEnum(ref enum_def, ref ast_generics) => {
|
||||
hir::ItemEnum(ref enum_def, ref ast_generics) => {
|
||||
self.check_type_defn(item, |fcx| {
|
||||
enum_variants(fcx, enum_def)
|
||||
});
|
||||
|
||||
self.check_variances_for_type_defn(item, ast_generics);
|
||||
}
|
||||
ast::ItemTrait(_, _, _, ref items) => {
|
||||
hir::ItemTrait(_, _, _, ref items) => {
|
||||
let trait_predicates =
|
||||
ccx.tcx.lookup_predicates(DefId::local(item.id));
|
||||
reject_non_type_param_bounds(ccx.tcx, item.span, &trait_predicates);
|
||||
|
|
@ -128,7 +129,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn with_fcx<F>(&mut self, item: &ast::Item, mut f: F) where
|
||||
fn with_fcx<F>(&mut self, item: &hir::Item, mut f: F) where
|
||||
F: for<'fcx> FnMut(&mut CheckTypeWellFormedVisitor<'ccx, 'tcx>, &FnCtxt<'fcx, 'tcx>),
|
||||
{
|
||||
let ccx = self.ccx;
|
||||
|
|
@ -149,7 +150,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
/// In a type definition, we check that to ensure that the types of the fields are well-formed.
|
||||
fn check_type_defn<F>(&mut self, item: &ast::Item, mut lookup_fields: F) where
|
||||
fn check_type_defn<F>(&mut self, item: &hir::Item, mut lookup_fields: F) where
|
||||
F: for<'fcx> FnMut(&FnCtxt<'fcx, 'tcx>) -> Vec<AdtVariant<'tcx>>,
|
||||
{
|
||||
self.with_fcx(item, |this, fcx| {
|
||||
|
|
@ -185,7 +186,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
fn check_item_type(&mut self,
|
||||
item: &ast::Item)
|
||||
item: &hir::Item)
|
||||
{
|
||||
self.with_fcx(item, |this, fcx| {
|
||||
let mut bounds_checker = BoundsChecker::new(fcx,
|
||||
|
|
@ -206,7 +207,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
fn check_impl(&mut self,
|
||||
item: &ast::Item)
|
||||
item: &hir::Item)
|
||||
{
|
||||
self.with_fcx(item, |this, fcx| {
|
||||
let mut bounds_checker = BoundsChecker::new(fcx,
|
||||
|
|
@ -275,8 +276,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
fn check_variances_for_type_defn(&self,
|
||||
item: &ast::Item,
|
||||
ast_generics: &ast::Generics)
|
||||
item: &hir::Item,
|
||||
ast_generics: &hir::Generics)
|
||||
{
|
||||
let item_def_id = DefId::local(item.id);
|
||||
let ty_predicates = self.tcx().lookup_predicates(item_def_id);
|
||||
|
|
@ -317,7 +318,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
fn param_ty(&self,
|
||||
ast_generics: &ast::Generics,
|
||||
ast_generics: &hir::Generics,
|
||||
space: ParamSpace,
|
||||
index: usize)
|
||||
-> ty::ParamTy
|
||||
|
|
@ -332,8 +333,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
fn ty_param_span(&self,
|
||||
ast_generics: &ast::Generics,
|
||||
item: &ast::Item,
|
||||
ast_generics: &hir::Generics,
|
||||
item: &hir::Item,
|
||||
space: ParamSpace,
|
||||
index: usize)
|
||||
-> Span
|
||||
|
|
@ -419,14 +420,14 @@ fn reject_shadowing_type_parameters<'tcx>(tcx: &ty::ctxt<'tcx>,
|
|||
}
|
||||
|
||||
impl<'ccx, 'tcx, 'v> Visitor<'v> for CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
||||
fn visit_item(&mut self, i: &ast::Item) {
|
||||
fn visit_item(&mut self, i: &hir::Item) {
|
||||
self.check_item_well_formed(i);
|
||||
visit::walk_item(self, i);
|
||||
}
|
||||
|
||||
fn visit_fn(&mut self,
|
||||
fk: FnKind<'v>, fd: &'v ast::FnDecl,
|
||||
b: &'v ast::Block, span: Span, id: ast::NodeId) {
|
||||
fk: FnKind<'v>, fd: &'v hir::FnDecl,
|
||||
b: &'v hir::Block, span: Span, id: ast::NodeId) {
|
||||
match fk {
|
||||
FnKind::Closure | FnKind::ItemFn(..) => {}
|
||||
FnKind::Method(..) => {
|
||||
|
|
@ -441,8 +442,8 @@ impl<'ccx, 'tcx, 'v> Visitor<'v> for CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
visit::walk_fn(self, fk, fd, b, span)
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, trait_item: &'v ast::TraitItem) {
|
||||
if let ast::MethodTraitItem(_, None) = trait_item.node {
|
||||
fn visit_trait_item(&mut self, trait_item: &'v hir::TraitItem) {
|
||||
if let hir::MethodTraitItem(_, None) = trait_item.node {
|
||||
match self.tcx().impl_or_trait_item(DefId::local(trait_item.id)) {
|
||||
ty::ImplOrTraitItem::MethodTraitItem(ty_method) => {
|
||||
reject_non_type_param_bounds(
|
||||
|
|
@ -622,7 +623,7 @@ struct AdtField<'tcx> {
|
|||
}
|
||||
|
||||
fn struct_variant<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
struct_def: &ast::StructDef)
|
||||
struct_def: &hir::StructDef)
|
||||
-> AdtVariant<'tcx> {
|
||||
let fields =
|
||||
struct_def.fields
|
||||
|
|
@ -642,12 +643,12 @@ fn struct_variant<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
}
|
||||
|
||||
fn enum_variants<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
enum_def: &ast::EnumDef)
|
||||
enum_def: &hir::EnumDef)
|
||||
-> Vec<AdtVariant<'tcx>> {
|
||||
enum_def.variants.iter()
|
||||
.map(|variant| {
|
||||
match variant.node.kind {
|
||||
ast::TupleVariantKind(ref args) if !args.is_empty() => {
|
||||
hir::TupleVariantKind(ref args) if !args.is_empty() => {
|
||||
let ctor_ty = fcx.tcx().node_id_to_type(variant.node.id);
|
||||
|
||||
// the regions in the argument types come from the
|
||||
|
|
@ -670,12 +671,12 @@ fn enum_variants<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
}).collect()
|
||||
}
|
||||
}
|
||||
ast::TupleVariantKind(_) => {
|
||||
hir::TupleVariantKind(_) => {
|
||||
AdtVariant {
|
||||
fields: Vec::new()
|
||||
}
|
||||
}
|
||||
ast::StructVariantKind(ref struct_def) => {
|
||||
hir::StructVariantKind(ref struct_def) => {
|
||||
struct_variant(fcx, &**struct_def)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,9 @@ use syntax::ast;
|
|||
use syntax::codemap::{Span};
|
||||
use syntax::parse::token::{special_idents};
|
||||
use syntax::ptr::P;
|
||||
use syntax::visit;
|
||||
use syntax::visit::Visitor;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::visit::Visitor;
|
||||
use rustc_front::hir;
|
||||
|
||||
pub struct CheckTypeWellFormedVisitor<'ccx, 'tcx:'ccx> {
|
||||
ccx: &'ccx CrateCtxt<'ccx, 'tcx>,
|
||||
|
|
@ -59,7 +60,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
/// We do this check as a pre-pass before checking fn bodies because if these constraints are
|
||||
/// not included it frequently leads to confusing errors in fn bodies. So it's better to check
|
||||
/// the types first.
|
||||
fn check_item_well_formed(&mut self, item: &ast::Item) {
|
||||
fn check_item_well_formed(&mut self, item: &hir::Item) {
|
||||
let ccx = self.ccx;
|
||||
debug!("check_item_well_formed(it.id={}, it.ident={})",
|
||||
item.id,
|
||||
|
|
@ -83,11 +84,11 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
///
|
||||
/// won't be allowed unless there's an *explicit* implementation of `Send`
|
||||
/// for `T`
|
||||
ast::ItemImpl(_, ast::ImplPolarity::Positive, _,
|
||||
hir::ItemImpl(_, hir::ImplPolarity::Positive, _,
|
||||
ref trait_ref, ref self_ty, _) => {
|
||||
self.check_impl(item, self_ty, trait_ref);
|
||||
}
|
||||
ast::ItemImpl(_, ast::ImplPolarity::Negative, _, Some(_), _, _) => {
|
||||
hir::ItemImpl(_, hir::ImplPolarity::Negative, _, Some(_), _, _) => {
|
||||
// FIXME(#27579) what amount of WF checking do we need for neg impls?
|
||||
|
||||
let trait_ref = ccx.tcx.impl_trait_ref(DefId::local(item.id)).unwrap();
|
||||
|
|
@ -101,30 +102,30 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
ast::ItemFn(_, _, _, _, _, ref body) => {
|
||||
hir::ItemFn(_, _, _, _, _, ref body) => {
|
||||
self.check_item_fn(item, body);
|
||||
}
|
||||
ast::ItemStatic(..) => {
|
||||
hir::ItemStatic(..) => {
|
||||
self.check_item_type(item);
|
||||
}
|
||||
ast::ItemConst(..) => {
|
||||
hir::ItemConst(..) => {
|
||||
self.check_item_type(item);
|
||||
}
|
||||
ast::ItemStruct(ref struct_def, ref ast_generics) => {
|
||||
hir::ItemStruct(ref struct_def, ref ast_generics) => {
|
||||
self.check_type_defn(item, |fcx| {
|
||||
vec![struct_variant(fcx, &**struct_def)]
|
||||
});
|
||||
|
||||
self.check_variances_for_type_defn(item, ast_generics);
|
||||
}
|
||||
ast::ItemEnum(ref enum_def, ref ast_generics) => {
|
||||
hir::ItemEnum(ref enum_def, ref ast_generics) => {
|
||||
self.check_type_defn(item, |fcx| {
|
||||
enum_variants(fcx, enum_def)
|
||||
});
|
||||
|
||||
self.check_variances_for_type_defn(item, ast_generics);
|
||||
}
|
||||
ast::ItemTrait(_, _, _, ref items) => {
|
||||
hir::ItemTrait(_, _, _, ref items) => {
|
||||
self.check_trait(item, items);
|
||||
}
|
||||
_ => {}
|
||||
|
|
@ -168,7 +169,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
})
|
||||
}
|
||||
|
||||
fn with_item_fcx<F>(&mut self, item: &ast::Item, f: F) where
|
||||
fn with_item_fcx<F>(&mut self, item: &hir::Item, f: F) where
|
||||
F: for<'fcx> FnMut(&FnCtxt<'fcx, 'tcx>,
|
||||
&mut CheckTypeWellFormedVisitor<'ccx,'tcx>) -> Vec<Ty<'tcx>>,
|
||||
{
|
||||
|
|
@ -190,7 +191,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
/// In a type definition, we check that to ensure that the types of the fields are well-formed.
|
||||
fn check_type_defn<F>(&mut self, item: &ast::Item, mut lookup_fields: F) where
|
||||
fn check_type_defn<F>(&mut self, item: &hir::Item, mut lookup_fields: F) where
|
||||
F: for<'fcx> FnMut(&FnCtxt<'fcx, 'tcx>) -> Vec<AdtVariant<'tcx>>,
|
||||
{
|
||||
self.with_item_fcx(item, |fcx, this| {
|
||||
|
|
@ -225,8 +226,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
fn check_trait(&mut self,
|
||||
item: &ast::Item,
|
||||
items: &[P<ast::TraitItem>])
|
||||
item: &hir::Item,
|
||||
items: &[P<hir::TraitItem>])
|
||||
{
|
||||
let trait_def_id = DefId::local(item.id);
|
||||
|
||||
|
|
@ -246,8 +247,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
fn check_item_fn(&mut self,
|
||||
item: &ast::Item,
|
||||
body: &ast::Block)
|
||||
item: &hir::Item,
|
||||
body: &hir::Block)
|
||||
{
|
||||
self.with_item_fcx(item, |fcx, this| {
|
||||
let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
|
||||
|
|
@ -271,7 +272,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
fn check_item_type(&mut self,
|
||||
item: &ast::Item)
|
||||
item: &hir::Item)
|
||||
{
|
||||
debug!("check_item_type: {:?}", item);
|
||||
|
||||
|
|
@ -291,9 +292,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
fn check_impl(&mut self,
|
||||
item: &ast::Item,
|
||||
ast_self_ty: &ast::Ty,
|
||||
ast_trait_ref: &Option<ast::TraitRef>)
|
||||
item: &hir::Item,
|
||||
ast_self_ty: &hir::Ty,
|
||||
ast_trait_ref: &Option<hir::TraitRef>)
|
||||
{
|
||||
debug!("check_impl: {:?}", item);
|
||||
|
||||
|
|
@ -383,8 +384,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
fn check_variances_for_type_defn(&self,
|
||||
item: &ast::Item,
|
||||
ast_generics: &ast::Generics)
|
||||
item: &hir::Item,
|
||||
ast_generics: &hir::Generics)
|
||||
{
|
||||
let item_def_id = DefId::local(item.id);
|
||||
let ty_predicates = self.tcx().lookup_predicates(item_def_id);
|
||||
|
|
@ -425,7 +426,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
fn param_ty(&self,
|
||||
ast_generics: &ast::Generics,
|
||||
ast_generics: &hir::Generics,
|
||||
space: ParamSpace,
|
||||
index: usize)
|
||||
-> ty::ParamTy
|
||||
|
|
@ -440,8 +441,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
}
|
||||
|
||||
fn ty_param_span(&self,
|
||||
ast_generics: &ast::Generics,
|
||||
item: &ast::Item,
|
||||
ast_generics: &hir::Generics,
|
||||
item: &hir::Item,
|
||||
space: ParamSpace,
|
||||
index: usize)
|
||||
-> Span
|
||||
|
|
@ -489,19 +490,19 @@ fn reject_shadowing_type_parameters<'tcx>(tcx: &ty::ctxt<'tcx>,
|
|||
}
|
||||
|
||||
impl<'ccx, 'tcx, 'v> Visitor<'v> for CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
||||
fn visit_item(&mut self, i: &ast::Item) {
|
||||
fn visit_item(&mut self, i: &hir::Item) {
|
||||
debug!("visit_item: {:?}", i);
|
||||
self.check_item_well_formed(i);
|
||||
visit::walk_item(self, i);
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, trait_item: &'v ast::TraitItem) {
|
||||
fn visit_trait_item(&mut self, trait_item: &'v hir::TraitItem) {
|
||||
debug!("visit_trait_item: {:?}", trait_item);
|
||||
self.check_trait_or_impl_item(trait_item.id, trait_item.span);
|
||||
visit::walk_trait_item(self, trait_item)
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &'v ast::ImplItem) {
|
||||
fn visit_impl_item(&mut self, impl_item: &'v hir::ImplItem) {
|
||||
debug!("visit_impl_item: {:?}", impl_item);
|
||||
self.check_trait_or_impl_item(impl_item.id, impl_item.span);
|
||||
visit::walk_impl_item(self, impl_item)
|
||||
|
|
@ -521,7 +522,7 @@ struct AdtField<'tcx> {
|
|||
}
|
||||
|
||||
fn struct_variant<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
struct_def: &ast::StructDef)
|
||||
struct_def: &hir::StructDef)
|
||||
-> AdtVariant<'tcx> {
|
||||
let fields =
|
||||
struct_def.fields
|
||||
|
|
@ -541,12 +542,12 @@ fn struct_variant<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
}
|
||||
|
||||
fn enum_variants<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
enum_def: &ast::EnumDef)
|
||||
enum_def: &hir::EnumDef)
|
||||
-> Vec<AdtVariant<'tcx>> {
|
||||
enum_def.variants.iter()
|
||||
.map(|variant| {
|
||||
match variant.node.kind {
|
||||
ast::TupleVariantKind(ref args) if !args.is_empty() => {
|
||||
hir::TupleVariantKind(ref args) if !args.is_empty() => {
|
||||
let ctor_ty = fcx.tcx().node_id_to_type(variant.node.id);
|
||||
|
||||
// the regions in the argument types come from the
|
||||
|
|
@ -569,12 +570,12 @@ fn enum_variants<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
}).collect()
|
||||
}
|
||||
}
|
||||
ast::TupleVariantKind(_) => {
|
||||
hir::TupleVariantKind(_) => {
|
||||
AdtVariant {
|
||||
fields: Vec::new()
|
||||
}
|
||||
}
|
||||
ast::StructVariantKind(ref struct_def) => {
|
||||
hir::StructVariantKind(ref struct_def) => {
|
||||
struct_variant(fcx, &**struct_def)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,16 +26,17 @@ use write_ty_to_tcx;
|
|||
use std::cell::Cell;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::ast_util;
|
||||
use syntax::codemap::{DUMMY_SP, Span};
|
||||
use syntax::print::pprust::pat_to_string;
|
||||
use syntax::visit;
|
||||
use syntax::visit::Visitor;
|
||||
use rustc_front::print::pprust::pat_to_string;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::visit::Visitor;
|
||||
use rustc_front::util as hir_util;
|
||||
use rustc_front::hir;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Entry point functions
|
||||
|
||||
pub fn resolve_type_vars_in_expr(fcx: &FnCtxt, e: &ast::Expr) {
|
||||
pub fn resolve_type_vars_in_expr(fcx: &FnCtxt, e: &hir::Expr) {
|
||||
assert_eq!(fcx.writeback_errors.get(), false);
|
||||
let mut wbcx = WritebackCx::new(fcx);
|
||||
wbcx.visit_expr(e);
|
||||
|
|
@ -44,8 +45,8 @@ pub fn resolve_type_vars_in_expr(fcx: &FnCtxt, e: &ast::Expr) {
|
|||
}
|
||||
|
||||
pub fn resolve_type_vars_in_fn(fcx: &FnCtxt,
|
||||
decl: &ast::FnDecl,
|
||||
blk: &ast::Block) {
|
||||
decl: &hir::FnDecl,
|
||||
blk: &hir::Block) {
|
||||
assert_eq!(fcx.writeback_errors.get(), false);
|
||||
let mut wbcx = WritebackCx::new(fcx);
|
||||
wbcx.visit_block(blk);
|
||||
|
|
@ -88,8 +89,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||
// as potentially overloaded. But then, during writeback, if
|
||||
// we observe that something like `a+b` is (known to be)
|
||||
// operating on scalars, we clear the overload.
|
||||
fn fix_scalar_binary_expr(&mut self, e: &ast::Expr) {
|
||||
if let ast::ExprBinary(ref op, ref lhs, ref rhs) = e.node {
|
||||
fn fix_scalar_binary_expr(&mut self, e: &hir::Expr) {
|
||||
if let hir::ExprBinary(ref op, ref lhs, ref rhs) = e.node {
|
||||
let lhs_ty = self.fcx.node_ty(lhs.id);
|
||||
let lhs_ty = self.fcx.infcx().resolve_type_vars_if_possible(&lhs_ty);
|
||||
|
||||
|
|
@ -103,7 +104,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||
// adjustment on the lhs but not the rhs; the
|
||||
// adjustment for rhs is kind of baked into the
|
||||
// system.
|
||||
if !ast_util::is_by_value_binop(op.node) {
|
||||
if !hir_util::is_by_value_binop(op.node) {
|
||||
self.fcx.inh.tables.borrow_mut().adjustments.remove(&lhs.id);
|
||||
}
|
||||
}
|
||||
|
|
@ -120,20 +121,20 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||
// traffic in node-ids or update tables in the type context etc.
|
||||
|
||||
impl<'cx, 'tcx, 'v> Visitor<'v> for WritebackCx<'cx, 'tcx> {
|
||||
fn visit_item(&mut self, _: &ast::Item) {
|
||||
fn visit_item(&mut self, _: &hir::Item) {
|
||||
// Ignore items
|
||||
}
|
||||
|
||||
fn visit_stmt(&mut self, s: &ast::Stmt) {
|
||||
fn visit_stmt(&mut self, s: &hir::Stmt) {
|
||||
if self.fcx.writeback_errors.get() {
|
||||
return;
|
||||
}
|
||||
|
||||
self.visit_node_id(ResolvingExpr(s.span), ast_util::stmt_id(s));
|
||||
self.visit_node_id(ResolvingExpr(s.span), hir_util::stmt_id(s));
|
||||
visit::walk_stmt(self, s);
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, e: &ast::Expr) {
|
||||
fn visit_expr(&mut self, e: &hir::Expr) {
|
||||
if self.fcx.writeback_errors.get() {
|
||||
return;
|
||||
}
|
||||
|
|
@ -144,7 +145,7 @@ impl<'cx, 'tcx, 'v> Visitor<'v> for WritebackCx<'cx, 'tcx> {
|
|||
self.visit_method_map_entry(ResolvingExpr(e.span),
|
||||
MethodCall::expr(e.id));
|
||||
|
||||
if let ast::ExprClosure(_, ref decl, _) = e.node {
|
||||
if let hir::ExprClosure(_, ref decl, _) = e.node {
|
||||
for input in &decl.inputs {
|
||||
self.visit_node_id(ResolvingExpr(e.span), input.id);
|
||||
}
|
||||
|
|
@ -153,7 +154,7 @@ impl<'cx, 'tcx, 'v> Visitor<'v> for WritebackCx<'cx, 'tcx> {
|
|||
visit::walk_expr(self, e);
|
||||
}
|
||||
|
||||
fn visit_block(&mut self, b: &ast::Block) {
|
||||
fn visit_block(&mut self, b: &hir::Block) {
|
||||
if self.fcx.writeback_errors.get() {
|
||||
return;
|
||||
}
|
||||
|
|
@ -162,7 +163,7 @@ impl<'cx, 'tcx, 'v> Visitor<'v> for WritebackCx<'cx, 'tcx> {
|
|||
visit::walk_block(self, b);
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, p: &ast::Pat) {
|
||||
fn visit_pat(&mut self, p: &hir::Pat) {
|
||||
if self.fcx.writeback_errors.get() {
|
||||
return;
|
||||
}
|
||||
|
|
@ -177,7 +178,7 @@ impl<'cx, 'tcx, 'v> Visitor<'v> for WritebackCx<'cx, 'tcx> {
|
|||
visit::walk_pat(self, p);
|
||||
}
|
||||
|
||||
fn visit_local(&mut self, l: &ast::Local) {
|
||||
fn visit_local(&mut self, l: &hir::Local) {
|
||||
if self.fcx.writeback_errors.get() {
|
||||
return;
|
||||
}
|
||||
|
|
@ -188,9 +189,9 @@ impl<'cx, 'tcx, 'v> Visitor<'v> for WritebackCx<'cx, 'tcx> {
|
|||
visit::walk_local(self, l);
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, t: &ast::Ty) {
|
||||
fn visit_ty(&mut self, t: &hir::Ty) {
|
||||
match t.node {
|
||||
ast::TyFixedLengthVec(ref ty, ref count_expr) => {
|
||||
hir::TyFixedLengthVec(ref ty, ref count_expr) => {
|
||||
self.visit_ty(&**ty);
|
||||
write_ty_to_tcx(self.tcx(), count_expr.id, self.tcx().types.usize);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,16 +33,16 @@ use middle::ty;
|
|||
use middle::free_region::FreeRegionMap;
|
||||
use CrateCtxt;
|
||||
use middle::infer::{self, InferCtxt, new_infer_ctxt};
|
||||
use rustc::ast_map::{self, NodeItem};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use syntax::ast::{Crate};
|
||||
use syntax::ast::{Item, ItemImpl};
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token;
|
||||
use syntax::visit;
|
||||
use util::nodemap::{DefIdMap, FnvHashMap};
|
||||
use rustc::front::map as hir_map;
|
||||
use rustc::front::map::NodeItem;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::hir::{Item, ItemImpl,Crate};
|
||||
use rustc_front::hir;
|
||||
|
||||
mod orphan;
|
||||
mod overlap;
|
||||
|
|
@ -254,19 +254,15 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
|
|||
let mut items: Vec<ImplOrTraitItemId> =
|
||||
impl_items.iter().map(|impl_item| {
|
||||
match impl_item.node {
|
||||
ast::ConstImplItem(..) => {
|
||||
hir::ConstImplItem(..) => {
|
||||
ConstTraitItemId(DefId::local(impl_item.id))
|
||||
}
|
||||
ast::MethodImplItem(..) => {
|
||||
hir::MethodImplItem(..) => {
|
||||
MethodTraitItemId(DefId::local(impl_item.id))
|
||||
}
|
||||
ast::TypeImplItem(_) => {
|
||||
hir::TypeImplItem(_) => {
|
||||
TypeTraitItemId(DefId::local(impl_item.id))
|
||||
}
|
||||
ast::MacImplItem(_) => {
|
||||
self.crate_context.tcx.sess.span_bug(impl_item.span,
|
||||
"unexpanded macro");
|
||||
}
|
||||
}
|
||||
}).collect();
|
||||
|
||||
|
|
@ -321,7 +317,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
|
|||
if impl_did.is_local() {
|
||||
{
|
||||
match tcx.map.find(impl_did.node) {
|
||||
Some(ast_map::NodeItem(item)) => {
|
||||
Some(hir_map::NodeItem(item)) => {
|
||||
span_err!(tcx.sess, item.span, E0120,
|
||||
"the Drop trait may only be implemented on structures");
|
||||
}
|
||||
|
|
@ -448,7 +444,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
|
|||
|
||||
let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>, mt_b: ty::TypeAndMut<'tcx>,
|
||||
mk_ptr: &Fn(Ty<'tcx>) -> Ty<'tcx>| {
|
||||
if (mt_a.mutbl, mt_b.mutbl) == (ast::MutImmutable, ast::MutMutable) {
|
||||
if (mt_a.mutbl, mt_b.mutbl) == (hir::MutImmutable, hir::MutMutable) {
|
||||
infcx.report_mismatched_types(span, mk_ptr(mt_b.ty),
|
||||
target, &ty::TypeError::Mutability);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@
|
|||
use middle::def_id::{DefId, LOCAL_CRATE};
|
||||
use middle::traits;
|
||||
use middle::ty;
|
||||
use syntax::ast::{Item, ItemImpl};
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::visit;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::hir::{Item, ItemImpl};
|
||||
|
||||
pub fn check(tcx: &ty::ctxt) {
|
||||
let mut orphan = OrphanChecker { tcx: tcx };
|
||||
|
|
@ -29,7 +29,7 @@ struct OrphanChecker<'cx, 'tcx:'cx> {
|
|||
}
|
||||
|
||||
impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
|
||||
fn check_def_id(&self, item: &ast::Item, def_id: DefId) {
|
||||
fn check_def_id(&self, item: &hir::Item, def_id: DefId) {
|
||||
if def_id.krate != LOCAL_CRATE {
|
||||
span_err!(self.tcx.sess, item.span, E0116,
|
||||
"cannot define inherent `impl` for a type outside of the \
|
||||
|
|
@ -61,10 +61,10 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
|
|||
/// apply to a specific impl, so just return after reporting one
|
||||
/// to prevent inundating the user with a bunch of similar error
|
||||
/// reports.
|
||||
fn check_item(&self, item: &ast::Item) {
|
||||
fn check_item(&self, item: &hir::Item) {
|
||||
let def_id = DefId::local(item.id);
|
||||
match item.node {
|
||||
ast::ItemImpl(_, _, _, None, _, _) => {
|
||||
hir::ItemImpl(_, _, _, None, _, _) => {
|
||||
// For inherent impls, self type must be a nominal type
|
||||
// defined in this crate.
|
||||
debug!("coherence2::orphan check: inherent impl {}",
|
||||
|
|
@ -105,98 +105,98 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
|
|||
"[T]",
|
||||
item.span);
|
||||
}
|
||||
ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: ast::MutImmutable }) => {
|
||||
ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: hir::MutImmutable }) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.const_ptr_impl(),
|
||||
"const_ptr",
|
||||
"*const T",
|
||||
item.span);
|
||||
}
|
||||
ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: ast::MutMutable }) => {
|
||||
ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: hir::MutMutable }) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.mut_ptr_impl(),
|
||||
"mut_ptr",
|
||||
"*mut T",
|
||||
item.span);
|
||||
}
|
||||
ty::TyInt(ast::TyI8) => {
|
||||
ty::TyInt(hir::TyI8) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.i8_impl(),
|
||||
"i8",
|
||||
"i8",
|
||||
item.span);
|
||||
}
|
||||
ty::TyInt(ast::TyI16) => {
|
||||
ty::TyInt(hir::TyI16) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.i16_impl(),
|
||||
"i16",
|
||||
"i16",
|
||||
item.span);
|
||||
}
|
||||
ty::TyInt(ast::TyI32) => {
|
||||
ty::TyInt(hir::TyI32) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.i32_impl(),
|
||||
"i32",
|
||||
"i32",
|
||||
item.span);
|
||||
}
|
||||
ty::TyInt(ast::TyI64) => {
|
||||
ty::TyInt(hir::TyI64) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.i64_impl(),
|
||||
"i64",
|
||||
"i64",
|
||||
item.span);
|
||||
}
|
||||
ty::TyInt(ast::TyIs) => {
|
||||
ty::TyInt(hir::TyIs) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.isize_impl(),
|
||||
"isize",
|
||||
"isize",
|
||||
item.span);
|
||||
}
|
||||
ty::TyUint(ast::TyU8) => {
|
||||
ty::TyUint(hir::TyU8) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.u8_impl(),
|
||||
"u8",
|
||||
"u8",
|
||||
item.span);
|
||||
}
|
||||
ty::TyUint(ast::TyU16) => {
|
||||
ty::TyUint(hir::TyU16) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.u16_impl(),
|
||||
"u16",
|
||||
"u16",
|
||||
item.span);
|
||||
}
|
||||
ty::TyUint(ast::TyU32) => {
|
||||
ty::TyUint(hir::TyU32) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.u32_impl(),
|
||||
"u32",
|
||||
"u32",
|
||||
item.span);
|
||||
}
|
||||
ty::TyUint(ast::TyU64) => {
|
||||
ty::TyUint(hir::TyU64) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.u64_impl(),
|
||||
"u64",
|
||||
"u64",
|
||||
item.span);
|
||||
}
|
||||
ty::TyUint(ast::TyUs) => {
|
||||
ty::TyUint(hir::TyUs) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.usize_impl(),
|
||||
"usize",
|
||||
"usize",
|
||||
item.span);
|
||||
}
|
||||
ty::TyFloat(ast::TyF32) => {
|
||||
ty::TyFloat(hir::TyF32) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.f32_impl(),
|
||||
"f32",
|
||||
"f32",
|
||||
item.span);
|
||||
}
|
||||
ty::TyFloat(ast::TyF64) => {
|
||||
ty::TyFloat(hir::TyF64) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.f64_impl(),
|
||||
"f64",
|
||||
|
|
@ -211,7 +211,7 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
ast::ItemImpl(_, _, _, Some(_), _, _) => {
|
||||
hir::ItemImpl(_, _, _, Some(_), _, _) => {
|
||||
// "Trait" impl
|
||||
debug!("coherence2::orphan check: trait impl {}",
|
||||
self.tcx.map.node_to_string(item.id));
|
||||
|
|
@ -333,7 +333,7 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
|
|||
return;
|
||||
}
|
||||
}
|
||||
ast::ItemDefaultImpl(..) => {
|
||||
hir::ItemDefaultImpl(..) => {
|
||||
// "Trait" impl
|
||||
debug!("coherence2::orphan check: default trait impl {}",
|
||||
self.tcx.map.node_to_string(item.id));
|
||||
|
|
@ -353,7 +353,7 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'cx, 'tcx,'v> visit::Visitor<'v> for OrphanChecker<'cx, 'tcx> {
|
||||
fn visit_item(&mut self, item: &ast::Item) {
|
||||
fn visit_item(&mut self, item: &hir::Item) {
|
||||
self.check_item(item);
|
||||
visit::walk_item(self, item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@ use middle::traits;
|
|||
use middle::ty;
|
||||
use middle::infer::{self, new_infer_ctxt};
|
||||
use syntax::ast;
|
||||
use syntax::visit;
|
||||
use syntax::codemap::Span;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::visit;
|
||||
use util::nodemap::DefIdMap;
|
||||
|
||||
pub fn check(tcx: &ty::ctxt) {
|
||||
|
|
@ -170,9 +171,9 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
|
|||
|
||||
|
||||
impl<'cx, 'tcx,'v> visit::Visitor<'v> for OverlapChecker<'cx, 'tcx> {
|
||||
fn visit_item(&mut self, item: &'v ast::Item) {
|
||||
fn visit_item(&mut self, item: &'v hir::Item) {
|
||||
match item.node {
|
||||
ast::ItemDefaultImpl(_, _) => {
|
||||
hir::ItemDefaultImpl(_, _) => {
|
||||
// look for another default impl; note that due to the
|
||||
// general orphan/coherence rules, it must always be
|
||||
// in this crate.
|
||||
|
|
@ -188,7 +189,7 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for OverlapChecker<'cx, 'tcx> {
|
|||
None => { }
|
||||
}
|
||||
}
|
||||
ast::ItemImpl(_, _, _, Some(_), ref self_ty, _) => {
|
||||
hir::ItemImpl(_, _, _, Some(_), ref self_ty, _) => {
|
||||
let impl_def_id = DefId::local(item.id);
|
||||
let trait_ref = self.tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||
let trait_def_id = trait_ref.def_id;
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@
|
|||
|
||||
use middle::def_id::DefId;
|
||||
use middle::ty;
|
||||
use syntax::ast::{Item, ItemImpl};
|
||||
use syntax::ast;
|
||||
use syntax::visit;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::hir::{Item, ItemImpl};
|
||||
|
||||
pub fn check(tcx: &ty::ctxt) {
|
||||
let mut orphan = UnsafetyChecker { tcx: tcx };
|
||||
|
|
@ -27,15 +27,15 @@ struct UnsafetyChecker<'cx, 'tcx:'cx> {
|
|||
}
|
||||
|
||||
impl<'cx, 'tcx, 'v> UnsafetyChecker<'cx, 'tcx> {
|
||||
fn check_unsafety_coherence(&mut self, item: &'v ast::Item,
|
||||
unsafety: ast::Unsafety,
|
||||
polarity: ast::ImplPolarity) {
|
||||
fn check_unsafety_coherence(&mut self, item: &'v hir::Item,
|
||||
unsafety: hir::Unsafety,
|
||||
polarity: hir::ImplPolarity) {
|
||||
match self.tcx.impl_trait_ref(DefId::local(item.id)) {
|
||||
None => {
|
||||
// Inherent impl.
|
||||
match unsafety {
|
||||
ast::Unsafety::Normal => { /* OK */ }
|
||||
ast::Unsafety::Unsafe => {
|
||||
hir::Unsafety::Normal => { /* OK */ }
|
||||
hir::Unsafety::Unsafe => {
|
||||
span_err!(self.tcx.sess, item.span, E0197,
|
||||
"inherent impls cannot be declared as unsafe");
|
||||
}
|
||||
|
|
@ -45,30 +45,30 @@ impl<'cx, 'tcx, 'v> UnsafetyChecker<'cx, 'tcx> {
|
|||
Some(trait_ref) => {
|
||||
let trait_def = self.tcx.lookup_trait_def(trait_ref.def_id);
|
||||
match (trait_def.unsafety, unsafety, polarity) {
|
||||
(ast::Unsafety::Unsafe,
|
||||
ast::Unsafety::Unsafe, ast::ImplPolarity::Negative) => {
|
||||
(hir::Unsafety::Unsafe,
|
||||
hir::Unsafety::Unsafe, hir::ImplPolarity::Negative) => {
|
||||
span_err!(self.tcx.sess, item.span, E0198,
|
||||
"negative implementations are not unsafe");
|
||||
}
|
||||
|
||||
(ast::Unsafety::Normal, ast::Unsafety::Unsafe, _) => {
|
||||
(hir::Unsafety::Normal, hir::Unsafety::Unsafe, _) => {
|
||||
span_err!(self.tcx.sess, item.span, E0199,
|
||||
"implementing the trait `{}` is not unsafe",
|
||||
trait_ref);
|
||||
}
|
||||
|
||||
(ast::Unsafety::Unsafe,
|
||||
ast::Unsafety::Normal, ast::ImplPolarity::Positive) => {
|
||||
(hir::Unsafety::Unsafe,
|
||||
hir::Unsafety::Normal, hir::ImplPolarity::Positive) => {
|
||||
span_err!(self.tcx.sess, item.span, E0200,
|
||||
"the trait `{}` requires an `unsafe impl` declaration",
|
||||
trait_ref);
|
||||
}
|
||||
|
||||
(ast::Unsafety::Unsafe,
|
||||
ast::Unsafety::Normal, ast::ImplPolarity::Negative) |
|
||||
(ast::Unsafety::Unsafe,
|
||||
ast::Unsafety::Unsafe, ast::ImplPolarity::Positive) |
|
||||
(ast::Unsafety::Normal, ast::Unsafety::Normal, _) => {
|
||||
(hir::Unsafety::Unsafe,
|
||||
hir::Unsafety::Normal, hir::ImplPolarity::Negative) |
|
||||
(hir::Unsafety::Unsafe,
|
||||
hir::Unsafety::Unsafe, hir::ImplPolarity::Positive) |
|
||||
(hir::Unsafety::Normal, hir::Unsafety::Normal, _) => {
|
||||
/* OK */
|
||||
}
|
||||
}
|
||||
|
|
@ -78,12 +78,12 @@ impl<'cx, 'tcx, 'v> UnsafetyChecker<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'cx, 'tcx,'v> visit::Visitor<'v> for UnsafetyChecker<'cx, 'tcx> {
|
||||
fn visit_item(&mut self, item: &'v ast::Item) {
|
||||
fn visit_item(&mut self, item: &'v hir::Item) {
|
||||
match item.node {
|
||||
ast::ItemDefaultImpl(unsafety, _) => {
|
||||
self.check_unsafety_coherence(item, unsafety, ast::ImplPolarity::Positive);
|
||||
hir::ItemDefaultImpl(unsafety, _) => {
|
||||
self.check_unsafety_coherence(item, unsafety, hir::ImplPolarity::Positive);
|
||||
}
|
||||
ast::ItemImpl(unsafety, polarity, _, _, _, _) => {
|
||||
hir::ItemImpl(unsafety, polarity, _, _, _, _) => {
|
||||
self.check_unsafety_coherence(item, unsafety, polarity);
|
||||
}
|
||||
_ => { }
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -97,6 +97,7 @@ extern crate arena;
|
|||
extern crate fmt_macros;
|
||||
extern crate rustc;
|
||||
extern crate rustc_platform_intrinsics as intrinsics;
|
||||
extern crate rustc_front;
|
||||
|
||||
pub use rustc::lint;
|
||||
pub use rustc::metadata;
|
||||
|
|
@ -109,9 +110,10 @@ use middle::def_id::DefId;
|
|||
use middle::infer;
|
||||
use middle::subst;
|
||||
use middle::ty::{self, Ty, HasTypeFlags};
|
||||
use rustc::ast_map;
|
||||
use session::config;
|
||||
use util::common::time;
|
||||
use rustc::front::map as hir_map;
|
||||
use rustc_front::hir;
|
||||
|
||||
use syntax::codemap::Span;
|
||||
use syntax::print::pprust::*;
|
||||
|
|
@ -178,7 +180,7 @@ fn lookup_full_def(tcx: &ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def {
|
|||
}
|
||||
|
||||
fn require_c_abi_if_variadic(tcx: &ty::ctxt,
|
||||
decl: &ast::FnDecl,
|
||||
decl: &hir::FnDecl,
|
||||
abi: abi::Abi,
|
||||
span: Span) {
|
||||
if decl.variadic && abi != abi::C {
|
||||
|
|
@ -225,9 +227,9 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
|
|||
match main_t.sty {
|
||||
ty::TyBareFn(..) => {
|
||||
match tcx.map.find(main_id) {
|
||||
Some(ast_map::NodeItem(it)) => {
|
||||
Some(hir_map::NodeItem(it)) => {
|
||||
match it.node {
|
||||
ast::ItemFn(_, _, _, _, ref ps, _)
|
||||
hir::ItemFn(_, _, _, _, ref ps, _)
|
||||
if ps.is_parameterized() => {
|
||||
span_err!(ccx.tcx.sess, main_span, E0131,
|
||||
"main function is not allowed to have type parameters");
|
||||
|
|
@ -239,7 +241,7 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
|
|||
_ => ()
|
||||
}
|
||||
let se_ty = tcx.mk_fn(Some(DefId::local(main_id)), tcx.mk_bare_fn(ty::BareFnTy {
|
||||
unsafety: ast::Unsafety::Normal,
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
abi: abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
inputs: Vec::new(),
|
||||
|
|
@ -270,9 +272,9 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
|
|||
match start_t.sty {
|
||||
ty::TyBareFn(..) => {
|
||||
match tcx.map.find(start_id) {
|
||||
Some(ast_map::NodeItem(it)) => {
|
||||
Some(hir_map::NodeItem(it)) => {
|
||||
match it.node {
|
||||
ast::ItemFn(_,_,_,_,ref ps,_)
|
||||
hir::ItemFn(_,_,_,_,ref ps,_)
|
||||
if ps.is_parameterized() => {
|
||||
span_err!(tcx.sess, start_span, E0132,
|
||||
"start function is not allowed to have type parameters");
|
||||
|
|
@ -285,7 +287,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
|
|||
}
|
||||
|
||||
let se_ty = tcx.mk_fn(Some(DefId::local(start_id)), tcx.mk_bare_fn(ty::BareFnTy {
|
||||
unsafety: ast::Unsafety::Normal,
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
abi: abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
inputs: vec!(
|
||||
|
|
|
|||
|
|
@ -271,12 +271,13 @@ use middle::resolve_lifetime as rl;
|
|||
use middle::subst;
|
||||
use middle::subst::{ParamSpace, FnSpace, TypeSpace, SelfSpace, VecPerParamSpace};
|
||||
use middle::ty::{self, Ty};
|
||||
use rustc::ast_map;
|
||||
use rustc::front::map as hir_map;
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
use syntax::ast;
|
||||
use syntax::visit;
|
||||
use syntax::visit::Visitor;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::visit::Visitor;
|
||||
use util::nodemap::NodeMap;
|
||||
|
||||
pub fn infer_variance(tcx: &ty::ctxt) {
|
||||
|
|
@ -364,7 +365,7 @@ struct InferredInfo<'a> {
|
|||
|
||||
fn determine_parameters_to_be_inferred<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>,
|
||||
arena: &'a mut TypedArena<VarianceTerm<'a>>,
|
||||
krate: &ast::Crate)
|
||||
krate: &hir::Crate)
|
||||
-> TermsContext<'a, 'tcx> {
|
||||
let mut terms_cx = TermsContext {
|
||||
tcx: tcx,
|
||||
|
|
@ -413,7 +414,7 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> {
|
|||
fn add_inferreds_for_item(&mut self,
|
||||
item_id: ast::NodeId,
|
||||
has_self: bool,
|
||||
generics: &ast::Generics)
|
||||
generics: &hir::Generics)
|
||||
{
|
||||
/*!
|
||||
* Add "inferreds" for the generic parameters declared on this
|
||||
|
|
@ -516,15 +517,15 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for TermsContext<'a, 'tcx> {
|
||||
fn visit_item(&mut self, item: &ast::Item) {
|
||||
fn visit_item(&mut self, item: &hir::Item) {
|
||||
debug!("add_inferreds for item {}", self.tcx.map.node_to_string(item.id));
|
||||
|
||||
match item.node {
|
||||
ast::ItemEnum(_, ref generics) |
|
||||
ast::ItemStruct(_, ref generics) => {
|
||||
hir::ItemEnum(_, ref generics) |
|
||||
hir::ItemStruct(_, ref generics) => {
|
||||
self.add_inferreds_for_item(item.id, false, generics);
|
||||
}
|
||||
ast::ItemTrait(_, ref generics, _, _) => {
|
||||
hir::ItemTrait(_, ref generics, _, _) => {
|
||||
// Note: all inputs for traits are ultimately
|
||||
// constrained to be invariant. See `visit_item` in
|
||||
// the impl for `ConstraintContext` below.
|
||||
|
|
@ -532,17 +533,16 @@ impl<'a, 'tcx, 'v> Visitor<'v> for TermsContext<'a, 'tcx> {
|
|||
visit::walk_item(self, item);
|
||||
}
|
||||
|
||||
ast::ItemExternCrate(_) |
|
||||
ast::ItemUse(_) |
|
||||
ast::ItemDefaultImpl(..) |
|
||||
ast::ItemImpl(..) |
|
||||
ast::ItemStatic(..) |
|
||||
ast::ItemConst(..) |
|
||||
ast::ItemFn(..) |
|
||||
ast::ItemMod(..) |
|
||||
ast::ItemForeignMod(..) |
|
||||
ast::ItemTy(..) |
|
||||
ast::ItemMac(..) => {
|
||||
hir::ItemExternCrate(_) |
|
||||
hir::ItemUse(_) |
|
||||
hir::ItemDefaultImpl(..) |
|
||||
hir::ItemImpl(..) |
|
||||
hir::ItemStatic(..) |
|
||||
hir::ItemConst(..) |
|
||||
hir::ItemFn(..) |
|
||||
hir::ItemMod(..) |
|
||||
hir::ItemForeignMod(..) |
|
||||
hir::ItemTy(..) => {
|
||||
visit::walk_item(self, item);
|
||||
}
|
||||
}
|
||||
|
|
@ -575,7 +575,7 @@ struct Constraint<'a> {
|
|||
}
|
||||
|
||||
fn add_constraints_from_crate<'a, 'tcx>(terms_cx: TermsContext<'a, 'tcx>,
|
||||
krate: &ast::Crate)
|
||||
krate: &hir::Crate)
|
||||
-> ConstraintContext<'a, 'tcx>
|
||||
{
|
||||
let covariant = terms_cx.arena.alloc(ConstantTerm(ty::Covariant));
|
||||
|
|
@ -595,14 +595,14 @@ fn add_constraints_from_crate<'a, 'tcx>(terms_cx: TermsContext<'a, 'tcx>,
|
|||
}
|
||||
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for ConstraintContext<'a, 'tcx> {
|
||||
fn visit_item(&mut self, item: &ast::Item) {
|
||||
fn visit_item(&mut self, item: &hir::Item) {
|
||||
let did = DefId::local(item.id);
|
||||
let tcx = self.terms_cx.tcx;
|
||||
|
||||
debug!("visit_item item={}", tcx.map.node_to_string(item.id));
|
||||
|
||||
match item.node {
|
||||
ast::ItemEnum(..) | ast::ItemStruct(..) => {
|
||||
hir::ItemEnum(..) | hir::ItemStruct(..) => {
|
||||
let scheme = tcx.lookup_item_type(did);
|
||||
|
||||
// Not entirely obvious: constraints on structs/enums do not
|
||||
|
|
@ -617,24 +617,23 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ConstraintContext<'a, 'tcx> {
|
|||
self.covariant);
|
||||
}
|
||||
}
|
||||
ast::ItemTrait(..) => {
|
||||
hir::ItemTrait(..) => {
|
||||
let trait_def = tcx.lookup_trait_def(did);
|
||||
self.add_constraints_from_trait_ref(&trait_def.generics,
|
||||
trait_def.trait_ref,
|
||||
self.invariant);
|
||||
}
|
||||
|
||||
ast::ItemExternCrate(_) |
|
||||
ast::ItemUse(_) |
|
||||
ast::ItemStatic(..) |
|
||||
ast::ItemConst(..) |
|
||||
ast::ItemFn(..) |
|
||||
ast::ItemMod(..) |
|
||||
ast::ItemForeignMod(..) |
|
||||
ast::ItemTy(..) |
|
||||
ast::ItemImpl(..) |
|
||||
ast::ItemDefaultImpl(..) |
|
||||
ast::ItemMac(..) => {
|
||||
hir::ItemExternCrate(_) |
|
||||
hir::ItemUse(_) |
|
||||
hir::ItemStatic(..) |
|
||||
hir::ItemConst(..) |
|
||||
hir::ItemFn(..) |
|
||||
hir::ItemMod(..) |
|
||||
hir::ItemForeignMod(..) |
|
||||
hir::ItemTy(..) |
|
||||
hir::ItemImpl(..) |
|
||||
hir::ItemDefaultImpl(..) => {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -643,9 +642,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ConstraintContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// Is `param_id` a lifetime according to `map`?
|
||||
fn is_lifetime(map: &ast_map::Map, param_id: ast::NodeId) -> bool {
|
||||
fn is_lifetime(map: &hir_map::Map, param_id: ast::NodeId) -> bool {
|
||||
match map.find(param_id) {
|
||||
Some(ast_map::NodeLifetime(..)) => true, _ => false
|
||||
Some(hir_map::NodeLifetime(..)) => true, _ => false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -706,18 +705,18 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
|||
} } }
|
||||
|
||||
match parent {
|
||||
ast_map::NodeItem(p) => {
|
||||
hir_map::NodeItem(p) => {
|
||||
match p.node {
|
||||
ast::ItemTy(..) |
|
||||
ast::ItemEnum(..) |
|
||||
ast::ItemStruct(..) |
|
||||
ast::ItemTrait(..) => is_inferred = true,
|
||||
ast::ItemFn(..) => is_inferred = false,
|
||||
hir::ItemTy(..) |
|
||||
hir::ItemEnum(..) |
|
||||
hir::ItemStruct(..) |
|
||||
hir::ItemTrait(..) => is_inferred = true,
|
||||
hir::ItemFn(..) => is_inferred = false,
|
||||
_ => cannot_happen!(),
|
||||
}
|
||||
}
|
||||
ast_map::NodeTraitItem(..) => is_inferred = false,
|
||||
ast_map::NodeImplItem(..) => is_inferred = false,
|
||||
hir_map::NodeTraitItem(..) => is_inferred = false,
|
||||
hir_map::NodeImplItem(..) => is_inferred = false,
|
||||
_ => cannot_happen!(),
|
||||
}
|
||||
|
||||
|
|
@ -1045,12 +1044,12 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
|||
mt: &ty::TypeAndMut<'tcx>,
|
||||
variance: VarianceTermPtr<'a>) {
|
||||
match mt.mutbl {
|
||||
ast::MutMutable => {
|
||||
hir::MutMutable => {
|
||||
let invar = self.invariant(variance);
|
||||
self.add_constraints_from_ty(generics, mt.ty, invar);
|
||||
}
|
||||
|
||||
ast::MutImmutable => {
|
||||
hir::MutImmutable => {
|
||||
self.add_constraints_from_ty(generics, mt.ty, variance);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue