X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_typeck%2Fcollect.rs;h=5682a73bed573ffd51f06bf3192a8a6921eac47b;hb=1b150c4043654f93fcf7250b560581d44fc2b43d;hp=f3c570e84009b9b3f06a5e30fb669bcca69684c5;hpb=c87c31b1114ff80110fa160cae648bc54275c553;p=rust.git diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index f3c570e8400..1aede7cf14c 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1,13 +1,3 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - //! "Collection" is the process of determining the type and other external //! details of each item in Rust. Collection is specifically concerned //! with *interprocedural* things -- for example, for a function @@ -43,7 +33,7 @@ use rustc_target::spec::abi; use syntax::ast; -use syntax::ast::MetaItemKind; +use syntax::ast::{Ident, MetaItemKind}; use syntax::attr::{InlineAttr, list_contains_name, mark_used}; use syntax::source_map::Spanned; use syntax::feature_gate; @@ -66,7 +56,7 @@ pub fn collect_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { let mut visitor = CollectItemTypesVisitor { tcx }; - tcx.hir + tcx.hir() .krate() .visit_all_item_likes(&mut visitor.as_deep_visitor()); } @@ -97,7 +87,7 @@ pub fn provide(providers: &mut Providers) { /// AstConv. It has information about the predicates that are defined /// on the trait. Unfortunately, this predicate information is /// available in various different forms at various points in the -/// process. So we can't just store a pointer to e.g. the AST or the +/// process. So we can't just store a pointer to e.g., the AST or the /// parsed ty form, we have to be more flexible. To this end, the /// `ItemCtxt` is parameterized by a `DefId` that it uses to satisfy /// `get_type_parameter_bounds` requests, drawing the information from @@ -115,7 +105,7 @@ struct CollectItemTypesVisitor<'a, 'tcx: 'a> { impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> { fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { - NestedVisitorMap::OnlyBodies(&self.tcx.hir) + NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } fn visit_item(&mut self, item: &'tcx hir::Item) { @@ -130,7 +120,7 @@ fn visit_generics(&mut self, generics: &'tcx hir::Generics) { hir::GenericParamKind::Type { default: Some(_), .. } => { - let def_id = self.tcx.hir.local_def_id(param.id); + let def_id = self.tcx.hir().local_def_id(param.id); self.tcx.type_of(def_id); } hir::GenericParamKind::Type { .. } => {} @@ -141,7 +131,7 @@ fn visit_generics(&mut self, generics: &'tcx hir::Generics) { fn visit_expr(&mut self, expr: &'tcx hir::Expr) { if let hir::ExprKind::Closure(..) = expr.node { - let def_id = self.tcx.hir.local_def_id(expr.id); + let def_id = self.tcx.hir().local_def_id(expr.id); self.tcx.generics_of(def_id); self.tcx.type_of(def_id); } @@ -252,12 +242,12 @@ fn type_param_predicates<'a, 'tcx>( // written inline like `` or in a where clause like // `where T : Foo`. - let param_id = tcx.hir.as_local_node_id(def_id).unwrap(); - let param_owner = tcx.hir.ty_param_owner(param_id); - let param_owner_def_id = tcx.hir.local_def_id(param_owner); + let param_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let param_owner = tcx.hir().ty_param_owner(param_id); + let param_owner_def_id = tcx.hir().local_def_id(param_owner); let generics = tcx.generics_of(param_owner_def_id); let index = generics.param_def_id_to_index[&def_id]; - let ty = tcx.mk_ty_param(index, tcx.hir.ty_param_name(param_id).as_interned_str()); + let ty = tcx.mk_ty_param(index, tcx.hir().ty_param_name(param_id).as_interned_str()); // Don't look for bounds where the type parameter isn't in scope. let parent = if item_def_id == param_owner_def_id { @@ -277,8 +267,8 @@ fn type_param_predicates<'a, 'tcx>( }, ); - let item_node_id = tcx.hir.as_local_node_id(item_def_id).unwrap(); - let ast_generics = match tcx.hir.get(item_node_id) { + let item_node_id = tcx.hir().as_local_node_id(item_def_id).unwrap(); + let ast_generics = match tcx.hir().get(item_node_id) { Node::TraitItem(item) => &item.generics, Node::ImplItem(item) => &item.generics, @@ -384,7 +374,7 @@ fn is_param<'a, 'tcx>( if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = ast_ty.node { match path.def { Def::SelfTy(Some(def_id), None) | Def::TyParam(def_id) => { - def_id == tcx.hir.local_def_id(param_id) + def_id == tcx.hir().local_def_id(param_id) } _ => false, } @@ -394,9 +384,9 @@ fn is_param<'a, 'tcx>( } fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { - let it = tcx.hir.expect_item(item_id); - debug!("convert: item {} with id {}", it.name, it.id); - let def_id = tcx.hir.local_def_id(item_id); + let it = tcx.hir().expect_item(item_id); + debug!("convert: item {} with id {}", it.ident, it.id); + let def_id = tcx.hir().local_def_id(item_id); match it.node { // These don't define types. hir::ItemKind::ExternCrate(_) @@ -405,7 +395,7 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { | hir::ItemKind::GlobalAsm(_) => {} hir::ItemKind::ForeignMod(ref foreign_mod) => { for item in &foreign_mod.items { - let def_id = tcx.hir.local_def_id(item.id); + let def_id = tcx.hir().local_def_id(item.id); tcx.generics_of(def_id); tcx.type_of(def_id); tcx.predicates_of(def_id); @@ -443,7 +433,7 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { tcx.predicates_of(def_id); for f in struct_def.fields() { - let def_id = tcx.hir.local_def_id(f.id); + let def_id = tcx.hir().local_def_id(f.id); tcx.generics_of(def_id); tcx.type_of(def_id); tcx.predicates_of(def_id); @@ -476,8 +466,8 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { } fn convert_trait_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_item_id: ast::NodeId) { - let trait_item = tcx.hir.expect_trait_item(trait_item_id); - let def_id = tcx.hir.local_def_id(trait_item.id); + let trait_item = tcx.hir().expect_trait_item(trait_item_id); + let def_id = tcx.hir().local_def_id(trait_item.id); tcx.generics_of(def_id); match trait_item.node { @@ -497,17 +487,17 @@ fn convert_trait_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_item_id: ast: } fn convert_impl_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_item_id: ast::NodeId) { - let def_id = tcx.hir.local_def_id(impl_item_id); + let def_id = tcx.hir().local_def_id(impl_item_id); tcx.generics_of(def_id); tcx.type_of(def_id); tcx.predicates_of(def_id); - if let hir::ImplItemKind::Method(..) = tcx.hir.expect_impl_item(impl_item_id).node { + if let hir::ImplItemKind::Method(..) = tcx.hir().expect_impl_item(impl_item_id).node { tcx.fn_sig(def_id); } } fn convert_variant_ctor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ctor_id: ast::NodeId) { - let def_id = tcx.hir.local_def_id(ctor_id); + let def_id = tcx.hir().local_def_id(ctor_id); tcx.generics_of(def_id); tcx.type_of(def_id); tcx.predicates_of(def_id); @@ -528,7 +518,7 @@ fn convert_enum_variant_types<'a, 'tcx>( let wrapped_discr = prev_discr.map_or(initial, |d| d.wrap_incr(tcx)); prev_discr = Some( if let Some(ref e) = variant.node.disr_expr { - let expr_did = tcx.hir.local_def_id(e.id); + let expr_did = tcx.hir().local_def_id(e.id); def.eval_explicit_discr(tcx, expr_did) } else if let Some(discr) = repr_type.disr_incr(tcx, prev_discr) { Some(discr) @@ -543,7 +533,7 @@ fn convert_enum_variant_types<'a, 'tcx>( format!("overflowed on value after {}", prev_discr.unwrap()), ).note(&format!( "explicitly set `{} = {}` if that is desired outcome", - variant.node.name, wrapped_discr + variant.node.ident, wrapped_discr )) .emit(); None @@ -551,7 +541,7 @@ fn convert_enum_variant_types<'a, 'tcx>( ); for f in variant.node.data.fields() { - let def_id = tcx.hir.local_def_id(f.id); + let def_id = tcx.hir().local_def_id(f.id); tcx.generics_of(def_id); tcx.type_of(def_id); tcx.predicates_of(def_id); @@ -566,19 +556,19 @@ fn convert_enum_variant_types<'a, 'tcx>( fn convert_variant<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId, - name: ast::Name, + ident: Ident, discr: ty::VariantDiscr, def: &hir::VariantData, adt_kind: ty::AdtKind, attribute_def_id: DefId ) -> ty::VariantDef { let mut seen_fields: FxHashMap = Default::default(); - let node_id = tcx.hir.as_local_node_id(did).unwrap(); + let node_id = tcx.hir().as_local_node_id(did).unwrap(); let fields = def .fields() .iter() .map(|f| { - let fid = tcx.hir.local_def_id(f.id); + let fid = tcx.hir().local_def_id(f.id); let dup_span = seen_fields.get(&f.ident.modern()).cloned(); if let Some(prev_span) = dup_span { struct_span_err!( @@ -603,19 +593,20 @@ fn convert_variant<'a, 'tcx>( .collect(); ty::VariantDef::new(tcx, did, - name, + ident, discr, fields, adt_kind, CtorKind::from_hir(def), - attribute_def_id) + attribute_def_id + ) } fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::AdtDef { use rustc::hir::*; - let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); - let item = match tcx.hir.get(node_id) { + let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let item = match tcx.hir().get(node_id) { Node::Item(item) => item, _ => bug!(), }; @@ -629,16 +620,16 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad def.variants .iter() .map(|v| { - let did = tcx.hir.local_def_id(v.node.data.id()); + let did = tcx.hir().local_def_id(v.node.data.id()); let discr = if let Some(ref e) = v.node.disr_expr { distance_from_explicit = 0; - ty::VariantDiscr::Explicit(tcx.hir.local_def_id(e.id)) + ty::VariantDiscr::Explicit(tcx.hir().local_def_id(e.id)) } else { ty::VariantDiscr::Relative(distance_from_explicit) }; distance_from_explicit += 1; - convert_variant(tcx, did, v.node.name, discr, &v.node.data, AdtKind::Enum, + convert_variant(tcx, did, v.node.ident, discr, &v.node.data, AdtKind::Enum, did) }) .collect(), @@ -647,7 +638,7 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad ItemKind::Struct(ref def, _) => { // Use separate constructor id for unit/tuple structs and reuse did for braced structs. let ctor_id = if !def.is_struct() { - Some(tcx.hir.local_def_id(def.id())) + Some(tcx.hir().local_def_id(def.id())) } else { None }; @@ -656,7 +647,7 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad std::iter::once(convert_variant( tcx, ctor_id.unwrap_or(def_id), - item.name, + item.ident, ty::VariantDiscr::Relative(0), def, AdtKind::Struct, @@ -669,7 +660,7 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad std::iter::once(convert_variant( tcx, def_id, - item.name, + item.ident, ty::VariantDiscr::Relative(0), def, AdtKind::Union, @@ -689,9 +680,9 @@ fn super_predicates_of<'a, 'tcx>( trait_def_id: DefId, ) -> Lrc> { debug!("super_predicates(trait_def_id={:?})", trait_def_id); - let trait_node_id = tcx.hir.as_local_node_id(trait_def_id).unwrap(); + let trait_node_id = tcx.hir().as_local_node_id(trait_def_id).unwrap(); - let item = match tcx.hir.get(trait_node_id) { + let item = match tcx.hir().get(trait_node_id) { Node::Item(item) => item, _ => bug!("trait_node_id {} is not an item", trait_node_id), }; @@ -704,16 +695,16 @@ fn super_predicates_of<'a, 'tcx>( let icx = ItemCtxt::new(tcx, trait_def_id); - // Convert the bounds that follow the colon, e.g. `Bar + Zed` in `trait Foo : Bar + Zed`. + // Convert the bounds that follow the colon, e.g., `Bar + Zed` in `trait Foo : Bar + Zed`. let self_param_ty = tcx.mk_self_type(); let superbounds1 = compute_bounds(&icx, self_param_ty, bounds, SizedByDefault::No, item.span); let superbounds1 = superbounds1.predicates(tcx, self_param_ty); // Convert any explicit superbounds in the where clause, - // e.g. `trait Foo where Self : Bar`. + // e.g., `trait Foo where Self : Bar`. // In the case of trait aliases, however, we include all bounds in the where clause, - // so e.g. `trait Foo = where u32: PartialEq` would include `u32: PartialEq` + // so e.g., `trait Foo = where u32: PartialEq` would include `u32: PartialEq` // as one of its "superpredicates". let is_trait_alias = ty::is_trait_alias(tcx, trait_def_id); let superbounds2 = icx.type_parameter_bounds_in_generics( @@ -738,8 +729,8 @@ fn super_predicates_of<'a, 'tcx>( } fn trait_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::TraitDef { - let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); - let item = tcx.hir.expect_item(node_id); + let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let item = tcx.hir().expect_item(node_id); let (is_auto, unsafety) = match item.node { hir::ItemKind::Trait(is_auto, unsafety, ..) => (is_auto == hir::IsAuto::Yes, unsafety), @@ -815,7 +806,7 @@ fn visit_lifetime(&mut self, lt: &'tcx hir::Lifetime) { return; } - let hir_id = self.tcx.hir.node_to_hir_id(lt.id); + let hir_id = self.tcx.hir().node_to_hir_id(lt.id); match self.tcx.named_region(hir_id) { Some(rl::Region::Static) | Some(rl::Region::EarlyBound(..)) => {} Some(rl::Region::LateBound(debruijn, _, _)) @@ -842,7 +833,7 @@ fn has_late_bound_regions<'a, 'tcx>( }; for param in &generics.params { if let GenericParamKind::Lifetime { .. } = param.kind { - let hir_id = tcx.hir.node_to_hir_id(param.id); + let hir_id = tcx.hir().node_to_hir_id(param.id); if tcx.is_late_bound(hir_id) { return Some(param.span); } @@ -884,14 +875,14 @@ fn has_late_bound_regions<'a, 'tcx>( fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Generics { use rustc::hir::*; - let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); + let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let node = tcx.hir.get(node_id); + let node = tcx.hir().get(node_id); let parent_def_id = match node { Node::ImplItem(_) | Node::TraitItem(_) | Node::Variant(_) | Node::StructCtor(_) | Node::Field(_) => { - let parent_id = tcx.hir.get_parent(node_id); - Some(tcx.hir.local_def_id(parent_id)) + let parent_id = tcx.hir().get_parent(node_id); + Some(tcx.hir().local_def_id(parent_id)) } Node::Expr(&hir::Expr { node: hir::ExprKind::Closure(..), @@ -938,8 +929,8 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty opt_self = Some(ty::GenericParamDef { index: 0, - name: keywords::SelfType.name().as_interned_str(), - def_id: tcx.hir.local_def_id(param_id), + name: keywords::SelfUpper.name().as_interned_str(), + def_id: tcx.hir().local_def_id(param_id), pure_wrt_drop: false, kind: ty::GenericParamDefKind::Type { has_default: false, @@ -985,13 +976,13 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty .map(|(i, param)| ty::GenericParamDef { name: param.name.ident().as_interned_str(), index: own_start + i as u32, - def_id: tcx.hir.local_def_id(param.id), + def_id: tcx.hir().local_def_id(param.id), pure_wrt_drop: param.pure_wrt_drop, kind: ty::GenericParamDefKind::Lifetime, }), ); - let hir_id = tcx.hir.node_to_hir_id(node_id); + let hir_id = tcx.hir().node_to_hir_id(node_id); let object_lifetime_defaults = tcx.object_lifetime_defaults(hir_id); // Now create the real type parameters. @@ -1007,7 +998,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty synthetic, .. } => { - if param.name.ident().name == keywords::SelfType.name() { + if param.name.ident().name == keywords::SelfUpper.name() { span_bug!( param.span, "`Self` should not be the name of a regular parameter" @@ -1031,7 +1022,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty let ty_param = ty::GenericParamDef { index: type_start + i as u32, name: param.name.ident().as_interned_str(), - def_id: tcx.hir.local_def_id(param.id), + def_id: tcx.hir().local_def_id(param.id), pure_wrt_drop: param.pure_wrt_drop, kind: ty::GenericParamDefKind::Type { has_default: default.is_some(), @@ -1123,11 +1114,11 @@ fn report_assoc_ty_on_inherent_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { use rustc::hir::*; - let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); + let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); let icx = ItemCtxt::new(tcx, def_id); - match tcx.hir.get(node_id) { + match tcx.hir().get(node_id) { Node::TraitItem(item) => match item.node { TraitItemKind::Method(..) => { let substs = Substs::identity_for_item(tcx, def_id); @@ -1147,7 +1138,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { ImplItemKind::Const(ref ty, _) => icx.to_ty(ty), ImplItemKind::Existential(_) => { if tcx - .impl_trait_ref(tcx.hir.get_parent_did(node_id)) + .impl_trait_ref(tcx.hir().get_parent_did(node_id)) .is_none() { report_assoc_ty_on_inherent_impl(tcx, item.span); @@ -1157,7 +1148,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { } ImplItemKind::Type(ref ty) => { if tcx - .impl_trait_ref(tcx.hir.get_parent_did(node_id)) + .impl_trait_ref(tcx.hir().get_parent_did(node_id)) .is_none() { report_assoc_ty_on_inherent_impl(tcx, item.span); @@ -1240,7 +1231,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { .. }) => match *def { VariantData::Unit(..) | VariantData::Struct(..) => { - tcx.type_of(tcx.hir.get_parent_did(node_id)) + tcx.type_of(tcx.hir().get_parent_did(node_id)) } VariantData::Tuple(..) => { let substs = Substs::identity_for_item(tcx, def_id); @@ -1255,7 +1246,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { .. }) => { if gen.is_some() { - let hir_id = tcx.hir.node_to_hir_id(node_id); + let hir_id = tcx.hir().node_to_hir_id(node_id); return tcx.typeck_tables_of(def_id).node_id_to_type(hir_id); } @@ -1266,7 +1257,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { tcx.mk_closure(def_id, substs) } - Node::AnonConst(_) => match tcx.hir.get(tcx.hir.get_parent_node(node_id)) { + Node::AnonConst(_) => match tcx.hir().get(tcx.hir().get_parent_node(node_id)) { Node::Ty(&hir::Ty { node: hir::TyKind::Array(_, ref constant), .. @@ -1292,7 +1283,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { .. }) if e.id == node_id => { - tcx.adt_def(tcx.hir.get_parent_did(node_id)) + tcx.adt_def(tcx.hir().get_parent_did(node_id)) .repr .discr_type() .to_ty(tcx) @@ -1365,10 +1356,10 @@ fn check(&mut self, def_id: DefId) { impl<'a, 'tcx> intravisit::Visitor<'tcx> for ConstraintLocator<'a, 'tcx> { fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { - intravisit::NestedVisitorMap::All(&self.tcx.hir) + intravisit::NestedVisitorMap::All(&self.tcx.hir()) } fn visit_item(&mut self, it: &'tcx Item) { - let def_id = self.tcx.hir.local_def_id(it.id); + let def_id = self.tcx.hir().local_def_id(it.id); // the existential type itself or its children are not within its reveal scope if def_id != self.def_id { self.check(def_id); @@ -1376,7 +1367,7 @@ fn visit_item(&mut self, it: &'tcx Item) { } } fn visit_impl_item(&mut self, it: &'tcx ImplItem) { - let def_id = self.tcx.hir.local_def_id(it.id); + let def_id = self.tcx.hir().local_def_id(it.id); // the existential type itself or its children are not within its reveal scope if def_id != self.def_id { self.check(def_id); @@ -1384,7 +1375,7 @@ fn visit_impl_item(&mut self, it: &'tcx ImplItem) { } } fn visit_trait_item(&mut self, it: &'tcx TraitItem) { - let def_id = self.tcx.hir.local_def_id(it.id); + let def_id = self.tcx.hir().local_def_id(it.id); self.check(def_id); intravisit::walk_trait_item(self, it); } @@ -1395,16 +1386,16 @@ fn visit_trait_item(&mut self, it: &'tcx TraitItem) { tcx, found: None, }; - let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); - let parent = tcx.hir.get_parent(node_id); + let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let parent = tcx.hir().get_parent(node_id); trace!("parent_id: {:?}", parent); if parent == ast::CRATE_NODE_ID { - intravisit::walk_crate(&mut locator, tcx.hir.krate()); + intravisit::walk_crate(&mut locator, tcx.hir().krate()); } else { - trace!("parent: {:?}", tcx.hir.get(parent)); - match tcx.hir.get(parent) { + trace!("parent: {:?}", tcx.hir().get(parent)); + match tcx.hir().get(parent) { Node::Item(ref it) => intravisit::walk_item(&mut locator, it), Node::ImplItem(ref it) => intravisit::walk_impl_item(&mut locator, it), Node::TraitItem(ref it) => intravisit::walk_trait_item(&mut locator, it), @@ -1429,11 +1420,11 @@ fn fn_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::PolyFnSig use rustc::hir::*; use rustc::hir::Node::*; - let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); + let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); let icx = ItemCtxt::new(tcx, def_id); - match tcx.hir.get(node_id) { + match tcx.hir().get(node_id) { TraitItem(hir::TraitItem { node: TraitItemKind::Method(sig, _), .. @@ -1452,7 +1443,7 @@ fn fn_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::PolyFnSig node: ForeignItemKind::Fn(ref fn_decl, _, _), .. }) => { - let abi = tcx.hir.get_foreign_abi(node_id); + let abi = tcx.hir().get_foreign_abi(node_id); compute_sig_of_foreign_fn_decl(tcx, def_id, fn_decl, abi) } @@ -1465,10 +1456,10 @@ fn fn_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::PolyFnSig }, .. }) => { - let ty = tcx.type_of(tcx.hir.get_parent_did(node_id)); + let ty = tcx.type_of(tcx.hir().get_parent_did(node_id)); let inputs = fields .iter() - .map(|f| tcx.type_of(tcx.hir.local_def_id(f.id))); + .map(|f| tcx.type_of(tcx.hir().local_def_id(f.id))); ty::Binder::bind(tcx.mk_fn_sig( inputs, ty, @@ -1512,8 +1503,8 @@ fn impl_trait_ref<'a, 'tcx>( ) -> Option> { let icx = ItemCtxt::new(tcx, def_id); - let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); - match tcx.hir.expect_item(node_id).node { + let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + match tcx.hir().expect_item(node_id).node { hir::ItemKind::Impl(.., ref opt_trait_ref, _, _) => { opt_trait_ref.as_ref().map(|ast_trait_ref| { let selfty = tcx.type_of(def_id); @@ -1525,8 +1516,8 @@ fn impl_trait_ref<'a, 'tcx>( } fn impl_polarity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> hir::ImplPolarity { - let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); - match tcx.hir.expect_item(node_id).node { + let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + match tcx.hir().expect_item(node_id).node { hir::ItemKind::Impl(_, polarity, ..) => polarity, ref item => bug!("impl_polarity: {:?} not an impl", item), } @@ -1597,7 +1588,7 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx>( .iter() .filter(move |param| match param.kind { GenericParamKind::Lifetime { .. } => { - let hir_id = tcx.hir.node_to_hir_id(param.id); + let hir_id = tcx.hir().node_to_hir_id(param.id); !tcx.is_late_bound(hir_id) } _ => false, @@ -1695,8 +1686,8 @@ fn extend, Span)>>(&mut self, iter: } } - let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); - let node = tcx.hir.get(node_id); + let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let node = tcx.hir().get(node_id); let mut is_trait = None; let mut is_default_impl_trait = None; @@ -1715,7 +1706,7 @@ fn extend, Span)>>(&mut self, iter: let substs = Substs::identity_for_item(tcx, def_id); let opaque_ty = tcx.mk_opaque(def_id, substs); - // Collect the bounds, i.e. the `A+B+'c` in `impl A+B+'c`. + // Collect the bounds, i.e., the `A+B+'c` in `impl A+B+'c`. let bounds = compute_bounds( &icx, opaque_ty, @@ -1760,7 +1751,7 @@ fn extend, Span)>>(&mut self, iter: let substs = Substs::identity_for_item(tcx, def_id); let opaque_ty = tcx.mk_opaque(def_id, substs); - // Collect the bounds, i.e. the `A+B+'c` in `impl A+B+'c`. + // Collect the bounds, i.e., the `A+B+'c` in `impl A+B+'c`. let bounds = compute_bounds( &icx, opaque_ty, @@ -1825,7 +1816,7 @@ fn extend, Span)>>(&mut self, iter: let mut index = parent_count + has_own_self as u32; for param in early_bound_lifetimes_from_generics(tcx, ast_generics) { let region = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { - def_id: tcx.hir.local_def_id(param.id), + def_id: tcx.hir().local_def_id(param.id), index, name: param.name.ident().as_interned_str(), })); @@ -1892,7 +1883,7 @@ fn extend, Span)>>(&mut self, iter: &hir::GenericBound::Trait(ref poly_trait_ref, _) => { let mut projections = Vec::new(); - let trait_ref = AstConv::instantiate_poly_trait_ref( + let (trait_ref, _) = AstConv::instantiate_poly_trait_ref( &icx, poly_trait_ref, ty, @@ -1938,14 +1929,14 @@ fn extend, Span)>>(&mut self, iter: // Add predicates from associated type bounds. if let Some((self_trait_ref, trait_items)) = is_trait { predicates.extend(trait_items.iter().flat_map(|trait_item_ref| { - let trait_item = tcx.hir.trait_item(trait_item_ref.id); + let trait_item = tcx.hir().trait_item(trait_item_ref.id); let bounds = match trait_item.node { hir::TraitItemKind::Type(ref bounds, _) => bounds, _ => return vec![].into_iter() }; let assoc_ty = - tcx.mk_projection(tcx.hir.local_def_id(trait_item.id), self_trait_ref.substs); + tcx.mk_projection(tcx.hir().local_def_id(trait_item.id), self_trait_ref.substs); let bounds = compute_bounds( &ItemCtxt::new(tcx, def_id), @@ -2016,7 +2007,12 @@ pub fn compute_bounds<'gcx: 'tcx, 'tcx>( let mut projection_bounds = Vec::new(); let mut trait_bounds: Vec<_> = trait_bounds.iter().map(|&bound| { - (astconv.instantiate_poly_trait_ref(bound, param_ty, &mut projection_bounds), bound.span) + let (poly_trait_ref, _) = astconv.instantiate_poly_trait_ref( + bound, + param_ty, + &mut projection_bounds, + ); + (poly_trait_ref, bound.span) }).collect(); let region_bounds = region_bounds @@ -2057,7 +2053,7 @@ fn predicates_from_bound<'tcx>( match *bound { hir::GenericBound::Trait(ref tr, hir::TraitBoundModifier::None) => { let mut projections = Vec::new(); - let pred = astconv.instantiate_poly_trait_ref(tr, param_ty, &mut projections); + let (pred, _) = astconv.instantiate_poly_trait_ref(tr, param_ty, &mut projections); iter::once((pred.to_predicate(), tr.span)).chain( projections .into_iter() @@ -2103,7 +2099,7 @@ fn compute_sig_of_foreign_fn_decl<'a, 'tcx>( &format!( "use of SIMD type `{}` in FFI is highly experimental and \ may result in invalid code", - tcx.hir.node_to_pretty_string(ast_ty.id) + tcx.hir().node_to_pretty_string(ast_ty.id) ), ) .help("add #![feature(simd_ffi)] to the crate attributes to enable") @@ -2122,7 +2118,7 @@ fn compute_sig_of_foreign_fn_decl<'a, 'tcx>( } fn is_foreign_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool { - match tcx.hir.get_if_local(def_id) { + match tcx.hir().get_if_local(def_id) { Some(Node::ForeignItem(..)) => true, Some(_) => false, _ => bug!("is_foreign_item applied to non-local def-id {:?}", def_id), @@ -2202,6 +2198,8 @@ fn from_target_feature( Some("sse4a_target_feature") => rust_features.sse4a_target_feature, Some("tbm_target_feature") => rust_features.tbm_target_feature, Some("wasm_target_feature") => rust_features.wasm_target_feature, + Some("cmpxchg16b_target_feature") => rust_features.cmpxchg16b_target_feature, + Some("adx_target_feature") => rust_features.adx_target_feature, Some(name) => bug!("unknown target feature gate {}", name), None => true, }; @@ -2244,7 +2242,7 @@ fn linkage_by_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, name: & "weak" => WeakAny, "weak_odr" => WeakODR, _ => { - let span = tcx.hir.span_if_local(def_id); + let span = tcx.hir().span_if_local(def_id); if let Some(span) = span { tcx.sess.span_fatal(span, "invalid linkage specified") } else {