Make type in ast::Local optional
This commit is contained in:
parent
ee3c5957ea
commit
f2a06f760b
11 changed files with 31 additions and 28 deletions
|
@ -649,7 +649,10 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor, local: &ast::Local) {
|
||||||
Some(ref expr) => {
|
Some(ref expr) => {
|
||||||
record_rvalue_scope_if_borrow_expr(visitor, &**expr, blk_scope);
|
record_rvalue_scope_if_borrow_expr(visitor, &**expr, blk_scope);
|
||||||
|
|
||||||
if is_binding_pat(&*local.pat) || is_borrowed_ty(&*local.ty) {
|
let is_borrow =
|
||||||
|
if let Some(ref ty) = local.ty { is_borrowed_ty(&**ty) } else { false };
|
||||||
|
|
||||||
|
if is_binding_pat(&*local.pat) || is_borrow {
|
||||||
record_rvalue_scope(visitor, &**expr, blk_scope);
|
record_rvalue_scope(visitor, &**expr, blk_scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3401,7 +3401,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
fn resolve_local(&mut self, local: &Local) {
|
fn resolve_local(&mut self, local: &Local) {
|
||||||
// Resolve the type.
|
// Resolve the type.
|
||||||
self.resolve_type(&*local.ty);
|
if let Some(ref ty) = local.ty {
|
||||||
|
self.resolve_type(&**ty);
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve the initializer, if necessary.
|
// Resolve the initializer, if necessary.
|
||||||
match local.init {
|
match local.init {
|
||||||
|
|
|
@ -1496,7 +1496,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
|
||||||
self.collected_paths.clear();
|
self.collected_paths.clear();
|
||||||
|
|
||||||
// Just walk the initialiser and type (don't want to walk the pattern again).
|
// Just walk the initialiser and type (don't want to walk the pattern again).
|
||||||
self.visit_ty(&*l.ty);
|
visit::walk_ty_opt(self, &l.ty);
|
||||||
visit::walk_expr_opt(self, &l.init);
|
visit::walk_expr_opt(self, &l.init);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -485,9 +485,9 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
|
||||||
impl<'a, 'tcx, 'v> Visitor<'v> for GatherLocalsVisitor<'a, 'tcx> {
|
impl<'a, 'tcx, 'v> Visitor<'v> for GatherLocalsVisitor<'a, 'tcx> {
|
||||||
// Add explicitly-declared locals.
|
// Add explicitly-declared locals.
|
||||||
fn visit_local(&mut self, local: &ast::Local) {
|
fn visit_local(&mut self, local: &ast::Local) {
|
||||||
let o_ty = match local.ty.node {
|
let o_ty = match local.ty {
|
||||||
ast::TyInfer => None,
|
Some(ref ty) => Some(self.fcx.to_ty(&**ty)),
|
||||||
_ => Some(self.fcx.to_ty(&*local.ty))
|
None => None
|
||||||
};
|
};
|
||||||
self.assign(local.span, local.id, o_ty);
|
self.assign(local.span, local.id, o_ty);
|
||||||
debug!("Local variable {} is assigned type {}",
|
debug!("Local variable {} is assigned type {}",
|
||||||
|
|
|
@ -643,8 +643,8 @@ pub enum LocalSource {
|
||||||
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
|
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
|
||||||
#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
|
#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
|
||||||
pub struct Local {
|
pub struct Local {
|
||||||
pub ty: P<Ty>,
|
|
||||||
pub pat: P<Pat>,
|
pub pat: P<Pat>,
|
||||||
|
pub ty: Option<P<Ty>>,
|
||||||
pub init: Option<P<Expr>>,
|
pub init: Option<P<Expr>>,
|
||||||
pub id: NodeId,
|
pub id: NodeId,
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
|
|
|
@ -482,8 +482,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
self.pat_ident(sp, ident)
|
self.pat_ident(sp, ident)
|
||||||
};
|
};
|
||||||
let local = P(ast::Local {
|
let local = P(ast::Local {
|
||||||
ty: self.ty_infer(sp),
|
|
||||||
pat: pat,
|
pat: pat,
|
||||||
|
ty: None,
|
||||||
init: Some(ex),
|
init: Some(ex),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
span: sp,
|
span: sp,
|
||||||
|
@ -506,8 +506,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
self.pat_ident(sp, ident)
|
self.pat_ident(sp, ident)
|
||||||
};
|
};
|
||||||
let local = P(ast::Local {
|
let local = P(ast::Local {
|
||||||
ty: typ,
|
|
||||||
pat: pat,
|
pat: pat,
|
||||||
|
ty: Some(typ),
|
||||||
init: Some(ex),
|
init: Some(ex),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
span: sp,
|
span: sp,
|
||||||
|
|
|
@ -712,7 +712,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE
|
||||||
let rewritten_local = local.map(|Local {id, pat, ty, init, source, span}| {
|
let rewritten_local = local.map(|Local {id, pat, ty, init, source, span}| {
|
||||||
// expand the ty since TyFixedLengthVec contains an Expr
|
// expand the ty since TyFixedLengthVec contains an Expr
|
||||||
// and thus may have a macro use
|
// and thus may have a macro use
|
||||||
let expanded_ty = fld.fold_ty(ty);
|
let expanded_ty = ty.map(|t| fld.fold_ty(t));
|
||||||
// expand the pat (it might contain macro uses):
|
// expand the pat (it might contain macro uses):
|
||||||
let expanded_pat = fld.fold_pat(pat);
|
let expanded_pat = fld.fold_pat(pat);
|
||||||
// find the PatIdents in the pattern:
|
// find the PatIdents in the pattern:
|
||||||
|
|
|
@ -553,7 +553,7 @@ pub fn noop_fold_parenthesized_parameter_data<T: Folder>(data: ParenthesizedPara
|
||||||
pub fn noop_fold_local<T: Folder>(l: P<Local>, fld: &mut T) -> P<Local> {
|
pub fn noop_fold_local<T: Folder>(l: P<Local>, fld: &mut T) -> P<Local> {
|
||||||
l.map(|Local {id, pat, ty, init, source, span}| Local {
|
l.map(|Local {id, pat, ty, init, source, span}| Local {
|
||||||
id: fld.new_id(id),
|
id: fld.new_id(id),
|
||||||
ty: fld.fold_ty(ty),
|
ty: ty.map(|t| fld.fold_ty(t)),
|
||||||
pat: fld.fold_pat(pat),
|
pat: fld.fold_pat(pat),
|
||||||
init: init.map(|e| fld.fold_expr(e)),
|
init: init.map(|e| fld.fold_expr(e)),
|
||||||
source: source,
|
source: source,
|
||||||
|
|
|
@ -3627,13 +3627,9 @@ impl<'a> Parser<'a> {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
let pat = self.parse_pat();
|
let pat = self.parse_pat();
|
||||||
|
|
||||||
let mut ty = P(Ty {
|
let mut ty = None;
|
||||||
id: ast::DUMMY_NODE_ID,
|
|
||||||
node: TyInfer,
|
|
||||||
span: mk_sp(lo, lo),
|
|
||||||
});
|
|
||||||
if self.eat(&token::Colon) {
|
if self.eat(&token::Colon) {
|
||||||
ty = self.parse_ty_sum();
|
ty = Some(self.parse_ty_sum());
|
||||||
}
|
}
|
||||||
let init = self.parse_initializer();
|
let init = self.parse_initializer();
|
||||||
P(ast::Local {
|
P(ast::Local {
|
||||||
|
|
|
@ -1858,13 +1858,11 @@ impl<'a> State<'a> {
|
||||||
|
|
||||||
pub fn print_local_decl(&mut self, loc: &ast::Local) -> IoResult<()> {
|
pub fn print_local_decl(&mut self, loc: &ast::Local) -> IoResult<()> {
|
||||||
try!(self.print_pat(&*loc.pat));
|
try!(self.print_pat(&*loc.pat));
|
||||||
match loc.ty.node {
|
if let Some(ref ty) = loc.ty {
|
||||||
ast::TyInfer => Ok(()),
|
try!(self.word_space(":"));
|
||||||
_ => {
|
try!(self.print_type(&**ty));
|
||||||
try!(self.word_space(":"));
|
|
||||||
self.print_type(&*loc.ty)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_decl(&mut self, decl: &ast::Decl) -> IoResult<()> {
|
pub fn print_decl(&mut self, decl: &ast::Decl) -> IoResult<()> {
|
||||||
|
|
|
@ -211,7 +211,7 @@ pub fn walk_view_item<'v, V: Visitor<'v>>(visitor: &mut V, vi: &'v ViewItem) {
|
||||||
|
|
||||||
pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) {
|
pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) {
|
||||||
visitor.visit_pat(&*local.pat);
|
visitor.visit_pat(&*local.pat);
|
||||||
visitor.visit_ty(&*local.ty);
|
walk_ty_opt(visitor, &local.ty);
|
||||||
walk_expr_opt(visitor, &local.init);
|
walk_expr_opt(visitor, &local.init);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,6 +381,13 @@ pub fn skip_ty<'v, V: Visitor<'v>>(_: &mut V, _: &'v Ty) {
|
||||||
// Empty!
|
// Empty!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn walk_ty_opt<'v, V: Visitor<'v>>(visitor: &mut V, optional_type: &'v Option<P<Ty>>) {
|
||||||
|
match *optional_type {
|
||||||
|
Some(ref ty) => visitor.visit_ty(&**ty),
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
|
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
|
||||||
match typ.node {
|
match typ.node {
|
||||||
TyVec(ref ty) | TyParen(ref ty) => {
|
TyVec(ref ty) | TyParen(ref ty) => {
|
||||||
|
@ -583,10 +590,7 @@ pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||||
pub fn walk_ty_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v TyParam) {
|
pub fn walk_ty_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v TyParam) {
|
||||||
visitor.visit_ident(param.span, param.ident);
|
visitor.visit_ident(param.span, param.ident);
|
||||||
walk_ty_param_bounds_helper(visitor, ¶m.bounds);
|
walk_ty_param_bounds_helper(visitor, ¶m.bounds);
|
||||||
match param.default {
|
walk_ty_opt(visitor, ¶m.default);
|
||||||
Some(ref ty) => visitor.visit_ty(&**ty),
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
|
pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue