2014-09-12 10:10:30 +00:00
|
|
|
//! AST walker. Each overridden visit method has full control over what
|
|
|
|
//! happens with its node, it can do its own traversal of the node's children,
|
|
|
|
//! call `visit::walk_*` to apply the default traversal algorithm, or prevent
|
|
|
|
//! deeper traversal by doing nothing.
|
2014-06-09 20:12:30 +00:00
|
|
|
//!
|
|
|
|
//! Note: it is an important invariant that the default visitor walks the body
|
|
|
|
//! of a function in "execution order" (more concretely, reverse post-order
|
|
|
|
//! with respect to the CFG implied by the AST), meaning that if AST node A may
|
2019-02-08 13:53:55 +00:00
|
|
|
//! execute before AST node B, then A is visited first. The borrow checker in
|
2014-06-09 20:12:30 +00:00
|
|
|
//! particular relies on this property.
|
|
|
|
//!
|
2014-07-09 21:48:12 +00:00
|
|
|
//! Note: walking an AST before macro expansion is probably a bad idea. For
|
|
|
|
//! instance, a walker looking for item names in a module will miss all of
|
|
|
|
//! those that are created by the expansion of a macro.
|
|
|
|
|
2023-11-10 02:11:24 +00:00
|
|
|
pub use rustc_ast_ir::visit::VisitorResult;
|
2024-06-26 12:25:57 +00:00
|
|
|
pub use rustc_ast_ir::{try_visit, visit_opt, walk_list, walk_visitable_list};
|
2024-12-12 23:29:23 +00:00
|
|
|
use rustc_span::{Ident, Span};
|
2012-12-23 22:41:37 +00:00
|
|
|
|
2024-02-24 20:22:42 +00:00
|
|
|
use crate::ast::*;
|
|
|
|
use crate::ptr::P;
|
|
|
|
|
2021-08-19 20:34:01 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
2020-01-29 23:18:54 +00:00
|
|
|
pub enum AssocCtxt {
|
|
|
|
Trait,
|
|
|
|
Impl,
|
|
|
|
}
|
|
|
|
|
2021-08-19 20:34:01 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
2020-01-29 23:18:54 +00:00
|
|
|
pub enum FnCtxt {
|
|
|
|
Free,
|
|
|
|
Foreign,
|
|
|
|
Assoc(AssocCtxt),
|
|
|
|
}
|
|
|
|
|
2022-04-20 11:06:32 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2022-04-21 02:09:32 +00:00
|
|
|
pub enum BoundKind {
|
|
|
|
/// Trait bounds in generics bounds and type/trait alias.
|
|
|
|
/// E.g., `<T: Bound>`, `type A: Bound`, or `where T: Bound`.
|
|
|
|
Bound,
|
|
|
|
|
|
|
|
/// Trait bounds in `impl` type.
|
|
|
|
/// E.g., `type Foo = impl Bound1 + Bound2 + Bound3`.
|
|
|
|
Impl,
|
|
|
|
|
|
|
|
/// Trait bounds in trait object type.
|
|
|
|
/// E.g., `dyn Bound1 + Bound2 + Bound3`.
|
2022-04-20 11:06:32 +00:00
|
|
|
TraitObject,
|
2022-04-21 02:09:32 +00:00
|
|
|
|
|
|
|
/// Super traits of a trait.
|
|
|
|
/// E.g., `trait A: B`
|
2022-04-20 11:06:32 +00:00
|
|
|
SuperTraits,
|
|
|
|
}
|
2024-06-05 20:18:52 +00:00
|
|
|
impl BoundKind {
|
|
|
|
pub fn descr(self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
BoundKind::Bound => "bounds",
|
|
|
|
BoundKind::Impl => "`impl Trait`",
|
|
|
|
BoundKind::TraitObject => "`dyn` trait object bounds",
|
|
|
|
BoundKind::SuperTraits => "supertrait bounds",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-20 11:06:32 +00:00
|
|
|
|
2021-08-19 20:34:01 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2014-01-09 13:05:33 +00:00
|
|
|
pub enum FnKind<'a> {
|
2020-01-29 23:18:54 +00:00
|
|
|
/// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.
|
2025-01-28 00:30:02 +00:00
|
|
|
Fn(FnCtxt, &'a Ident, &'a Visibility, &'a Fn),
|
2013-03-14 02:25:28 +00:00
|
|
|
|
2019-09-06 02:56:45 +00:00
|
|
|
/// E.g., `|x, y| body`.
|
2024-08-24 01:44:52 +00:00
|
|
|
Closure(&'a ClosureBinder, &'a Option<CoroutineKind>, &'a FnDecl, &'a Expr),
|
2011-12-30 04:07:55 +00:00
|
|
|
}
|
|
|
|
|
2019-04-18 18:15:43 +00:00
|
|
|
impl<'a> FnKind<'a> {
|
|
|
|
pub fn header(&self) -> Option<&'a FnHeader> {
|
|
|
|
match *self {
|
2025-01-28 00:30:02 +00:00
|
|
|
FnKind::Fn(_, _, _, Fn { sig, .. }) => Some(&sig.header),
|
2024-08-24 01:44:52 +00:00
|
|
|
FnKind::Closure(..) => None,
|
2020-01-29 23:18:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-14 00:52:33 +00:00
|
|
|
pub fn ident(&self) -> Option<&Ident> {
|
|
|
|
match self {
|
|
|
|
FnKind::Fn(_, ident, ..) => Some(ident),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 23:18:54 +00:00
|
|
|
pub fn decl(&self) -> &'a FnDecl {
|
|
|
|
match self {
|
2025-01-28 00:30:02 +00:00
|
|
|
FnKind::Fn(_, _, _, Fn { sig, .. }) => &sig.decl,
|
2024-08-24 01:44:52 +00:00
|
|
|
FnKind::Closure(_, _, decl, _) => decl,
|
2020-01-29 23:18:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn ctxt(&self) -> Option<FnCtxt> {
|
|
|
|
match self {
|
|
|
|
FnKind::Fn(ctxt, ..) => Some(*ctxt),
|
|
|
|
FnKind::Closure(..) => None,
|
2019-04-18 18:15:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-10 17:56:46 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
|
|
pub enum LifetimeCtxt {
|
|
|
|
/// Appears in a reference type.
|
2022-12-28 17:06:11 +00:00
|
|
|
Ref,
|
2022-05-10 17:56:46 +00:00
|
|
|
/// Appears as a bound on a type or another lifetime.
|
|
|
|
Bound,
|
|
|
|
/// Appears as a generic argument.
|
|
|
|
GenericArg,
|
|
|
|
}
|
|
|
|
|
2024-11-12 16:20:17 +00:00
|
|
|
pub trait WalkItemKind {
|
2024-11-08 21:51:28 +00:00
|
|
|
type Ctxt;
|
2024-04-24 17:31:51 +00:00
|
|
|
fn walk<'a, V: Visitor<'a>>(
|
|
|
|
&'a self,
|
2024-11-12 16:20:17 +00:00
|
|
|
span: Span,
|
|
|
|
id: NodeId,
|
|
|
|
ident: &'a Ident,
|
|
|
|
visibility: &'a Visibility,
|
2024-11-08 21:51:28 +00:00
|
|
|
ctxt: Self::Ctxt,
|
2024-04-24 17:31:51 +00:00
|
|
|
visitor: &mut V,
|
|
|
|
) -> V::Result;
|
|
|
|
}
|
|
|
|
|
2019-09-06 02:56:45 +00:00
|
|
|
/// Each method of the `Visitor` trait is a hook to be potentially
|
2019-02-08 13:53:55 +00:00
|
|
|
/// overridden. Each method's default implementation recursively visits
|
2014-05-12 16:58:23 +00:00
|
|
|
/// the substructure of the input via the corresponding `walk` method;
|
2021-02-14 18:14:12 +00:00
|
|
|
/// e.g., the `visit_item` method by default calls `visit::walk_item`.
|
2014-05-12 16:58:23 +00:00
|
|
|
///
|
|
|
|
/// If you want to ensure that your code handles every variant
|
2019-02-08 13:53:55 +00:00
|
|
|
/// explicitly, you need to override each method. (And you also need
|
2014-05-12 16:58:23 +00:00
|
|
|
/// to monitor future changes to `Visitor` in case a new method with a
|
|
|
|
/// new default implementation gets introduced.)
|
2016-12-06 10:26:52 +00:00
|
|
|
pub trait Visitor<'ast>: Sized {
|
2024-02-18 08:12:44 +00:00
|
|
|
/// The result type of the `visit_*` methods. Can be either `()`,
|
|
|
|
/// or `ControlFlow<T>`.
|
|
|
|
type Result: VisitorResult = ();
|
|
|
|
|
2024-10-24 13:41:44 +00:00
|
|
|
fn visit_ident(&mut self, _ident: &'ast Ident) -> Self::Result {
|
2024-02-18 08:12:44 +00:00
|
|
|
Self::Result::output()
|
|
|
|
}
|
|
|
|
fn visit_foreign_item(&mut self, i: &'ast ForeignItem) -> Self::Result {
|
2024-04-24 17:31:51 +00:00
|
|
|
walk_item(self, i)
|
2016-12-06 10:26:52 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_item(&mut self, i: &'ast Item) -> Self::Result {
|
2016-12-06 10:26:52 +00:00
|
|
|
walk_item(self, i)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_local(&mut self, l: &'ast Local) -> Self::Result {
|
2016-12-06 10:26:52 +00:00
|
|
|
walk_local(self, l)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_block(&mut self, b: &'ast Block) -> Self::Result {
|
2016-12-06 10:26:52 +00:00
|
|
|
walk_block(self, b)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_stmt(&mut self, s: &'ast Stmt) -> Self::Result {
|
2016-12-06 10:26:52 +00:00
|
|
|
walk_stmt(self, s)
|
2019-08-27 11:24:32 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_param(&mut self, param: &'ast Param) -> Self::Result {
|
2019-08-27 11:24:32 +00:00
|
|
|
walk_param(self, param)
|
2016-12-06 10:26:52 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_arm(&mut self, a: &'ast Arm) -> Self::Result {
|
2016-12-06 10:26:52 +00:00
|
|
|
walk_arm(self, a)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_pat(&mut self, p: &'ast Pat) -> Self::Result {
|
2016-12-06 10:26:52 +00:00
|
|
|
walk_pat(self, p)
|
2018-05-17 18:28:50 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_anon_const(&mut self, c: &'ast AnonConst) -> Self::Result {
|
2018-05-17 18:28:50 +00:00
|
|
|
walk_anon_const(self, c)
|
2016-12-06 10:26:52 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_expr(&mut self, ex: &'ast Expr) -> Self::Result {
|
2016-12-06 10:26:52 +00:00
|
|
|
walk_expr(self, ex)
|
|
|
|
}
|
2022-10-23 09:22:19 +00:00
|
|
|
/// This method is a hack to workaround unstable of `stmt_expr_attributes`.
|
|
|
|
/// It can be removed once that feature is stabilized.
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_method_receiver_expr(&mut self, ex: &'ast Expr) -> Self::Result {
|
2022-10-23 09:22:19 +00:00
|
|
|
self.visit_expr(ex)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_ty(&mut self, t: &'ast Ty) -> Self::Result {
|
2016-12-06 10:26:52 +00:00
|
|
|
walk_ty(self, t)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_generic_param(&mut self, param: &'ast GenericParam) -> Self::Result {
|
2018-05-25 23:27:54 +00:00
|
|
|
walk_generic_param(self, param)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_generics(&mut self, g: &'ast Generics) -> Self::Result {
|
2016-12-06 10:26:52 +00:00
|
|
|
walk_generics(self, g)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_closure_binder(&mut self, b: &'ast ClosureBinder) -> Self::Result {
|
2022-06-02 16:15:05 +00:00
|
|
|
walk_closure_binder(self, b)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_where_predicate(&mut self, p: &'ast WherePredicate) -> Self::Result {
|
2017-01-25 20:01:11 +00:00
|
|
|
walk_where_predicate(self, p)
|
|
|
|
}
|
2024-11-25 08:38:35 +00:00
|
|
|
fn visit_where_predicate_kind(&mut self, k: &'ast WherePredicateKind) -> Self::Result {
|
|
|
|
walk_where_predicate_kind(self, k)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_fn(&mut self, fk: FnKind<'ast>, _: Span, _: NodeId) -> Self::Result {
|
2022-09-12 03:13:22 +00:00
|
|
|
walk_fn(self, fk)
|
2019-12-02 01:03:31 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_assoc_item(&mut self, i: &'ast AssocItem, ctxt: AssocCtxt) -> Self::Result {
|
2020-01-29 23:18:54 +00:00
|
|
|
walk_assoc_item(self, i, ctxt)
|
2019-12-02 01:03:31 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_trait_ref(&mut self, t: &'ast TraitRef) -> Self::Result {
|
2016-12-06 10:26:52 +00:00
|
|
|
walk_trait_ref(self, t)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_param_bound(&mut self, bounds: &'ast GenericBound, _ctxt: BoundKind) -> Self::Result {
|
2018-05-28 14:23:16 +00:00
|
|
|
walk_param_bound(self, bounds)
|
2014-11-15 21:55:27 +00:00
|
|
|
}
|
2024-11-14 20:07:46 +00:00
|
|
|
fn visit_precise_capturing_arg(&mut self, arg: &'ast PreciseCapturingArg) -> Self::Result {
|
|
|
|
walk_precise_capturing_arg(self, arg)
|
2024-04-04 01:47:02 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef) -> Self::Result {
|
2022-08-11 01:05:26 +00:00
|
|
|
walk_poly_trait_ref(self, t)
|
2014-11-07 11:53:45 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_variant_data(&mut self, s: &'ast VariantData) -> Self::Result {
|
2014-09-12 10:10:30 +00:00
|
|
|
walk_struct_def(self, s)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_field_def(&mut self, s: &'ast FieldDef) -> Self::Result {
|
2021-03-15 21:36:07 +00:00
|
|
|
walk_field_def(self, s)
|
2016-12-06 10:26:52 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_enum_def(&mut self, enum_definition: &'ast EnumDef) -> Self::Result {
|
2022-08-10 02:02:48 +00:00
|
|
|
walk_enum_def(self, enum_definition)
|
2015-10-02 13:14:20 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_variant(&mut self, v: &'ast Variant) -> Self::Result {
|
2019-08-24 16:54:40 +00:00
|
|
|
walk_variant(self, v)
|
2015-06-23 02:55:57 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_variant_discr(&mut self, discr: &'ast AnonConst) -> Self::Result {
|
|
|
|
self.visit_anon_const(discr)
|
2023-05-05 20:31:00 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_label(&mut self, label: &'ast Label) -> Self::Result {
|
2018-01-15 22:44:32 +00:00
|
|
|
walk_label(self, label)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, _: LifetimeCtxt) -> Self::Result {
|
2015-09-28 11:26:26 +00:00
|
|
|
walk_lifetime(self, lifetime)
|
2013-10-28 21:37:10 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_mac_call(&mut self, mac: &'ast MacCall) -> Self::Result {
|
2020-11-03 17:26:17 +00:00
|
|
|
walk_mac(self, mac)
|
2013-10-28 21:37:10 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_mac_def(&mut self, _mac: &'ast MacroDef, _id: NodeId) -> Self::Result {
|
|
|
|
Self::Result::output()
|
2017-05-12 06:05:52 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_path(&mut self, path: &'ast Path, _id: NodeId) -> Self::Result {
|
2014-09-12 10:10:30 +00:00
|
|
|
walk_path(self, path)
|
2013-12-08 19:25:35 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_use_tree(
|
|
|
|
&mut self,
|
|
|
|
use_tree: &'ast UseTree,
|
|
|
|
id: NodeId,
|
|
|
|
_nested: bool,
|
|
|
|
) -> Self::Result {
|
2017-09-26 21:04:00 +00:00
|
|
|
walk_use_tree(self, use_tree, id)
|
2015-09-12 13:10:12 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) -> Self::Result {
|
2022-09-12 00:43:34 +00:00
|
|
|
walk_path_segment(self, path_segment)
|
2014-11-15 21:55:27 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_generic_args(&mut self, generic_args: &'ast GenericArgs) -> Self::Result {
|
2022-09-12 00:43:34 +00:00
|
|
|
walk_generic_args(self, generic_args)
|
2018-02-13 11:32:37 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArg) -> Self::Result {
|
2020-10-09 22:20:06 +00:00
|
|
|
walk_generic_arg(self, generic_arg)
|
2014-11-15 21:55:27 +00:00
|
|
|
}
|
2024-05-27 21:53:46 +00:00
|
|
|
fn visit_assoc_item_constraint(
|
|
|
|
&mut self,
|
|
|
|
constraint: &'ast AssocItemConstraint,
|
|
|
|
) -> Self::Result {
|
|
|
|
walk_assoc_item_constraint(self, constraint)
|
2014-12-28 15:07:21 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_attribute(&mut self, attr: &'ast Attribute) -> Self::Result {
|
2017-10-23 08:22:28 +00:00
|
|
|
walk_attribute(self, attr)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_vis(&mut self, vis: &'ast Visibility) -> Self::Result {
|
2016-03-31 19:10:38 +00:00
|
|
|
walk_vis(self, vis)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_fn_ret_ty(&mut self, ret_ty: &'ast FnRetTy) -> Self::Result {
|
2016-08-01 12:15:54 +00:00
|
|
|
walk_fn_ret_ty(self, ret_ty)
|
|
|
|
}
|
2024-11-12 16:44:46 +00:00
|
|
|
fn visit_fn_header(&mut self, header: &'ast FnHeader) -> Self::Result {
|
|
|
|
walk_fn_header(self, header)
|
2019-02-23 18:39:27 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_expr_field(&mut self, f: &'ast ExprField) -> Self::Result {
|
2021-03-15 21:36:07 +00:00
|
|
|
walk_expr_field(self, f)
|
2019-08-24 16:54:40 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_pat_field(&mut self, fp: &'ast PatField) -> Self::Result {
|
2021-03-15 21:36:07 +00:00
|
|
|
walk_pat_field(self, fp)
|
2019-08-24 16:54:40 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_crate(&mut self, krate: &'ast Crate) -> Self::Result {
|
2021-10-17 16:32:34 +00:00
|
|
|
walk_crate(self, krate)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_inline_asm(&mut self, asm: &'ast InlineAsm) -> Self::Result {
|
2022-03-01 00:50:56 +00:00
|
|
|
walk_inline_asm(self, asm)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_format_args(&mut self, fmt: &'ast FormatArgs) -> Self::Result {
|
2023-01-11 20:41:13 +00:00
|
|
|
walk_format_args(self, fmt)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_inline_asm_sym(&mut self, sym: &'ast InlineAsmSym) -> Self::Result {
|
2022-03-01 00:50:56 +00:00
|
|
|
walk_inline_asm_sym(self, sym)
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
fn visit_capture_by(&mut self, _capture_by: &'ast CaptureBy) -> Self::Result {
|
|
|
|
Self::Result::output()
|
2023-11-04 19:39:15 +00:00
|
|
|
}
|
2024-11-12 16:44:46 +00:00
|
|
|
fn visit_coroutine_kind(&mut self, _coroutine_kind: &'ast CoroutineKind) -> Self::Result {
|
|
|
|
Self::Result::output()
|
|
|
|
}
|
2024-11-18 18:40:34 +00:00
|
|
|
fn visit_fn_decl(&mut self, fn_decl: &'ast FnDecl) -> Self::Result {
|
|
|
|
walk_fn_decl(self, fn_decl)
|
|
|
|
}
|
2024-11-18 18:43:35 +00:00
|
|
|
fn visit_qself(&mut self, qs: &'ast Option<P<QSelf>>) -> Self::Result {
|
|
|
|
walk_qself(self, qs)
|
|
|
|
}
|
2013-08-08 12:23:25 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Crate { attrs, items, spans: _, id: _, is_placeholder: _ } = krate;
|
|
|
|
walk_list!(visitor, visit_attribute, attrs);
|
|
|
|
walk_list!(visitor, visit_item, items);
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2015-09-28 11:26:26 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_local<'a, V: Visitor<'a>>(visitor: &mut V, local: &'a Local) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Local { id: _, pat, ty, kind, span: _, colon_sp: _, attrs, tokens: _ } = local;
|
|
|
|
walk_list!(visitor, visit_attribute, attrs);
|
|
|
|
try_visit!(visitor.visit_pat(pat));
|
|
|
|
visit_opt!(visitor, visit_ty, ty);
|
|
|
|
if let Some((init, els)) = kind.init_else_opt() {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(init));
|
|
|
|
visit_opt!(visitor, visit_block, els);
|
2021-06-22 18:00:58 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2014-12-13 10:34:34 +00:00
|
|
|
}
|
|
|
|
|
2024-06-26 12:25:57 +00:00
|
|
|
pub fn walk_label<'a, V: Visitor<'a>>(visitor: &mut V, Label { ident }: &'a Label) -> V::Result {
|
2024-10-24 13:41:44 +00:00
|
|
|
visitor.visit_ident(ident)
|
2018-01-15 22:44:32 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_lifetime<'a, V: Visitor<'a>>(visitor: &mut V, lifetime: &'a Lifetime) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Lifetime { id: _, ident } = lifetime;
|
2024-10-24 13:41:44 +00:00
|
|
|
visitor.visit_ident(ident)
|
2015-09-28 11:26:26 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_poly_trait_ref<'a, V>(visitor: &mut V, trait_ref: &'a PolyTraitRef) -> V::Result
|
2022-08-11 01:05:26 +00:00
|
|
|
where
|
2016-12-06 10:26:52 +00:00
|
|
|
V: Visitor<'a>,
|
2014-11-07 11:53:45 +00:00
|
|
|
{
|
2024-10-13 13:31:22 +00:00
|
|
|
let PolyTraitRef { bound_generic_params, modifiers: _, trait_ref, span: _ } = trait_ref;
|
2024-06-26 12:25:57 +00:00
|
|
|
walk_list!(visitor, visit_generic_param, bound_generic_params);
|
|
|
|
visitor.visit_trait_ref(trait_ref)
|
2014-11-07 11:53:45 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitRef) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let TraitRef { path, ref_id } = trait_ref;
|
|
|
|
visitor.visit_path(path, *ref_id)
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
|
|
|
|
2024-04-24 17:31:51 +00:00
|
|
|
impl WalkItemKind for ItemKind {
|
2024-11-08 21:51:28 +00:00
|
|
|
type Ctxt = ();
|
2024-04-24 17:31:51 +00:00
|
|
|
fn walk<'a, V: Visitor<'a>>(
|
|
|
|
&'a self,
|
2024-11-12 16:20:17 +00:00
|
|
|
span: Span,
|
|
|
|
id: NodeId,
|
|
|
|
ident: &'a Ident,
|
|
|
|
vis: &'a Visibility,
|
2024-11-08 21:51:28 +00:00
|
|
|
_ctxt: Self::Ctxt,
|
2024-04-24 17:31:51 +00:00
|
|
|
visitor: &mut V,
|
|
|
|
) -> V::Result {
|
|
|
|
match self {
|
2024-06-26 12:25:57 +00:00
|
|
|
ItemKind::ExternCrate(_rename) => {}
|
2024-11-12 16:20:17 +00:00
|
|
|
ItemKind::Use(use_tree) => try_visit!(visitor.visit_use_tree(use_tree, id, false)),
|
2024-05-07 12:43:23 +00:00
|
|
|
ItemKind::Static(box StaticItem { ty, safety: _, mutability: _, expr }) => {
|
2024-04-24 17:31:51 +00:00
|
|
|
try_visit!(visitor.visit_ty(ty));
|
|
|
|
visit_opt!(visitor, visit_expr, expr);
|
2021-02-16 21:56:07 +00:00
|
|
|
}
|
2024-04-24 17:31:51 +00:00
|
|
|
ItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => {
|
|
|
|
try_visit!(visitor.visit_generics(generics));
|
|
|
|
try_visit!(visitor.visit_ty(ty));
|
|
|
|
visit_opt!(visitor, visit_expr, expr);
|
|
|
|
}
|
2025-01-28 00:30:02 +00:00
|
|
|
ItemKind::Fn(func) => {
|
|
|
|
let kind = FnKind::Fn(FnCtxt::Free, ident, vis, &*func);
|
2024-11-12 16:20:17 +00:00
|
|
|
try_visit!(visitor.visit_fn(kind, span, id));
|
2024-04-24 17:31:51 +00:00
|
|
|
}
|
|
|
|
ItemKind::Mod(_unsafety, mod_kind) => match mod_kind {
|
2024-12-05 21:19:08 +00:00
|
|
|
ModKind::Loaded(items, _inline, _inner_span, _) => {
|
2024-04-24 17:31:51 +00:00
|
|
|
walk_list!(visitor, visit_item, items);
|
|
|
|
}
|
|
|
|
ModKind::Unloaded => {}
|
|
|
|
},
|
2024-10-30 12:12:08 +00:00
|
|
|
ItemKind::ForeignMod(ForeignMod { extern_span: _, safety: _, abi: _, items }) => {
|
2024-06-26 12:25:57 +00:00
|
|
|
walk_list!(visitor, visit_foreign_item, items);
|
2024-04-24 17:31:51 +00:00
|
|
|
}
|
|
|
|
ItemKind::GlobalAsm(asm) => try_visit!(visitor.visit_inline_asm(asm)),
|
2024-06-26 12:25:57 +00:00
|
|
|
ItemKind::TyAlias(box TyAlias {
|
|
|
|
generics,
|
|
|
|
bounds,
|
|
|
|
ty,
|
|
|
|
defaultness: _,
|
|
|
|
where_clauses: _,
|
|
|
|
}) => {
|
2024-04-24 17:31:51 +00:00
|
|
|
try_visit!(visitor.visit_generics(generics));
|
|
|
|
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
|
|
|
visit_opt!(visitor, visit_ty, ty);
|
|
|
|
}
|
|
|
|
ItemKind::Enum(enum_definition, generics) => {
|
|
|
|
try_visit!(visitor.visit_generics(generics));
|
|
|
|
try_visit!(visitor.visit_enum_def(enum_definition));
|
|
|
|
}
|
|
|
|
ItemKind::Impl(box Impl {
|
|
|
|
defaultness: _,
|
2024-05-17 17:17:48 +00:00
|
|
|
safety: _,
|
2024-04-24 17:31:51 +00:00
|
|
|
generics,
|
|
|
|
constness: _,
|
|
|
|
polarity: _,
|
|
|
|
of_trait,
|
|
|
|
self_ty,
|
|
|
|
items,
|
|
|
|
}) => {
|
|
|
|
try_visit!(visitor.visit_generics(generics));
|
|
|
|
visit_opt!(visitor, visit_trait_ref, of_trait);
|
|
|
|
try_visit!(visitor.visit_ty(self_ty));
|
|
|
|
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Impl);
|
|
|
|
}
|
|
|
|
ItemKind::Struct(struct_definition, generics)
|
|
|
|
| ItemKind::Union(struct_definition, generics) => {
|
|
|
|
try_visit!(visitor.visit_generics(generics));
|
|
|
|
try_visit!(visitor.visit_variant_data(struct_definition));
|
|
|
|
}
|
2024-05-17 17:17:48 +00:00
|
|
|
ItemKind::Trait(box Trait { safety: _, is_auto: _, generics, bounds, items }) => {
|
2024-04-24 17:31:51 +00:00
|
|
|
try_visit!(visitor.visit_generics(generics));
|
|
|
|
walk_list!(visitor, visit_param_bound, bounds, BoundKind::SuperTraits);
|
|
|
|
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Trait);
|
|
|
|
}
|
|
|
|
ItemKind::TraitAlias(generics, bounds) => {
|
|
|
|
try_visit!(visitor.visit_generics(generics));
|
|
|
|
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
|
|
|
}
|
|
|
|
ItemKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
|
2024-11-12 16:20:17 +00:00
|
|
|
ItemKind::MacroDef(ts) => try_visit!(visitor.visit_mac_def(ts, id)),
|
2024-03-15 11:21:03 +00:00
|
|
|
ItemKind::Delegation(box Delegation {
|
|
|
|
id,
|
|
|
|
qself,
|
|
|
|
path,
|
|
|
|
rename,
|
|
|
|
body,
|
|
|
|
from_glob: _,
|
|
|
|
}) => {
|
2024-11-18 18:43:35 +00:00
|
|
|
try_visit!(visitor.visit_qself(qself));
|
2024-04-24 17:31:51 +00:00
|
|
|
try_visit!(visitor.visit_path(path, *id));
|
2024-10-24 13:41:44 +00:00
|
|
|
visit_opt!(visitor, visit_ident, rename);
|
2024-04-24 17:31:51 +00:00
|
|
|
visit_opt!(visitor, visit_block, body);
|
2023-11-26 12:57:31 +00:00
|
|
|
}
|
2024-03-15 11:21:03 +00:00
|
|
|
ItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
|
2024-11-18 18:43:35 +00:00
|
|
|
try_visit!(visitor.visit_qself(qself));
|
2024-11-12 16:20:17 +00:00
|
|
|
try_visit!(visitor.visit_path(prefix, id));
|
2024-03-15 11:21:03 +00:00
|
|
|
if let Some(suffixes) = suffixes {
|
|
|
|
for (ident, rename) in suffixes {
|
2024-10-24 13:41:44 +00:00
|
|
|
visitor.visit_ident(ident);
|
2024-03-15 11:21:03 +00:00
|
|
|
if let Some(rename) = rename {
|
2024-10-24 13:41:44 +00:00
|
|
|
visitor.visit_ident(rename);
|
2024-03-15 11:21:03 +00:00
|
|
|
}
|
2024-03-15 11:21:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
visit_opt!(visitor, visit_block, body);
|
|
|
|
}
|
2023-11-26 12:57:31 +00:00
|
|
|
}
|
2024-04-24 17:31:51 +00:00
|
|
|
V::Result::output()
|
2014-06-08 06:02:48 +00:00
|
|
|
}
|
2024-04-24 17:31:51 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_enum_def<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V,
|
2024-06-26 12:25:57 +00:00
|
|
|
EnumDef { variants }: &'a EnumDef,
|
2024-02-18 08:12:44 +00:00
|
|
|
) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
walk_list!(visitor, visit_variant, variants);
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2013-11-12 04:17:47 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_variant<'a, V: Visitor<'a>>(visitor: &mut V, variant: &'a Variant) -> V::Result
|
2016-12-06 10:26:52 +00:00
|
|
|
where
|
|
|
|
V: Visitor<'a>,
|
2016-06-12 07:51:31 +00:00
|
|
|
{
|
2024-06-26 12:25:57 +00:00
|
|
|
let Variant { attrs, id: _, span: _, vis, ident, data, disr_expr, is_placeholder: _ } = variant;
|
|
|
|
walk_list!(visitor, visit_attribute, attrs);
|
|
|
|
try_visit!(visitor.visit_vis(vis));
|
2024-10-24 13:41:44 +00:00
|
|
|
try_visit!(visitor.visit_ident(ident));
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_variant_data(data));
|
|
|
|
visit_opt!(visitor, visit_variant_discr, disr_expr);
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2015-01-02 11:55:31 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_expr_field<'a, V: Visitor<'a>>(visitor: &mut V, f: &'a ExprField) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let ExprField { attrs, id: _, span: _, ident, expr, is_shorthand: _, is_placeholder: _ } = f;
|
|
|
|
walk_list!(visitor, visit_attribute, attrs);
|
2024-10-24 13:41:44 +00:00
|
|
|
try_visit!(visitor.visit_ident(ident));
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_expr(expr));
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2019-08-24 16:54:40 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_pat_field<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a PatField) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let PatField { ident, pat, is_shorthand: _, attrs, id: _, span: _, is_placeholder: _ } = fp;
|
|
|
|
walk_list!(visitor, visit_attribute, attrs);
|
2024-10-24 13:41:44 +00:00
|
|
|
try_visit!(visitor.visit_ident(ident));
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_pat(pat));
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2019-08-24 16:54:40 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Ty { id, kind, span: _, tokens: _ } = typ;
|
|
|
|
match kind {
|
2024-02-18 08:12:44 +00:00
|
|
|
TyKind::Slice(ty) | TyKind::Paren(ty) => try_visit!(visitor.visit_ty(ty)),
|
2024-06-26 12:25:57 +00:00
|
|
|
TyKind::Ptr(MutTy { ty, mutbl: _ }) => try_visit!(visitor.visit_ty(ty)),
|
2024-09-20 19:09:18 +00:00
|
|
|
TyKind::Ref(opt_lifetime, MutTy { ty, mutbl: _ })
|
|
|
|
| TyKind::PinnedRef(opt_lifetime, MutTy { ty, mutbl: _ }) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Ref);
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_ty(ty));
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2023-01-30 18:08:50 +00:00
|
|
|
TyKind::Tup(tuple_element_types) => {
|
|
|
|
walk_list!(visitor, visit_ty, tuple_element_types);
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
TyKind::BareFn(function_declaration) => {
|
2024-06-26 12:25:57 +00:00
|
|
|
let BareFnTy { safety: _, ext: _, generic_params, decl, decl_span: _ } =
|
|
|
|
&**function_declaration;
|
|
|
|
walk_list!(visitor, visit_generic_param, generic_params);
|
2024-11-18 18:40:34 +00:00
|
|
|
try_visit!(visitor.visit_fn_decl(decl));
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2024-08-30 21:01:28 +00:00
|
|
|
TyKind::UnsafeBinder(binder) => {
|
|
|
|
walk_list!(visitor, visit_generic_param, &binder.generic_params);
|
|
|
|
try_visit!(visitor.visit_ty(&binder.inner_ty));
|
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
TyKind::Path(maybe_qself, path) => {
|
2024-11-18 18:43:35 +00:00
|
|
|
try_visit!(visitor.visit_qself(maybe_qself));
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_path(path, *id));
|
2014-11-20 20:08:48 +00:00
|
|
|
}
|
2023-01-30 09:50:16 +00:00
|
|
|
TyKind::Pat(ty, pat) => {
|
|
|
|
try_visit!(visitor.visit_ty(ty));
|
|
|
|
try_visit!(visitor.visit_pat(pat));
|
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
TyKind::Array(ty, length) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_ty(ty));
|
|
|
|
try_visit!(visitor.visit_anon_const(length));
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
TyKind::TraitObject(bounds, _syntax) => {
|
2022-04-21 02:09:32 +00:00
|
|
|
walk_list!(visitor, visit_param_bound, bounds, BoundKind::TraitObject);
|
2022-04-20 11:06:32 +00:00
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
TyKind::ImplTrait(_id, bounds) => {
|
2022-04-21 02:09:32 +00:00
|
|
|
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Impl);
|
2016-08-01 01:25:32 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
TyKind::Typeof(expression) => try_visit!(visitor.visit_anon_const(expression)),
|
2024-06-26 12:25:57 +00:00
|
|
|
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Dummy => {}
|
|
|
|
TyKind::Err(_guar) => {}
|
2024-02-18 08:12:44 +00:00
|
|
|
TyKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
|
2019-09-06 02:56:45 +00:00
|
|
|
TyKind::Never | TyKind::CVarArgs => {}
|
2011-06-08 20:48:19 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2011-06-08 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
2024-06-26 12:25:57 +00:00
|
|
|
fn walk_qself<'a, V: Visitor<'a>>(visitor: &mut V, qself: &'a Option<P<QSelf>>) -> V::Result {
|
|
|
|
if let Some(qself) = qself {
|
|
|
|
let QSelf { ty, path_span: _, position: _ } = &**qself;
|
|
|
|
try_visit!(visitor.visit_ty(ty));
|
|
|
|
}
|
|
|
|
V::Result::output()
|
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Path { span: _, segments, tokens: _ } = path;
|
|
|
|
walk_list!(visitor, visit_path_segment, segments);
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2014-11-15 21:55:27 +00:00
|
|
|
}
|
2013-11-22 12:24:49 +00:00
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_use_tree<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V,
|
|
|
|
use_tree: &'a UseTree,
|
|
|
|
id: NodeId,
|
|
|
|
) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let UseTree { prefix, kind, span: _ } = use_tree;
|
|
|
|
try_visit!(visitor.visit_path(prefix, id));
|
|
|
|
match kind {
|
2022-12-01 15:51:20 +00:00
|
|
|
UseTreeKind::Simple(rename) => {
|
2024-02-11 08:22:52 +00:00
|
|
|
// The extra IDs are handled during AST lowering.
|
2024-10-24 13:41:44 +00:00
|
|
|
visit_opt!(visitor, visit_ident, rename);
|
2017-09-26 21:04:00 +00:00
|
|
|
}
|
|
|
|
UseTreeKind::Glob => {}
|
2024-06-26 12:25:57 +00:00
|
|
|
UseTreeKind::Nested { ref items, span: _ } => {
|
2024-04-01 22:26:10 +00:00
|
|
|
for &(ref nested_tree, nested_id) in items {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_use_tree(nested_tree, nested_id, true));
|
2017-09-26 21:04:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2015-09-12 13:10:12 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_path_segment<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V,
|
|
|
|
segment: &'a PathSegment,
|
|
|
|
) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let PathSegment { ident, id: _, args } = segment;
|
2024-10-24 13:41:44 +00:00
|
|
|
try_visit!(visitor.visit_ident(ident));
|
2024-06-26 12:25:57 +00:00
|
|
|
visit_opt!(visitor, visit_generic_args, args);
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2014-11-15 21:55:27 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_generic_args<'a, V>(visitor: &mut V, generic_args: &'a GenericArgs) -> V::Result
|
2016-12-06 10:26:52 +00:00
|
|
|
where
|
|
|
|
V: Visitor<'a>,
|
2016-06-12 07:51:31 +00:00
|
|
|
{
|
2022-11-16 19:26:38 +00:00
|
|
|
match generic_args {
|
2024-06-26 12:25:57 +00:00
|
|
|
GenericArgs::AngleBracketed(AngleBracketedArgs { span: _, args }) => {
|
|
|
|
for arg in args {
|
2020-03-22 03:40:05 +00:00
|
|
|
match arg {
|
2024-02-18 08:12:44 +00:00
|
|
|
AngleBracketedArg::Arg(a) => try_visit!(visitor.visit_generic_arg(a)),
|
|
|
|
AngleBracketedArg::Constraint(c) => {
|
2024-05-27 21:53:46 +00:00
|
|
|
try_visit!(visitor.visit_assoc_item_constraint(c))
|
2024-02-18 08:12:44 +00:00
|
|
|
}
|
2020-03-22 03:40:05 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-15 21:55:27 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
GenericArgs::Parenthesized(data) => {
|
2024-06-26 12:25:57 +00:00
|
|
|
let ParenthesizedArgs { span: _, inputs, inputs_span: _, output } = data;
|
|
|
|
walk_list!(visitor, visit_ty, inputs);
|
|
|
|
try_visit!(visitor.visit_fn_ret_ty(output));
|
2013-08-07 16:47:28 +00:00
|
|
|
}
|
2024-06-28 15:49:16 +00:00
|
|
|
GenericArgs::ParenthesizedElided(_span) => {}
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2011-12-13 12:19:56 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_generic_arg<'a, V>(visitor: &mut V, generic_arg: &'a GenericArg) -> V::Result
|
2020-10-09 22:20:06 +00:00
|
|
|
where
|
|
|
|
V: Visitor<'a>,
|
|
|
|
{
|
|
|
|
match generic_arg {
|
2022-05-10 17:56:46 +00:00
|
|
|
GenericArg::Lifetime(lt) => visitor.visit_lifetime(lt, LifetimeCtxt::GenericArg),
|
2020-10-09 22:20:06 +00:00
|
|
|
GenericArg::Type(ty) => visitor.visit_ty(ty),
|
|
|
|
GenericArg::Const(ct) => visitor.visit_anon_const(ct),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-27 21:53:46 +00:00
|
|
|
pub fn walk_assoc_item_constraint<'a, V: Visitor<'a>>(
|
2024-02-18 08:12:44 +00:00
|
|
|
visitor: &mut V,
|
2024-05-27 21:53:46 +00:00
|
|
|
constraint: &'a AssocItemConstraint,
|
2024-02-18 08:12:44 +00:00
|
|
|
) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let AssocItemConstraint { id: _, ident, gen_args, kind, span: _ } = constraint;
|
2024-10-24 13:41:44 +00:00
|
|
|
try_visit!(visitor.visit_ident(ident));
|
2024-06-26 12:25:57 +00:00
|
|
|
visit_opt!(visitor, visit_generic_args, gen_args);
|
|
|
|
match kind {
|
2024-05-27 21:53:46 +00:00
|
|
|
AssocItemConstraintKind::Equality { term } => match term {
|
2024-02-18 08:12:44 +00:00
|
|
|
Term::Ty(ty) => try_visit!(visitor.visit_ty(ty)),
|
|
|
|
Term::Const(c) => try_visit!(visitor.visit_anon_const(c)),
|
2022-01-07 03:58:32 +00:00
|
|
|
},
|
2024-05-27 21:53:46 +00:00
|
|
|
AssocItemConstraintKind::Bound { bounds } => {
|
2022-04-21 02:09:32 +00:00
|
|
|
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
2019-02-28 22:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2014-12-28 15:07:21 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Pat { id, kind, span: _, tokens: _ } = pattern;
|
|
|
|
match kind {
|
2022-11-16 19:26:38 +00:00
|
|
|
PatKind::TupleStruct(opt_qself, path, elems) => {
|
2024-11-18 18:43:35 +00:00
|
|
|
try_visit!(visitor.visit_qself(opt_qself));
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_path(path, *id));
|
2019-07-09 07:25:18 +00:00
|
|
|
walk_list!(visitor, visit_pat, elems);
|
2012-08-07 00:01:14 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
PatKind::Path(opt_qself, path) => {
|
2024-11-18 18:43:35 +00:00
|
|
|
try_visit!(visitor.visit_qself(opt_qself));
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_path(path, *id))
|
2015-03-25 16:53:28 +00:00
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
PatKind::Struct(opt_qself, path, fields, _rest) => {
|
2024-11-18 18:43:35 +00:00
|
|
|
try_visit!(visitor.visit_qself(opt_qself));
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_path(path, *id));
|
2021-03-15 21:36:07 +00:00
|
|
|
walk_list!(visitor, visit_pat_field, fields);
|
2013-02-18 06:20:36 +00:00
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
PatKind::Box(subpattern) | PatKind::Deref(subpattern) | PatKind::Paren(subpattern) => {
|
|
|
|
try_visit!(visitor.visit_pat(subpattern));
|
|
|
|
}
|
|
|
|
PatKind::Ref(subpattern, _ /*mutbl*/) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_pat(subpattern));
|
2022-11-16 19:26:38 +00:00
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
PatKind::Ident(_bmode, ident, optional_subpattern) => {
|
2024-10-24 13:41:44 +00:00
|
|
|
try_visit!(visitor.visit_ident(ident));
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_pat, optional_subpattern);
|
2012-12-08 20:22:43 +00:00
|
|
|
}
|
2025-01-07 08:56:23 +00:00
|
|
|
PatKind::Expr(expression) => try_visit!(visitor.visit_expr(expression)),
|
2024-06-26 12:25:57 +00:00
|
|
|
PatKind::Range(lower_bound, upper_bound, _end) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_expr, lower_bound);
|
|
|
|
visit_opt!(visitor, visit_expr, upper_bound);
|
2013-02-18 06:20:36 +00:00
|
|
|
}
|
2024-08-22 23:49:45 +00:00
|
|
|
PatKind::Guard(subpattern, guard_condition) => {
|
|
|
|
try_visit!(visitor.visit_pat(subpattern));
|
|
|
|
try_visit!(visitor.visit_expr(guard_condition));
|
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
PatKind::Wild | PatKind::Rest | PatKind::Never => {}
|
|
|
|
PatKind::Err(_guar) => {}
|
2022-11-16 19:26:38 +00:00
|
|
|
PatKind::Tuple(elems) | PatKind::Slice(elems) | PatKind::Or(elems) => {
|
2019-07-09 07:25:18 +00:00
|
|
|
walk_list!(visitor, visit_pat, elems);
|
2012-12-08 20:22:43 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
PatKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
|
2011-06-08 20:48:19 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2011-06-08 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
2024-04-24 17:31:51 +00:00
|
|
|
impl WalkItemKind for ForeignItemKind {
|
2024-11-08 21:51:28 +00:00
|
|
|
type Ctxt = ();
|
2024-04-24 17:31:51 +00:00
|
|
|
fn walk<'a, V: Visitor<'a>>(
|
|
|
|
&'a self,
|
2024-11-12 16:20:17 +00:00
|
|
|
span: Span,
|
|
|
|
id: NodeId,
|
|
|
|
ident: &'a Ident,
|
|
|
|
vis: &'a Visibility,
|
2024-11-08 21:51:28 +00:00
|
|
|
_ctxt: Self::Ctxt,
|
2024-04-24 17:31:51 +00:00
|
|
|
visitor: &mut V,
|
|
|
|
) -> V::Result {
|
|
|
|
match self {
|
2024-06-20 23:50:57 +00:00
|
|
|
ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => {
|
2024-04-24 17:31:51 +00:00
|
|
|
try_visit!(visitor.visit_ty(ty));
|
|
|
|
visit_opt!(visitor, visit_expr, expr);
|
|
|
|
}
|
2025-01-28 00:30:02 +00:00
|
|
|
ForeignItemKind::Fn(func) => {
|
|
|
|
let kind = FnKind::Fn(FnCtxt::Foreign, ident, vis, &*func);
|
2024-04-24 17:31:51 +00:00
|
|
|
try_visit!(visitor.visit_fn(kind, span, id));
|
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
ForeignItemKind::TyAlias(box TyAlias {
|
|
|
|
generics,
|
|
|
|
bounds,
|
|
|
|
ty,
|
|
|
|
defaultness: _,
|
|
|
|
where_clauses: _,
|
|
|
|
}) => {
|
2024-04-24 17:31:51 +00:00
|
|
|
try_visit!(visitor.visit_generics(generics));
|
|
|
|
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
|
|
|
visit_opt!(visitor, visit_ty, ty);
|
|
|
|
}
|
|
|
|
ForeignItemKind::MacCall(mac) => {
|
|
|
|
try_visit!(visitor.visit_mac_call(mac));
|
|
|
|
}
|
2020-02-29 12:51:08 +00:00
|
|
|
}
|
2024-04-24 17:31:51 +00:00
|
|
|
V::Result::output()
|
2020-02-29 12:51:08 +00:00
|
|
|
}
|
2014-11-15 21:55:27 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) -> V::Result {
|
2022-11-16 19:26:38 +00:00
|
|
|
match bound {
|
2024-10-13 13:31:22 +00:00
|
|
|
GenericBound::Trait(trait_ref) => visitor.visit_poly_trait_ref(trait_ref),
|
2022-11-16 19:26:38 +00:00
|
|
|
GenericBound::Outlives(lifetime) => visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound),
|
2024-06-26 12:25:57 +00:00
|
|
|
GenericBound::Use(args, _span) => {
|
2024-06-05 20:18:52 +00:00
|
|
|
walk_list!(visitor, visit_precise_capturing_arg, args);
|
|
|
|
V::Result::output()
|
|
|
|
}
|
2012-08-07 01:54:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-04 01:47:02 +00:00
|
|
|
pub fn walk_precise_capturing_arg<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V,
|
|
|
|
arg: &'a PreciseCapturingArg,
|
2024-11-14 20:07:46 +00:00
|
|
|
) -> V::Result {
|
2024-04-04 01:47:02 +00:00
|
|
|
match arg {
|
2024-11-14 20:07:46 +00:00
|
|
|
PreciseCapturingArg::Lifetime(lt) => visitor.visit_lifetime(lt, LifetimeCtxt::GenericArg),
|
|
|
|
PreciseCapturingArg::Arg(path, id) => visitor.visit_path(path, *id),
|
2024-04-04 01:47:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_generic_param<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V,
|
|
|
|
param: &'a GenericParam,
|
|
|
|
) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let GenericParam { id: _, ident, attrs, bounds, is_placeholder: _, kind, colon_span: _ } =
|
|
|
|
param;
|
|
|
|
walk_list!(visitor, visit_attribute, attrs);
|
2024-10-24 13:41:44 +00:00
|
|
|
try_visit!(visitor.visit_ident(ident));
|
2024-06-26 12:25:57 +00:00
|
|
|
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
|
|
|
match kind {
|
2019-02-28 22:43:53 +00:00
|
|
|
GenericParamKind::Lifetime => (),
|
2024-02-18 08:12:44 +00:00
|
|
|
GenericParamKind::Type { default } => visit_opt!(visitor, visit_ty, default),
|
2024-06-26 12:25:57 +00:00
|
|
|
GenericParamKind::Const { ty, default, kw_span: _ } => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_ty(ty));
|
|
|
|
visit_opt!(visitor, visit_anon_const, default);
|
2020-12-31 00:58:27 +00:00
|
|
|
}
|
2011-12-28 16:50:12 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2017-10-16 19:07:26 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_generics<'a, V: Visitor<'a>>(visitor: &mut V, generics: &'a Generics) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Generics { params, where_clause, span: _ } = generics;
|
|
|
|
let WhereClause { has_where_token: _, predicates, span: _ } = where_clause;
|
|
|
|
walk_list!(visitor, visit_generic_param, params);
|
|
|
|
walk_list!(visitor, visit_where_predicate, predicates);
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2017-01-25 20:01:11 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_closure_binder<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V,
|
|
|
|
binder: &'a ClosureBinder,
|
|
|
|
) -> V::Result {
|
2022-06-02 16:15:05 +00:00
|
|
|
match binder {
|
|
|
|
ClosureBinder::NotPresent => {}
|
2022-07-12 09:34:24 +00:00
|
|
|
ClosureBinder::For { generic_params, span: _ } => {
|
2022-06-02 16:15:05 +00:00
|
|
|
walk_list!(visitor, visit_generic_param, generic_params)
|
|
|
|
}
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2022-06-02 16:15:05 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_where_predicate<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V,
|
|
|
|
predicate: &'a WherePredicate,
|
|
|
|
) -> V::Result {
|
2024-11-25 08:38:35 +00:00
|
|
|
let WherePredicate { kind, id: _, span: _ } = predicate;
|
|
|
|
visitor.visit_where_predicate_kind(kind)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn walk_where_predicate_kind<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V,
|
|
|
|
kind: &'a WherePredicateKind,
|
|
|
|
) -> V::Result {
|
|
|
|
match kind {
|
|
|
|
WherePredicateKind::BoundPredicate(WhereBoundPredicate {
|
2022-11-16 19:26:38 +00:00
|
|
|
bounded_ty,
|
|
|
|
bounds,
|
|
|
|
bound_generic_params,
|
2017-01-25 20:01:11 +00:00
|
|
|
}) => {
|
2024-06-26 12:25:57 +00:00
|
|
|
walk_list!(visitor, visit_generic_param, bound_generic_params);
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_ty(bounded_ty));
|
2022-04-21 02:09:32 +00:00
|
|
|
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
2017-01-25 20:01:11 +00:00
|
|
|
}
|
2024-11-25 08:38:35 +00:00
|
|
|
WherePredicateKind::RegionPredicate(WhereRegionPredicate { lifetime, bounds }) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound));
|
2022-04-21 02:09:32 +00:00
|
|
|
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
2017-01-25 20:01:11 +00:00
|
|
|
}
|
2024-11-25 08:38:35 +00:00
|
|
|
WherePredicateKind::EqPredicate(WhereEqPredicate { lhs_ty, rhs_ty }) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_ty(lhs_ty));
|
|
|
|
try_visit!(visitor.visit_ty(rhs_ty));
|
2014-11-29 04:08:30 +00:00
|
|
|
}
|
2014-08-11 16:32:26 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2011-12-28 16:50:12 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
match ret_ty {
|
|
|
|
FnRetTy::Default(_span) => {}
|
|
|
|
FnRetTy::Ty(output_ty) => try_visit!(visitor.visit_ty(output_ty)),
|
2015-09-28 21:23:54 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2015-09-28 21:23:54 +00:00
|
|
|
}
|
|
|
|
|
2024-11-13 00:57:25 +00:00
|
|
|
pub fn walk_fn_header<'a, V: Visitor<'a>>(visitor: &mut V, fn_header: &'a FnHeader) -> V::Result {
|
2024-11-12 16:44:46 +00:00
|
|
|
let FnHeader { safety: _, coroutine_kind, constness: _, ext: _ } = fn_header;
|
|
|
|
visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
|
|
|
|
V::Result::output()
|
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_fn_decl<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V,
|
2024-06-26 12:25:57 +00:00
|
|
|
FnDecl { inputs, output }: &'a FnDecl,
|
2024-02-18 08:12:44 +00:00
|
|
|
) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
walk_list!(visitor, visit_param, inputs);
|
|
|
|
visitor.visit_fn_ret_ty(output)
|
2011-06-08 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Result {
|
2016-10-25 23:17:29 +00:00
|
|
|
match kind {
|
2025-01-28 00:30:02 +00:00
|
|
|
FnKind::Fn(
|
|
|
|
_ctxt,
|
|
|
|
_ident,
|
|
|
|
_vis,
|
|
|
|
Fn { defaultness: _, sig: FnSig { header, decl, span: _ }, generics, body },
|
|
|
|
) => {
|
2024-06-26 12:25:57 +00:00
|
|
|
// Identifier and visibility are visited as a part of the item.
|
|
|
|
try_visit!(visitor.visit_fn_header(header));
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_generics(generics));
|
2024-11-18 18:40:34 +00:00
|
|
|
try_visit!(visitor.visit_fn_decl(decl));
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_block, body);
|
2016-10-25 23:17:29 +00:00
|
|
|
}
|
2024-11-12 16:44:46 +00:00
|
|
|
FnKind::Closure(binder, coroutine_kind, decl, body) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_closure_binder(binder));
|
2024-11-12 16:44:46 +00:00
|
|
|
visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
|
2024-11-18 18:40:34 +00:00
|
|
|
try_visit!(visitor.visit_fn_decl(decl));
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(body));
|
2013-10-28 21:37:10 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2015-09-28 21:23:54 +00:00
|
|
|
}
|
2013-10-28 21:37:10 +00:00
|
|
|
|
2024-04-24 17:31:51 +00:00
|
|
|
impl WalkItemKind for AssocItemKind {
|
2024-11-08 21:51:28 +00:00
|
|
|
type Ctxt = AssocCtxt;
|
2024-04-24 17:31:51 +00:00
|
|
|
fn walk<'a, V: Visitor<'a>>(
|
|
|
|
&'a self,
|
2024-11-12 16:20:17 +00:00
|
|
|
span: Span,
|
|
|
|
id: NodeId,
|
|
|
|
ident: &'a Ident,
|
|
|
|
vis: &'a Visibility,
|
2024-11-08 21:51:28 +00:00
|
|
|
ctxt: Self::Ctxt,
|
2024-04-24 17:31:51 +00:00
|
|
|
visitor: &mut V,
|
|
|
|
) -> V::Result {
|
|
|
|
match self {
|
|
|
|
AssocItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => {
|
|
|
|
try_visit!(visitor.visit_generics(generics));
|
|
|
|
try_visit!(visitor.visit_ty(ty));
|
|
|
|
visit_opt!(visitor, visit_expr, expr);
|
|
|
|
}
|
2025-01-28 00:30:02 +00:00
|
|
|
AssocItemKind::Fn(func) => {
|
|
|
|
let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, vis, &*func);
|
2024-04-24 17:31:51 +00:00
|
|
|
try_visit!(visitor.visit_fn(kind, span, id));
|
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
AssocItemKind::Type(box TyAlias {
|
|
|
|
generics,
|
|
|
|
bounds,
|
|
|
|
ty,
|
|
|
|
defaultness: _,
|
|
|
|
where_clauses: _,
|
|
|
|
}) => {
|
2024-04-24 17:31:51 +00:00
|
|
|
try_visit!(visitor.visit_generics(generics));
|
|
|
|
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
|
|
|
visit_opt!(visitor, visit_ty, ty);
|
|
|
|
}
|
|
|
|
AssocItemKind::MacCall(mac) => {
|
|
|
|
try_visit!(visitor.visit_mac_call(mac));
|
|
|
|
}
|
2024-03-15 11:21:03 +00:00
|
|
|
AssocItemKind::Delegation(box Delegation {
|
|
|
|
id,
|
|
|
|
qself,
|
|
|
|
path,
|
|
|
|
rename,
|
|
|
|
body,
|
|
|
|
from_glob: _,
|
|
|
|
}) => {
|
2024-11-18 18:43:35 +00:00
|
|
|
try_visit!(visitor.visit_qself(qself));
|
2024-04-24 17:31:51 +00:00
|
|
|
try_visit!(visitor.visit_path(path, *id));
|
2024-10-24 13:41:44 +00:00
|
|
|
visit_opt!(visitor, visit_ident, rename);
|
2024-04-24 17:31:51 +00:00
|
|
|
visit_opt!(visitor, visit_block, body);
|
2024-03-15 11:21:03 +00:00
|
|
|
}
|
|
|
|
AssocItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
|
2024-11-18 18:43:35 +00:00
|
|
|
try_visit!(visitor.visit_qself(qself));
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_path(prefix, id));
|
2024-03-15 11:21:03 +00:00
|
|
|
if let Some(suffixes) = suffixes {
|
|
|
|
for (ident, rename) in suffixes {
|
2024-10-24 13:41:44 +00:00
|
|
|
visitor.visit_ident(ident);
|
2024-03-15 11:21:03 +00:00
|
|
|
if let Some(rename) = rename {
|
2024-10-24 13:41:44 +00:00
|
|
|
visitor.visit_ident(rename);
|
2024-03-15 11:21:03 +00:00
|
|
|
}
|
2024-03-15 11:21:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
visit_opt!(visitor, visit_block, body);
|
2024-04-24 17:31:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
V::Result::output()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-17 23:11:49 +00:00
|
|
|
pub fn walk_item<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V,
|
|
|
|
item: &'a Item<impl WalkItemKind<Ctxt = ()>>,
|
|
|
|
) -> V::Result {
|
|
|
|
walk_item_ctxt(visitor, item, ())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn walk_assoc_item<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V,
|
|
|
|
item: &'a AssocItem,
|
|
|
|
ctxt: AssocCtxt,
|
|
|
|
) -> V::Result {
|
|
|
|
walk_item_ctxt(visitor, item, ctxt)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn walk_item_ctxt<'a, V: Visitor<'a>, K: WalkItemKind>(
|
2024-02-18 08:12:44 +00:00
|
|
|
visitor: &mut V,
|
2024-11-08 21:51:28 +00:00
|
|
|
item: &'a Item<K>,
|
|
|
|
ctxt: K::Ctxt,
|
2024-02-18 08:12:44 +00:00
|
|
|
) -> V::Result {
|
2024-11-12 16:20:17 +00:00
|
|
|
let Item { id, span, ident, vis, attrs, kind, tokens: _ } = item;
|
2024-05-29 20:36:11 +00:00
|
|
|
walk_list!(visitor, visit_attribute, attrs);
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_vis(vis));
|
|
|
|
try_visit!(visitor.visit_ident(ident));
|
2024-11-12 16:20:17 +00:00
|
|
|
try_visit!(kind.walk(*span, *id, ident, vis, ctxt, visitor));
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2012-07-10 20:44:20 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_struct_def<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V,
|
|
|
|
struct_definition: &'a VariantData,
|
|
|
|
) -> V::Result {
|
2021-03-15 21:36:07 +00:00
|
|
|
walk_list!(visitor, visit_field_def, struct_definition.fields());
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2012-08-07 22:54:59 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_field_def<'a, V: Visitor<'a>>(visitor: &mut V, field: &'a FieldDef) -> V::Result {
|
2024-08-24 17:22:48 +00:00
|
|
|
let FieldDef { attrs, id: _, span: _, vis, ident, ty, is_placeholder: _, safety: _, default } =
|
|
|
|
field;
|
2024-06-26 12:25:57 +00:00
|
|
|
walk_list!(visitor, visit_attribute, attrs);
|
|
|
|
try_visit!(visitor.visit_vis(vis));
|
2024-10-24 13:41:44 +00:00
|
|
|
visit_opt!(visitor, visit_ident, ident);
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_ty(ty));
|
2024-08-24 17:22:48 +00:00
|
|
|
visit_opt!(visitor, visit_anon_const, &*default);
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2012-08-15 22:53:58 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Block { stmts, id: _, rules: _, span: _, tokens: _, could_be_bare_literal: _ } = block;
|
|
|
|
walk_list!(visitor, visit_stmt, stmts);
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2011-06-08 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Stmt { id: _, kind, span: _ } = statement;
|
|
|
|
match kind {
|
2024-03-14 10:25:05 +00:00
|
|
|
StmtKind::Let(local) => try_visit!(visitor.visit_local(local)),
|
2024-02-18 08:12:44 +00:00
|
|
|
StmtKind::Item(item) => try_visit!(visitor.visit_item(item)),
|
|
|
|
StmtKind::Expr(expr) | StmtKind::Semi(expr) => try_visit!(visitor.visit_expr(expr)),
|
2020-02-27 03:10:42 +00:00
|
|
|
StmtKind::Empty => {}
|
2022-11-16 19:26:38 +00:00
|
|
|
StmtKind::MacCall(mac) => {
|
|
|
|
let MacCallStmt { mac, attrs, style: _, tokens: _ } = &**mac;
|
2024-02-18 08:12:44 +00:00
|
|
|
walk_list!(visitor, visit_attribute, attrs);
|
2024-05-29 20:36:11 +00:00
|
|
|
try_visit!(visitor.visit_mac_call(mac));
|
2015-11-03 16:39:51 +00:00
|
|
|
}
|
2011-06-08 20:48:19 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2011-06-08 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_mac<'a, V: Visitor<'a>>(visitor: &mut V, mac: &'a MacCall) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let MacCall { path, args: _ } = mac;
|
|
|
|
visitor.visit_path(path, DUMMY_NODE_ID)
|
2011-07-08 23:35:09 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_anon_const<'a, V: Visitor<'a>>(visitor: &mut V, constant: &'a AnonConst) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let AnonConst { id: _, value } = constant;
|
|
|
|
visitor.visit_expr(value)
|
2018-05-17 18:28:50 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let InlineAsm {
|
2024-09-10 12:42:17 +00:00
|
|
|
asm_macro: _,
|
2024-06-26 12:25:57 +00:00
|
|
|
template: _,
|
|
|
|
template_strs: _,
|
|
|
|
operands,
|
|
|
|
clobber_abis: _,
|
|
|
|
options: _,
|
|
|
|
line_spans: _,
|
|
|
|
} = asm;
|
|
|
|
for (op, _span) in operands {
|
2021-04-11 19:51:28 +00:00
|
|
|
match op {
|
2024-06-26 12:25:57 +00:00
|
|
|
InlineAsmOperand::In { expr, reg: _ }
|
|
|
|
| InlineAsmOperand::Out { expr: Some(expr), reg: _, late: _ }
|
|
|
|
| InlineAsmOperand::InOut { expr, reg: _, late: _ } => {
|
|
|
|
try_visit!(visitor.visit_expr(expr))
|
|
|
|
}
|
|
|
|
InlineAsmOperand::Out { expr: None, reg: _, late: _ } => {}
|
|
|
|
InlineAsmOperand::SplitInOut { in_expr, out_expr, reg: _, late: _ } => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(in_expr));
|
|
|
|
visit_opt!(visitor, visit_expr, out_expr);
|
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
InlineAsmOperand::Const { anon_const } => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_anon_const(anon_const))
|
2021-04-11 19:51:28 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
InlineAsmOperand::Sym { sym } => try_visit!(visitor.visit_inline_asm_sym(sym)),
|
2023-12-25 20:53:01 +00:00
|
|
|
InlineAsmOperand::Label { block } => try_visit!(visitor.visit_block(block)),
|
2021-04-11 19:51:28 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2021-04-11 19:51:28 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_inline_asm_sym<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V,
|
2024-06-26 12:25:57 +00:00
|
|
|
InlineAsmSym { id, qself, path }: &'a InlineAsmSym,
|
2024-02-18 08:12:44 +00:00
|
|
|
) -> V::Result {
|
2024-11-18 18:43:35 +00:00
|
|
|
try_visit!(visitor.visit_qself(qself));
|
2024-06-26 12:25:57 +00:00
|
|
|
visitor.visit_path(path, *id)
|
2022-03-01 00:50:56 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_format_args<'a, V: Visitor<'a>>(visitor: &mut V, fmt: &'a FormatArgs) -> V::Result {
|
2024-12-31 05:03:22 +00:00
|
|
|
let FormatArgs { span: _, template: _, arguments, uncooked_fmt_str: _ } = fmt;
|
2024-06-26 12:25:57 +00:00
|
|
|
for FormatArgument { kind, expr } in arguments.all_args() {
|
|
|
|
match kind {
|
|
|
|
FormatArgumentKind::Named(ident) | FormatArgumentKind::Captured(ident) => {
|
2024-10-24 13:41:44 +00:00
|
|
|
try_visit!(visitor.visit_ident(ident))
|
2024-06-26 12:25:57 +00:00
|
|
|
}
|
|
|
|
FormatArgumentKind::Normal => {}
|
2023-01-11 20:41:13 +00:00
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_expr(expr));
|
2023-01-11 20:41:13 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2023-01-11 20:41:13 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Expr { id, kind, span, attrs, tokens: _ } = expression;
|
|
|
|
walk_list!(visitor, visit_attribute, attrs);
|
|
|
|
match kind {
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Array(subexpressions) => {
|
2015-09-28 11:26:26 +00:00
|
|
|
walk_list!(visitor, visit_expr, subexpressions);
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2024-06-03 09:11:58 +00:00
|
|
|
ExprKind::ConstBlock(anon_const) => try_visit!(visitor.visit_anon_const(anon_const)),
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Repeat(element, count) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(element));
|
|
|
|
try_visit!(visitor.visit_anon_const(count));
|
2013-02-18 06:20:36 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Struct(se) => {
|
2024-06-26 12:25:57 +00:00
|
|
|
let StructExpr { qself, path, fields, rest } = &**se;
|
2024-11-18 18:43:35 +00:00
|
|
|
try_visit!(visitor.visit_qself(qself));
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_path(path, *id));
|
|
|
|
walk_list!(visitor, visit_expr_field, fields);
|
|
|
|
match rest {
|
2024-02-18 08:12:44 +00:00
|
|
|
StructRest::Base(expr) => try_visit!(visitor.visit_expr(expr)),
|
2020-11-07 14:28:55 +00:00
|
|
|
StructRest::Rest(_span) => {}
|
|
|
|
StructRest::None => {}
|
|
|
|
}
|
2013-02-18 06:20:36 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Tup(subexpressions) => {
|
2015-09-28 11:26:26 +00:00
|
|
|
walk_list!(visitor, visit_expr, subexpressions);
|
2013-02-18 06:20:36 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Call(callee_expression, arguments) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(callee_expression));
|
2015-09-28 11:26:26 +00:00
|
|
|
walk_list!(visitor, visit_expr, arguments);
|
2013-02-18 06:20:36 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::MethodCall(box MethodCall { seg, receiver, args, span: _ }) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(receiver));
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_path_segment(seg));
|
2022-09-08 00:52:51 +00:00
|
|
|
walk_list!(visitor, visit_expr, args);
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
ExprKind::Binary(_op, left_expression, right_expression) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(left_expression));
|
|
|
|
try_visit!(visitor.visit_expr(right_expression));
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
ExprKind::AddrOf(_kind, _mutbl, subexpression) => {
|
|
|
|
try_visit!(visitor.visit_expr(subexpression));
|
|
|
|
}
|
|
|
|
ExprKind::Unary(_op, subexpression) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(subexpression));
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Cast(subexpression, typ) | ExprKind::Type(subexpression, typ) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(subexpression));
|
|
|
|
try_visit!(visitor.visit_ty(typ));
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
ExprKind::Let(pat, expr, _span, _recovered) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_pat(pat));
|
|
|
|
try_visit!(visitor.visit_expr(expr));
|
2019-05-15 14:06:58 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::If(head_expression, if_block, optional_else) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(head_expression));
|
|
|
|
try_visit!(visitor.visit_block(if_block));
|
|
|
|
visit_opt!(visitor, visit_expr, optional_else);
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::While(subexpression, block, opt_label) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_label, opt_label);
|
|
|
|
try_visit!(visitor.visit_expr(subexpression));
|
|
|
|
try_visit!(visitor.visit_block(block));
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2023-12-08 22:51:50 +00:00
|
|
|
ExprKind::ForLoop { pat, iter, body, label, kind: _ } => {
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_label, label);
|
|
|
|
try_visit!(visitor.visit_pat(pat));
|
|
|
|
try_visit!(visitor.visit_expr(iter));
|
|
|
|
try_visit!(visitor.visit_block(body));
|
2015-09-28 11:26:26 +00:00
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
ExprKind::Loop(block, opt_label, _span) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_label, opt_label);
|
|
|
|
try_visit!(visitor.visit_block(block));
|
2015-09-28 11:26:26 +00:00
|
|
|
}
|
2024-02-17 17:43:54 +00:00
|
|
|
ExprKind::Match(subexpression, arms, _kind) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(subexpression));
|
2015-09-28 11:26:26 +00:00
|
|
|
walk_list!(visitor, visit_arm, arms);
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2022-09-08 00:52:51 +00:00
|
|
|
ExprKind::Closure(box Closure {
|
2022-11-16 19:26:38 +00:00
|
|
|
binder,
|
2023-11-04 19:39:15 +00:00
|
|
|
capture_clause,
|
2024-08-24 01:44:52 +00:00
|
|
|
coroutine_kind,
|
2022-12-20 16:15:55 +00:00
|
|
|
constness: _,
|
2022-09-08 00:52:51 +00:00
|
|
|
movability: _,
|
2022-11-16 19:26:38 +00:00
|
|
|
fn_decl,
|
|
|
|
body,
|
2022-09-08 00:52:51 +00:00
|
|
|
fn_decl_span: _,
|
2022-11-09 15:09:28 +00:00
|
|
|
fn_arg_span: _,
|
2022-09-08 00:52:51 +00:00
|
|
|
}) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_capture_by(capture_clause));
|
2024-08-24 01:44:52 +00:00
|
|
|
try_visit!(visitor.visit_fn(
|
|
|
|
FnKind::Closure(binder, coroutine_kind, fn_decl, body),
|
|
|
|
*span,
|
|
|
|
*id
|
|
|
|
))
|
2020-01-29 23:18:54 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Block(block, opt_label) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_label, opt_label);
|
|
|
|
try_visit!(visitor.visit_block(block));
|
2018-04-16 03:44:39 +00:00
|
|
|
}
|
2024-06-27 18:56:57 +00:00
|
|
|
ExprKind::Gen(_capt, body, _kind, _decl_span) => try_visit!(visitor.visit_block(body)),
|
2024-06-26 12:25:57 +00:00
|
|
|
ExprKind::Await(expr, _span) => try_visit!(visitor.visit_expr(expr)),
|
|
|
|
ExprKind::Assign(lhs, rhs, _span) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(lhs));
|
|
|
|
try_visit!(visitor.visit_expr(rhs));
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
ExprKind::AssignOp(_op, left_expression, right_expression) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(left_expression));
|
|
|
|
try_visit!(visitor.visit_expr(right_expression));
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Field(subexpression, ident) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(subexpression));
|
2024-10-24 13:41:44 +00:00
|
|
|
try_visit!(visitor.visit_ident(ident));
|
2013-02-18 06:20:36 +00:00
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
ExprKind::Index(main_expression, index_expression, _span) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
try_visit!(visitor.visit_expr(main_expression));
|
|
|
|
try_visit!(visitor.visit_expr(index_expression));
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
ExprKind::Range(start, end, _limit) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_expr, start);
|
|
|
|
visit_opt!(visitor, visit_expr, end);
|
2014-12-13 05:41:02 +00:00
|
|
|
}
|
2020-11-11 13:15:15 +00:00
|
|
|
ExprKind::Underscore => {}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Path(maybe_qself, path) => {
|
2024-11-18 18:43:35 +00:00
|
|
|
try_visit!(visitor.visit_qself(maybe_qself));
|
2024-06-26 12:25:57 +00:00
|
|
|
try_visit!(visitor.visit_path(path, *id));
|
2013-12-08 19:25:35 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Break(opt_label, opt_expr) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_label, opt_label);
|
|
|
|
visit_opt!(visitor, visit_expr, opt_expr);
|
Implement the `loop_break_value` feature.
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, `loop` loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop. `while` loops are unchanged.
- `break` respects contexts in which expressions may not end with braced
blocks. That is, `while break { break-value } { while-body }` is
illegal; this preserves backwards compatibility.
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
2016-10-29 22:15:06 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Continue(opt_label) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_label, opt_label);
|
2015-09-28 11:26:26 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Ret(optional_expression) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_expr, optional_expression);
|
2013-07-20 01:42:11 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Yeet(optional_expression) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_expr, optional_expression);
|
2022-03-26 06:43:54 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
ExprKind::Become(expr) => try_visit!(visitor.visit_expr(expr)),
|
|
|
|
ExprKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
|
|
|
|
ExprKind::Paren(subexpression) => try_visit!(visitor.visit_expr(subexpression)),
|
|
|
|
ExprKind::InlineAsm(asm) => try_visit!(visitor.visit_inline_asm(asm)),
|
|
|
|
ExprKind::FormatArgs(f) => try_visit!(visitor.visit_format_args(f)),
|
2022-09-11 07:37:49 +00:00
|
|
|
ExprKind::OffsetOf(container, fields) => {
|
2024-03-18 15:21:06 +00:00
|
|
|
try_visit!(visitor.visit_ty(container));
|
2024-10-24 13:41:44 +00:00
|
|
|
walk_list!(visitor, visit_ident, fields.iter());
|
2022-09-11 07:37:49 +00:00
|
|
|
}
|
2022-11-16 19:26:38 +00:00
|
|
|
ExprKind::Yield(optional_expression) => {
|
2024-02-18 08:12:44 +00:00
|
|
|
visit_opt!(visitor, visit_expr, optional_expression);
|
2016-12-26 13:34:03 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
ExprKind::Try(subexpression) => try_visit!(visitor.visit_expr(subexpression)),
|
|
|
|
ExprKind::TryBlock(body) => try_visit!(visitor.visit_block(body)),
|
2024-06-26 12:25:57 +00:00
|
|
|
ExprKind::Lit(_token) => {}
|
|
|
|
ExprKind::IncludedBytes(_bytes) => {}
|
2024-09-13 18:00:10 +00:00
|
|
|
ExprKind::UnsafeBinderCast(_kind, expr, ty) => {
|
|
|
|
try_visit!(visitor.visit_expr(expr));
|
|
|
|
visit_opt!(visitor, visit_ty, ty);
|
|
|
|
}
|
2024-06-26 12:25:57 +00:00
|
|
|
ExprKind::Err(_guar) => {}
|
|
|
|
ExprKind::Dummy => {}
|
2011-06-08 20:48:19 +00:00
|
|
|
}
|
2013-07-20 01:42:11 +00:00
|
|
|
|
2024-10-24 13:59:40 +00:00
|
|
|
V::Result::output()
|
2011-06-08 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Param) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Param { attrs, ty, pat, id: _, span: _, is_placeholder: _ } = param;
|
|
|
|
walk_list!(visitor, visit_attribute, attrs);
|
|
|
|
try_visit!(visitor.visit_pat(pat));
|
|
|
|
try_visit!(visitor.visit_ty(ty));
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2019-07-26 22:52:37 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Arm { attrs, pat, guard, body, span: _, id: _, is_placeholder: _ } = arm;
|
|
|
|
walk_list!(visitor, visit_attribute, attrs);
|
|
|
|
try_visit!(visitor.visit_pat(pat));
|
|
|
|
visit_opt!(visitor, visit_expr, guard);
|
|
|
|
visit_opt!(visitor, visit_expr, body);
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2011-06-08 20:48:19 +00:00
|
|
|
}
|
2016-03-31 19:10:38 +00:00
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Visibility { kind, span: _, tokens: _ } = vis;
|
|
|
|
match kind {
|
|
|
|
VisibilityKind::Restricted { path, id, shorthand: _ } => {
|
|
|
|
try_visit!(visitor.visit_path(path, *id));
|
|
|
|
}
|
|
|
|
VisibilityKind::Public | VisibilityKind::Inherited => {}
|
2016-03-31 19:10:38 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2016-03-31 19:10:38 +00:00
|
|
|
}
|
2017-10-23 08:22:28 +00:00
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) -> V::Result {
|
2024-06-26 12:25:57 +00:00
|
|
|
let Attribute { kind, id: _, style: _, span: _ } = attr;
|
|
|
|
match kind {
|
|
|
|
AttrKind::Normal(normal) => {
|
|
|
|
let NormalAttr { item, tokens: _ } = &**normal;
|
|
|
|
let AttrItem { unsafety: _, path, args, tokens: _ } = item;
|
|
|
|
try_visit!(visitor.visit_path(path, DUMMY_NODE_ID));
|
|
|
|
try_visit!(walk_attr_args(visitor, args));
|
|
|
|
}
|
|
|
|
AttrKind::DocComment(_kind, _sym) => {}
|
2019-10-23 19:33:12 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2017-10-23 08:22:28 +00:00
|
|
|
}
|
|
|
|
|
2024-02-18 08:12:44 +00:00
|
|
|
pub fn walk_attr_args<'a, V: Visitor<'a>>(visitor: &mut V, args: &'a AttrArgs) -> V::Result {
|
2019-12-01 14:07:38 +00:00
|
|
|
match args {
|
2022-11-18 00:24:21 +00:00
|
|
|
AttrArgs::Empty => {}
|
2024-06-26 12:25:57 +00:00
|
|
|
AttrArgs::Delimited(_args) => {}
|
2024-10-16 23:14:01 +00:00
|
|
|
AttrArgs::Eq { expr, .. } => try_visit!(visitor.visit_expr(expr)),
|
2017-10-23 08:22:28 +00:00
|
|
|
}
|
2024-02-18 08:12:44 +00:00
|
|
|
V::Result::output()
|
2017-10-23 08:22:28 +00:00
|
|
|
}
|