Introduce LifetimeCtxt.
This commit is contained in:
parent
52cc779524
commit
5953c57f27
6 changed files with 23 additions and 11 deletions
|
@ -89,6 +89,16 @@ impl<'a> FnKind<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
pub enum LifetimeCtxt {
|
||||||
|
/// Appears in a reference type.
|
||||||
|
Rptr,
|
||||||
|
/// Appears as a bound on a type or another lifetime.
|
||||||
|
Bound,
|
||||||
|
/// Appears as a generic argument.
|
||||||
|
GenericArg,
|
||||||
|
}
|
||||||
|
|
||||||
/// Each method of the `Visitor` trait is a hook to be potentially
|
/// Each method of the `Visitor` trait is a hook to be potentially
|
||||||
/// overridden. Each method's default implementation recursively visits
|
/// overridden. Each method's default implementation recursively visits
|
||||||
/// the substructure of the input via the corresponding `walk` method;
|
/// the substructure of the input via the corresponding `walk` method;
|
||||||
|
@ -184,7 +194,7 @@ pub trait Visitor<'ast>: Sized {
|
||||||
fn visit_label(&mut self, label: &'ast Label) {
|
fn visit_label(&mut self, label: &'ast Label) {
|
||||||
walk_label(self, label)
|
walk_label(self, label)
|
||||||
}
|
}
|
||||||
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) {
|
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, _: LifetimeCtxt) {
|
||||||
walk_lifetime(self, lifetime)
|
walk_lifetime(self, lifetime)
|
||||||
}
|
}
|
||||||
fn visit_mac_call(&mut self, mac: &'ast MacCall) {
|
fn visit_mac_call(&mut self, mac: &'ast MacCall) {
|
||||||
|
@ -414,7 +424,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
|
||||||
TyKind::Slice(ref ty) | TyKind::Paren(ref ty) => visitor.visit_ty(ty),
|
TyKind::Slice(ref ty) | TyKind::Paren(ref ty) => visitor.visit_ty(ty),
|
||||||
TyKind::Ptr(ref mutable_type) => visitor.visit_ty(&mutable_type.ty),
|
TyKind::Ptr(ref mutable_type) => visitor.visit_ty(&mutable_type.ty),
|
||||||
TyKind::Rptr(ref opt_lifetime, ref mutable_type) => {
|
TyKind::Rptr(ref opt_lifetime, ref mutable_type) => {
|
||||||
walk_list!(visitor, visit_lifetime, opt_lifetime);
|
walk_list!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Rptr);
|
||||||
visitor.visit_ty(&mutable_type.ty)
|
visitor.visit_ty(&mutable_type.ty)
|
||||||
}
|
}
|
||||||
TyKind::Tup(ref tuple_element_types) => {
|
TyKind::Tup(ref tuple_element_types) => {
|
||||||
|
@ -507,7 +517,7 @@ where
|
||||||
V: Visitor<'a>,
|
V: Visitor<'a>,
|
||||||
{
|
{
|
||||||
match generic_arg {
|
match generic_arg {
|
||||||
GenericArg::Lifetime(lt) => visitor.visit_lifetime(lt),
|
GenericArg::Lifetime(lt) => visitor.visit_lifetime(lt, LifetimeCtxt::GenericArg),
|
||||||
GenericArg::Type(ty) => visitor.visit_ty(ty),
|
GenericArg::Type(ty) => visitor.visit_ty(ty),
|
||||||
GenericArg::Const(ct) => visitor.visit_anon_const(ct),
|
GenericArg::Const(ct) => visitor.visit_anon_const(ct),
|
||||||
}
|
}
|
||||||
|
@ -599,7 +609,9 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI
|
||||||
pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) {
|
pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) {
|
||||||
match *bound {
|
match *bound {
|
||||||
GenericBound::Trait(ref typ, ref modifier) => visitor.visit_poly_trait_ref(typ, modifier),
|
GenericBound::Trait(ref typ, ref modifier) => visitor.visit_poly_trait_ref(typ, modifier),
|
||||||
GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime),
|
GenericBound::Outlives(ref lifetime) => {
|
||||||
|
visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,7 +651,7 @@ pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a
|
||||||
WherePredicate::RegionPredicate(WhereRegionPredicate {
|
WherePredicate::RegionPredicate(WhereRegionPredicate {
|
||||||
ref lifetime, ref bounds, ..
|
ref lifetime, ref bounds, ..
|
||||||
}) => {
|
}) => {
|
||||||
visitor.visit_lifetime(lifetime);
|
visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound);
|
||||||
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
||||||
}
|
}
|
||||||
WherePredicate::EqPredicate(WhereEqPredicate { ref lhs_ty, ref rhs_ty, .. }) => {
|
WherePredicate::EqPredicate(WhereEqPredicate { ref lhs_ty, ref rhs_ty, .. }) => {
|
||||||
|
|
|
@ -1070,7 +1070,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
visit::walk_label(self, label);
|
visit::walk_label(self, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_lifetime(&mut self, lifetime: &'a Lifetime) {
|
fn visit_lifetime(&mut self, lifetime: &'a Lifetime, _: visit::LifetimeCtxt) {
|
||||||
self.check_lifetime(lifetime.ident);
|
self.check_lifetime(lifetime.ident);
|
||||||
visit::walk_lifetime(self, lifetime);
|
visit::walk_lifetime(self, lifetime);
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ impl<'ast> Visitor<'ast> for NodeCounter {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
walk_variant(self, v)
|
walk_variant(self, v)
|
||||||
}
|
}
|
||||||
fn visit_lifetime(&mut self, lifetime: &Lifetime) {
|
fn visit_lifetime(&mut self, lifetime: &Lifetime, _: visit::LifetimeCtxt) {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
walk_lifetime(self, lifetime)
|
walk_lifetime(self, lifetime)
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,7 +272,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_lifetime(&mut self, lt: &'a ast::Lifetime) {
|
fn visit_lifetime(&mut self, lt: &'a ast::Lifetime, _: ast_visit::LifetimeCtxt) {
|
||||||
run_early_pass!(self, check_lifetime, lt);
|
run_early_pass!(self, check_lifetime, lt);
|
||||||
self.check_id(lt.id);
|
self.check_id(lt.id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,7 +318,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
|
||||||
ast_visit::walk_variant(self, v)
|
ast_visit::walk_variant(self, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_lifetime(&mut self, lifetime: &'v ast::Lifetime) {
|
fn visit_lifetime(&mut self, lifetime: &'v ast::Lifetime, _: ast_visit::LifetimeCtxt) {
|
||||||
self.record("Lifetime", Id::None, lifetime);
|
self.record("Lifetime", Id::None, lifetime);
|
||||||
ast_visit::walk_lifetime(self, lifetime)
|
ast_visit::walk_lifetime(self, lifetime)
|
||||||
}
|
}
|
||||||
|
|
|
@ -793,7 +793,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
});
|
});
|
||||||
self.diagnostic_metadata.current_function = previous_value;
|
self.diagnostic_metadata.current_function = previous_value;
|
||||||
}
|
}
|
||||||
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) {
|
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, _: visit::LifetimeCtxt) {
|
||||||
self.resolve_lifetime(lifetime)
|
self.resolve_lifetime(lifetime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -859,7 +859,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
|
|
||||||
self.visit_ty(ty);
|
self.visit_ty(ty);
|
||||||
}
|
}
|
||||||
GenericArg::Lifetime(lt) => self.visit_lifetime(lt),
|
GenericArg::Lifetime(lt) => self.visit_lifetime(lt, visit::LifetimeCtxt::GenericArg),
|
||||||
GenericArg::Const(ct) => self.visit_anon_const(ct),
|
GenericArg::Const(ct) => self.visit_anon_const(ct),
|
||||||
}
|
}
|
||||||
self.diagnostic_metadata.currently_processing_generics = prev;
|
self.diagnostic_metadata.currently_processing_generics = prev;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue