Visit for hir::Ty.

This commit is contained in:
Camille GILLOT 2019-12-01 00:17:43 +01:00
parent 6b87d5cdf1
commit 5865d563ea
5 changed files with 55 additions and 60 deletions

View File

@ -450,7 +450,7 @@ pub fn walk_poly_trait_ref<'v, V>(
) where
V: Visitor<'v>,
{
walk_list!(visitor, visit_generic_param, &trait_ref.bound_generic_params);
walk_list!(visitor, visit_generic_param, trait_ref.bound_generic_params);
visitor.visit_trait_ref(&trait_ref.trait_ref);
}
@ -509,7 +509,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
visitor.visit_ty(ty);
visitor.visit_generics(generics)
}
ItemKind::OpaqueTy(OpaqueTy { ref generics, ref bounds, .. }) => {
ItemKind::OpaqueTy(OpaqueTy { ref generics, bounds, .. }) => {
visitor.visit_id(item.hir_id);
walk_generics(visitor, generics);
walk_list!(visitor, visit_param_bound, bounds);
@ -538,13 +538,13 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
item.span,
);
}
ItemKind::Trait(.., ref generics, ref bounds, trait_item_refs) => {
ItemKind::Trait(.., ref generics, bounds, trait_item_refs) => {
visitor.visit_id(item.hir_id);
visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_trait_item_ref, trait_item_refs);
}
ItemKind::TraitAlias(ref generics, ref bounds) => {
ItemKind::TraitAlias(ref generics, bounds) => {
visitor.visit_id(item.hir_id);
visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds);
@ -598,17 +598,17 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
visitor.visit_ty(&mutable_type.ty)
}
TyKind::Never => {}
TyKind::Tup(ref tuple_element_types) => {
TyKind::Tup(tuple_element_types) => {
walk_list!(visitor, visit_ty, tuple_element_types);
}
TyKind::BareFn(ref function_declaration) => {
walk_list!(visitor, visit_generic_param, &function_declaration.generic_params);
walk_list!(visitor, visit_generic_param, function_declaration.generic_params);
visitor.visit_fn_decl(&function_declaration.decl);
}
TyKind::Path(ref qpath) => {
visitor.visit_qpath(qpath, typ.hir_id, typ.span);
}
TyKind::Def(item_id, ref lifetimes) => {
TyKind::Def(item_id, lifetimes) => {
visitor.visit_nested_item(item_id);
walk_list!(visitor, visit_generic_arg, lifetimes);
}
@ -616,7 +616,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
visitor.visit_ty(ty);
visitor.visit_anon_const(length)
}
TyKind::TraitObject(ref bounds, ref lifetime) => {
TyKind::TraitObject(bounds, ref lifetime) => {
for bound in bounds {
visitor.visit_poly_trait_ref(bound, TraitBoundModifier::None);
}
@ -648,7 +648,7 @@ pub fn walk_qpath<'v, V: Visitor<'v>>(
}
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>) {
for segment in &path.segments {
for segment in path.segments {
visitor.visit_path_segment(path.span, segment);
}
}
@ -673,7 +673,7 @@ pub fn walk_generic_args<'v, V: Visitor<'v>>(
generic_args: &'v GenericArgs<'v>,
) {
walk_list!(visitor, visit_generic_arg, &generic_args.args);
walk_list!(visitor, visit_assoc_type_binding, &generic_args.bindings);
walk_list!(visitor, visit_assoc_type_binding, generic_args.bindings);
}
pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(
@ -686,7 +686,7 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(
TypeBindingKind::Equality { ref ty } => {
visitor.visit_ty(ty);
}
TypeBindingKind::Constraint { ref bounds } => {
TypeBindingKind::Constraint { bounds } => {
walk_list!(visitor, visit_param_bound, bounds);
}
}
@ -766,7 +766,7 @@ pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericB
pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam<'v>) {
visitor.visit_id(param.hir_id);
walk_list!(visitor, visit_attribute, &param.attrs);
walk_list!(visitor, visit_attribute, param.attrs);
match param.name {
ParamName::Plain(ident) => visitor.visit_ident(ident),
ParamName::Error | ParamName::Fresh(_) => {}
@ -776,12 +776,12 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi
GenericParamKind::Type { ref default, .. } => walk_list!(visitor, visit_ty, default),
GenericParamKind::Const { ref ty } => visitor.visit_ty(ty),
}
walk_list!(visitor, visit_param_bound, &param.bounds);
walk_list!(visitor, visit_param_bound, param.bounds);
}
pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics<'v>) {
walk_list!(visitor, visit_generic_param, &generics.params);
walk_list!(visitor, visit_where_predicate, &generics.where_clause.predicates);
walk_list!(visitor, visit_where_predicate, generics.where_clause.predicates);
}
pub fn walk_where_predicate<'v, V: Visitor<'v>>(
@ -791,17 +791,15 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(
match predicate {
&WherePredicate::BoundPredicate(WhereBoundPredicate {
ref bounded_ty,
ref bounds,
ref bound_generic_params,
bounds,
bound_generic_params,
..
}) => {
visitor.visit_ty(bounded_ty);
walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_generic_param, bound_generic_params);
}
&WherePredicate::RegionPredicate(WhereRegionPredicate {
ref lifetime, ref bounds, ..
}) => {
&WherePredicate::RegionPredicate(WhereRegionPredicate { ref lifetime, bounds, .. }) => {
visitor.visit_lifetime(lifetime);
walk_list!(visitor, visit_param_bound, bounds);
}
@ -822,7 +820,7 @@ pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionR
}
pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl<'v>) {
for ty in &function_declaration.inputs {
for ty in function_declaration.inputs {
visitor.visit_ty(ty)
}
walk_fn_ret_ty(visitor, &function_declaration.output)
@ -877,7 +875,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
trait_item.hir_id,
);
}
TraitItemKind::Type(ref bounds, ref default) => {
TraitItemKind::Type(bounds, ref default) => {
visitor.visit_id(trait_item.hir_id);
walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_ty, default);
@ -931,7 +929,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
visitor.visit_id(impl_item.hir_id);
visitor.visit_ty(ty);
}
ImplItemKind::OpaqueTy(ref bounds) => {
ImplItemKind::OpaqueTy(bounds) => {
visitor.visit_id(impl_item.hir_id);
walk_list!(visitor, visit_param_bound, bounds);
}

View File

@ -443,7 +443,7 @@ pub struct GenericArgs<'hir> {
impl GenericArgs<'_> {
pub const fn none() -> Self {
Self { args: HirVec::new(), bindings: HirVec::new(), parenthesized: false }
Self { args: HirVec::new(), bindings: &[], parenthesized: false }
}
pub fn is_empty(&self) -> bool {
@ -580,7 +580,7 @@ impl Generics<'hir> {
pub const fn empty() -> Generics<'hir> {
Generics {
params: HirVec::new(),
where_clause: WhereClause { predicates: HirVec::new(), span: DUMMY_SP },
where_clause: WhereClause { predicates: &[], span: DUMMY_SP },
span: DUMMY_SP,
}
}

View File

@ -10,6 +10,7 @@
use syntax_pos::{self, BytePos, FileName};
use crate::hir;
use crate::hir::HirVec;
use crate::hir::{GenericArg, GenericParam, GenericParamKind};
use crate::hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
@ -307,7 +308,7 @@ pub fn print_type(&mut self, ty: &hir::Ty<'_>) {
}
hir::TyKind::Def(..) => {}
hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false),
hir::TyKind::TraitObject(ref bounds, ref lifetime) => {
hir::TyKind::TraitObject(bounds, ref lifetime) => {
let mut first = true;
for bound in bounds {
if first {
@ -418,7 +419,7 @@ fn print_associated_const(
fn print_associated_type(
&mut self,
ident: ast::Ident,
bounds: Option<&hir::GenericBounds<'_>>,
bounds: Option<hir::GenericBounds<'_>>,
ty: Option<&hir::Ty<'_>>,
) {
self.word_space("type");
@ -891,7 +892,7 @@ pub fn print_impl_item(&mut self, ii: &hir::ImplItem<'_>) {
hir::ImplItemKind::TyAlias(ref ty) => {
self.print_associated_type(ii.ident, None, Some(ty));
}
hir::ImplItemKind::OpaqueTy(ref bounds) => {
hir::ImplItemKind::OpaqueTy(bounds) => {
self.word_space("type");
self.print_ident(ii.ident);
self.print_bounds("= impl", bounds);
@ -1586,7 +1587,7 @@ fn print_generic_args(
self.word_space("=");
self.print_type(ty);
}
hir::TypeBindingKind::Constraint { ref bounds } => {
hir::TypeBindingKind::Constraint { bounds } => {
self.print_bounds(":", bounds);
}
}
@ -1953,9 +1954,9 @@ pub fn print_generic_param(&mut self, param: &GenericParam<'_>) {
match param.kind {
GenericParamKind::Lifetime { .. } => {
let mut sep = ":";
for bound in &param.bounds {
for bound in param.bounds {
match bound {
GenericBound::Outlives(lt) => {
GenericBound::Outlives(ref lt) => {
self.s.word(sep);
self.print_lifetime(lt);
sep = "+";
@ -1965,7 +1966,7 @@ pub fn print_generic_param(&mut self, param: &GenericParam<'_>) {
}
}
GenericParamKind::Type { ref default, .. } => {
self.print_bounds(":", &param.bounds);
self.print_bounds(":", param.bounds);
match default {
Some(default) => {
self.s.space();
@ -2003,7 +2004,7 @@ pub fn print_where_clause(&mut self, where_clause: &hir::WhereClause<'_>) {
&hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
ref bound_generic_params,
ref bounded_ty,
ref bounds,
bounds,
..
}) => {
self.print_formal_generic_params(bound_generic_params);
@ -2096,11 +2097,8 @@ pub fn print_ty_fn(
self.print_generic_params(generic_params);
}
let generics = hir::Generics {
params: hir::HirVec::new(),
where_clause: hir::WhereClause {
predicates: hir::HirVec::new(),
span: syntax_pos::DUMMY_SP,
},
params: HirVec::new(),
where_clause: hir::WhereClause { predicates: &[], span: syntax_pos::DUMMY_SP },
span: syntax_pos::DUMMY_SP,
};
self.print_fn(

View File

@ -103,7 +103,7 @@ fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx>) {
return;
}
hir::TyKind::TraitObject(ref bounds, _) => {
hir::TyKind::TraitObject(bounds, _) => {
for bound in bounds {
self.current_index.shift_in(1);
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);

View File

@ -8,7 +8,6 @@
use crate::hir::def::{DefKind, Res};
use crate::hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use crate::hir::map::Map;
use crate::hir::ptr::P;
use crate::hir::{GenericArg, GenericParam, ItemLocalId, LifetimeName, Node, ParamName, QPath};
use crate::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt};
@ -549,7 +548,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
});
self.is_in_fn_syntax = was_in_fn_syntax;
}
hir::TyKind::TraitObject(ref bounds, ref lifetime) => {
hir::TyKind::TraitObject(bounds, ref lifetime) => {
debug!("visit_ty: TraitObject(bounds={:?}, lifetime={:?})", bounds, lifetime);
for bound in bounds {
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
@ -590,7 +589,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
};
self.with(scope, |_, this| this.visit_ty(&mt.ty));
}
hir::TyKind::Def(item_id, ref lifetimes) => {
hir::TyKind::Def(item_id, lifetimes) => {
// Resolve the lifetimes in the bounds to the lifetime defs in the generics.
// `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to
// `type MyAnonTy<'b> = impl MyTrait<'b>;`
@ -604,7 +603,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
return;
}
// RPIT (return position impl trait)
hir::ItemKind::OpaqueTy(hir::OpaqueTy { ref generics, ref bounds, .. }) => {
hir::ItemKind::OpaqueTy(hir::OpaqueTy { ref generics, bounds, .. }) => {
(generics, bounds)
}
ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i),
@ -738,7 +737,7 @@ fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
|this| intravisit::walk_trait_item(this, trait_item),
);
}
Type(ref bounds, ref ty) => {
Type(bounds, ref ty) => {
let generics = &trait_item.generics;
let mut index = self.next_early_index();
debug!("visit_ty: index = {}", index);
@ -823,7 +822,7 @@ fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
this.visit_ty(ty);
});
}
OpaqueTy(ref bounds) => {
OpaqueTy(bounds) => {
let generics = &impl_item.generics;
let mut index = self.next_early_index();
let mut next_early_index = index;
@ -904,22 +903,22 @@ fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
match param.kind {
GenericParamKind::Lifetime { .. } => {}
GenericParamKind::Type { ref default, .. } => {
walk_list!(self, visit_param_bound, &param.bounds);
walk_list!(self, visit_param_bound, param.bounds);
if let Some(ref ty) = default {
self.visit_ty(&ty);
}
}
GenericParamKind::Const { ref ty, .. } => {
walk_list!(self, visit_param_bound, &param.bounds);
walk_list!(self, visit_param_bound, param.bounds);
self.visit_ty(&ty);
}
}
}
for predicate in &generics.where_clause.predicates {
for predicate in generics.where_clause.predicates {
match predicate {
&hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
ref bounded_ty,
ref bounds,
bounds,
ref bound_generic_params,
..
}) => {
@ -956,7 +955,7 @@ fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
}
&hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
ref lifetime,
ref bounds,
bounds,
..
}) => {
self.visit_lifetime(lifetime);
@ -1014,7 +1013,7 @@ fn visit_poly_trait_ref(
};
self.with(scope, |old_scope, this| {
this.check_lifetime_params(old_scope, &trait_ref.bound_generic_params);
walk_list!(this, visit_generic_param, &trait_ref.bound_generic_params);
walk_list!(this, visit_generic_param, trait_ref.bound_generic_params);
this.visit_trait_ref(&trait_ref.trait_ref)
})
} else {
@ -1059,7 +1058,7 @@ fn desc(&self) -> &'static str {
}
}
fn check_mixed_explicit_and_in_band_defs(tcx: TyCtxt<'_>, params: &P<[hir::GenericParam<'_>]>) {
fn check_mixed_explicit_and_in_band_defs(tcx: TyCtxt<'_>, params: &[hir::GenericParam<'_>]) {
let lifetime_params: Vec<_> = params
.iter()
.filter_map(|param| match param.kind {
@ -1273,7 +1272,7 @@ fn add_bounds(set: &mut Set1<hir::LifetimeName>, bounds: &[hir::GenericBound<'_>
add_bounds(&mut set, &param.bounds);
let param_def_id = tcx.hir().local_def_id(param.hir_id);
for predicate in &generics.where_clause.predicates {
for predicate in generics.where_clause.predicates {
// Look for `type: ...` where clauses.
let data = match *predicate {
hir::WherePredicate::BoundPredicate(ref data) => data,
@ -1421,7 +1420,7 @@ fn suggest_eliding_single_use_lifetime(
let mut remove_use = None;
let mut elide_use = None;
let mut find_arg_use_span = |inputs: &hir::HirVec<hir::Ty<'_>>| {
let mut find_arg_use_span = |inputs: &[hir::Ty<'_>]| {
for input in inputs {
match input.kind {
hir::TyKind::Rptr(lt, _) => {
@ -1463,12 +1462,12 @@ fn suggest_eliding_single_use_lifetime(
match parent {
Node::Item(item) => {
if let hir::ItemKind::Fn(sig, _, _) = &item.kind {
find_arg_use_span(&sig.decl.inputs);
find_arg_use_span(sig.decl.inputs);
}
}
Node::ImplItem(impl_item) => {
if let hir::ImplItemKind::Method(sig, _) = &impl_item.kind {
find_arg_use_span(&sig.decl.inputs);
find_arg_use_span(sig.decl.inputs);
}
}
_ => {}
@ -2045,7 +2044,7 @@ fn visit_segment_args(
});
// Resolve lifetimes found in the type `XX` from `Item = XX` bindings.
for b in &generic_args.bindings {
for b in generic_args.bindings {
let scope = Scope::ObjectLifetimeDefault {
lifetime: if has_lifetime_parameter { None } else { Some(Region::Static) },
s: self.scope,
@ -2269,7 +2268,7 @@ fn visit_ty(&mut self, ty: &hir::Ty<'_>) {
self.outer_index.shift_in(1);
}
match ty.kind {
hir::TyKind::TraitObject(ref bounds, ref lifetime) => {
hir::TyKind::TraitObject(bounds, ref lifetime) => {
for bound in bounds {
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
}
@ -2583,9 +2582,9 @@ fn check_lifetime_params(
// It is a soft error to shadow a lifetime within a parent scope.
self.check_lifetime_param_for_shadowing(old_scope, &lifetime_i);
for bound in &lifetime_i.bounds {
for bound in lifetime_i.bounds {
match bound {
hir::GenericBound::Outlives(lt) => match lt.name {
hir::GenericBound::Outlives(ref lt) => match lt.name {
hir::LifetimeName::Underscore => self.tcx.sess.delay_span_bug(
lt.span,
"use of `'_` in illegal place, but not caught by lowering",
@ -2774,7 +2773,7 @@ fn insert_late_bound_lifetimes(
debug!("insert_late_bound_lifetimes(decl={:?}, generics={:?})", decl, generics);
let mut constrained_by_input = ConstrainedCollector::default();
for arg_ty in &decl.inputs {
for arg_ty in decl.inputs {
constrained_by_input.visit_ty(arg_ty);
}