}
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 \
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!")
};
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);
}
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);
}
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 {}",
}
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
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));
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);
});
}
_ => {
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> {
// * 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();
}
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();
// 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) {
}
// 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,
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);
}
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);
}
}
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.
//
// 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 {
}
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");
}
// 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)
}
_ => {
// 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 \
// 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;
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 `{}`",
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
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,
}
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,
}
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
*/
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,
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,
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);
/// 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>`
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)
}
}
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> {
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
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, .. }] => {
}
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))
parameters: ast::PathParameters::none(),
}
),
- }, ast::DUMMY_NODE_ID),
+ }),
span:sp(10,13)
}),
pat: P(ast::Pat {
}
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:
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,
})
}
_ => {
&generics,
None));
}
- ast::TyPath(ref path, _) => {
+ ast::TyPath(ref path) => {
try!(self.print_path(path, false));
}
ast::TyObjectSum(ref ty, ref bounds) => {
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);