syntax: don't store a secondary NodeId for TyPath.

This commit is contained in:
Eduard Burtescu 2015-01-29 21:18:17 +02:00
parent 27747ac1a7
commit a817c69297
21 changed files with 74 additions and 101 deletions

View file

@ -405,8 +405,8 @@ struct ImproperCTypesVisitor<'a, 'tcx: 'a> {
}
impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
fn check_def(&mut self, sp: Span, ty_id: ast::NodeId, path_id: ast::NodeId) {
match self.cx.tcx.def_map.borrow()[path_id].clone() {
fn check_def(&mut self, sp: Span, id: ast::NodeId) {
match self.cx.tcx.def_map.borrow()[id].clone() {
def::DefPrimTy(ast::TyInt(ast::TyIs(_))) => {
self.cx.span_lint(IMPROPER_CTYPES, sp,
"found rust type `isize` in foreign module, while \
@ -418,7 +418,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
libc::c_uint or libc::c_ulong should be used");
}
def::DefTy(..) => {
let tty = match self.cx.tcx.ast_ty_to_ty_cache.borrow().get(&ty_id) {
let tty = match self.cx.tcx.ast_ty_to_ty_cache.borrow().get(&id) {
Some(&ty::atttce_resolved(t)) => t,
_ => panic!("ast_ty_to_ty_cache was incomplete after typeck!")
};
@ -437,9 +437,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for ImproperCTypesVisitor<'a, 'tcx> {
fn visit_ty(&mut self, ty: &ast::Ty) {
match ty.node {
ast::TyPath(_, id) => self.check_def(ty.span, ty.id, id),
_ => (),
if let ast::TyPath(_) = ty.node {
self.check_def(ty.span, ty.id);
}
visit::walk_ty(self, ty);
}

View file

@ -1221,7 +1221,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_unsafety(rbml_w, unsafety);
encode_polarity(rbml_w, polarity);
match ty.node {
ast::TyPath(ref path, _) if path.segments.len() == 1 => {
ast::TyPath(ref path) if path.segments.len() == 1 => {
let ident = path.segments.last().unwrap().identifier;
encode_impl_type_basename(rbml_w, ident);
}

View file

@ -43,8 +43,8 @@ pub fn check_path_args(tcx: &ty::ctxt,
pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty)
-> Option<Ty<'tcx>> {
match ast_ty.node {
ast::TyPath(ref path, id) => {
let a_def = match tcx.def_map.borrow().get(&id) {
ast::TyPath(ref path) => {
let a_def = match tcx.def_map.borrow().get(&ast_ty.id) {
None => {
tcx.sess.span_bug(ast_ty.span,
&format!("unbound path {}",

View file

@ -1233,8 +1233,8 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
}
ty_queue.push(&*mut_ty.ty);
}
ast::TyPath(ref path, id) => {
let a_def = match self.tcx.def_map.borrow().get(&id) {
ast::TyPath(ref path) => {
let a_def = match self.tcx.def_map.borrow().get(&cur_ty.id) {
None => {
self.tcx
.sess
@ -1279,7 +1279,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
let new_path = self.rebuild_path(rebuild_info, lifetime);
let to = ast::Ty {
id: cur_ty.id,
node: ast::TyPath(new_path, id),
node: ast::TyPath(new_path),
span: cur_ty.span
};
new_ty = self.rebuild_ty(new_ty, P(to));

View file

@ -165,13 +165,13 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
visit::walk_ty(this, ty);
});
}
ast::TyPath(ref path, id) => {
ast::TyPath(ref path) => {
// if this path references a trait, then this will resolve to
// a trait ref, which introduces a binding scope.
match self.def_map.borrow().get(&id) {
match self.def_map.borrow().get(&ty.id) {
Some(&def::DefTrait(..)) => {
self.with(LateScope(&Vec::new(), self.scope), |_, this| {
this.visit_path(path, id);
this.visit_path(path, ty.id);
});
}
_ => {
@ -270,16 +270,12 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
for lifetime in &trait_ref.bound_lifetimes {
this.visit_lifetime_def(lifetime);
}
this.visit_trait_ref(&trait_ref.trait_ref)
visit::walk_path(this, &trait_ref.trait_ref.path)
})
} else {
self.visit_trait_ref(&trait_ref.trait_ref)
}
}
fn visit_trait_ref(&mut self, trait_ref: &ast::TraitRef) {
self.visit_path(&trait_ref.path, trait_ref.ref_id);
}
}
impl<'a> LifetimeContext<'a> {

View file

@ -259,8 +259,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
// * Private trait impls for private types can be completely ignored
ast::ItemImpl(_, _, _, _, ref ty, ref impl_items) => {
let public_ty = match ty.node {
ast::TyPath(_, id) => {
match self.tcx.def_map.borrow()[id].clone() {
ast::TyPath(_) => {
match self.tcx.def_map.borrow()[ty.id].clone() {
def::DefPrimTy(..) => true,
def => {
let did = def.def_id();
@ -326,8 +326,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
}
ast::ItemTy(ref ty, _) if public_first => {
if let ast::TyPath(_, id) = ty.node {
match self.tcx.def_map.borrow()[id].clone() {
if let ast::TyPath(_) = ty.node {
match self.tcx.def_map.borrow()[ty.id].clone() {
def::DefPrimTy(..) | def::DefTyParam(..) => {},
def => {
let did = def.def_id();
@ -628,11 +628,11 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
// back up the chains to find the relevant struct/enum that
// was private.
ast::ItemImpl(_, _, _, _, ref ty, _) => {
let id = match ty.node {
ast::TyPath(_, id) => id,
match ty.node {
ast::TyPath(_) => {}
_ => return Some((err_span, err_msg, None)),
};
let def = self.tcx.def_map.borrow()[id].clone();
let def = self.tcx.def_map.borrow()[ty.id].clone();
let did = def.def_id();
assert!(is_local(did));
match self.tcx.map.get(did.node) {
@ -716,13 +716,13 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
}
// Checks that a path is in scope.
fn check_path(&mut self, span: Span, path_id: ast::NodeId, path: &ast::Path) {
fn check_path(&mut self, span: Span, path_id: ast::NodeId, last: ast::Ident) {
debug!("privacy - path {}", self.nodestr(path_id));
let orig_def = self.tcx.def_map.borrow()[path_id].clone();
let ck = |tyname: &str| {
let ck_public = |def: ast::DefId| {
debug!("privacy - ck_public {:?}", def);
let name = token::get_ident(path.segments.last().unwrap().identifier);
let name = token::get_ident(last);
let origdid = orig_def.def_id();
self.ensure_public(span,
def,
@ -832,37 +832,22 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
fn visit_item(&mut self, item: &ast::Item) {
match item.node {
ast::ItemUse(ref vpath) => {
match vpath.node {
ast::ViewPathSimple(..) | ast::ViewPathGlob(..) => {}
ast::ViewPathList(ref prefix, ref list) => {
for pid in list {
match pid.node {
ast::PathListIdent { id, name } => {
debug!("privacy - ident item {}", id);
let seg = ast::PathSegment {
identifier: name,
parameters: ast::PathParameters::none(),
};
let segs = vec![seg];
let path = ast::Path {
global: false,
span: pid.span,
segments: segs,
};
self.check_path(pid.span, id, &path);
}
ast::PathListMod { id } => {
debug!("privacy - mod item {}", id);
self.check_path(pid.span, id, prefix);
}
}
if let ast::ItemUse(ref vpath) = item.node {
if let ast::ViewPathList(ref prefix, ref list) = vpath.node {
for pid in list {
match pid.node {
ast::PathListIdent { id, name } => {
debug!("privacy - ident item {}", id);
self.check_path(pid.span, id, name);
}
ast::PathListMod { id } => {
debug!("privacy - mod item {}", id);
let name = prefix.segments.last().unwrap().identifier;
self.check_path(pid.span, id, name);
}
}
}
}
_ => {}
}
let orig_curitem = replace(&mut self.curitem, item.id);
visit::walk_item(self, item);
@ -1033,7 +1018,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
}
fn visit_path(&mut self, path: &ast::Path, id: ast::NodeId) {
self.check_path(path.span, id, path);
self.check_path(path.span, id, path.segments.last().unwrap().identifier);
visit::walk_path(self, path);
}
}
@ -1273,8 +1258,8 @@ impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> {
impl<'a, 'b, 'tcx, 'v> Visitor<'v> for CheckTypeForPrivatenessVisitor<'a, 'b, 'tcx> {
fn visit_ty(&mut self, ty: &ast::Ty) {
if let ast::TyPath(_, path_id) = ty.node {
if self.inner.path_is_private_type(path_id) {
if let ast::TyPath(_) = ty.node {
if self.inner.path_is_private_type(ty.id) {
self.contains_private = true;
// found what we're looking for so let's stop
// working.
@ -1398,7 +1383,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
//
// Those in 2. are warned via walk_generics and this
// call here.
self.visit_trait_ref(tr)
visit::walk_path(self, &tr.path);
}
}
} else if trait_ref.is_none() && self_is_public_path {
@ -1479,9 +1464,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
}
fn visit_ty(&mut self, t: &ast::Ty) {
if let ast::TyPath(ref p, path_id) = t.node {
if let ast::TyPath(ref p) = t.node {
if !self.tcx.sess.features.borrow().visible_private_types &&
self.path_is_private_type(path_id) {
self.path_is_private_type(t.id) {
self.tcx.sess.span_err(p.span,
"private type in exported type signature");
}

View file

@ -523,14 +523,14 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
// within this module.
let mod_name = match ty.node {
TyPath(ref path, _) if path.segments.len() == 1 => {
TyPath(ref path) if path.segments.len() == 1 => {
// FIXME(18446) we should distinguish between the name of
// a trait and the name of an impl of that trait.
Some(path.segments.last().unwrap().identifier.name)
}
TyObjectSum(ref lhs_ty, _) => {
match lhs_ty.node {
TyPath(ref path, _) if path.segments.len() == 1 => {
TyPath(ref path) if path.segments.len() == 1 => {
Some(path.segments.last().unwrap().identifier.name)
}
_ => {

View file

@ -3387,8 +3387,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// type, the result will be that the type name resolves to a module but not
// a type (shadowing any imported modules or types with this name), leading
// to weird user-visible bugs. So we ward this off here. See #15060.
TyPath(ref path, path_id) => {
match self.def_map.borrow().get(&path_id) {
TyPath(ref path) => {
match self.def_map.borrow().get(&self_type.id) {
// FIXME: should we catch other options and give more precise errors?
Some(&DefMod(_)) => {
self.resolve_error(path.span, "inherent implementations are not \
@ -3576,7 +3576,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// Like path expressions, the interpretation of path types depends
// on whether the path has multiple elements in it or not.
TyPath(ref path, path_id) => {
TyPath(ref path) => {
// This is a path in the type namespace. Walk through scopes
// looking for it.
let mut result_def = None;
@ -3617,8 +3617,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
debug!("(resolving type) writing resolution for `{}` \
(id {}) = {:?}",
self.path_names_to_string(path),
path_id, def);
self.record_def(path_id, def);
ty.id, def);
self.record_def(ty.id, def);
}
None => {
let msg = format!("use of undeclared type name `{}`",
@ -4281,7 +4281,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
fn extract_path_and_node_id(t: &Ty, allow: FallbackChecks)
-> Option<(Path, NodeId, FallbackChecks)> {
match t.node {
TyPath(ref path, node_id) => Some((path.clone(), node_id, allow)),
TyPath(ref path) => Some((path.clone(), t.id, allow)),
TyPtr(ref mut_ty) => extract_path_and_node_id(&*mut_ty.ty, OnlyTraitAndStatics),
TyRptr(_, ref mut_ty) => extract_path_and_node_id(&*mut_ty.ty, allow),
// This doesn't handle the remaining `Ty` variants as they are not

View file

@ -662,9 +662,9 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
let trait_id = trait_ref.as_ref().and_then(|tr| self.lookup_type_ref(tr.ref_id));
match typ.node {
// Common case impl for a struct or something basic.
ast::TyPath(ref path, id) => {
ast::TyPath(ref path) => {
let sub_span = self.span.sub_span_for_type_name(path.span);
let self_id = self.lookup_type_ref(id).map(|id| {
let self_id = self.lookup_type_ref(typ.id).map(|id| {
self.fmt.ref_str(recorder::TypeRef,
path.span,
sub_span,
@ -1303,8 +1303,8 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
}
match t.node {
ast::TyPath(ref path, id) => {
match self.lookup_type_ref(id) {
ast::TyPath(ref path) => {
match self.lookup_type_ref(t.id) {
Some(id) => {
let sub_span = self.span.sub_span_for_type_name(t.span);
self.fmt.ref_str(recorder::TypeRef,

View file

@ -852,8 +852,8 @@ pub fn ast_ty_to_builtin_ty<'tcx>(
}
match ast_ty.node {
ast::TyPath(ref path, id) => {
let a_def = match this.tcx().def_map.borrow().get(&id) {
ast::TyPath(ref path) => {
let a_def = match this.tcx().def_map.borrow().get(&ast_ty.id) {
None => {
this.tcx()
.sess
@ -912,8 +912,8 @@ fn ast_ty_to_trait_ref<'tcx>(this: &AstConv<'tcx>,
*/
match ty.node {
ast::TyPath(ref path, id) => {
match this.tcx().def_map.borrow().get(&id) {
ast::TyPath(ref path) => {
match this.tcx().def_map.borrow().get(&ty.id) {
Some(&def::DefTrait(trait_def_id)) => {
let mut projection_bounds = Vec::new();
let trait_ref = object_path_to_poly_trait_ref(this,
@ -1183,8 +1183,8 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
ast::TyPolyTraitRef(ref bounds) => {
conv_ty_poly_trait_ref(this, rscope, ast_ty.span, &bounds[..])
}
ast::TyPath(ref path, id) => {
let a_def = match tcx.def_map.borrow().get(&id) {
ast::TyPath(ref path) => {
let a_def = match tcx.def_map.borrow().get(&ast_ty.id) {
None => {
tcx.sess
.span_bug(ast_ty.span,

View file

@ -1496,8 +1496,8 @@ impl Clean<Type> for ast::Ty {
TyFixedLengthVec(ref ty, ref e) => FixedVector(box ty.clean(cx),
e.span.to_src(cx)),
TyTup(ref tys) => Tuple(tys.clean(cx)),
TyPath(ref p, id) => {
resolve_type(cx, p.clean(cx), id)
TyPath(ref p) => {
resolve_type(cx, p.clean(cx), self.id)
}
TyObjectSum(ref lhs, ref bounds) => {
let lhs_ty = lhs.clean(cx);

View file

@ -1257,7 +1257,7 @@ pub enum Ty_ {
/// A path (`module::module::...::Type`) or primitive
///
/// Type parameters are stored in the Path itself
TyPath(Path, NodeId),
TyPath(Path),
/// Something like `A+B`. Note that `B` must always be a path.
TyObjectSum(P<Ty>, TyParamBounds),
/// A type like `for<'a> Foo<&'a Bar>`

View file

@ -488,9 +488,6 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
fn visit_ty(&mut self, typ: &Ty) {
self.operation.visit_id(typ.id);
if let TyPath(_, id) = typ.node {
self.operation.visit_id(id);
}
visit::walk_ty(self, typ)
}

View file

@ -398,7 +398,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}
fn ty_path(&self, path: ast::Path) -> P<ast::Ty> {
self.ty(path.span, ast::TyPath(path, ast::DUMMY_NODE_ID))
self.ty(path.span, ast::TyPath(path))
}
fn ty_sum(&self, path: ast::Path, bounds: OwnedSlice<ast::TyParamBound>) -> P<ast::Ty> {

View file

@ -41,7 +41,7 @@ pub fn expand_type(t: P<ast::Ty>,
debug!("expanding type {:?} with impl_ty {:?}", t, impl_ty);
let t = match (t.node.clone(), impl_ty) {
// Expand uses of `Self` in impls to the concrete type.
(ast::Ty_::TyPath(ref path, _), Some(ref impl_ty)) => {
(ast::Ty_::TyPath(ref path), Some(ref impl_ty)) => {
let path_as_ident = path_to_ident(path);
// Note unhygenic comparison here. I think this is correct, since
// even though `Self` is almost just a type parameter, the treatment

View file

@ -549,7 +549,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
fn visit_ty(&mut self, t: &ast::Ty) {
match t.node {
ast::TyPath(ref p, _) => {
ast::TyPath(ref p) => {
match &*p.segments {
[ast::PathSegment { identifier, .. }] => {

View file

@ -428,10 +428,7 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
}
TyTup(tys) => TyTup(tys.move_map(|ty| fld.fold_ty(ty))),
TyParen(ty) => TyParen(fld.fold_ty(ty)),
TyPath(path, id) => {
let id = fld.new_id(id);
TyPath(fld.fold_path(path), id)
}
TyPath(path) => TyPath(fld.fold_path(path)),
TyObjectSum(ty, bounds) => {
TyObjectSum(fld.fold_ty(ty),
fld.fold_bounds(bounds))

View file

@ -1051,7 +1051,7 @@ mod test {
parameters: ast::PathParameters::none(),
}
),
}, ast::DUMMY_NODE_ID),
}),
span:sp(10,13)
}),
pat: P(ast::Pat {

View file

@ -1076,8 +1076,7 @@ impl<'a> Parser<'a> {
}
pub fn parse_ty_path(&mut self) -> Ty_ {
let path = self.parse_path(LifetimeAndTypesWithoutColons);
TyPath(path, ast::DUMMY_NODE_ID)
TyPath(self.parse_path(LifetimeAndTypesWithoutColons))
}
/// parse a TyBareFn type:
@ -4815,10 +4814,10 @@ impl<'a> Parser<'a> {
let opt_trait = if could_be_trait && self.eat_keyword(keywords::For) {
// New-style trait. Reinterpret the type as a trait.
match ty.node {
TyPath(ref path, node_id) => {
TyPath(ref path) => {
Some(TraitRef {
path: (*path).clone(),
ref_id: node_id,
ref_id: ty.id,
})
}
_ => {

View file

@ -729,7 +729,7 @@ impl<'a> State<'a> {
&generics,
None));
}
ast::TyPath(ref path, _) => {
ast::TyPath(ref path) => {
try!(self.print_path(path, false));
}
ast::TyObjectSum(ref ty, ref bounds) => {

View file

@ -399,8 +399,8 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
walk_fn_ret_ty(visitor, &function_declaration.decl.output);
walk_lifetime_decls_helper(visitor, &function_declaration.lifetimes);
}
TyPath(ref path, id) => {
visitor.visit_path(path, id);
TyPath(ref path) => {
visitor.visit_path(path, typ.id);
}
TyObjectSum(ref ty, ref bounds) => {
visitor.visit_ty(&**ty);