diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index 6414c8e904196..6e42cf37b865c 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -12,10 +12,12 @@ #![allow(internal_features)] #![feature(rustdoc_internals)] #![feature(associated_type_bounds)] +#![feature(associated_type_defaults)] #![feature(box_patterns)] #![feature(if_let_guard)] #![feature(let_chains)] #![cfg_attr(bootstrap, feature(min_specialization))] +#![feature(never_type)] #![feature(negative_impls)] #![feature(stmt_expr_attributes)] diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 83f6746bdeb23..ecf379cc2408a 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -15,6 +15,8 @@ use crate::ast::*; +use core::ops::ControlFlow; + use rustc_span::symbol::Ident; use rustc_span::Span; @@ -99,6 +101,51 @@ pub enum LifetimeCtxt { GenericArg, } +/// Similar to the `Try` trait, but also implemented for `()`. +pub trait VisitorResult { + type Residual; + fn output() -> Self; + fn from_residual(residual: Self::Residual) -> Self; + fn branch(self) -> ControlFlow; +} + +impl VisitorResult for () { + type Residual = !; + + fn output() -> Self {} + fn from_residual(_: !) -> Self {} + fn branch(self) -> ControlFlow { + ControlFlow::Continue(()) + } +} + +impl VisitorResult for ControlFlow { + type Residual = T; + + fn output() -> Self { + ControlFlow::Continue(()) + } + fn from_residual(residual: Self::Residual) -> Self { + ControlFlow::Break(residual) + } + fn branch(self) -> ControlFlow { + self + } +} + +#[macro_export] +macro_rules! try_visit { + ($e:expr) => { + match $crate::visit::VisitorResult::branch($e) { + core::ops::ControlFlow::Continue(()) => (), + #[allow(unreachable_code)] + core::ops::ControlFlow::Break(r) => { + return $crate::visit::VisitorResult::from_residual(r); + } + } + }; +} + /// Each method of the `Visitor` trait is a hook to be potentially /// overridden. Each method's default implementation recursively visits /// the substructure of the input via the corresponding `walk` method; @@ -109,240 +156,259 @@ pub enum LifetimeCtxt { /// to monitor future changes to `Visitor` in case a new method with a /// new default implementation gets introduced.) pub trait Visitor<'ast>: Sized { - fn visit_ident(&mut self, _ident: Ident) {} - fn visit_foreign_item(&mut self, i: &'ast ForeignItem) { + /// The result type of the `visit_*` methods. Can be either `()`, + /// or `ControlFlow`. + type Result: VisitorResult = (); + + fn visit_ident(&mut self, _ident: Ident) -> Self::Result { + Self::Result::output() + } + fn visit_foreign_item(&mut self, i: &'ast ForeignItem) -> Self::Result { walk_foreign_item(self, i) } - fn visit_item(&mut self, i: &'ast Item) { + fn visit_item(&mut self, i: &'ast Item) -> Self::Result { walk_item(self, i) } - fn visit_local(&mut self, l: &'ast Local) { + fn visit_local(&mut self, l: &'ast Local) -> Self::Result { walk_local(self, l) } - fn visit_block(&mut self, b: &'ast Block) { + fn visit_block(&mut self, b: &'ast Block) -> Self::Result { walk_block(self, b) } - fn visit_stmt(&mut self, s: &'ast Stmt) { + fn visit_stmt(&mut self, s: &'ast Stmt) -> Self::Result { walk_stmt(self, s) } - fn visit_param(&mut self, param: &'ast Param) { + fn visit_param(&mut self, param: &'ast Param) -> Self::Result { walk_param(self, param) } - fn visit_arm(&mut self, a: &'ast Arm) { + fn visit_arm(&mut self, a: &'ast Arm) -> Self::Result { walk_arm(self, a) } - fn visit_pat(&mut self, p: &'ast Pat) { + fn visit_pat(&mut self, p: &'ast Pat) -> Self::Result { walk_pat(self, p) } - fn visit_anon_const(&mut self, c: &'ast AnonConst) { + fn visit_anon_const(&mut self, c: &'ast AnonConst) -> Self::Result { walk_anon_const(self, c) } - fn visit_expr(&mut self, ex: &'ast Expr) { + fn visit_expr(&mut self, ex: &'ast Expr) -> Self::Result { walk_expr(self, ex) } /// This method is a hack to workaround unstable of `stmt_expr_attributes`. /// It can be removed once that feature is stabilized. - fn visit_method_receiver_expr(&mut self, ex: &'ast Expr) { + fn visit_method_receiver_expr(&mut self, ex: &'ast Expr) -> Self::Result { self.visit_expr(ex) } - fn visit_expr_post(&mut self, _ex: &'ast Expr) {} - fn visit_ty(&mut self, t: &'ast Ty) { + fn visit_expr_post(&mut self, _ex: &'ast Expr) -> Self::Result { + Self::Result::output() + } + fn visit_ty(&mut self, t: &'ast Ty) -> Self::Result { walk_ty(self, t) } - fn visit_generic_param(&mut self, param: &'ast GenericParam) { + fn visit_generic_param(&mut self, param: &'ast GenericParam) -> Self::Result { walk_generic_param(self, param) } - fn visit_generics(&mut self, g: &'ast Generics) { + fn visit_generics(&mut self, g: &'ast Generics) -> Self::Result { walk_generics(self, g) } - fn visit_closure_binder(&mut self, b: &'ast ClosureBinder) { + fn visit_closure_binder(&mut self, b: &'ast ClosureBinder) -> Self::Result { walk_closure_binder(self, b) } - fn visit_where_predicate(&mut self, p: &'ast WherePredicate) { + fn visit_where_predicate(&mut self, p: &'ast WherePredicate) -> Self::Result { walk_where_predicate(self, p) } - fn visit_fn(&mut self, fk: FnKind<'ast>, _: Span, _: NodeId) { + fn visit_fn(&mut self, fk: FnKind<'ast>, _: Span, _: NodeId) -> Self::Result { walk_fn(self, fk) } - fn visit_assoc_item(&mut self, i: &'ast AssocItem, ctxt: AssocCtxt) { + fn visit_assoc_item(&mut self, i: &'ast AssocItem, ctxt: AssocCtxt) -> Self::Result { walk_assoc_item(self, i, ctxt) } - fn visit_trait_ref(&mut self, t: &'ast TraitRef) { + fn visit_trait_ref(&mut self, t: &'ast TraitRef) -> Self::Result { walk_trait_ref(self, t) } - fn visit_param_bound(&mut self, bounds: &'ast GenericBound, _ctxt: BoundKind) { + fn visit_param_bound(&mut self, bounds: &'ast GenericBound, _ctxt: BoundKind) -> Self::Result { walk_param_bound(self, bounds) } - fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef) { + fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef) -> Self::Result { walk_poly_trait_ref(self, t) } - fn visit_variant_data(&mut self, s: &'ast VariantData) { + fn visit_variant_data(&mut self, s: &'ast VariantData) -> Self::Result { walk_struct_def(self, s) } - fn visit_field_def(&mut self, s: &'ast FieldDef) { + fn visit_field_def(&mut self, s: &'ast FieldDef) -> Self::Result { walk_field_def(self, s) } - fn visit_enum_def(&mut self, enum_definition: &'ast EnumDef) { + fn visit_enum_def(&mut self, enum_definition: &'ast EnumDef) -> Self::Result { walk_enum_def(self, enum_definition) } - fn visit_variant(&mut self, v: &'ast Variant) { + fn visit_variant(&mut self, v: &'ast Variant) -> Self::Result { walk_variant(self, v) } - fn visit_variant_discr(&mut self, discr: &'ast AnonConst) { - self.visit_anon_const(discr); + fn visit_variant_discr(&mut self, discr: &'ast AnonConst) -> Self::Result { + self.visit_anon_const(discr) } - fn visit_label(&mut self, label: &'ast Label) { + fn visit_label(&mut self, label: &'ast Label) -> Self::Result { walk_label(self, label) } - fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, _: LifetimeCtxt) { + fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, _: LifetimeCtxt) -> Self::Result { walk_lifetime(self, lifetime) } - fn visit_mac_call(&mut self, mac: &'ast MacCall) { + fn visit_mac_call(&mut self, mac: &'ast MacCall) -> Self::Result { walk_mac(self, mac) } - fn visit_mac_def(&mut self, _mac: &'ast MacroDef, _id: NodeId) { - // Nothing to do + fn visit_mac_def(&mut self, _mac: &'ast MacroDef, _id: NodeId) -> Self::Result { + Self::Result::output() } - fn visit_path(&mut self, path: &'ast Path, _id: NodeId) { + fn visit_path(&mut self, path: &'ast Path, _id: NodeId) -> Self::Result { walk_path(self, path) } - fn visit_use_tree(&mut self, use_tree: &'ast UseTree, id: NodeId, _nested: bool) { + fn visit_use_tree( + &mut self, + use_tree: &'ast UseTree, + id: NodeId, + _nested: bool, + ) -> Self::Result { walk_use_tree(self, use_tree, id) } - fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) { + fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) -> Self::Result { walk_path_segment(self, path_segment) } - fn visit_generic_args(&mut self, generic_args: &'ast GenericArgs) { + fn visit_generic_args(&mut self, generic_args: &'ast GenericArgs) -> Self::Result { walk_generic_args(self, generic_args) } - fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArg) { + fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArg) -> Self::Result { walk_generic_arg(self, generic_arg) } - fn visit_assoc_constraint(&mut self, constraint: &'ast AssocConstraint) { + fn visit_assoc_constraint(&mut self, constraint: &'ast AssocConstraint) -> Self::Result { walk_assoc_constraint(self, constraint) } - fn visit_attribute(&mut self, attr: &'ast Attribute) { + fn visit_attribute(&mut self, attr: &'ast Attribute) -> Self::Result { walk_attribute(self, attr) } - fn visit_vis(&mut self, vis: &'ast Visibility) { + fn visit_vis(&mut self, vis: &'ast Visibility) -> Self::Result { walk_vis(self, vis) } - fn visit_fn_ret_ty(&mut self, ret_ty: &'ast FnRetTy) { + fn visit_fn_ret_ty(&mut self, ret_ty: &'ast FnRetTy) -> Self::Result { walk_fn_ret_ty(self, ret_ty) } - fn visit_fn_header(&mut self, _header: &'ast FnHeader) { - // Nothing to do + fn visit_fn_header(&mut self, _header: &'ast FnHeader) -> Self::Result { + Self::Result::output() } - fn visit_expr_field(&mut self, f: &'ast ExprField) { + fn visit_expr_field(&mut self, f: &'ast ExprField) -> Self::Result { walk_expr_field(self, f) } - fn visit_pat_field(&mut self, fp: &'ast PatField) { + fn visit_pat_field(&mut self, fp: &'ast PatField) -> Self::Result { walk_pat_field(self, fp) } - fn visit_crate(&mut self, krate: &'ast Crate) { + fn visit_crate(&mut self, krate: &'ast Crate) -> Self::Result { walk_crate(self, krate) } - fn visit_inline_asm(&mut self, asm: &'ast InlineAsm) { + fn visit_inline_asm(&mut self, asm: &'ast InlineAsm) -> Self::Result { walk_inline_asm(self, asm) } - fn visit_format_args(&mut self, fmt: &'ast FormatArgs) { + fn visit_format_args(&mut self, fmt: &'ast FormatArgs) -> Self::Result { walk_format_args(self, fmt) } - fn visit_inline_asm_sym(&mut self, sym: &'ast InlineAsmSym) { + fn visit_inline_asm_sym(&mut self, sym: &'ast InlineAsmSym) -> Self::Result { walk_inline_asm_sym(self, sym) } - fn visit_capture_by(&mut self, _capture_by: &'ast CaptureBy) { - // Nothing to do + fn visit_capture_by(&mut self, _capture_by: &'ast CaptureBy) -> Self::Result { + Self::Result::output() } } #[macro_export] macro_rules! walk_list { ($visitor: expr, $method: ident, $list: expr $(, $($extra_args: expr),* )?) => { - { - #[allow(for_loops_over_fallibles)] - for elem in $list { - $visitor.$method(elem $(, $($extra_args,)* )?) - } + for elem in $list { + $crate::try_visit!($visitor.$method(elem $(, $($extra_args,)* )?)); } } } -pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) { +#[macro_export] +macro_rules! visit_opt { + ($visitor: expr, $method: ident, $opt: expr $(, $($extra_args: expr),* )?) => { + if let Some(x) = $opt { + $crate::try_visit!($visitor.$method(x $(, $($extra_args,)* )?)); + } + } +} + +pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) -> V::Result { walk_list!(visitor, visit_item, &krate.items); walk_list!(visitor, visit_attribute, &krate.attrs); + V::Result::output() } -pub fn walk_local<'a, V: Visitor<'a>>(visitor: &mut V, local: &'a Local) { - for attr in local.attrs.iter() { - visitor.visit_attribute(attr); - } - visitor.visit_pat(&local.pat); - walk_list!(visitor, visit_ty, &local.ty); +pub fn walk_local<'a, V: Visitor<'a>>(visitor: &mut V, local: &'a Local) -> V::Result { + walk_list!(visitor, visit_attribute, &local.attrs); + try_visit!(visitor.visit_pat(&local.pat)); + visit_opt!(visitor, visit_ty, &local.ty); if let Some((init, els)) = local.kind.init_else_opt() { - visitor.visit_expr(init); - walk_list!(visitor, visit_block, els); + try_visit!(visitor.visit_expr(init)); + visit_opt!(visitor, visit_block, els); } + V::Result::output() } -pub fn walk_label<'a, V: Visitor<'a>>(visitor: &mut V, label: &'a Label) { - visitor.visit_ident(label.ident); +pub fn walk_label<'a, V: Visitor<'a>>(visitor: &mut V, label: &'a Label) -> V::Result { + visitor.visit_ident(label.ident) } -pub fn walk_lifetime<'a, V: Visitor<'a>>(visitor: &mut V, lifetime: &'a Lifetime) { - visitor.visit_ident(lifetime.ident); +pub fn walk_lifetime<'a, V: Visitor<'a>>(visitor: &mut V, lifetime: &'a Lifetime) -> V::Result { + visitor.visit_ident(lifetime.ident) } -pub fn walk_poly_trait_ref<'a, V>(visitor: &mut V, trait_ref: &'a PolyTraitRef) +pub fn walk_poly_trait_ref<'a, V>(visitor: &mut V, trait_ref: &'a PolyTraitRef) -> V::Result where V: Visitor<'a>, { walk_list!(visitor, visit_generic_param, &trait_ref.bound_generic_params); - visitor.visit_trait_ref(&trait_ref.trait_ref); + visitor.visit_trait_ref(&trait_ref.trait_ref) } -pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitRef) { +pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitRef) -> V::Result { visitor.visit_path(&trait_ref.path, trait_ref.ref_id) } -pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { - visitor.visit_vis(&item.vis); - visitor.visit_ident(item.ident); +pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) -> V::Result { + try_visit!(visitor.visit_vis(&item.vis)); + try_visit!(visitor.visit_ident(item.ident)); match &item.kind { ItemKind::ExternCrate(_) => {} - ItemKind::Use(use_tree) => visitor.visit_use_tree(use_tree, item.id, false), + ItemKind::Use(use_tree) => try_visit!(visitor.visit_use_tree(use_tree, item.id, false)), ItemKind::Static(box StaticItem { ty, mutability: _, expr }) => { - visitor.visit_ty(ty); - walk_list!(visitor, visit_expr, expr); + try_visit!(visitor.visit_ty(ty)); + visit_opt!(visitor, visit_expr, expr); } ItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => { - visitor.visit_generics(generics); - visitor.visit_ty(ty); - walk_list!(visitor, visit_expr, expr); + try_visit!(visitor.visit_generics(generics)); + try_visit!(visitor.visit_ty(ty)); + visit_opt!(visitor, visit_expr, expr); } ItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => { let kind = FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, generics, body.as_deref()); - visitor.visit_fn(kind, item.span, item.id) + try_visit!(visitor.visit_fn(kind, item.span, item.id)); } ItemKind::Mod(_unsafety, mod_kind) => match mod_kind { ModKind::Loaded(items, _inline, _inner_span) => { - walk_list!(visitor, visit_item, items) + walk_list!(visitor, visit_item, items); } ModKind::Unloaded => {} }, ItemKind::ForeignMod(foreign_module) => { walk_list!(visitor, visit_foreign_item, &foreign_module.items); } - ItemKind::GlobalAsm(asm) => visitor.visit_inline_asm(asm), + ItemKind::GlobalAsm(asm) => try_visit!(visitor.visit_inline_asm(asm)), ItemKind::TyAlias(box TyAlias { generics, bounds, ty, .. }) => { - visitor.visit_generics(generics); + try_visit!(visitor.visit_generics(generics)); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); - walk_list!(visitor, visit_ty, ty); + visit_opt!(visitor, visit_ty, ty); } ItemKind::Enum(enum_definition, generics) => { - visitor.visit_generics(generics); - visitor.visit_enum_def(enum_definition) + try_visit!(visitor.visit_generics(generics)); + try_visit!(visitor.visit_enum_def(enum_definition)); } ItemKind::Impl(box Impl { defaultness: _, @@ -354,91 +420,97 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { self_ty, items, }) => { - visitor.visit_generics(generics); - walk_list!(visitor, visit_trait_ref, of_trait); - visitor.visit_ty(self_ty); + 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) => { - visitor.visit_generics(generics); - visitor.visit_variant_data(struct_definition); + try_visit!(visitor.visit_generics(generics)); + try_visit!(visitor.visit_variant_data(struct_definition)); } ItemKind::Trait(box Trait { unsafety: _, is_auto: _, generics, bounds, items }) => { - visitor.visit_generics(generics); + 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) => { - visitor.visit_generics(generics); + try_visit!(visitor.visit_generics(generics)); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); } - ItemKind::MacCall(mac) => visitor.visit_mac_call(mac), - ItemKind::MacroDef(ts) => visitor.visit_mac_def(ts, item.id), + ItemKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)), + ItemKind::MacroDef(ts) => try_visit!(visitor.visit_mac_def(ts, item.id)), ItemKind::Delegation(box Delegation { id, qself, path, body }) => { if let Some(qself) = qself { - visitor.visit_ty(&qself.ty); - } - visitor.visit_path(path, *id); - if let Some(body) = body { - visitor.visit_block(body); + try_visit!(visitor.visit_ty(&qself.ty)); } + try_visit!(visitor.visit_path(path, *id)); + visit_opt!(visitor, visit_block, body); } } walk_list!(visitor, visit_attribute, &item.attrs); + V::Result::output() } -pub fn walk_enum_def<'a, V: Visitor<'a>>(visitor: &mut V, enum_definition: &'a EnumDef) { +pub fn walk_enum_def<'a, V: Visitor<'a>>( + visitor: &mut V, + enum_definition: &'a EnumDef, +) -> V::Result { walk_list!(visitor, visit_variant, &enum_definition.variants); + V::Result::output() } -pub fn walk_variant<'a, V: Visitor<'a>>(visitor: &mut V, variant: &'a Variant) +pub fn walk_variant<'a, V: Visitor<'a>>(visitor: &mut V, variant: &'a Variant) -> V::Result where V: Visitor<'a>, { - visitor.visit_ident(variant.ident); - visitor.visit_vis(&variant.vis); - visitor.visit_variant_data(&variant.data); - walk_list!(visitor, visit_variant_discr, &variant.disr_expr); + try_visit!(visitor.visit_ident(variant.ident)); + try_visit!(visitor.visit_vis(&variant.vis)); + try_visit!(visitor.visit_variant_data(&variant.data)); + visit_opt!(visitor, visit_variant_discr, &variant.disr_expr); walk_list!(visitor, visit_attribute, &variant.attrs); + V::Result::output() } -pub fn walk_expr_field<'a, V: Visitor<'a>>(visitor: &mut V, f: &'a ExprField) { - visitor.visit_expr(&f.expr); - visitor.visit_ident(f.ident); - walk_list!(visitor, visit_attribute, f.attrs.iter()); +pub fn walk_expr_field<'a, V: Visitor<'a>>(visitor: &mut V, f: &'a ExprField) -> V::Result { + try_visit!(visitor.visit_expr(&f.expr)); + try_visit!(visitor.visit_ident(f.ident)); + walk_list!(visitor, visit_attribute, &f.attrs); + V::Result::output() } -pub fn walk_pat_field<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a PatField) { - visitor.visit_ident(fp.ident); - visitor.visit_pat(&fp.pat); - walk_list!(visitor, visit_attribute, fp.attrs.iter()); +pub fn walk_pat_field<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a PatField) -> V::Result { + try_visit!(visitor.visit_ident(fp.ident)); + try_visit!(visitor.visit_pat(&fp.pat)); + walk_list!(visitor, visit_attribute, &fp.attrs); + V::Result::output() } -pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) { +pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) -> V::Result { match &typ.kind { - TyKind::Slice(ty) | TyKind::Paren(ty) => visitor.visit_ty(ty), - TyKind::Ptr(mutable_type) => visitor.visit_ty(&mutable_type.ty), + TyKind::Slice(ty) | TyKind::Paren(ty) => try_visit!(visitor.visit_ty(ty)), + TyKind::Ptr(mutable_type) => try_visit!(visitor.visit_ty(&mutable_type.ty)), TyKind::Ref(opt_lifetime, mutable_type) => { - walk_list!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Ref); - visitor.visit_ty(&mutable_type.ty) + visit_opt!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Ref); + try_visit!(visitor.visit_ty(&mutable_type.ty)); } TyKind::Tup(tuple_element_types) => { walk_list!(visitor, visit_ty, tuple_element_types); } TyKind::BareFn(function_declaration) => { walk_list!(visitor, visit_generic_param, &function_declaration.generic_params); - walk_fn_decl(visitor, &function_declaration.decl); + try_visit!(walk_fn_decl(visitor, &function_declaration.decl)); } TyKind::Path(maybe_qself, path) => { if let Some(qself) = maybe_qself { - visitor.visit_ty(&qself.ty); + try_visit!(visitor.visit_ty(&qself.ty)); } - visitor.visit_path(path, typ.id); + try_visit!(visitor.visit_path(path, typ.id)); } TyKind::Array(ty, length) => { - visitor.visit_ty(ty); - visitor.visit_anon_const(length) + try_visit!(visitor.visit_ty(ty)); + try_visit!(visitor.visit_anon_const(length)); } TyKind::TraitObject(bounds, ..) => { walk_list!(visitor, visit_param_bound, bounds, BoundKind::TraitObject); @@ -446,48 +518,53 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) { TyKind::ImplTrait(_, bounds) => { walk_list!(visitor, visit_param_bound, bounds, BoundKind::Impl); } - TyKind::Typeof(expression) => visitor.visit_anon_const(expression), + TyKind::Typeof(expression) => try_visit!(visitor.visit_anon_const(expression)), TyKind::Infer | TyKind::ImplicitSelf | TyKind::Dummy | TyKind::Err(_) => {} - TyKind::MacCall(mac) => visitor.visit_mac_call(mac), + TyKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)), TyKind::Never | TyKind::CVarArgs => {} TyKind::AnonStruct(_, ref fields) | TyKind::AnonUnion(_, ref fields) => { - walk_list!(visitor, visit_field_def, fields) + walk_list!(visitor, visit_field_def, fields); } } + V::Result::output() } -pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) { - for segment in &path.segments { - visitor.visit_path_segment(segment); - } +pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) -> V::Result { + walk_list!(visitor, visit_path_segment, &path.segments); + V::Result::output() } -pub fn walk_use_tree<'a, V: Visitor<'a>>(visitor: &mut V, use_tree: &'a UseTree, id: NodeId) { - visitor.visit_path(&use_tree.prefix, id); - match &use_tree.kind { +pub fn walk_use_tree<'a, V: Visitor<'a>>( + visitor: &mut V, + use_tree: &'a UseTree, + id: NodeId, +) -> V::Result { + try_visit!(visitor.visit_path(&use_tree.prefix, id)); + match use_tree.kind { UseTreeKind::Simple(rename) => { // The extra IDs are handled during HIR lowering. - if let &Some(rename) = rename { - visitor.visit_ident(rename); - } + visit_opt!(visitor, visit_ident, rename); } UseTreeKind::Glob => {} - UseTreeKind::Nested(use_trees) => { + UseTreeKind::Nested(ref use_trees) => { for &(ref nested_tree, nested_id) in use_trees { - visitor.visit_use_tree(nested_tree, nested_id, true); + try_visit!(visitor.visit_use_tree(nested_tree, nested_id, true)); } } } + V::Result::output() } -pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V, segment: &'a PathSegment) { - visitor.visit_ident(segment.ident); - if let Some(args) = &segment.args { - visitor.visit_generic_args(args); - } +pub fn walk_path_segment<'a, V: Visitor<'a>>( + visitor: &mut V, + segment: &'a PathSegment, +) -> V::Result { + try_visit!(visitor.visit_ident(segment.ident)); + visit_opt!(visitor, visit_generic_args, &segment.args); + V::Result::output() } -pub fn walk_generic_args<'a, V>(visitor: &mut V, generic_args: &'a GenericArgs) +pub fn walk_generic_args<'a, V>(visitor: &mut V, generic_args: &'a GenericArgs) -> V::Result where V: Visitor<'a>, { @@ -495,19 +572,22 @@ where GenericArgs::AngleBracketed(data) => { for arg in &data.args { match arg { - AngleBracketedArg::Arg(a) => visitor.visit_generic_arg(a), - AngleBracketedArg::Constraint(c) => visitor.visit_assoc_constraint(c), + AngleBracketedArg::Arg(a) => try_visit!(visitor.visit_generic_arg(a)), + AngleBracketedArg::Constraint(c) => { + try_visit!(visitor.visit_assoc_constraint(c)) + } } } } GenericArgs::Parenthesized(data) => { walk_list!(visitor, visit_ty, &data.inputs); - visitor.visit_fn_ret_ty(&data.output); + try_visit!(visitor.visit_fn_ret_ty(&data.output)); } } + V::Result::output() } -pub fn walk_generic_arg<'a, V>(visitor: &mut V, generic_arg: &'a GenericArg) +pub fn walk_generic_arg<'a, V>(visitor: &mut V, generic_arg: &'a GenericArg) -> V::Result where V: Visitor<'a>, { @@ -518,127 +598,141 @@ where } } -pub fn walk_assoc_constraint<'a, V: Visitor<'a>>(visitor: &mut V, constraint: &'a AssocConstraint) { - visitor.visit_ident(constraint.ident); - if let Some(gen_args) = &constraint.gen_args { - visitor.visit_generic_args(gen_args); - } +pub fn walk_assoc_constraint<'a, V: Visitor<'a>>( + visitor: &mut V, + constraint: &'a AssocConstraint, +) -> V::Result { + try_visit!(visitor.visit_ident(constraint.ident)); + visit_opt!(visitor, visit_generic_args, &constraint.gen_args); match &constraint.kind { AssocConstraintKind::Equality { term } => match term { - Term::Ty(ty) => visitor.visit_ty(ty), - Term::Const(c) => visitor.visit_anon_const(c), + Term::Ty(ty) => try_visit!(visitor.visit_ty(ty)), + Term::Const(c) => try_visit!(visitor.visit_anon_const(c)), }, AssocConstraintKind::Bound { bounds } => { walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); } } + V::Result::output() } -pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) { +pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Result { match &pattern.kind { PatKind::TupleStruct(opt_qself, path, elems) => { if let Some(qself) = opt_qself { - visitor.visit_ty(&qself.ty); + try_visit!(visitor.visit_ty(&qself.ty)); } - visitor.visit_path(path, pattern.id); + try_visit!(visitor.visit_path(path, pattern.id)); walk_list!(visitor, visit_pat, elems); } PatKind::Path(opt_qself, path) => { if let Some(qself) = opt_qself { - visitor.visit_ty(&qself.ty); + try_visit!(visitor.visit_ty(&qself.ty)); } - visitor.visit_path(path, pattern.id) + try_visit!(visitor.visit_path(path, pattern.id)) } PatKind::Struct(opt_qself, path, fields, _) => { if let Some(qself) = opt_qself { - visitor.visit_ty(&qself.ty); + try_visit!(visitor.visit_ty(&qself.ty)); } - visitor.visit_path(path, pattern.id); + try_visit!(visitor.visit_path(path, pattern.id)); walk_list!(visitor, visit_pat_field, fields); } PatKind::Box(subpattern) | PatKind::Ref(subpattern, _) | PatKind::Paren(subpattern) => { - visitor.visit_pat(subpattern) + try_visit!(visitor.visit_pat(subpattern)); } PatKind::Ident(_, ident, optional_subpattern) => { - visitor.visit_ident(*ident); - walk_list!(visitor, visit_pat, optional_subpattern); + try_visit!(visitor.visit_ident(*ident)); + visit_opt!(visitor, visit_pat, optional_subpattern); } - PatKind::Lit(expression) => visitor.visit_expr(expression), + PatKind::Lit(expression) => try_visit!(visitor.visit_expr(expression)), PatKind::Range(lower_bound, upper_bound, _) => { - walk_list!(visitor, visit_expr, lower_bound); - walk_list!(visitor, visit_expr, upper_bound); + visit_opt!(visitor, visit_expr, lower_bound); + visit_opt!(visitor, visit_expr, upper_bound); } PatKind::Wild | PatKind::Rest | PatKind::Never | PatKind::Err(_) => {} PatKind::Tuple(elems) | PatKind::Slice(elems) | PatKind::Or(elems) => { walk_list!(visitor, visit_pat, elems); } - PatKind::MacCall(mac) => visitor.visit_mac_call(mac), + PatKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)), } + V::Result::output() } -pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignItem) { +pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignItem) -> V::Result { let &Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = item; - visitor.visit_vis(vis); - visitor.visit_ident(ident); + try_visit!(visitor.visit_vis(vis)); + try_visit!(visitor.visit_ident(ident)); walk_list!(visitor, visit_attribute, attrs); match kind { ForeignItemKind::Static(ty, _, expr) => { - visitor.visit_ty(ty); - walk_list!(visitor, visit_expr, expr); + try_visit!(visitor.visit_ty(ty)); + visit_opt!(visitor, visit_expr, expr); } ForeignItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => { let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body.as_deref()); - visitor.visit_fn(kind, span, id); + try_visit!(visitor.visit_fn(kind, span, id)); } ForeignItemKind::TyAlias(box TyAlias { generics, bounds, ty, .. }) => { - visitor.visit_generics(generics); + try_visit!(visitor.visit_generics(generics)); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); - walk_list!(visitor, visit_ty, ty); + visit_opt!(visitor, visit_ty, ty); } ForeignItemKind::MacCall(mac) => { - visitor.visit_mac_call(mac); + try_visit!(visitor.visit_mac_call(mac)); } } + V::Result::output() } -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) -> V::Result { match bound { GenericBound::Trait(typ, _modifier) => visitor.visit_poly_trait_ref(typ), GenericBound::Outlives(lifetime) => visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound), } } -pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a GenericParam) { - visitor.visit_ident(param.ident); - walk_list!(visitor, visit_attribute, param.attrs.iter()); +pub fn walk_generic_param<'a, V: Visitor<'a>>( + visitor: &mut V, + param: &'a GenericParam, +) -> V::Result { + try_visit!(visitor.visit_ident(param.ident)); + walk_list!(visitor, visit_attribute, ¶m.attrs); walk_list!(visitor, visit_param_bound, ¶m.bounds, BoundKind::Bound); match ¶m.kind { GenericParamKind::Lifetime => (), - GenericParamKind::Type { default } => walk_list!(visitor, visit_ty, default), + GenericParamKind::Type { default } => visit_opt!(visitor, visit_ty, default), GenericParamKind::Const { ty, default, .. } => { - visitor.visit_ty(ty); - if let Some(default) = default { - visitor.visit_anon_const(default); - } + try_visit!(visitor.visit_ty(ty)); + visit_opt!(visitor, visit_anon_const, default); } } + V::Result::output() } -pub fn walk_generics<'a, V: Visitor<'a>>(visitor: &mut V, generics: &'a Generics) { +pub fn walk_generics<'a, V: Visitor<'a>>(visitor: &mut V, generics: &'a Generics) -> V::Result { walk_list!(visitor, visit_generic_param, &generics.params); walk_list!(visitor, visit_where_predicate, &generics.where_clause.predicates); + V::Result::output() } -pub fn walk_closure_binder<'a, V: Visitor<'a>>(visitor: &mut V, binder: &'a ClosureBinder) { +pub fn walk_closure_binder<'a, V: Visitor<'a>>( + visitor: &mut V, + binder: &'a ClosureBinder, +) -> V::Result { match binder { ClosureBinder::NotPresent => {} ClosureBinder::For { generic_params, span: _ } => { walk_list!(visitor, visit_generic_param, generic_params) } } + V::Result::output() } -pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a WherePredicate) { +pub fn walk_where_predicate<'a, V: Visitor<'a>>( + visitor: &mut V, + predicate: &'a WherePredicate, +) -> V::Result { match predicate { WherePredicate::BoundPredicate(WhereBoundPredicate { bounded_ty, @@ -646,181 +740,196 @@ pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a bound_generic_params, .. }) => { - visitor.visit_ty(bounded_ty); + try_visit!(visitor.visit_ty(bounded_ty)); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); walk_list!(visitor, visit_generic_param, bound_generic_params); } WherePredicate::RegionPredicate(WhereRegionPredicate { lifetime, bounds, .. }) => { - visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound); + try_visit!(visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound)); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); } WherePredicate::EqPredicate(WhereEqPredicate { lhs_ty, rhs_ty, .. }) => { - visitor.visit_ty(lhs_ty); - visitor.visit_ty(rhs_ty); + try_visit!(visitor.visit_ty(lhs_ty)); + try_visit!(visitor.visit_ty(rhs_ty)); } } + V::Result::output() } -pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy) { +pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy) -> V::Result { if let FnRetTy::Ty(output_ty) = ret_ty { - visitor.visit_ty(output_ty) + try_visit!(visitor.visit_ty(output_ty)); } + V::Result::output() } -pub fn walk_fn_decl<'a, V: Visitor<'a>>(visitor: &mut V, function_declaration: &'a FnDecl) { - for param in &function_declaration.inputs { - visitor.visit_param(param); - } - visitor.visit_fn_ret_ty(&function_declaration.output); +pub fn walk_fn_decl<'a, V: Visitor<'a>>( + visitor: &mut V, + function_declaration: &'a FnDecl, +) -> V::Result { + walk_list!(visitor, visit_param, &function_declaration.inputs); + visitor.visit_fn_ret_ty(&function_declaration.output) } -pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) { +pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Result { match kind { FnKind::Fn(_, _, sig, _, generics, body) => { - visitor.visit_generics(generics); - visitor.visit_fn_header(&sig.header); - walk_fn_decl(visitor, &sig.decl); - walk_list!(visitor, visit_block, body); + try_visit!(visitor.visit_generics(generics)); + try_visit!(visitor.visit_fn_header(&sig.header)); + try_visit!(walk_fn_decl(visitor, &sig.decl)); + visit_opt!(visitor, visit_block, body); } FnKind::Closure(binder, decl, body) => { - visitor.visit_closure_binder(binder); - walk_fn_decl(visitor, decl); - visitor.visit_expr(body); + try_visit!(visitor.visit_closure_binder(binder)); + try_visit!(walk_fn_decl(visitor, decl)); + try_visit!(visitor.visit_expr(body)); } } + V::Result::output() } -pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem, ctxt: AssocCtxt) { +pub fn walk_assoc_item<'a, V: Visitor<'a>>( + visitor: &mut V, + item: &'a AssocItem, + ctxt: AssocCtxt, +) -> V::Result { let &Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = item; - visitor.visit_vis(vis); - visitor.visit_ident(ident); + try_visit!(visitor.visit_vis(vis)); + try_visit!(visitor.visit_ident(ident)); walk_list!(visitor, visit_attribute, attrs); match kind { AssocItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => { - visitor.visit_generics(generics); - visitor.visit_ty(ty); - walk_list!(visitor, visit_expr, expr); + try_visit!(visitor.visit_generics(generics)); + try_visit!(visitor.visit_ty(ty)); + visit_opt!(visitor, visit_expr, expr); } AssocItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => { let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, generics, body.as_deref()); - visitor.visit_fn(kind, span, id); + try_visit!(visitor.visit_fn(kind, span, id)); } AssocItemKind::Type(box TyAlias { generics, bounds, ty, .. }) => { - visitor.visit_generics(generics); + try_visit!(visitor.visit_generics(generics)); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); - walk_list!(visitor, visit_ty, ty); + visit_opt!(visitor, visit_ty, ty); } AssocItemKind::MacCall(mac) => { - visitor.visit_mac_call(mac); + try_visit!(visitor.visit_mac_call(mac)); } AssocItemKind::Delegation(box Delegation { id, qself, path, body }) => { if let Some(qself) = qself { visitor.visit_ty(&qself.ty); } - visitor.visit_path(path, *id); - if let Some(body) = body { - visitor.visit_block(body); - } + try_visit!(visitor.visit_path(path, *id)); + visit_opt!(visitor, visit_block, body); } } + V::Result::output() } -pub fn walk_struct_def<'a, V: Visitor<'a>>(visitor: &mut V, struct_definition: &'a VariantData) { +pub fn walk_struct_def<'a, V: Visitor<'a>>( + visitor: &mut V, + struct_definition: &'a VariantData, +) -> V::Result { walk_list!(visitor, visit_field_def, struct_definition.fields()); + V::Result::output() } -pub fn walk_field_def<'a, V: Visitor<'a>>(visitor: &mut V, field: &'a FieldDef) { - visitor.visit_vis(&field.vis); - if let Some(ident) = field.ident { - visitor.visit_ident(ident); - } - visitor.visit_ty(&field.ty); +pub fn walk_field_def<'a, V: Visitor<'a>>(visitor: &mut V, field: &'a FieldDef) -> V::Result { + try_visit!(visitor.visit_vis(&field.vis)); + visit_opt!(visitor, visit_ident, field.ident); + try_visit!(visitor.visit_ty(&field.ty)); walk_list!(visitor, visit_attribute, &field.attrs); + V::Result::output() } -pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) { +pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) -> V::Result { walk_list!(visitor, visit_stmt, &block.stmts); + V::Result::output() } -pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) { +pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V::Result { match &statement.kind { - StmtKind::Local(local) => visitor.visit_local(local), - StmtKind::Item(item) => visitor.visit_item(item), - StmtKind::Expr(expr) | StmtKind::Semi(expr) => visitor.visit_expr(expr), + StmtKind::Local(local) => try_visit!(visitor.visit_local(local)), + StmtKind::Item(item) => try_visit!(visitor.visit_item(item)), + StmtKind::Expr(expr) | StmtKind::Semi(expr) => try_visit!(visitor.visit_expr(expr)), StmtKind::Empty => {} StmtKind::MacCall(mac) => { let MacCallStmt { mac, attrs, style: _, tokens: _ } = &**mac; - visitor.visit_mac_call(mac); - for attr in attrs.iter() { - visitor.visit_attribute(attr); - } + try_visit!(visitor.visit_mac_call(mac)); + walk_list!(visitor, visit_attribute, attrs); } } + V::Result::output() } -pub fn walk_mac<'a, V: Visitor<'a>>(visitor: &mut V, mac: &'a MacCall) { - visitor.visit_path(&mac.path, DUMMY_NODE_ID); +pub fn walk_mac<'a, V: Visitor<'a>>(visitor: &mut V, mac: &'a MacCall) -> V::Result { + visitor.visit_path(&mac.path, DUMMY_NODE_ID) } -pub fn walk_anon_const<'a, V: Visitor<'a>>(visitor: &mut V, constant: &'a AnonConst) { - visitor.visit_expr(&constant.value); +pub fn walk_anon_const<'a, V: Visitor<'a>>(visitor: &mut V, constant: &'a AnonConst) -> V::Result { + visitor.visit_expr(&constant.value) } -pub fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm) { +pub fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm) -> V::Result { for (op, _) in &asm.operands { match op { InlineAsmOperand::In { expr, .. } | InlineAsmOperand::Out { expr: Some(expr), .. } - | InlineAsmOperand::InOut { expr, .. } => visitor.visit_expr(expr), + | InlineAsmOperand::InOut { expr, .. } => try_visit!(visitor.visit_expr(expr)), InlineAsmOperand::Out { expr: None, .. } => {} InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { - visitor.visit_expr(in_expr); - if let Some(out_expr) = out_expr { - visitor.visit_expr(out_expr); - } + try_visit!(visitor.visit_expr(in_expr)); + visit_opt!(visitor, visit_expr, out_expr); + } + InlineAsmOperand::Const { anon_const, .. } => { + try_visit!(visitor.visit_anon_const(anon_const)) } - InlineAsmOperand::Const { anon_const, .. } => visitor.visit_anon_const(anon_const), - InlineAsmOperand::Sym { sym } => visitor.visit_inline_asm_sym(sym), + InlineAsmOperand::Sym { sym } => try_visit!(visitor.visit_inline_asm_sym(sym)), } } + V::Result::output() } -pub fn walk_inline_asm_sym<'a, V: Visitor<'a>>(visitor: &mut V, sym: &'a InlineAsmSym) { +pub fn walk_inline_asm_sym<'a, V: Visitor<'a>>( + visitor: &mut V, + sym: &'a InlineAsmSym, +) -> V::Result { if let Some(qself) = &sym.qself { - visitor.visit_ty(&qself.ty); + try_visit!(visitor.visit_ty(&qself.ty)); } - visitor.visit_path(&sym.path, sym.id); + visitor.visit_path(&sym.path, sym.id) } -pub fn walk_format_args<'a, V: Visitor<'a>>(visitor: &mut V, fmt: &'a FormatArgs) { +pub fn walk_format_args<'a, V: Visitor<'a>>(visitor: &mut V, fmt: &'a FormatArgs) -> V::Result { for arg in fmt.arguments.all_args() { if let FormatArgumentKind::Named(name) = arg.kind { - visitor.visit_ident(name); + try_visit!(visitor.visit_ident(name)); } - visitor.visit_expr(&arg.expr); + try_visit!(visitor.visit_expr(&arg.expr)); } + V::Result::output() } -pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { - walk_list!(visitor, visit_attribute, expression.attrs.iter()); +pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V::Result { + walk_list!(visitor, visit_attribute, &expression.attrs); match &expression.kind { ExprKind::Array(subexpressions) => { walk_list!(visitor, visit_expr, subexpressions); } - ExprKind::ConstBlock(anon_const) => visitor.visit_anon_const(anon_const), + ExprKind::ConstBlock(anon_const) => try_visit!(visitor.visit_anon_const(anon_const)), ExprKind::Repeat(element, count) => { - visitor.visit_expr(element); - visitor.visit_anon_const(count) + try_visit!(visitor.visit_expr(element)); + try_visit!(visitor.visit_anon_const(count)); } ExprKind::Struct(se) => { if let Some(qself) = &se.qself { - visitor.visit_ty(&qself.ty); + try_visit!(visitor.visit_ty(&qself.ty)); } - visitor.visit_path(&se.path, expression.id); + try_visit!(visitor.visit_path(&se.path, expression.id)); walk_list!(visitor, visit_expr_field, &se.fields); match &se.rest { - StructRest::Base(expr) => visitor.visit_expr(expr), + StructRest::Base(expr) => try_visit!(visitor.visit_expr(expr)), StructRest::Rest(_span) => {} StructRest::None => {} } @@ -829,51 +938,51 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { walk_list!(visitor, visit_expr, subexpressions); } ExprKind::Call(callee_expression, arguments) => { - visitor.visit_expr(callee_expression); + try_visit!(visitor.visit_expr(callee_expression)); walk_list!(visitor, visit_expr, arguments); } ExprKind::MethodCall(box MethodCall { seg, receiver, args, span: _ }) => { - visitor.visit_path_segment(seg); - visitor.visit_expr(receiver); + try_visit!(visitor.visit_path_segment(seg)); + try_visit!(visitor.visit_expr(receiver)); walk_list!(visitor, visit_expr, args); } ExprKind::Binary(_, left_expression, right_expression) => { - visitor.visit_expr(left_expression); - visitor.visit_expr(right_expression) + try_visit!(visitor.visit_expr(left_expression)); + try_visit!(visitor.visit_expr(right_expression)); } ExprKind::AddrOf(_, _, subexpression) | ExprKind::Unary(_, subexpression) => { - visitor.visit_expr(subexpression) + try_visit!(visitor.visit_expr(subexpression)); } ExprKind::Cast(subexpression, typ) | ExprKind::Type(subexpression, typ) => { - visitor.visit_expr(subexpression); - visitor.visit_ty(typ) + try_visit!(visitor.visit_expr(subexpression)); + try_visit!(visitor.visit_ty(typ)); } ExprKind::Let(pat, expr, _, _) => { - visitor.visit_pat(pat); - visitor.visit_expr(expr); + try_visit!(visitor.visit_pat(pat)); + try_visit!(visitor.visit_expr(expr)); } ExprKind::If(head_expression, if_block, optional_else) => { - visitor.visit_expr(head_expression); - visitor.visit_block(if_block); - walk_list!(visitor, visit_expr, optional_else); + try_visit!(visitor.visit_expr(head_expression)); + try_visit!(visitor.visit_block(if_block)); + visit_opt!(visitor, visit_expr, optional_else); } ExprKind::While(subexpression, block, opt_label) => { - walk_list!(visitor, visit_label, opt_label); - visitor.visit_expr(subexpression); - visitor.visit_block(block); + visit_opt!(visitor, visit_label, opt_label); + try_visit!(visitor.visit_expr(subexpression)); + try_visit!(visitor.visit_block(block)); } ExprKind::ForLoop { pat, iter, body, label, kind: _ } => { - walk_list!(visitor, visit_label, label); - visitor.visit_pat(pat); - visitor.visit_expr(iter); - visitor.visit_block(body); + visit_opt!(visitor, visit_label, label); + try_visit!(visitor.visit_pat(pat)); + try_visit!(visitor.visit_expr(iter)); + try_visit!(visitor.visit_block(body)); } ExprKind::Loop(block, opt_label, _) => { - walk_list!(visitor, visit_label, opt_label); - visitor.visit_block(block); + visit_opt!(visitor, visit_label, opt_label); + try_visit!(visitor.visit_block(block)); } ExprKind::Match(subexpression, arms) => { - visitor.visit_expr(subexpression); + try_visit!(visitor.visit_expr(subexpression)); walk_list!(visitor, visit_arm, arms); } ExprKind::Closure(box Closure { @@ -887,112 +996,117 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { fn_decl_span: _, fn_arg_span: _, }) => { - visitor.visit_capture_by(capture_clause); - visitor.visit_fn(FnKind::Closure(binder, fn_decl, body), expression.span, expression.id) + try_visit!(visitor.visit_capture_by(capture_clause)); + try_visit!(visitor.visit_fn( + FnKind::Closure(binder, fn_decl, body), + expression.span, + expression.id + )) } ExprKind::Block(block, opt_label) => { - walk_list!(visitor, visit_label, opt_label); - visitor.visit_block(block); + visit_opt!(visitor, visit_label, opt_label); + try_visit!(visitor.visit_block(block)); } - ExprKind::Gen(_, body, _) => { - visitor.visit_block(body); - } - ExprKind::Await(expr, _) => visitor.visit_expr(expr), + ExprKind::Gen(_, body, _) => try_visit!(visitor.visit_block(body)), + ExprKind::Await(expr, _) => try_visit!(visitor.visit_expr(expr)), ExprKind::Assign(lhs, rhs, _) => { - visitor.visit_expr(lhs); - visitor.visit_expr(rhs); + try_visit!(visitor.visit_expr(lhs)); + try_visit!(visitor.visit_expr(rhs)); } ExprKind::AssignOp(_, left_expression, right_expression) => { - visitor.visit_expr(left_expression); - visitor.visit_expr(right_expression); + try_visit!(visitor.visit_expr(left_expression)); + try_visit!(visitor.visit_expr(right_expression)); } ExprKind::Field(subexpression, ident) => { - visitor.visit_expr(subexpression); - visitor.visit_ident(*ident); + try_visit!(visitor.visit_expr(subexpression)); + try_visit!(visitor.visit_ident(*ident)); } ExprKind::Index(main_expression, index_expression, _) => { - visitor.visit_expr(main_expression); - visitor.visit_expr(index_expression) + try_visit!(visitor.visit_expr(main_expression)); + try_visit!(visitor.visit_expr(index_expression)); } ExprKind::Range(start, end, _) => { - walk_list!(visitor, visit_expr, start); - walk_list!(visitor, visit_expr, end); + visit_opt!(visitor, visit_expr, start); + visit_opt!(visitor, visit_expr, end); } ExprKind::Underscore => {} ExprKind::Path(maybe_qself, path) => { if let Some(qself) = maybe_qself { - visitor.visit_ty(&qself.ty); + try_visit!(visitor.visit_ty(&qself.ty)); } - visitor.visit_path(path, expression.id) + try_visit!(visitor.visit_path(path, expression.id)); } ExprKind::Break(opt_label, opt_expr) => { - walk_list!(visitor, visit_label, opt_label); - walk_list!(visitor, visit_expr, opt_expr); + visit_opt!(visitor, visit_label, opt_label); + visit_opt!(visitor, visit_expr, opt_expr); } ExprKind::Continue(opt_label) => { - walk_list!(visitor, visit_label, opt_label); + visit_opt!(visitor, visit_label, opt_label); } ExprKind::Ret(optional_expression) => { - walk_list!(visitor, visit_expr, optional_expression); + visit_opt!(visitor, visit_expr, optional_expression); } ExprKind::Yeet(optional_expression) => { - walk_list!(visitor, visit_expr, optional_expression); + visit_opt!(visitor, visit_expr, optional_expression); } - ExprKind::Become(expr) => visitor.visit_expr(expr), - ExprKind::MacCall(mac) => visitor.visit_mac_call(mac), - ExprKind::Paren(subexpression) => visitor.visit_expr(subexpression), - ExprKind::InlineAsm(asm) => visitor.visit_inline_asm(asm), - ExprKind::FormatArgs(f) => visitor.visit_format_args(f), + 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)), ExprKind::OffsetOf(container, fields) => { visitor.visit_ty(container); - for &field in fields { - visitor.visit_ident(field); - } + walk_list!(visitor, visit_ident, fields.iter().copied()); } ExprKind::Yield(optional_expression) => { - walk_list!(visitor, visit_expr, optional_expression); + visit_opt!(visitor, visit_expr, optional_expression); } - ExprKind::Try(subexpression) => visitor.visit_expr(subexpression), - ExprKind::TryBlock(body) => visitor.visit_block(body), + ExprKind::Try(subexpression) => try_visit!(visitor.visit_expr(subexpression)), + ExprKind::TryBlock(body) => try_visit!(visitor.visit_block(body)), ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err => {} } visitor.visit_expr_post(expression) } -pub fn walk_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Param) { - walk_list!(visitor, visit_attribute, param.attrs.iter()); - visitor.visit_pat(¶m.pat); - visitor.visit_ty(¶m.ty); +pub fn walk_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Param) -> V::Result { + walk_list!(visitor, visit_attribute, ¶m.attrs); + try_visit!(visitor.visit_pat(¶m.pat)); + try_visit!(visitor.visit_ty(¶m.ty)); + V::Result::output() } -pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) { - visitor.visit_pat(&arm.pat); - walk_list!(visitor, visit_expr, &arm.guard); - walk_list!(visitor, visit_expr, &arm.body); +pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) -> V::Result { + try_visit!(visitor.visit_pat(&arm.pat)); + visit_opt!(visitor, visit_expr, &arm.guard); + visit_opt!(visitor, visit_expr, &arm.body); walk_list!(visitor, visit_attribute, &arm.attrs); + V::Result::output() } -pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) { +pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) -> V::Result { if let VisibilityKind::Restricted { ref path, id, shorthand: _ } = vis.kind { - visitor.visit_path(path, id); + try_visit!(visitor.visit_path(path, id)); } + V::Result::output() } -pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) { +pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) -> V::Result { match &attr.kind { - AttrKind::Normal(normal) => walk_attr_args(visitor, &normal.item.args), + AttrKind::Normal(normal) => try_visit!(walk_attr_args(visitor, &normal.item.args)), AttrKind::DocComment(..) => {} } + V::Result::output() } -pub fn walk_attr_args<'a, V: Visitor<'a>>(visitor: &mut V, args: &'a AttrArgs) { +pub fn walk_attr_args<'a, V: Visitor<'a>>(visitor: &mut V, args: &'a AttrArgs) -> V::Result { match args { AttrArgs::Empty => {} AttrArgs::Delimited(_) => {} - AttrArgs::Eq(_eq_span, AttrArgsEq::Ast(expr)) => visitor.visit_expr(expr), + AttrArgs::Eq(_eq_span, AttrArgsEq::Ast(expr)) => try_visit!(visitor.visit_expr(expr)), AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => { unreachable!("in literal form when walking mac args eq: {:?}", lit) } } + V::Result::output() } diff --git a/compiler/rustc_borrowck/src/type_check/canonical.rs b/compiler/rustc_borrowck/src/type_check/canonical.rs index fc600af1b76f0..e5ebf97cfc4ee 100644 --- a/compiler/rustc_borrowck/src/type_check/canonical.rs +++ b/compiler/rustc_borrowck/src/type_check/canonical.rs @@ -100,7 +100,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { locations: Locations, ) { for (predicate, span) in instantiated_predicates { - debug!(?predicate); + debug!(?span, ?predicate); let category = ConstraintCategory::Predicate(span); let predicate = self.normalize_with_category(predicate, locations, category); self.prove_predicate(predicate, locations, category); diff --git a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs index c97e31701669c..de75a9857f8b5 100644 --- a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs +++ b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs @@ -8,7 +8,7 @@ use rustc_middle::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, Const use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::{self, GenericArgKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt}; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::Span; use rustc_trait_selection::solve::deeply_normalize; use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp; use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput}; @@ -183,7 +183,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> { // we don't actually use this for anything, but // the `TypeOutlives` code needs an origin. - let origin = infer::RelateParamBound(DUMMY_SP, t1, None); + let origin = infer::RelateParamBound(self.span, t1, None); TypeOutlives::new( &mut *self, diff --git a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs index 2e0caf4481902..356f0024c071e 100644 --- a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs +++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs @@ -10,7 +10,7 @@ use rustc_middle::mir::ConstraintCategory; use rustc_middle::traits::query::OutlivesBound; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::{self, RegionVid, Ty, TypeVisitableExt}; -use rustc_span::{ErrorGuaranteed, DUMMY_SP}; +use rustc_span::{ErrorGuaranteed, Span}; use rustc_trait_selection::solve::deeply_normalize; use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt; use rustc_trait_selection::traits::query::type_op::{self, TypeOp}; @@ -269,7 +269,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> { debug!("build: input_or_output={:?}", ty); // We add implied bounds from both the unnormalized and normalized ty. // See issue #87748 - let constraints_unnorm = self.add_implied_bounds(ty); + let constraints_unnorm = self.add_implied_bounds(ty, span); if let Some(c) = constraints_unnorm { constraints.push(c) } @@ -299,7 +299,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> { // ``` // Both &Self::Bar and &() are WF if ty != norm_ty { - let constraints_norm = self.add_implied_bounds(norm_ty); + let constraints_norm = self.add_implied_bounds(norm_ty, span); if let Some(c) = constraints_norm { constraints.push(c) } @@ -323,7 +323,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> { // We currently add implied bounds from the normalized ty only. // This is more conservative and matches wfcheck behavior. - let c = self.add_implied_bounds(norm_ty); + let c = self.add_implied_bounds(norm_ty, span); constraints.extend(c); } } @@ -361,11 +361,15 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> { /// the same time, compute and add any implied bounds that come /// from this local. #[instrument(level = "debug", skip(self))] - fn add_implied_bounds(&mut self, ty: Ty<'tcx>) -> Option<&'tcx QueryRegionConstraints<'tcx>> { + fn add_implied_bounds( + &mut self, + ty: Ty<'tcx>, + span: Span, + ) -> Option<&'tcx QueryRegionConstraints<'tcx>> { let TypeOpOutput { output: bounds, constraints, .. } = self .param_env .and(type_op::implied_outlives_bounds::ImpliedOutlivesBounds { ty }) - .fully_perform(self.infcx, DUMMY_SP) + .fully_perform(self.infcx, span) .map_err(|_: ErrorGuaranteed| debug!("failed to compute implied bounds {:?}", ty)) .ok()?; debug!(?bounds, ?constraints); diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 64469727d0dbe..f96c2cbd8c05b 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -37,7 +37,7 @@ use rustc_mir_dataflow::points::DenseLocationMap; use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::source_map::Spanned; use rustc_span::symbol::sym; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::Span; use rustc_target::abi::{FieldIdx, FIRST_VARIANT}; use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints; use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp; @@ -1014,7 +1014,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ) -> Self { let mut checker = Self { infcx, - last_span: DUMMY_SP, + last_span: body.span, body, user_type_annotations: &body.user_type_annotations, param_env, @@ -2766,7 +2766,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.param_env, self.known_type_outlives_obligations, locations, - DUMMY_SP, // irrelevant; will be overridden. + self.body.span, // irrelevant; will be overridden. ConstraintCategory::Boring, // same as above. self.borrowck_context.constraints, ) diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 0914452365856..f602276aad243 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -96,7 +96,7 @@ impl Annotatable { } } - pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) { + pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) -> V::Result { match self { Annotatable::Item(item) => visitor.visit_item(item), Annotatable::TraitItem(item) => visitor.visit_assoc_item(item, AssocCtxt::Trait), diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 9c411be9ff938..2752d3ebd68b8 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -14,7 +14,8 @@ use rustc_ast::mut_visit::*; use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter}; use rustc_ast::tokenstream::TokenStream; -use rustc_ast::visit::{self, AssocCtxt, Visitor}; +use rustc_ast::visit::{self, AssocCtxt, Visitor, VisitorResult}; +use rustc_ast::{try_visit, walk_list}; use rustc_ast::{AssocItemKind, AstNodeWrapper, AttrArgs, AttrStyle, AttrVec, ExprKind}; use rustc_ast::{ForeignItemKind, HasAttrs, HasNodeId}; use rustc_ast::{Inline, ItemKind, MacStmtStyle, MetaItemKind, ModKind}; @@ -143,16 +144,15 @@ macro_rules! ast_fragments { } } - pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) { + pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) -> V::Result { match self { - AstFragment::OptExpr(Some(expr)) => visitor.visit_expr(expr), + AstFragment::OptExpr(Some(expr)) => try_visit!(visitor.visit_expr(expr)), AstFragment::OptExpr(None) => {} - AstFragment::MethodReceiverExpr(expr) => visitor.visit_method_receiver_expr(expr), - $($(AstFragment::$Kind(ast) => visitor.$visit_ast(ast),)?)* - $($(AstFragment::$Kind(ast) => for ast_elt in &ast[..] { - visitor.$visit_ast_elt(ast_elt, $($args)*); - })?)* + AstFragment::MethodReceiverExpr(expr) => try_visit!(visitor.visit_method_receiver_expr(expr)), + $($(AstFragment::$Kind(ast) => try_visit!(visitor.$visit_ast(ast)),)?)* + $($(AstFragment::$Kind(ast) => walk_list!(visitor, $visit_ast_elt, &ast[..], $($args)*),)?)* } + V::Result::output() } } diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index e9337dd3586ea..1c38a45d3a32f 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -65,7 +65,8 @@ //! example coroutine inference, and possibly also HIR borrowck. use crate::hir::*; -use rustc_ast::walk_list; +use rustc_ast::visit::VisitorResult; +use rustc_ast::{try_visit, visit_opt, walk_list}; use rustc_ast::{Attribute, Label}; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::{Ident, Symbol}; @@ -216,6 +217,10 @@ pub trait Visitor<'v>: Sized { /// and fixed appropriately. type NestedFilter: NestedFilter<'v> = nested_filter::None; + /// The result type of the `visit_*` methods. Can be either `()`, + /// or `ControlFlow`. + type Result: VisitorResult = (); + /// If `type NestedFilter` is set to visit nested items, this method /// must also be overridden to provide a map to retrieve nested items. fn nested_visit_map(&mut self) -> Self::Map { @@ -233,287 +238,299 @@ pub trait Visitor<'v>: Sized { /// [`rustc_hir::intravisit`]. The only reason to override /// this method is if you want a nested pattern but cannot supply a /// [`Map`]; see `nested_visit_map` for advice. - fn visit_nested_item(&mut self, id: ItemId) { + fn visit_nested_item(&mut self, id: ItemId) -> Self::Result { if Self::NestedFilter::INTER { let item = self.nested_visit_map().item(id); - self.visit_item(item); + try_visit!(self.visit_item(item)); } + Self::Result::output() } /// Like `visit_nested_item()`, but for trait items. See /// `visit_nested_item()` for advice on when to override this /// method. - fn visit_nested_trait_item(&mut self, id: TraitItemId) { + fn visit_nested_trait_item(&mut self, id: TraitItemId) -> Self::Result { if Self::NestedFilter::INTER { let item = self.nested_visit_map().trait_item(id); - self.visit_trait_item(item); + try_visit!(self.visit_trait_item(item)); } + Self::Result::output() } /// Like `visit_nested_item()`, but for impl items. See /// `visit_nested_item()` for advice on when to override this /// method. - fn visit_nested_impl_item(&mut self, id: ImplItemId) { + fn visit_nested_impl_item(&mut self, id: ImplItemId) -> Self::Result { if Self::NestedFilter::INTER { let item = self.nested_visit_map().impl_item(id); - self.visit_impl_item(item); + try_visit!(self.visit_impl_item(item)); } + Self::Result::output() } /// Like `visit_nested_item()`, but for foreign items. See /// `visit_nested_item()` for advice on when to override this /// method. - fn visit_nested_foreign_item(&mut self, id: ForeignItemId) { + fn visit_nested_foreign_item(&mut self, id: ForeignItemId) -> Self::Result { if Self::NestedFilter::INTER { let item = self.nested_visit_map().foreign_item(id); - self.visit_foreign_item(item); + try_visit!(self.visit_foreign_item(item)); } + Self::Result::output() } /// Invoked to visit the body of a function, method or closure. Like /// `visit_nested_item`, does nothing by default unless you override /// `Self::NestedFilter`. - fn visit_nested_body(&mut self, id: BodyId) { + fn visit_nested_body(&mut self, id: BodyId) -> Self::Result { if Self::NestedFilter::INTRA { let body = self.nested_visit_map().body(id); - self.visit_body(body); + try_visit!(self.visit_body(body)); } + Self::Result::output() } - fn visit_param(&mut self, param: &'v Param<'v>) { + fn visit_param(&mut self, param: &'v Param<'v>) -> Self::Result { walk_param(self, param) } /// Visits the top-level item and (optionally) nested items / impl items. See /// `visit_nested_item` for details. - fn visit_item(&mut self, i: &'v Item<'v>) { + fn visit_item(&mut self, i: &'v Item<'v>) -> Self::Result { walk_item(self, i) } - fn visit_body(&mut self, b: &'v Body<'v>) { - walk_body(self, b); + fn visit_body(&mut self, b: &'v Body<'v>) -> Self::Result { + walk_body(self, b) } /////////////////////////////////////////////////////////////////////////// - fn visit_id(&mut self, _hir_id: HirId) { - // Nothing to do. + fn visit_id(&mut self, _hir_id: HirId) -> Self::Result { + Self::Result::output() } - fn visit_name(&mut self, _name: Symbol) { - // Nothing to do. + fn visit_name(&mut self, _name: Symbol) -> Self::Result { + Self::Result::output() } - fn visit_ident(&mut self, ident: Ident) { + fn visit_ident(&mut self, ident: Ident) -> Self::Result { walk_ident(self, ident) } - fn visit_mod(&mut self, m: &'v Mod<'v>, _s: Span, n: HirId) { + fn visit_mod(&mut self, m: &'v Mod<'v>, _s: Span, n: HirId) -> Self::Result { walk_mod(self, m, n) } - fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) { + fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) -> Self::Result { walk_foreign_item(self, i) } - fn visit_local(&mut self, l: &'v Local<'v>) { + fn visit_local(&mut self, l: &'v Local<'v>) -> Self::Result { walk_local(self, l) } - fn visit_block(&mut self, b: &'v Block<'v>) { + fn visit_block(&mut self, b: &'v Block<'v>) -> Self::Result { walk_block(self, b) } - fn visit_stmt(&mut self, s: &'v Stmt<'v>) { + fn visit_stmt(&mut self, s: &'v Stmt<'v>) -> Self::Result { walk_stmt(self, s) } - fn visit_arm(&mut self, a: &'v Arm<'v>) { + fn visit_arm(&mut self, a: &'v Arm<'v>) -> Self::Result { walk_arm(self, a) } - fn visit_pat(&mut self, p: &'v Pat<'v>) { + fn visit_pat(&mut self, p: &'v Pat<'v>) -> Self::Result { walk_pat(self, p) } - fn visit_pat_field(&mut self, f: &'v PatField<'v>) { + fn visit_pat_field(&mut self, f: &'v PatField<'v>) -> Self::Result { walk_pat_field(self, f) } - fn visit_array_length(&mut self, len: &'v ArrayLen) { + fn visit_array_length(&mut self, len: &'v ArrayLen) -> Self::Result { walk_array_len(self, len) } - fn visit_anon_const(&mut self, c: &'v AnonConst) { + fn visit_anon_const(&mut self, c: &'v AnonConst) -> Self::Result { walk_anon_const(self, c) } - fn visit_inline_const(&mut self, c: &'v ConstBlock) { + fn visit_inline_const(&mut self, c: &'v ConstBlock) -> Self::Result { walk_inline_const(self, c) } - fn visit_expr(&mut self, ex: &'v Expr<'v>) { + fn visit_expr(&mut self, ex: &'v Expr<'v>) -> Self::Result { walk_expr(self, ex) } - fn visit_expr_field(&mut self, field: &'v ExprField<'v>) { + fn visit_expr_field(&mut self, field: &'v ExprField<'v>) -> Self::Result { walk_expr_field(self, field) } - fn visit_ty(&mut self, t: &'v Ty<'v>) { + fn visit_ty(&mut self, t: &'v Ty<'v>) -> Self::Result { walk_ty(self, t) } - fn visit_generic_param(&mut self, p: &'v GenericParam<'v>) { + fn visit_generic_param(&mut self, p: &'v GenericParam<'v>) -> Self::Result { walk_generic_param(self, p) } - fn visit_const_param_default(&mut self, _param: HirId, ct: &'v AnonConst) { + fn visit_const_param_default(&mut self, _param: HirId, ct: &'v AnonConst) -> Self::Result { walk_const_param_default(self, ct) } - fn visit_generics(&mut self, g: &'v Generics<'v>) { + fn visit_generics(&mut self, g: &'v Generics<'v>) -> Self::Result { walk_generics(self, g) } - fn visit_where_predicate(&mut self, predicate: &'v WherePredicate<'v>) { + fn visit_where_predicate(&mut self, predicate: &'v WherePredicate<'v>) -> Self::Result { walk_where_predicate(self, predicate) } - fn visit_fn_ret_ty(&mut self, ret_ty: &'v FnRetTy<'v>) { + fn visit_fn_ret_ty(&mut self, ret_ty: &'v FnRetTy<'v>) -> Self::Result { walk_fn_ret_ty(self, ret_ty) } - fn visit_fn_decl(&mut self, fd: &'v FnDecl<'v>) { + fn visit_fn_decl(&mut self, fd: &'v FnDecl<'v>) -> Self::Result { walk_fn_decl(self, fd) } - fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl<'v>, b: BodyId, _: Span, id: LocalDefId) { + fn visit_fn( + &mut self, + fk: FnKind<'v>, + fd: &'v FnDecl<'v>, + b: BodyId, + _: Span, + id: LocalDefId, + ) -> Self::Result { walk_fn(self, fk, fd, b, id) } - fn visit_use(&mut self, path: &'v UsePath<'v>, hir_id: HirId) { + fn visit_use(&mut self, path: &'v UsePath<'v>, hir_id: HirId) -> Self::Result { walk_use(self, path, hir_id) } - fn visit_trait_item(&mut self, ti: &'v TraitItem<'v>) { + fn visit_trait_item(&mut self, ti: &'v TraitItem<'v>) -> Self::Result { walk_trait_item(self, ti) } - fn visit_trait_item_ref(&mut self, ii: &'v TraitItemRef) { + fn visit_trait_item_ref(&mut self, ii: &'v TraitItemRef) -> Self::Result { walk_trait_item_ref(self, ii) } - fn visit_impl_item(&mut self, ii: &'v ImplItem<'v>) { + fn visit_impl_item(&mut self, ii: &'v ImplItem<'v>) -> Self::Result { walk_impl_item(self, ii) } - fn visit_foreign_item_ref(&mut self, ii: &'v ForeignItemRef) { + fn visit_foreign_item_ref(&mut self, ii: &'v ForeignItemRef) -> Self::Result { walk_foreign_item_ref(self, ii) } - fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef) { + fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef) -> Self::Result { walk_impl_item_ref(self, ii) } - fn visit_trait_ref(&mut self, t: &'v TraitRef<'v>) { + fn visit_trait_ref(&mut self, t: &'v TraitRef<'v>) -> Self::Result { walk_trait_ref(self, t) } - fn visit_param_bound(&mut self, bounds: &'v GenericBound<'v>) { + fn visit_param_bound(&mut self, bounds: &'v GenericBound<'v>) -> Self::Result { walk_param_bound(self, bounds) } - fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef<'v>) { + fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef<'v>) -> Self::Result { walk_poly_trait_ref(self, t) } - fn visit_variant_data(&mut self, s: &'v VariantData<'v>) { + fn visit_variant_data(&mut self, s: &'v VariantData<'v>) -> Self::Result { walk_struct_def(self, s) } - fn visit_field_def(&mut self, s: &'v FieldDef<'v>) { + fn visit_field_def(&mut self, s: &'v FieldDef<'v>) -> Self::Result { walk_field_def(self, s) } - fn visit_enum_def(&mut self, enum_definition: &'v EnumDef<'v>, item_id: HirId) { + fn visit_enum_def(&mut self, enum_definition: &'v EnumDef<'v>, item_id: HirId) -> Self::Result { walk_enum_def(self, enum_definition, item_id) } - fn visit_variant(&mut self, v: &'v Variant<'v>) { + fn visit_variant(&mut self, v: &'v Variant<'v>) -> Self::Result { walk_variant(self, v) } - fn visit_label(&mut self, label: &'v Label) { + fn visit_label(&mut self, label: &'v Label) -> Self::Result { walk_label(self, label) } - fn visit_infer(&mut self, inf: &'v InferArg) { - walk_inf(self, inf); + fn visit_infer(&mut self, inf: &'v InferArg) -> Self::Result { + walk_inf(self, inf) } - fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg<'v>) { - walk_generic_arg(self, generic_arg); + fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg<'v>) -> Self::Result { + walk_generic_arg(self, generic_arg) } - fn visit_lifetime(&mut self, lifetime: &'v Lifetime) { + fn visit_lifetime(&mut self, lifetime: &'v Lifetime) -> Self::Result { walk_lifetime(self, lifetime) } // The span is that of the surrounding type/pattern/expr/whatever. - fn visit_qpath(&mut self, qpath: &'v QPath<'v>, id: HirId, _span: Span) { + fn visit_qpath(&mut self, qpath: &'v QPath<'v>, id: HirId, _span: Span) -> Self::Result { walk_qpath(self, qpath, id) } - fn visit_path(&mut self, path: &Path<'v>, _id: HirId) { + fn visit_path(&mut self, path: &Path<'v>, _id: HirId) -> Self::Result { walk_path(self, path) } - fn visit_path_segment(&mut self, path_segment: &'v PathSegment<'v>) { + fn visit_path_segment(&mut self, path_segment: &'v PathSegment<'v>) -> Self::Result { walk_path_segment(self, path_segment) } - fn visit_generic_args(&mut self, generic_args: &'v GenericArgs<'v>) { + fn visit_generic_args(&mut self, generic_args: &'v GenericArgs<'v>) -> Self::Result { walk_generic_args(self, generic_args) } - fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding<'v>) { + fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding<'v>) -> Self::Result { walk_assoc_type_binding(self, type_binding) } - fn visit_attribute(&mut self, _attr: &'v Attribute) {} - fn visit_associated_item_kind(&mut self, kind: &'v AssocItemKind) { - walk_associated_item_kind(self, kind); + fn visit_attribute(&mut self, _attr: &'v Attribute) -> Self::Result { + Self::Result::output() + } + fn visit_associated_item_kind(&mut self, kind: &'v AssocItemKind) -> Self::Result { + walk_associated_item_kind(self, kind) } - fn visit_defaultness(&mut self, defaultness: &'v Defaultness) { - walk_defaultness(self, defaultness); + fn visit_defaultness(&mut self, defaultness: &'v Defaultness) -> Self::Result { + walk_defaultness(self, defaultness) } - fn visit_inline_asm(&mut self, asm: &'v InlineAsm<'v>, id: HirId) { - walk_inline_asm(self, asm, id); + fn visit_inline_asm(&mut self, asm: &'v InlineAsm<'v>, id: HirId) -> Self::Result { + walk_inline_asm(self, asm, id) } } -pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) { - visitor.visit_id(param.hir_id); - visitor.visit_pat(param.pat); +pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) -> V::Result { + try_visit!(visitor.visit_id(param.hir_id)); + visitor.visit_pat(param.pat) } -pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) { - visitor.visit_ident(item.ident); +pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::Result { + try_visit!(visitor.visit_ident(item.ident)); match item.kind { ItemKind::ExternCrate(orig_name) => { - visitor.visit_id(item.hir_id()); - if let Some(orig_name) = orig_name { - visitor.visit_name(orig_name); - } + try_visit!(visitor.visit_id(item.hir_id())); + visit_opt!(visitor, visit_name, orig_name); } ItemKind::Use(ref path, _) => { - visitor.visit_use(path, item.hir_id()); + try_visit!(visitor.visit_use(path, item.hir_id())); } ItemKind::Static(ref typ, _, body) => { - visitor.visit_id(item.hir_id()); - visitor.visit_ty(typ); - visitor.visit_nested_body(body); + try_visit!(visitor.visit_id(item.hir_id())); + try_visit!(visitor.visit_ty(typ)); + try_visit!(visitor.visit_nested_body(body)); } ItemKind::Const(ref typ, ref generics, body) => { - visitor.visit_id(item.hir_id()); - visitor.visit_ty(typ); - visitor.visit_generics(generics); - visitor.visit_nested_body(body); + try_visit!(visitor.visit_id(item.hir_id())); + try_visit!(visitor.visit_ty(typ)); + try_visit!(visitor.visit_generics(generics)); + try_visit!(visitor.visit_nested_body(body)); } ItemKind::Fn(ref sig, ref generics, body_id) => { - visitor.visit_id(item.hir_id()); - visitor.visit_fn( + try_visit!(visitor.visit_id(item.hir_id())); + try_visit!(visitor.visit_fn( FnKind::ItemFn(item.ident, generics, sig.header), sig.decl, body_id, item.span, item.owner_id.def_id, - ) + )); } ItemKind::Macro(..) => { - visitor.visit_id(item.hir_id()); + try_visit!(visitor.visit_id(item.hir_id())); } ItemKind::Mod(ref module) => { // `visit_mod()` takes care of visiting the `Item`'s `HirId`. - visitor.visit_mod(module, item.span, item.hir_id()) + try_visit!(visitor.visit_mod(module, item.span, item.hir_id())); } ItemKind::ForeignMod { abi: _, items } => { - visitor.visit_id(item.hir_id()); + try_visit!(visitor.visit_id(item.hir_id())); walk_list!(visitor, visit_foreign_item_ref, items); } ItemKind::GlobalAsm(asm) => { - visitor.visit_id(item.hir_id()); - visitor.visit_inline_asm(asm, item.hir_id()); + try_visit!(visitor.visit_id(item.hir_id())); + try_visit!(visitor.visit_inline_asm(asm, item.hir_id())); } ItemKind::TyAlias(ref ty, ref generics) => { - visitor.visit_id(item.hir_id()); - visitor.visit_ty(ty); - visitor.visit_generics(generics) + try_visit!(visitor.visit_id(item.hir_id())); + try_visit!(visitor.visit_ty(ty)); + try_visit!(visitor.visit_generics(generics)); } ItemKind::OpaqueTy(&OpaqueTy { generics, bounds, .. }) => { - visitor.visit_id(item.hir_id()); - walk_generics(visitor, generics); + try_visit!(visitor.visit_id(item.hir_id())); + try_visit!(walk_generics(visitor, generics)); walk_list!(visitor, visit_param_bound, bounds); } ItemKind::Enum(ref enum_definition, ref generics) => { - visitor.visit_generics(generics); + try_visit!(visitor.visit_generics(generics)); // `visit_enum_def()` takes care of visiting the `Item`'s `HirId`. - visitor.visit_enum_def(enum_definition, item.hir_id()) + try_visit!(visitor.visit_enum_def(enum_definition, item.hir_id())); } ItemKind::Impl(Impl { unsafety: _, @@ -525,85 +542,91 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) { ref self_ty, items, }) => { - visitor.visit_id(item.hir_id()); - visitor.visit_generics(generics); - walk_list!(visitor, visit_trait_ref, of_trait); - visitor.visit_ty(self_ty); + try_visit!(visitor.visit_id(item.hir_id())); + 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_impl_item_ref, *items); } ItemKind::Struct(ref struct_definition, ref generics) | ItemKind::Union(ref struct_definition, ref generics) => { - visitor.visit_generics(generics); - visitor.visit_id(item.hir_id()); - visitor.visit_variant_data(struct_definition); + try_visit!(visitor.visit_generics(generics)); + try_visit!(visitor.visit_id(item.hir_id())); + try_visit!(visitor.visit_variant_data(struct_definition)); } ItemKind::Trait(.., ref generics, bounds, trait_item_refs) => { - visitor.visit_id(item.hir_id()); - visitor.visit_generics(generics); + try_visit!(visitor.visit_id(item.hir_id())); + try_visit!(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, bounds) => { - visitor.visit_id(item.hir_id()); - visitor.visit_generics(generics); + try_visit!(visitor.visit_id(item.hir_id())); + try_visit!(visitor.visit_generics(generics)); walk_list!(visitor, visit_param_bound, bounds); } } + V::Result::output() } -pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) { +pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) -> V::Result { walk_list!(visitor, visit_param, body.params); - visitor.visit_expr(body.value); + visitor.visit_expr(body.value) } -pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) { - visitor.visit_name(ident.name); +pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) -> V::Result { + visitor.visit_name(ident.name) } -pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod<'v>, mod_hir_id: HirId) { - visitor.visit_id(mod_hir_id); - for &item_id in module.item_ids { - visitor.visit_nested_item(item_id); - } +pub fn walk_mod<'v, V: Visitor<'v>>( + visitor: &mut V, + module: &'v Mod<'v>, + mod_hir_id: HirId, +) -> V::Result { + try_visit!(visitor.visit_id(mod_hir_id)); + walk_list!(visitor, visit_nested_item, module.item_ids.iter().copied()); + V::Result::output() } -pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem<'v>) { - visitor.visit_id(foreign_item.hir_id()); - visitor.visit_ident(foreign_item.ident); +pub fn walk_foreign_item<'v, V: Visitor<'v>>( + visitor: &mut V, + foreign_item: &'v ForeignItem<'v>, +) -> V::Result { + try_visit!(visitor.visit_id(foreign_item.hir_id())); + try_visit!(visitor.visit_ident(foreign_item.ident)); match foreign_item.kind { ForeignItemKind::Fn(ref function_declaration, param_names, ref generics) => { - visitor.visit_generics(generics); - visitor.visit_fn_decl(function_declaration); - for ¶m_name in param_names { - visitor.visit_ident(param_name); - } + try_visit!(visitor.visit_generics(generics)); + try_visit!(visitor.visit_fn_decl(function_declaration)); + walk_list!(visitor, visit_ident, param_names.iter().copied()); } - ForeignItemKind::Static(ref typ, _) => visitor.visit_ty(typ), + ForeignItemKind::Static(ref typ, _) => try_visit!(visitor.visit_ty(typ)), ForeignItemKind::Type => (), } + V::Result::output() } -pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) { +pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) -> V::Result { // Intentionally visiting the expr first - the initialization expr // dominates the local's definition. - walk_list!(visitor, visit_expr, &local.init); - visitor.visit_id(local.hir_id); - visitor.visit_pat(local.pat); - if let Some(els) = local.els { - visitor.visit_block(els); - } - walk_list!(visitor, visit_ty, &local.ty); + visit_opt!(visitor, visit_expr, local.init); + try_visit!(visitor.visit_id(local.hir_id)); + try_visit!(visitor.visit_pat(local.pat)); + visit_opt!(visitor, visit_block, local.els); + visit_opt!(visitor, visit_ty, local.ty); + V::Result::output() } -pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) { - visitor.visit_id(block.hir_id); +pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) -> V::Result { + try_visit!(visitor.visit_id(block.hir_id)); walk_list!(visitor, visit_stmt, block.stmts); - walk_list!(visitor, visit_expr, &block.expr); + visit_opt!(visitor, visit_expr, block.expr); + V::Result::output() } -pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) { - visitor.visit_id(statement.hir_id); +pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) -> V::Result { + try_visit!(visitor.visit_id(statement.hir_id)); match statement.kind { StmtKind::Local(ref local) => visitor.visit_local(local), StmtKind::Item(item) => visitor.visit_nested_item(item), @@ -613,27 +636,25 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) { } } -pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) { - visitor.visit_id(arm.hir_id); - visitor.visit_pat(arm.pat); - if let Some(ref e) = arm.guard { - visitor.visit_expr(e); - } - visitor.visit_expr(arm.body); +pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) -> V::Result { + try_visit!(visitor.visit_id(arm.hir_id)); + try_visit!(visitor.visit_pat(arm.pat)); + visit_opt!(visitor, visit_expr, arm.guard); + visitor.visit_expr(arm.body) } -pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) { - visitor.visit_id(pattern.hir_id); +pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) -> V::Result { + try_visit!(visitor.visit_id(pattern.hir_id)); match pattern.kind { PatKind::TupleStruct(ref qpath, children, _) => { - visitor.visit_qpath(qpath, pattern.hir_id, pattern.span); + try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span)); walk_list!(visitor, visit_pat, children); } PatKind::Path(ref qpath) => { - visitor.visit_qpath(qpath, pattern.hir_id, pattern.span); + try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span)); } PatKind::Struct(ref qpath, fields, _) => { - visitor.visit_qpath(qpath, pattern.hir_id, pattern.span); + try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span)); walk_list!(visitor, visit_pat_field, fields); } PatKind::Or(pats) => walk_list!(visitor, visit_pat, pats), @@ -641,33 +662,34 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) { walk_list!(visitor, visit_pat, tuple_elements); } PatKind::Box(ref subpattern) | PatKind::Ref(ref subpattern, _) => { - visitor.visit_pat(subpattern) + try_visit!(visitor.visit_pat(subpattern)); } PatKind::Binding(_, _hir_id, ident, ref optional_subpattern) => { - visitor.visit_ident(ident); - walk_list!(visitor, visit_pat, optional_subpattern); + try_visit!(visitor.visit_ident(ident)); + visit_opt!(visitor, visit_pat, optional_subpattern); } - PatKind::Lit(ref expression) => visitor.visit_expr(expression), + PatKind::Lit(ref expression) => try_visit!(visitor.visit_expr(expression)), PatKind::Range(ref lower_bound, ref upper_bound, _) => { - walk_list!(visitor, visit_expr, lower_bound); - walk_list!(visitor, visit_expr, upper_bound); + visit_opt!(visitor, visit_expr, lower_bound); + visit_opt!(visitor, visit_expr, upper_bound); } PatKind::Never | PatKind::Wild | PatKind::Err(_) => (), PatKind::Slice(prepatterns, ref slice_pattern, postpatterns) => { walk_list!(visitor, visit_pat, prepatterns); - walk_list!(visitor, visit_pat, slice_pattern); + visit_opt!(visitor, visit_pat, slice_pattern); walk_list!(visitor, visit_pat, postpatterns); } } + V::Result::output() } -pub fn walk_pat_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v PatField<'v>) { - visitor.visit_id(field.hir_id); - visitor.visit_ident(field.ident); +pub fn walk_pat_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v PatField<'v>) -> V::Result { + try_visit!(visitor.visit_id(field.hir_id)); + try_visit!(visitor.visit_ident(field.ident)); visitor.visit_pat(field.pat) } -pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) { +pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) -> V::Result { match len { // FIXME: Use `visit_infer` here. ArrayLen::Infer(InferArg { hir_id, span: _ }) => visitor.visit_id(*hir_id), @@ -675,75 +697,80 @@ pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) { } } -pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonConst) { - visitor.visit_id(constant.hir_id); - visitor.visit_nested_body(constant.body); +pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonConst) -> V::Result { + try_visit!(visitor.visit_id(constant.hir_id)); + visitor.visit_nested_body(constant.body) } -pub fn walk_inline_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v ConstBlock) { - visitor.visit_id(constant.hir_id); - visitor.visit_nested_body(constant.body); +pub fn walk_inline_const<'v, V: Visitor<'v>>( + visitor: &mut V, + constant: &'v ConstBlock, +) -> V::Result { + try_visit!(visitor.visit_id(constant.hir_id)); + visitor.visit_nested_body(constant.body) } -pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) { - visitor.visit_id(expression.hir_id); +pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) -> V::Result { + try_visit!(visitor.visit_id(expression.hir_id)); match expression.kind { ExprKind::Array(subexpressions) => { walk_list!(visitor, visit_expr, subexpressions); } - ExprKind::ConstBlock(ref const_block) => visitor.visit_inline_const(const_block), + ExprKind::ConstBlock(ref const_block) => { + try_visit!(visitor.visit_inline_const(const_block)) + } ExprKind::Repeat(ref element, ref count) => { - visitor.visit_expr(element); - visitor.visit_array_length(count) + try_visit!(visitor.visit_expr(element)); + try_visit!(visitor.visit_array_length(count)); } ExprKind::Struct(ref qpath, fields, ref optional_base) => { - visitor.visit_qpath(qpath, expression.hir_id, expression.span); + try_visit!(visitor.visit_qpath(qpath, expression.hir_id, expression.span)); walk_list!(visitor, visit_expr_field, fields); - walk_list!(visitor, visit_expr, optional_base); + visit_opt!(visitor, visit_expr, optional_base); } ExprKind::Tup(subexpressions) => { walk_list!(visitor, visit_expr, subexpressions); } ExprKind::Call(ref callee_expression, arguments) => { - visitor.visit_expr(callee_expression); + try_visit!(visitor.visit_expr(callee_expression)); walk_list!(visitor, visit_expr, arguments); } ExprKind::MethodCall(ref segment, receiver, arguments, _) => { - visitor.visit_path_segment(segment); - visitor.visit_expr(receiver); + try_visit!(visitor.visit_path_segment(segment)); + try_visit!(visitor.visit_expr(receiver)); walk_list!(visitor, visit_expr, arguments); } ExprKind::Binary(_, ref left_expression, ref right_expression) => { - visitor.visit_expr(left_expression); - visitor.visit_expr(right_expression) + try_visit!(visitor.visit_expr(left_expression)); + try_visit!(visitor.visit_expr(right_expression)); } ExprKind::AddrOf(_, _, ref subexpression) | ExprKind::Unary(_, ref subexpression) => { - visitor.visit_expr(subexpression) + try_visit!(visitor.visit_expr(subexpression)); } ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => { - visitor.visit_expr(subexpression); - visitor.visit_ty(typ) + try_visit!(visitor.visit_expr(subexpression)); + try_visit!(visitor.visit_ty(typ)); } ExprKind::DropTemps(ref subexpression) => { - visitor.visit_expr(subexpression); + try_visit!(visitor.visit_expr(subexpression)); } ExprKind::Let(Let { span: _, pat, ty, init, is_recovered: _ }) => { // match the visit order in walk_local - visitor.visit_expr(init); - visitor.visit_pat(pat); - walk_list!(visitor, visit_ty, ty); + try_visit!(visitor.visit_expr(init)); + try_visit!(visitor.visit_pat(pat)); + visit_opt!(visitor, visit_ty, ty); } ExprKind::If(ref cond, ref then, ref else_opt) => { - visitor.visit_expr(cond); - visitor.visit_expr(then); - walk_list!(visitor, visit_expr, else_opt); + try_visit!(visitor.visit_expr(cond)); + try_visit!(visitor.visit_expr(then)); + visit_opt!(visitor, visit_expr, else_opt); } ExprKind::Loop(ref block, ref opt_label, _, _) => { - walk_list!(visitor, visit_label, opt_label); - visitor.visit_block(block); + visit_opt!(visitor, visit_label, opt_label); + try_visit!(visitor.visit_block(block)); } ExprKind::Match(ref subexpression, arms, _) => { - visitor.visit_expr(subexpression); + try_visit!(visitor.visit_expr(subexpression)); walk_list!(visitor, visit_arm, arms); } ExprKind::Closure(&Closure { @@ -759,71 +786,72 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) constness: _, }) => { walk_list!(visitor, visit_generic_param, bound_generic_params); - visitor.visit_fn(FnKind::Closure, fn_decl, body, expression.span, def_id) + try_visit!(visitor.visit_fn(FnKind::Closure, fn_decl, body, expression.span, def_id)); } ExprKind::Block(ref block, ref opt_label) => { - walk_list!(visitor, visit_label, opt_label); - visitor.visit_block(block); + visit_opt!(visitor, visit_label, opt_label); + try_visit!(visitor.visit_block(block)); } ExprKind::Assign(ref lhs, ref rhs, _) => { - visitor.visit_expr(rhs); - visitor.visit_expr(lhs) + try_visit!(visitor.visit_expr(rhs)); + try_visit!(visitor.visit_expr(lhs)); } ExprKind::AssignOp(_, ref left_expression, ref right_expression) => { - visitor.visit_expr(right_expression); - visitor.visit_expr(left_expression); + try_visit!(visitor.visit_expr(right_expression)); + try_visit!(visitor.visit_expr(left_expression)); } ExprKind::Field(ref subexpression, ident) => { - visitor.visit_expr(subexpression); - visitor.visit_ident(ident); + try_visit!(visitor.visit_expr(subexpression)); + try_visit!(visitor.visit_ident(ident)); } ExprKind::Index(ref main_expression, ref index_expression, _) => { - visitor.visit_expr(main_expression); - visitor.visit_expr(index_expression) + try_visit!(visitor.visit_expr(main_expression)); + try_visit!(visitor.visit_expr(index_expression)); } ExprKind::Path(ref qpath) => { - visitor.visit_qpath(qpath, expression.hir_id, expression.span); + try_visit!(visitor.visit_qpath(qpath, expression.hir_id, expression.span)); } ExprKind::Break(ref destination, ref opt_expr) => { - walk_list!(visitor, visit_label, &destination.label); - walk_list!(visitor, visit_expr, opt_expr); + visit_opt!(visitor, visit_label, &destination.label); + visit_opt!(visitor, visit_expr, opt_expr); } ExprKind::Continue(ref destination) => { - walk_list!(visitor, visit_label, &destination.label); + visit_opt!(visitor, visit_label, &destination.label); } ExprKind::Ret(ref optional_expression) => { - walk_list!(visitor, visit_expr, optional_expression); + visit_opt!(visitor, visit_expr, optional_expression); } - ExprKind::Become(ref expr) => visitor.visit_expr(expr), + ExprKind::Become(ref expr) => try_visit!(visitor.visit_expr(expr)), ExprKind::InlineAsm(ref asm) => { - visitor.visit_inline_asm(asm, expression.hir_id); + try_visit!(visitor.visit_inline_asm(asm, expression.hir_id)); } ExprKind::OffsetOf(ref container, ref fields) => { - visitor.visit_ty(container); + try_visit!(visitor.visit_ty(container)); walk_list!(visitor, visit_ident, fields.iter().copied()); } ExprKind::Yield(ref subexpression, _) => { - visitor.visit_expr(subexpression); + try_visit!(visitor.visit_expr(subexpression)); } ExprKind::Lit(_) | ExprKind::Err(_) => {} } + V::Result::output() } -pub fn walk_expr_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v ExprField<'v>) { - visitor.visit_id(field.hir_id); - visitor.visit_ident(field.ident); +pub fn walk_expr_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v ExprField<'v>) -> V::Result { + try_visit!(visitor.visit_id(field.hir_id)); + try_visit!(visitor.visit_ident(field.ident)); visitor.visit_expr(field.expr) } -pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) { - visitor.visit_id(typ.hir_id); +pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) -> V::Result { + try_visit!(visitor.visit_id(typ.hir_id)); match typ.kind { - TyKind::Slice(ref ty) => visitor.visit_ty(ty), - TyKind::Ptr(ref mutable_type) => visitor.visit_ty(mutable_type.ty), + TyKind::Slice(ref ty) => try_visit!(visitor.visit_ty(ty)), + TyKind::Ptr(ref mutable_type) => try_visit!(visitor.visit_ty(mutable_type.ty)), TyKind::Ref(ref lifetime, ref mutable_type) => { - visitor.visit_lifetime(lifetime); - visitor.visit_ty(mutable_type.ty) + try_visit!(visitor.visit_lifetime(lifetime)); + try_visit!(visitor.visit_ty(mutable_type.ty)); } TyKind::Never => {} TyKind::Tup(tuple_element_types) => { @@ -831,64 +859,71 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) { } TyKind::BareFn(ref function_declaration) => { walk_list!(visitor, visit_generic_param, function_declaration.generic_params); - visitor.visit_fn_decl(function_declaration.decl); + try_visit!(visitor.visit_fn_decl(function_declaration.decl)); } TyKind::Path(ref qpath) => { - visitor.visit_qpath(qpath, typ.hir_id, typ.span); + try_visit!(visitor.visit_qpath(qpath, typ.hir_id, typ.span)); } TyKind::OpaqueDef(item_id, lifetimes, _in_trait) => { - visitor.visit_nested_item(item_id); + try_visit!(visitor.visit_nested_item(item_id)); walk_list!(visitor, visit_generic_arg, lifetimes); } TyKind::Array(ref ty, ref length) => { - visitor.visit_ty(ty); - visitor.visit_array_length(length) + try_visit!(visitor.visit_ty(ty)); + try_visit!(visitor.visit_array_length(length)); } TyKind::TraitObject(bounds, ref lifetime, _syntax) => { - for bound in bounds { - visitor.visit_poly_trait_ref(bound); - } - visitor.visit_lifetime(lifetime); + walk_list!(visitor, visit_poly_trait_ref, bounds); + try_visit!(visitor.visit_lifetime(lifetime)); } - TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression), + TyKind::Typeof(ref expression) => try_visit!(visitor.visit_anon_const(expression)), TyKind::Infer | TyKind::InferDelegation(..) | TyKind::Err(_) => {} TyKind::AnonAdt(item_id) => { - visitor.visit_nested_item(item_id); + try_visit!(visitor.visit_nested_item(item_id)); } } + V::Result::output() } -pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam<'v>) { - visitor.visit_id(param.hir_id); +pub fn walk_generic_param<'v, V: Visitor<'v>>( + visitor: &mut V, + param: &'v GenericParam<'v>, +) -> V::Result { + try_visit!(visitor.visit_id(param.hir_id)); match param.name { - ParamName::Plain(ident) => visitor.visit_ident(ident), + ParamName::Plain(ident) => try_visit!(visitor.visit_ident(ident)), ParamName::Error | ParamName::Fresh => {} } match param.kind { GenericParamKind::Lifetime { .. } => {} - GenericParamKind::Type { ref default, .. } => walk_list!(visitor, visit_ty, default), + GenericParamKind::Type { ref default, .. } => visit_opt!(visitor, visit_ty, default), GenericParamKind::Const { ref ty, ref default, is_host_effect: _ } => { - visitor.visit_ty(ty); + try_visit!(visitor.visit_ty(ty)); if let Some(ref default) = default { visitor.visit_const_param_default(param.hir_id, default); } } } + V::Result::output() } -pub fn walk_const_param_default<'v, V: Visitor<'v>>(visitor: &mut V, ct: &'v AnonConst) { +pub fn walk_const_param_default<'v, V: Visitor<'v>>( + visitor: &mut V, + ct: &'v AnonConst, +) -> V::Result { visitor.visit_anon_const(ct) } -pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics<'v>) { +pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics<'v>) -> V::Result { walk_list!(visitor, visit_generic_param, generics.params); walk_list!(visitor, visit_where_predicate, generics.predicates); + V::Result::output() } pub fn walk_where_predicate<'v, V: Visitor<'v>>( visitor: &mut V, predicate: &'v WherePredicate<'v>, -) { +) -> V::Result { match *predicate { WherePredicate::BoundPredicate(WhereBoundPredicate { hir_id, @@ -898,8 +933,8 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>( origin: _, span: _, }) => { - visitor.visit_id(hir_id); - visitor.visit_ty(bounded_ty); + try_visit!(visitor.visit_id(hir_id)); + try_visit!(visitor.visit_ty(bounded_ty)); walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_generic_param, bound_generic_params); } @@ -909,27 +944,30 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>( span: _, in_where_clause: _, }) => { - visitor.visit_lifetime(lifetime); + try_visit!(visitor.visit_lifetime(lifetime)); walk_list!(visitor, visit_param_bound, bounds); } WherePredicate::EqPredicate(WhereEqPredicate { ref lhs_ty, ref rhs_ty, span: _ }) => { - visitor.visit_ty(lhs_ty); - visitor.visit_ty(rhs_ty); + try_visit!(visitor.visit_ty(lhs_ty)); + try_visit!(visitor.visit_ty(rhs_ty)); } } + V::Result::output() } -pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl<'v>) { - for ty in function_declaration.inputs { - visitor.visit_ty(ty) - } +pub fn walk_fn_decl<'v, V: Visitor<'v>>( + visitor: &mut V, + function_declaration: &'v FnDecl<'v>, +) -> V::Result { + walk_list!(visitor, visit_ty, function_declaration.inputs); visitor.visit_fn_ret_ty(&function_declaration.output) } -pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FnRetTy<'v>) { - if let FnRetTy::Return(ref output_ty) = *ret_ty { - visitor.visit_ty(output_ty) +pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FnRetTy<'v>) -> V::Result { + if let FnRetTy::Return(output_ty) = *ret_ty { + try_visit!(visitor.visit_ty(output_ty)); } + V::Result::output() } pub fn walk_fn<'v, V: Visitor<'v>>( @@ -938,73 +976,87 @@ pub fn walk_fn<'v, V: Visitor<'v>>( function_declaration: &'v FnDecl<'v>, body_id: BodyId, _: LocalDefId, -) { - visitor.visit_fn_decl(function_declaration); - walk_fn_kind(visitor, function_kind); +) -> V::Result { + try_visit!(visitor.visit_fn_decl(function_declaration)); + try_visit!(walk_fn_kind(visitor, function_kind)); visitor.visit_nested_body(body_id) } -pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'v>) { +pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'v>) -> V::Result { match function_kind { FnKind::ItemFn(_, generics, ..) => { - visitor.visit_generics(generics); + try_visit!(visitor.visit_generics(generics)); } FnKind::Closure | FnKind::Method(..) => {} } + V::Result::output() } -pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v UsePath<'v>, hir_id: HirId) { - visitor.visit_id(hir_id); +pub fn walk_use<'v, V: Visitor<'v>>( + visitor: &mut V, + path: &'v UsePath<'v>, + hir_id: HirId, +) -> V::Result { + try_visit!(visitor.visit_id(hir_id)); let UsePath { segments, ref res, span } = *path; for &res in res { - visitor.visit_path(&Path { segments, res, span }, hir_id); + try_visit!(visitor.visit_path(&Path { segments, res, span }, hir_id)); } + V::Result::output() } -pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem<'v>) { +pub fn walk_trait_item<'v, V: Visitor<'v>>( + visitor: &mut V, + trait_item: &'v TraitItem<'v>, +) -> V::Result { // N.B., deliberately force a compilation error if/when new fields are added. let TraitItem { ident, generics, ref defaultness, ref kind, span, owner_id: _ } = *trait_item; let hir_id = trait_item.hir_id(); - visitor.visit_ident(ident); - visitor.visit_generics(&generics); - visitor.visit_defaultness(&defaultness); - visitor.visit_id(hir_id); + try_visit!(visitor.visit_ident(ident)); + try_visit!(visitor.visit_generics(&generics)); + try_visit!(visitor.visit_defaultness(&defaultness)); + try_visit!(visitor.visit_id(hir_id)); match *kind { TraitItemKind::Const(ref ty, default) => { - visitor.visit_ty(ty); - walk_list!(visitor, visit_nested_body, default); + try_visit!(visitor.visit_ty(ty)); + visit_opt!(visitor, visit_nested_body, default); } TraitItemKind::Fn(ref sig, TraitFn::Required(param_names)) => { - visitor.visit_fn_decl(sig.decl); - for ¶m_name in param_names { - visitor.visit_ident(param_name); - } + try_visit!(visitor.visit_fn_decl(sig.decl)); + walk_list!(visitor, visit_ident, param_names.iter().copied()); } TraitItemKind::Fn(ref sig, TraitFn::Provided(body_id)) => { - visitor.visit_fn( + try_visit!(visitor.visit_fn( FnKind::Method(ident, sig), sig.decl, body_id, span, trait_item.owner_id.def_id, - ); + )); } TraitItemKind::Type(bounds, ref default) => { walk_list!(visitor, visit_param_bound, bounds); - walk_list!(visitor, visit_ty, default); + visit_opt!(visitor, visit_ty, default); } } + V::Result::output() } -pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref: &'v TraitItemRef) { +pub fn walk_trait_item_ref<'v, V: Visitor<'v>>( + visitor: &mut V, + trait_item_ref: &'v TraitItemRef, +) -> V::Result { // N.B., deliberately force a compilation error if/when new fields are added. let TraitItemRef { id, ident, ref kind, span: _ } = *trait_item_ref; - visitor.visit_nested_trait_item(id); - visitor.visit_ident(ident); - visitor.visit_associated_item_kind(kind); + try_visit!(visitor.visit_nested_trait_item(id)); + try_visit!(visitor.visit_ident(ident)); + visitor.visit_associated_item_kind(kind) } -pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) { +pub fn walk_impl_item<'v, V: Visitor<'v>>( + visitor: &mut V, + impl_item: &'v ImplItem<'v>, +) -> V::Result { // N.B., deliberately force a compilation error if/when new fields are added. let ImplItem { owner_id: _, @@ -1016,106 +1068,118 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt vis_span: _, } = *impl_item; - visitor.visit_ident(ident); - visitor.visit_generics(generics); - visitor.visit_defaultness(defaultness); - visitor.visit_id(impl_item.hir_id()); + try_visit!(visitor.visit_ident(ident)); + try_visit!(visitor.visit_generics(generics)); + try_visit!(visitor.visit_defaultness(defaultness)); + try_visit!(visitor.visit_id(impl_item.hir_id())); match *kind { ImplItemKind::Const(ref ty, body) => { - visitor.visit_ty(ty); - visitor.visit_nested_body(body); - } - ImplItemKind::Fn(ref sig, body_id) => { - visitor.visit_fn( - FnKind::Method(impl_item.ident, sig), - sig.decl, - body_id, - impl_item.span, - impl_item.owner_id.def_id, - ); - } - ImplItemKind::Type(ref ty) => { - visitor.visit_ty(ty); - } + try_visit!(visitor.visit_ty(ty)); + visitor.visit_nested_body(body) + } + ImplItemKind::Fn(ref sig, body_id) => visitor.visit_fn( + FnKind::Method(impl_item.ident, sig), + sig.decl, + body_id, + impl_item.span, + impl_item.owner_id.def_id, + ), + ImplItemKind::Type(ref ty) => visitor.visit_ty(ty), } } pub fn walk_foreign_item_ref<'v, V: Visitor<'v>>( visitor: &mut V, foreign_item_ref: &'v ForeignItemRef, -) { +) -> V::Result { // N.B., deliberately force a compilation error if/when new fields are added. let ForeignItemRef { id, ident, span: _ } = *foreign_item_ref; - visitor.visit_nested_foreign_item(id); - visitor.visit_ident(ident); + try_visit!(visitor.visit_nested_foreign_item(id)); + visitor.visit_ident(ident) } -pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef) { +pub fn walk_impl_item_ref<'v, V: Visitor<'v>>( + visitor: &mut V, + impl_item_ref: &'v ImplItemRef, +) -> V::Result { // N.B., deliberately force a compilation error if/when new fields are added. let ImplItemRef { id, ident, ref kind, span: _, trait_item_def_id: _ } = *impl_item_ref; - visitor.visit_nested_impl_item(id); - visitor.visit_ident(ident); - visitor.visit_associated_item_kind(kind); + try_visit!(visitor.visit_nested_impl_item(id)); + try_visit!(visitor.visit_ident(ident)); + visitor.visit_associated_item_kind(kind) } -pub fn walk_trait_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v TraitRef<'v>) { - visitor.visit_id(trait_ref.hir_ref_id); +pub fn walk_trait_ref<'v, V: Visitor<'v>>( + visitor: &mut V, + trait_ref: &'v TraitRef<'v>, +) -> V::Result { + try_visit!(visitor.visit_id(trait_ref.hir_ref_id)); visitor.visit_path(trait_ref.path, trait_ref.hir_ref_id) } -pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound<'v>) { +pub fn walk_param_bound<'v, V: Visitor<'v>>( + visitor: &mut V, + bound: &'v GenericBound<'v>, +) -> V::Result { match *bound { - GenericBound::Trait(ref typ, _modifier) => { - visitor.visit_poly_trait_ref(typ); - } + GenericBound::Trait(ref typ, _modifier) => visitor.visit_poly_trait_ref(typ), GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime), } } -pub fn walk_poly_trait_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v PolyTraitRef<'v>) { +pub fn walk_poly_trait_ref<'v, V: Visitor<'v>>( + visitor: &mut V, + trait_ref: &'v PolyTraitRef<'v>, +) -> V::Result { walk_list!(visitor, visit_generic_param, trait_ref.bound_generic_params); - visitor.visit_trait_ref(&trait_ref.trait_ref); + visitor.visit_trait_ref(&trait_ref.trait_ref) } pub fn walk_struct_def<'v, V: Visitor<'v>>( visitor: &mut V, struct_definition: &'v VariantData<'v>, -) { - walk_list!(visitor, visit_id, struct_definition.ctor_hir_id()); +) -> V::Result { + visit_opt!(visitor, visit_id, struct_definition.ctor_hir_id()); walk_list!(visitor, visit_field_def, struct_definition.fields()); + V::Result::output() } -pub fn walk_field_def<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v FieldDef<'v>) { - visitor.visit_id(field.hir_id); - visitor.visit_ident(field.ident); - visitor.visit_ty(field.ty); +pub fn walk_field_def<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v FieldDef<'v>) -> V::Result { + try_visit!(visitor.visit_id(field.hir_id)); + try_visit!(visitor.visit_ident(field.ident)); + visitor.visit_ty(field.ty) } pub fn walk_enum_def<'v, V: Visitor<'v>>( visitor: &mut V, enum_definition: &'v EnumDef<'v>, item_id: HirId, -) { - visitor.visit_id(item_id); +) -> V::Result { + try_visit!(visitor.visit_id(item_id)); walk_list!(visitor, visit_variant, enum_definition.variants); + V::Result::output() } -pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, variant: &'v Variant<'v>) { - visitor.visit_ident(variant.ident); - visitor.visit_id(variant.hir_id); - visitor.visit_variant_data(&variant.data); - walk_list!(visitor, visit_anon_const, &variant.disr_expr); +pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, variant: &'v Variant<'v>) -> V::Result { + try_visit!(visitor.visit_ident(variant.ident)); + try_visit!(visitor.visit_id(variant.hir_id)); + try_visit!(visitor.visit_variant_data(&variant.data)); + visit_opt!(visitor, visit_anon_const, &variant.disr_expr); + V::Result::output() } -pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) { - visitor.visit_ident(label.ident); +pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) -> V::Result { + visitor.visit_ident(label.ident) } -pub fn walk_inf<'v, V: Visitor<'v>>(visitor: &mut V, inf: &'v InferArg) { - visitor.visit_id(inf.hir_id); +pub fn walk_inf<'v, V: Visitor<'v>>(visitor: &mut V, inf: &'v InferArg) -> V::Result { + visitor.visit_id(inf.hir_id) } -pub fn walk_generic_arg<'v, V: Visitor<'v>>(visitor: &mut V, generic_arg: &'v GenericArg<'v>) { +pub fn walk_generic_arg<'v, V: Visitor<'v>>( + visitor: &mut V, + generic_arg: &'v GenericArg<'v>, +) -> V::Result { match generic_arg { GenericArg::Lifetime(lt) => visitor.visit_lifetime(lt), GenericArg::Type(ty) => visitor.visit_ty(ty), @@ -1124,92 +1188,109 @@ pub fn walk_generic_arg<'v, V: Visitor<'v>>(visitor: &mut V, generic_arg: &'v Ge } } -pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) { - visitor.visit_id(lifetime.hir_id); - visitor.visit_ident(lifetime.ident); +pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) -> V::Result { + try_visit!(visitor.visit_id(lifetime.hir_id)); + visitor.visit_ident(lifetime.ident) } -pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath<'v>, id: HirId) { +pub fn walk_qpath<'v, V: Visitor<'v>>( + visitor: &mut V, + qpath: &'v QPath<'v>, + id: HirId, +) -> V::Result { match *qpath { QPath::Resolved(ref maybe_qself, ref path) => { - walk_list!(visitor, visit_ty, maybe_qself); + visit_opt!(visitor, visit_ty, maybe_qself); visitor.visit_path(path, id) } QPath::TypeRelative(ref qself, ref segment) => { - visitor.visit_ty(qself); - visitor.visit_path_segment(segment); + try_visit!(visitor.visit_ty(qself)); + visitor.visit_path_segment(segment) } - QPath::LangItem(..) => {} + QPath::LangItem(..) => V::Result::output(), } } -pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &Path<'v>) { - for segment in path.segments { - visitor.visit_path_segment(segment); - } +pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &Path<'v>) -> V::Result { + walk_list!(visitor, visit_path_segment, path.segments); + V::Result::output() } -pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, segment: &'v PathSegment<'v>) { - visitor.visit_ident(segment.ident); - visitor.visit_id(segment.hir_id); - if let Some(ref args) = segment.args { - visitor.visit_generic_args(args); - } +pub fn walk_path_segment<'v, V: Visitor<'v>>( + visitor: &mut V, + segment: &'v PathSegment<'v>, +) -> V::Result { + try_visit!(visitor.visit_ident(segment.ident)); + try_visit!(visitor.visit_id(segment.hir_id)); + visit_opt!(visitor, visit_generic_args, segment.args); + V::Result::output() } -pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V, generic_args: &'v GenericArgs<'v>) { +pub fn walk_generic_args<'v, V: Visitor<'v>>( + visitor: &mut V, + generic_args: &'v GenericArgs<'v>, +) -> V::Result { walk_list!(visitor, visit_generic_arg, generic_args.args); walk_list!(visitor, visit_assoc_type_binding, generic_args.bindings); + V::Result::output() } pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>( visitor: &mut V, type_binding: &'v TypeBinding<'v>, -) { - visitor.visit_id(type_binding.hir_id); - visitor.visit_ident(type_binding.ident); - visitor.visit_generic_args(type_binding.gen_args); +) -> V::Result { + try_visit!(visitor.visit_id(type_binding.hir_id)); + try_visit!(visitor.visit_ident(type_binding.ident)); + try_visit!(visitor.visit_generic_args(type_binding.gen_args)); match type_binding.kind { TypeBindingKind::Equality { ref term } => match term { - Term::Ty(ref ty) => visitor.visit_ty(ty), - Term::Const(ref c) => visitor.visit_anon_const(c), + Term::Ty(ref ty) => try_visit!(visitor.visit_ty(ty)), + Term::Const(ref c) => try_visit!(visitor.visit_anon_const(c)), }, TypeBindingKind::Constraint { bounds } => walk_list!(visitor, visit_param_bound, bounds), } + V::Result::output() } -pub fn walk_associated_item_kind<'v, V: Visitor<'v>>(_: &mut V, _: &'v AssocItemKind) { +pub fn walk_associated_item_kind<'v, V: Visitor<'v>>(_: &mut V, _: &'v AssocItemKind) -> V::Result { // No visitable content here: this fn exists so you can call it if // the right thing to do, should content be added in the future, // would be to walk it. + V::Result::output() } -pub fn walk_defaultness<'v, V: Visitor<'v>>(_: &mut V, _: &'v Defaultness) { +pub fn walk_defaultness<'v, V: Visitor<'v>>(_: &mut V, _: &'v Defaultness) -> V::Result { // No visitable content here: this fn exists so you can call it if // the right thing to do, should content be added in the future, // would be to walk it. + V::Result::output() } -pub fn walk_inline_asm<'v, V: Visitor<'v>>(visitor: &mut V, asm: &'v InlineAsm<'v>, id: HirId) { +pub fn walk_inline_asm<'v, V: Visitor<'v>>( + visitor: &mut V, + asm: &'v InlineAsm<'v>, + id: HirId, +) -> V::Result { for (op, op_sp) in asm.operands { match op { InlineAsmOperand::In { expr, .. } | InlineAsmOperand::InOut { expr, .. } => { - visitor.visit_expr(expr) + try_visit!(visitor.visit_expr(expr)); } InlineAsmOperand::Out { expr, .. } => { - if let Some(expr) = expr { - visitor.visit_expr(expr); - } + visit_opt!(visitor, visit_expr, expr); } InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { - visitor.visit_expr(in_expr); - if let Some(out_expr) = out_expr { - visitor.visit_expr(out_expr); - } + try_visit!(visitor.visit_expr(in_expr)); + visit_opt!(visitor, visit_expr, out_expr); } InlineAsmOperand::Const { anon_const, .. } - | InlineAsmOperand::SymFn { anon_const, .. } => visitor.visit_anon_const(anon_const), - InlineAsmOperand::SymStatic { path, .. } => visitor.visit_qpath(path, id, *op_sp), + | InlineAsmOperand::SymFn { anon_const, .. } => { + try_visit!(visitor.visit_anon_const(anon_const)); + } + InlineAsmOperand::SymStatic { path, .. } => { + try_visit!(visitor.visit_qpath(path, id, *op_sp)); + } } } + V::Result::output() } diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 45641be52d2f2..07bbaa1926edf 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -1,20 +1,12 @@ //! Orphan checker: every impl either implements a trait defined in this //! crate or pertains to a type defined in this crate. -use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{DelayDm, ErrorGuaranteed}; +use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; -use rustc_middle::ty::util::CheckRegions; -use rustc_middle::ty::GenericArgs; -use rustc_middle::ty::{ - self, AliasKind, ImplPolarity, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, - TypeVisitor, -}; -use rustc_session::lint; -use rustc_span::def_id::{DefId, LocalDefId}; +use rustc_middle::ty::{self, AliasKind, Ty, TyCtxt, TypeVisitableExt}; +use rustc_span::def_id::LocalDefId; use rustc_span::Span; use rustc_trait_selection::traits; -use std::ops::ControlFlow; use crate::errors; @@ -26,30 +18,17 @@ pub(crate) fn orphan_check_impl( let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity(); trait_ref.error_reported()?; - let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id); - if tcx.trait_is_auto(trait_ref.def_id) { - lint_auto_trait_impl(tcx, trait_ref, impl_def_id); - } - - ret -} - -fn do_orphan_check_impl<'tcx>( - tcx: TyCtxt<'tcx>, - trait_ref: ty::TraitRef<'tcx>, - def_id: LocalDefId, -) -> Result<(), ErrorGuaranteed> { let trait_def_id = trait_ref.def_id; - match traits::orphan_check(tcx, def_id.to_def_id()) { + match traits::orphan_check(tcx, impl_def_id.to_def_id()) { Ok(()) => {} Err(err) => { - let item = tcx.hir().expect_item(def_id); + let item = tcx.hir().expect_item(impl_def_id); let hir::ItemKind::Impl(impl_) = item.kind else { - bug!("{:?} is not an impl: {:?}", def_id, item); + bug!("{:?} is not an impl: {:?}", impl_def_id, item); }; let tr = impl_.of_trait.as_ref().unwrap(); - let sp = tcx.def_span(def_id); + let sp = tcx.def_span(impl_def_id); emit_orphan_check_error( tcx, @@ -193,7 +172,7 @@ fn do_orphan_check_impl<'tcx>( // impl AutoTrait for T {} // impl AutoTrait for T {} ty::Param(..) => ( - if self_ty.is_sized(tcx, tcx.param_env(def_id)) { + if self_ty.is_sized(tcx, tcx.param_env(impl_def_id)) { LocalImpl::Allow } else { LocalImpl::Disallow { problematic_kind: "generic type" } @@ -250,7 +229,7 @@ fn do_orphan_check_impl<'tcx>( | ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) => { - let sp = tcx.def_span(def_id); + let sp = tcx.def_span(impl_def_id); span_bug!(sp, "weird self type for autotrait impl") } @@ -262,7 +241,7 @@ fn do_orphan_check_impl<'tcx>( LocalImpl::Allow => {} LocalImpl::Disallow { problematic_kind } => { return Err(tcx.dcx().emit_err(errors::TraitsWithDefaultImpl { - span: tcx.def_span(def_id), + span: tcx.def_span(impl_def_id), traits: tcx.def_path_str(trait_def_id), problematic_kind, self_ty, @@ -274,13 +253,13 @@ fn do_orphan_check_impl<'tcx>( NonlocalImpl::Allow => {} NonlocalImpl::DisallowBecauseNonlocal => { return Err(tcx.dcx().emit_err(errors::CrossCrateTraitsDefined { - span: tcx.def_span(def_id), + span: tcx.def_span(impl_def_id), traits: tcx.def_path_str(trait_def_id), })); } NonlocalImpl::DisallowOther => { return Err(tcx.dcx().emit_err(errors::CrossCrateTraits { - span: tcx.def_span(def_id), + span: tcx.def_span(impl_def_id), traits: tcx.def_path_str(trait_def_id), self_ty, })); @@ -445,146 +424,3 @@ fn emit_orphan_check_error<'tcx>( } }) } - -/// Lint impls of auto traits if they are likely to have -/// unsound or surprising effects on auto impls. -fn lint_auto_trait_impl<'tcx>( - tcx: TyCtxt<'tcx>, - trait_ref: ty::TraitRef<'tcx>, - impl_def_id: LocalDefId, -) { - if trait_ref.args.len() != 1 { - tcx.dcx().span_delayed_bug( - tcx.def_span(impl_def_id), - "auto traits cannot have generic parameters", - ); - return; - } - let self_ty = trait_ref.self_ty(); - let (self_type_did, args) = match self_ty.kind() { - ty::Adt(def, args) => (def.did(), args), - _ => { - // FIXME: should also lint for stuff like `&i32` but - // considering that auto traits are unstable, that - // isn't too important for now as this only affects - // crates using `nightly`, and std. - return; - } - }; - - // Impls which completely cover a given root type are fine as they - // disable auto impls entirely. So only lint if the args - // are not a permutation of the identity args. - let Err(arg) = tcx.uses_unique_generic_params(args, CheckRegions::No) else { - // ok - return; - }; - - // Ideally: - // - // - compute the requirements for the auto impl candidate - // - check whether these are implied by the non covering impls - // - if not, emit the lint - // - // What we do here is a bit simpler: - // - // - badly check if an auto impl candidate definitely does not apply - // for the given simplified type - // - if so, do not lint - if fast_reject_auto_impl(tcx, trait_ref.def_id, self_ty) { - // ok - return; - } - - tcx.node_span_lint( - lint::builtin::SUSPICIOUS_AUTO_TRAIT_IMPLS, - tcx.local_def_id_to_hir_id(impl_def_id), - tcx.def_span(impl_def_id), - DelayDm(|| { - format!( - "cross-crate traits with a default impl, like `{}`, \ - should not be specialized", - tcx.def_path_str(trait_ref.def_id), - ) - }), - |lint| { - let item_span = tcx.def_span(self_type_did); - let self_descr = tcx.def_descr(self_type_did); - match arg { - ty::util::NotUniqueParam::DuplicateParam(arg) => { - lint.note(format!("`{arg}` is mentioned multiple times")); - } - ty::util::NotUniqueParam::NotParam(arg) => { - lint.note(format!("`{arg}` is not a generic parameter")); - } - } - lint.span_note( - item_span, - format!( - "try using the same sequence of generic parameters as the {self_descr} definition", - ), - ); - }, - ); -} - -fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty: Ty<'tcx>) -> bool { - struct DisableAutoTraitVisitor<'tcx> { - tcx: TyCtxt<'tcx>, - trait_def_id: DefId, - self_ty_root: Ty<'tcx>, - seen: FxHashSet, - } - - impl<'tcx> TypeVisitor> for DisableAutoTraitVisitor<'tcx> { - type BreakTy = (); - fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { - let tcx = self.tcx; - if ty != self.self_ty_root { - for impl_def_id in tcx.non_blanket_impls_for_ty(self.trait_def_id, ty) { - match tcx.impl_polarity(impl_def_id) { - ImplPolarity::Negative => return ControlFlow::Break(()), - ImplPolarity::Reservation => {} - // FIXME(@lcnr): That's probably not good enough, idk - // - // We might just want to take the rustdoc code and somehow avoid - // explicit impls for `Self`. - ImplPolarity::Positive => return ControlFlow::Continue(()), - } - } - } - - match ty.kind() { - ty::Adt(def, args) if def.is_phantom_data() => args.visit_with(self), - ty::Adt(def, args) => { - // @lcnr: This is the only place where cycles can happen. We avoid this - // by only visiting each `DefId` once. - // - // This will be is incorrect in subtle cases, but I don't care :) - if self.seen.insert(def.did()) { - for ty in def.all_fields().map(|field| field.ty(tcx, args)) { - ty.visit_with(self)?; - } - } - - ControlFlow::Continue(()) - } - _ => ty.super_visit_with(self), - } - } - } - - let self_ty_root = match self_ty.kind() { - ty::Adt(def, _) => Ty::new_adt(tcx, *def, GenericArgs::identity_for_item(tcx, def.did())), - _ => unimplemented!("unexpected self ty {:?}", self_ty), - }; - - self_ty_root - .visit_with(&mut DisableAutoTraitVisitor { - tcx, - self_ty_root, - trait_def_id, - seen: FxHashSet::default(), - }) - .is_break() -} diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index a5ef1490bce97..cffb88a1365b2 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -1630,7 +1630,7 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx: 'a>( #[instrument(level = "debug", skip(tcx))] fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> { let mut result = tcx.explicit_predicates_of(def_id); - debug!("predicates_defined_on: explicit_predicates_of({:?}) = {:?}", def_id, result,); + debug!("predicates_defined_on: explicit_predicates_of({:?}) = {:?}", def_id, result); let inferred_outlives = tcx.inferred_outlives_of(def_id); if !inferred_outlives.is_empty() { debug!( diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 4539ebf8754c7..5a2795e790d65 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -405,7 +405,7 @@ impl<'tcx> InferCtxt<'tcx> { /// will instantiate fresh inference variables for each canonical /// variable instead. Therefore, the result of this method must be /// properly unified - #[instrument(level = "debug", skip(self, cause, param_env))] + #[instrument(level = "debug", skip(self, param_env))] fn query_response_instantiation_guess( &self, cause: &ObligationCause<'tcx>, diff --git a/compiler/rustc_infer/src/infer/relate/equate.rs b/compiler/rustc_infer/src/infer/relate/equate.rs index 0087add4c725e..aefa9a5a0d61c 100644 --- a/compiler/rustc_infer/src/infer/relate/equate.rs +++ b/compiler/rustc_infer/src/infer/relate/equate.rs @@ -90,6 +90,11 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> { infcx.instantiate_ty_var(self, !self.a_is_expected, b_vid, ty::Invariant, a)?; } + (&ty::Error(e), _) | (_, &ty::Error(e)) => { + infcx.set_tainted_by_errors(e); + return Ok(Ty::new_error(self.tcx(), e)); + } + ( &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index e50f4ca338bd7..d600932440212 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -524,6 +524,11 @@ fn register_builtins(store: &mut LintStore) { "no longer needed, see RFC #3535 \ for more information", ); + store.register_removed( + "suspicious_auto_trait_impls", + "no longer needed, see #93367 \ + for more information", + ); } fn register_internals(store: &mut LintStore) { diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 3f5d3c2597151..84a050a242a69 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -90,7 +90,6 @@ declare_lint_pass! { SOFT_UNSTABLE, STABLE_FEATURES, STATIC_MUT_REFS, - SUSPICIOUS_AUTO_TRAIT_IMPLS, TEST_UNSTABLE_LINT, TEXT_DIRECTION_CODEPOINT_IN_COMMENT, TRIVIAL_CASTS, @@ -1503,7 +1502,7 @@ declare_lint! { Warn, "distinct impls distinguished only by the leak-check code", @future_incompatible = FutureIncompatibleInfo { - reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps, + reason: FutureIncompatibilityReason::Custom("the behavior may change in a future release"), reference: "issue #56105 ", }; } @@ -4032,40 +4031,6 @@ declare_lint! { "duplicated attribute" } -declare_lint! { - /// The `suspicious_auto_trait_impls` lint checks for potentially incorrect - /// implementations of auto traits. - /// - /// ### Example - /// - /// ```rust - /// struct Foo(T); - /// - /// unsafe impl Send for Foo<*const T> {} - /// ``` - /// - /// {{produces}} - /// - /// ### Explanation - /// - /// A type can implement auto traits, e.g. `Send`, `Sync` and `Unpin`, - /// in two different ways: either by writing an explicit impl or if - /// all fields of the type implement that auto trait. - /// - /// The compiler disables the automatic implementation if an explicit one - /// exists for given type constructor. The exact rules governing this - /// were previously unsound, quite subtle, and have been recently modified. - /// This change caused the automatic implementation to be disabled in more - /// cases, potentially breaking some code. - pub SUSPICIOUS_AUTO_TRAIT_IMPLS, - Warn, - "the rules governing auto traits have recently changed resulting in potential breakage", - @future_incompatible = FutureIncompatibleInfo { - reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange, - reference: "issue #93367 ", - }; -} - declare_lint! { /// The `deprecated_where_clause_location` lint detects when a where clause in front of the equals /// in an associated type. diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index e7d9dc04886b8..db27e2bd6301b 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -3,6 +3,8 @@ use crate::middle::debugger_visualizer::DebuggerVisualizerFile; use crate::query::LocalCrate; use crate::ty::TyCtxt; use rustc_ast as ast; +use rustc_ast::visit::VisitorResult; +use rustc_ast::walk_list; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::svh::Svh; @@ -431,23 +433,28 @@ impl<'hir> Map<'hir> { } /// Walks the contents of the local crate. See also `visit_all_item_likes_in_crate`. - pub fn walk_toplevel_module(self, visitor: &mut impl Visitor<'hir>) { + pub fn walk_toplevel_module(self, visitor: &mut V) -> V::Result + where + V: Visitor<'hir>, + { let (top_mod, span, hir_id) = self.get_module(LocalModDefId::CRATE_DEF_ID); - visitor.visit_mod(top_mod, span, hir_id); + visitor.visit_mod(top_mod, span, hir_id) } /// Walks the attributes in a crate. - pub fn walk_attributes(self, visitor: &mut impl Visitor<'hir>) { + pub fn walk_attributes(self, visitor: &mut V) -> V::Result + where + V: Visitor<'hir>, + { let krate = self.krate(); for info in krate.owners.iter() { if let MaybeOwner::Owner(info) = info { for attrs in info.attrs.map.values() { - for a in *attrs { - visitor.visit_attribute(a) - } + walk_list!(visitor, visit_attribute, *attrs); } } } + V::Result::output() } /// Visits all item-likes in the crate in some deterministic (but unspecified) order. If you @@ -460,52 +467,38 @@ impl<'hir> Map<'hir> { /// provided by `tcx.hir_crate_items(())`. /// /// Please see the notes in `intravisit.rs` for more information. - pub fn visit_all_item_likes_in_crate(self, visitor: &mut V) + pub fn visit_all_item_likes_in_crate(self, visitor: &mut V) -> V::Result where V: Visitor<'hir>, { let krate = self.tcx.hir_crate_items(()); - - for id in krate.items() { - visitor.visit_item(self.item(id)); - } - - for id in krate.trait_items() { - visitor.visit_trait_item(self.trait_item(id)); - } - - for id in krate.impl_items() { - visitor.visit_impl_item(self.impl_item(id)); - } - - for id in krate.foreign_items() { - visitor.visit_foreign_item(self.foreign_item(id)); - } + walk_list!(visitor, visit_item, krate.items().map(|id| self.item(id))); + walk_list!(visitor, visit_trait_item, krate.trait_items().map(|id| self.trait_item(id))); + walk_list!(visitor, visit_impl_item, krate.impl_items().map(|id| self.impl_item(id))); + walk_list!( + visitor, + visit_foreign_item, + krate.foreign_items().map(|id| self.foreign_item(id)) + ); + V::Result::output() } /// This method is the equivalent of `visit_all_item_likes_in_crate` but restricted to /// item-likes in a single module. - pub fn visit_item_likes_in_module(self, module: LocalModDefId, visitor: &mut V) + pub fn visit_item_likes_in_module(self, module: LocalModDefId, visitor: &mut V) -> V::Result where V: Visitor<'hir>, { let module = self.tcx.hir_module_items(module); - - for id in module.items() { - visitor.visit_item(self.item(id)); - } - - for id in module.trait_items() { - visitor.visit_trait_item(self.trait_item(id)); - } - - for id in module.impl_items() { - visitor.visit_impl_item(self.impl_item(id)); - } - - for id in module.foreign_items() { - visitor.visit_foreign_item(self.foreign_item(id)); - } + walk_list!(visitor, visit_item, module.items().map(|id| self.item(id))); + walk_list!(visitor, visit_trait_item, module.trait_items().map(|id| self.trait_item(id))); + walk_list!(visitor, visit_impl_item, module.impl_items().map(|id| self.impl_item(id))); + walk_list!( + visitor, + visit_foreign_item, + module.foreign_items().map(|id| self.foreign_item(id)) + ); + V::Result::output() } pub fn for_each_module(self, mut f: impl FnMut(LocalModDefId)) { diff --git a/compiler/rustc_smir/src/rustc_internal/mod.rs b/compiler/rustc_smir/src/rustc_internal/mod.rs index 6bb8c5452b989..6e870728bafc4 100644 --- a/compiler/rustc_smir/src/rustc_internal/mod.rs +++ b/compiler/rustc_smir/src/rustc_internal/mod.rs @@ -347,8 +347,14 @@ macro_rules! run_driver { Err(CompilerError::Interrupted(value)) } (Ok(Ok(_)), None) => Err(CompilerError::Skipped), - (Ok(Err(_)), _) => Err(CompilerError::CompilationFailed), - (Err(_), _) => Err(CompilerError::ICE), + // Two cases here: + // - `run` finished normally and returned `Err` + // - `run` panicked with `FatalErr` + // You might think that normal compile errors cause the former, and + // ICEs cause the latter. But some normal compiler errors also cause + // the latter. So we can't meaningfully distinguish them, and group + // them together. + (Ok(Err(_)), _) | (Err(_), _) => Err(CompilerError::Failed), } } } diff --git a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs index 6825dd4ac713d..8b2e8b54aee64 100644 --- a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs +++ b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs @@ -62,9 +62,10 @@ fn implied_outlives_bounds<'a, 'tcx>( }; let mut constraints = QueryRegionConstraints::default(); + let span = infcx.tcx.def_span(body_id); let Ok(InferOk { value: mut bounds, obligations }) = infcx .instantiate_nll_query_response_and_region_obligations( - &ObligationCause::dummy(), + &ObligationCause::dummy_with_span(span), param_env, &canonical_var_values, canonical_result, @@ -80,8 +81,6 @@ fn implied_outlives_bounds<'a, 'tcx>( bounds.retain(|bound| !bound.has_placeholders()); if !constraints.is_empty() { - let span = infcx.tcx.def_span(body_id); - debug!(?constraints); if !constraints.member_constraints.is_empty() { span_bug!(span, "{:#?}", constraints.member_constraints); diff --git a/compiler/stable_mir/src/error.rs b/compiler/stable_mir/src/error.rs index 7085fa937c98e..9e3f49369442d 100644 --- a/compiler/stable_mir/src/error.rs +++ b/compiler/stable_mir/src/error.rs @@ -15,10 +15,8 @@ macro_rules! error { /// An error type used to represent an error that has already been reported by the compiler. #[derive(Clone, Copy, PartialEq, Eq)] pub enum CompilerError { - /// Internal compiler error (I.e.: Compiler crashed). - ICE, - /// Compilation failed. - CompilationFailed, + /// Compilation failed, either due to normal errors or ICE. + Failed, /// Compilation was interrupted. Interrupted(T), /// Compilation skipped. This happens when users invoke rustc to retrieve information such as @@ -54,8 +52,7 @@ where { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { - CompilerError::ICE => write!(f, "Internal Compiler Error"), - CompilerError::CompilationFailed => write!(f, "Compilation Failed"), + CompilerError::Failed => write!(f, "Compilation Failed"), CompilerError::Interrupted(reason) => write!(f, "Compilation Interrupted: {reason}"), CompilerError::Skipped => write!(f, "Compilation Skipped"), } @@ -68,8 +65,7 @@ where { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { - CompilerError::ICE => write!(f, "Internal Compiler Error"), - CompilerError::CompilationFailed => write!(f, "Compilation Failed"), + CompilerError::Failed => write!(f, "Compilation Failed"), CompilerError::Interrupted(reason) => write!(f, "Compilation Interrupted: {reason:?}"), CompilerError::Skipped => write!(f, "Compilation Skipped"), } diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index ce1876d5a2f2f..9ee61f97c91e8 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2693,6 +2693,7 @@ pub(crate) fn is_valid_allocation_size(size: usize, len: usize) -> bool { /// Checks whether the regions of memory starting at `src` and `dst` of size /// `count * size` do *not* overlap. +#[inline] pub(crate) fn is_nonoverlapping(src: *const (), dst: *const (), size: usize, count: usize) -> bool { let src_usize = src.addr(); let dst_usize = dst.addr(); diff --git a/library/std/src/io/buffered/bufreader.rs b/library/std/src/io/buffered/bufreader.rs index e920500d7d07f..e0dc9f96ae9b2 100644 --- a/library/std/src/io/buffered/bufreader.rs +++ b/library/std/src/io/buffered/bufreader.rs @@ -26,8 +26,7 @@ use buffer::Buffer; /// unwrapping the `BufReader` with [`BufReader::into_inner`] can also cause /// data loss. /// -// HACK(#78696): can't use `crate` for associated items -/// [`TcpStream::read`]: super::super::super::net::TcpStream::read +/// [`TcpStream::read`]: crate::net::TcpStream::read /// [`TcpStream`]: crate::net::TcpStream /// /// # Examples diff --git a/library/std/src/io/buffered/bufwriter.rs b/library/std/src/io/buffered/bufwriter.rs index 95ba82e1e0755..665d8602c0800 100644 --- a/library/std/src/io/buffered/bufwriter.rs +++ b/library/std/src/io/buffered/bufwriter.rs @@ -62,8 +62,7 @@ use crate::ptr; /// together by the buffer and will all be written out in one system call when /// the `stream` is flushed. /// -// HACK(#78696): can't use `crate` for associated items -/// [`TcpStream::write`]: super::super::super::net::TcpStream::write +/// [`TcpStream::write`]: crate::net::TcpStream::write /// [`TcpStream`]: crate::net::TcpStream /// [`flush`]: BufWriter::flush #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/doc/unstable-book/src/compiler-flags/sanitizer.md b/src/doc/unstable-book/src/compiler-flags/sanitizer.md index 502853f39ae41..523617eb3e15f 100644 --- a/src/doc/unstable-book/src/compiler-flags/sanitizer.md +++ b/src/doc/unstable-book/src/compiler-flags/sanitizer.md @@ -1,5 +1,14 @@ # `sanitizer` +Sanitizers are tools that help detect and prevent various types of bugs and +vulnerabilities in software. They are available in compilers and work by +instrumenting the code to add additional runtime checks. While they provide +powerful tools for identifying bugs or security issues, it's important to note +that using sanitizers can introduce runtime overhead and might not catch all +possible issues. Therefore, they are typically used alongside other best +practices in software development, such as testing and fuzzing, to ensure the +highest level of software quality and security. + The tracking issues for this feature are: * [#39699](https://github.com/rust-lang/rust/issues/39699). @@ -9,21 +18,26 @@ The tracking issues for this feature are: This feature allows for use of one of following sanitizers: -* [AddressSanitizer](#addresssanitizer) a fast memory error detector. -* [ControlFlowIntegrity](#controlflowintegrity) LLVM Control Flow Integrity (CFI) provides - forward-edge control flow protection. -* [HWAddressSanitizer](#hwaddresssanitizer) a memory error detector similar to - AddressSanitizer, but based on partial hardware assistance. -* [KernelControlFlowIntegrity](#kernelcontrolflowintegrity) LLVM Kernel Control - Flow Integrity (KCFI) provides forward-edge control flow protection for - operating systems kernels. -* [LeakSanitizer](#leaksanitizer) a run-time memory leak detector. -* [MemorySanitizer](#memorysanitizer) a detector of uninitialized reads. -* [MemTagSanitizer](#memtagsanitizer) fast memory error detector based on - Armv8.5-A Memory Tagging Extension. -* [SafeStack](#safestack) provides backward-edge control flow protection by separating the stack into safe and unsafe regions. -* [ShadowCallStack](#shadowcallstack) provides backward-edge control flow protection (aarch64 only). -* [ThreadSanitizer](#threadsanitizer) a fast data race detector. +* Those intended for testing or fuzzing (but not production use): + * [AddressSanitizer](#addresssanitizer) a fast memory error detector. + * [HWAddressSanitizer](#hwaddresssanitizer) a memory error detector similar to + AddressSanitizer, but based on partial hardware assistance. + * [LeakSanitizer](#leaksanitizer) a run-time memory leak detector. + * [MemorySanitizer](#memorysanitizer) a detector of uninitialized reads. + * [ThreadSanitizer](#threadsanitizer) a fast data race detector. + +* Those that apart from testing, may be used in production: + * [ControlFlowIntegrity](#controlflowintegrity) LLVM Control Flow Integrity + (CFI) provides forward-edge control flow protection. + * [KernelControlFlowIntegrity](#kernelcontrolflowintegrity) LLVM Kernel + Control Flow Integrity (KCFI) provides forward-edge control flow protection + for operating systems kernels. + * [MemTagSanitizer](#memtagsanitizer) fast memory error detector based on + Armv8.5-A Memory Tagging Extension. + * [SafeStack](#safestack) provides backward-edge control flow protection by + separating the stack into safe and unsafe regions. + * [ShadowCallStack](#shadowcallstack) provides backward-edge control flow + protection (aarch64 only). To enable a sanitizer compile with `-Zsanitizer=address`,`-Zsanitizer=cfi`, `-Zsanitizer=hwaddress`, `-Zsanitizer=leak`, `-Zsanitizer=memory`, diff --git a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs index c6855a0969681..046ea70b08f16 100644 --- a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs +++ b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs @@ -1,5 +1,4 @@ #![warn(clippy::non_send_fields_in_send_ty)] -#![allow(suspicious_auto_trait_impls)] #![feature(extern_types)] use std::cell::UnsafeCell; diff --git a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr index 1ea76196af938..99fd4ea60b608 100644 --- a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr +++ b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr @@ -1,11 +1,11 @@ error: some fields in `RingBuffer` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:17:1 + --> $DIR/non_send_fields_in_send_ty.rs:16:1 | LL | unsafe impl Send for RingBuffer {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `data` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:12:5 + --> $DIR/non_send_fields_in_send_ty.rs:11:5 | LL | data: Vec>, | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -14,155 +14,155 @@ LL | data: Vec>, = help: to override `-D warnings` add `#[allow(clippy::non_send_fields_in_send_ty)]` error: some fields in `MvccRwLock` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:26:1 + --> $DIR/non_send_fields_in_send_ty.rs:25:1 | LL | unsafe impl Send for MvccRwLock {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `lock` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:23:5 + --> $DIR/non_send_fields_in_send_ty.rs:22:5 | LL | lock: Mutex>, | ^^^^^^^^^^^^^^^^^^^ = help: add bounds on type parameter `T` that satisfy `Mutex>: Send` error: some fields in `ArcGuard` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:35:1 + --> $DIR/non_send_fields_in_send_ty.rs:34:1 | LL | unsafe impl Send for ArcGuard {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `head` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:32:5 + --> $DIR/non_send_fields_in_send_ty.rs:31:5 | LL | head: Arc, | ^^^^^^^^^^^^^ = help: add bounds on type parameter `RC` that satisfy `Arc: Send` error: some fields in `DeviceHandle` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:52:1 + --> $DIR/non_send_fields_in_send_ty.rs:51:1 | LL | unsafe impl Send for DeviceHandle {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `context` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:48:5 + --> $DIR/non_send_fields_in_send_ty.rs:47:5 | LL | context: T, | ^^^^^^^^^^ = help: add `T: Send` bound in `Send` impl error: some fields in `NoGeneric` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:60:1 + --> $DIR/non_send_fields_in_send_ty.rs:59:1 | LL | unsafe impl Send for NoGeneric {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `rc_is_not_send` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:57:5 + --> $DIR/non_send_fields_in_send_ty.rs:56:5 | LL | rc_is_not_send: Rc, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `MultiField` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:69:1 + --> $DIR/non_send_fields_in_send_ty.rs:68:1 | LL | unsafe impl Send for MultiField {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:64:5 + --> $DIR/non_send_fields_in_send_ty.rs:63:5 | LL | field1: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:65:5 + --> $DIR/non_send_fields_in_send_ty.rs:64:5 | LL | field2: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field3` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:66:5 + --> $DIR/non_send_fields_in_send_ty.rs:65:5 | LL | field3: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl error: some fields in `MyOption` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:77:1 + --> $DIR/non_send_fields_in_send_ty.rs:76:1 | LL | unsafe impl Send for MyOption {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:73:12 + --> $DIR/non_send_fields_in_send_ty.rs:72:12 | LL | MySome(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `MultiParam` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:90:1 + --> $DIR/non_send_fields_in_send_ty.rs:89:1 | LL | unsafe impl Send for MultiParam {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `vec` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:87:5 + --> $DIR/non_send_fields_in_send_ty.rs:86:5 | LL | vec: Vec<(A, B)>, | ^^^^^^^^^^^^^^^^ = help: add bounds on type parameters `A, B` that satisfy `Vec<(A, B)>: Send` error: some fields in `HeuristicTest` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:109:1 + --> $DIR/non_send_fields_in_send_ty.rs:108:1 | LL | unsafe impl Send for HeuristicTest {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field4` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:104:5 + --> $DIR/non_send_fields_in_send_ty.rs:103:5 | LL | field4: (*const NonSend, Rc), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `AttrTest3` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:129:1 + --> $DIR/non_send_fields_in_send_ty.rs:128:1 | LL | unsafe impl Send for AttrTest3 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:124:11 + --> $DIR/non_send_fields_in_send_ty.rs:123:11 | LL | Enum2(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `Complex` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:138:1 + --> $DIR/non_send_fields_in_send_ty.rs:137:1 | LL | unsafe impl

Send for Complex {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:134:5 + --> $DIR/non_send_fields_in_send_ty.rs:133:5 | LL | field1: A, | ^^^^^^^^^ = help: add `P: Send` bound in `Send` impl error: some fields in `Complex>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:142:1 + --> $DIR/non_send_fields_in_send_ty.rs:141:1 | LL | unsafe impl Send for Complex> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:135:5 + --> $DIR/non_send_fields_in_send_ty.rs:134:5 | LL | field2: B, | ^^^^^^^^^ diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 117828645a94f..7f765fd86c87f 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -55,7 +55,7 @@ impl EarlyProps { &mut poisoned, testfile, rdr, - &mut |_, _, ln, _| { + &mut |HeaderLine { directive: ln, .. }| { config.push_name_value_directive(ln, directives::AUX_BUILD, &mut props.aux, |r| { r.trim().to_string() }); @@ -330,8 +330,8 @@ impl TestProps { &mut poisoned, testfile, file, - &mut |revision, _, ln, _| { - if revision.is_some() && revision != cfg { + &mut |HeaderLine { header_revision, directive: ln, .. }| { + if header_revision.is_some() && header_revision != cfg { return; } @@ -672,17 +672,6 @@ pub fn line_directive<'line>( } } -fn iter_header( - mode: Mode, - suite: &str, - poisoned: &mut bool, - testfile: &Path, - rdr: R, - it: &mut dyn FnMut(Option<&str>, &str, &str, usize), -) { - iter_header_extra(mode, suite, poisoned, testfile, rdr, &[], it) -} - /// This is generated by collecting directives from ui tests and then extracting their directive /// names. This is **not** an exhaustive list of all possible directives. Instead, this is a /// best-effort approximation for diagnostics. @@ -801,23 +790,49 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[ "unset-rustc-env", ]; -fn iter_header_extra( +/// Arguments passed to the callback in [`iter_header`]. +struct HeaderLine<'ln> { + /// Contents of the square brackets preceding this header, if present. + header_revision: Option<&'ln str>, + /// Raw line from the test file, including comment prefix and any revision. + original_line: &'ln str, + /// Remainder of the directive line, after the initial comment prefix + /// (`//` or `//@` or `#`) and revision (if any) have been stripped. + directive: &'ln str, + line_number: usize, +} + +fn iter_header( mode: Mode, suite: &str, poisoned: &mut bool, testfile: &Path, rdr: impl Read, - extra_directives: &[&str], - it: &mut dyn FnMut(Option<&str>, &str, &str, usize), + it: &mut dyn FnMut(HeaderLine<'_>), ) { if testfile.is_dir() { return; } - // Process any extra directives supplied by the caller (e.g. because they - // are implied by the test mode), with a dummy line number of 0. - for directive in extra_directives { - it(None, directive, directive, 0); + // Coverage tests in coverage-run mode always have these extra directives, + // without needing to specify them manually in every test file. + // (Some of the comments below have been copied over from the old + // `tests/run-make/coverage-reports/Makefile`, which no longer exists.) + if mode == Mode::CoverageRun { + let extra_directives: &[&str] = &[ + "needs-profiler-support", + // FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works + // properly. Since we only have GCC on the CI ignore the test for now. + "ignore-windows-gnu", + // FIXME(pietroalbini): this test currently does not work on cross-compiled + // targets because remote-test is not capable of sending back the *.profraw + // files generated by the LLVM instrumentation. + "ignore-cross-compile", + ]; + // Process the extra implied directives, with a dummy line number of 0. + for directive in extra_directives { + it(HeaderLine { header_revision: None, original_line: "", directive, line_number: 0 }); + } } let comment = if testfile.extension().is_some_and(|e| e == "rs") { @@ -843,14 +858,14 @@ fn iter_header_extra( // Assume that any directives will be found before the first // module or function. This doesn't seem to be an optimization // with a warm page cache. Maybe with a cold one. - let orig_ln = &ln; + let original_line = &ln; let ln = ln.trim(); if ln.starts_with("fn") || ln.starts_with("mod") { return; // First try to accept `ui_test` style comments - } else if let Some((lncfg, ln)) = line_directive(comment, ln) { - it(lncfg, orig_ln, ln, line_number); + } else if let Some((header_revision, directive)) = line_directive(comment, ln) { + it(HeaderLine { header_revision, original_line, directive, line_number }); } else if mode == Mode::Ui && suite == "ui" && !REVISION_MAGIC_COMMENT_RE.is_match(ln) { let Some((_, rest)) = line_directive("//", ln) else { continue; @@ -1150,37 +1165,16 @@ pub fn make_test_description( let mut ignore_message = None; let mut should_fail = false; - let extra_directives: &[&str] = match config.mode { - // The coverage-run tests are treated as having these extra directives, - // without needing to specify them manually in every test file. - // (Some of the comments below have been copied over from - // `tests/run-make/coverage-reports/Makefile`, which no longer exists.) - Mode::CoverageRun => { - &[ - "needs-profiler-support", - // FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works - // properly. Since we only have GCC on the CI ignore the test for now. - "ignore-windows-gnu", - // FIXME(pietroalbini): this test currently does not work on cross-compiled - // targets because remote-test is not capable of sending back the *.profraw - // files generated by the LLVM instrumentation. - "ignore-cross-compile", - ] - } - _ => &[], - }; - let mut local_poisoned = false; - iter_header_extra( + iter_header( config.mode, &config.suite, &mut local_poisoned, path, src, - extra_directives, - &mut |revision, og_ln, ln, line_number| { - if revision.is_some() && revision != cfg { + &mut |HeaderLine { header_revision, original_line, directive: ln, line_number }| { + if header_revision.is_some() && header_revision != cfg { return; } @@ -1204,7 +1198,7 @@ pub fn make_test_description( }; } - if let Some((_, post)) = og_ln.trim_start().split_once("//") { + if let Some((_, post)) = original_line.trim_start().split_once("//") { let post = post.trim_start(); if post.starts_with("ignore-tidy") && config.mode == Mode::Ui diff --git a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs index 2fc0793320039..3329909e9dab4 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs @@ -502,10 +502,6 @@ pub const DEFAULT_LINTS: &[Lint] = &[ label: "stable_features", description: r##"stable features found in `#[feature]` directive"##, }, - Lint { - label: "suspicious_auto_trait_impls", - description: r##"the rules governing auto traits have recently changed resulting in potential breakage"##, - }, Lint { label: "suspicious_double_ref_op", description: r##"suspicious call of trait method on `&&T`"##, @@ -778,7 +774,6 @@ pub const DEFAULT_LINT_GROUPS: &[LintGroup] = &[ "repr_transparent_external_private_fields", "semicolon_in_expressions_from_macros", "soft_unstable", - "suspicious_auto_trait_impls", "uninhabited_static", "unstable_name_collisions", "unstable_syntax_pre_expansion", diff --git a/tests/ui-fulldeps/stable-mir/compilation-result.rs b/tests/ui-fulldeps/stable-mir/compilation-result.rs index e6dd9fa132d83..cd61d599eb43d 100644 --- a/tests/ui-fulldeps/stable-mir/compilation-result.rs +++ b/tests/ui-fulldeps/stable-mir/compilation-result.rs @@ -55,7 +55,7 @@ fn test_skipped(mut args: Vec) { fn test_failed(mut args: Vec) { args.push("--cfg=broken".to_string()); let result = run!(args, || unreachable!() as ControlFlow<()>); - assert_eq!(result, Err(stable_mir::CompilerError::CompilationFailed)); + assert_eq!(result, Err(stable_mir::CompilerError::Failed)); } /// Test that we are able to pass a closure and set the return according to the captured value. diff --git a/tests/ui/auto-traits/issue-117789.rs b/tests/ui/auto-traits/issue-117789.rs index 0c30931a1b508..63f796771db08 100644 --- a/tests/ui/auto-traits/issue-117789.rs +++ b/tests/ui/auto-traits/issue-117789.rs @@ -1,5 +1,3 @@ -#![deny(suspicious_auto_trait_impls)] - auto trait Trait

{} //~ ERROR auto traits cannot have generic parameters //~^ ERROR auto traits are experimental and possibly buggy impl

Trait

for () {} diff --git a/tests/ui/auto-traits/issue-117789.stderr b/tests/ui/auto-traits/issue-117789.stderr index 1f8880b1ef460..99efb21341758 100644 --- a/tests/ui/auto-traits/issue-117789.stderr +++ b/tests/ui/auto-traits/issue-117789.stderr @@ -1,5 +1,5 @@ error[E0567]: auto traits cannot have generic parameters - --> $DIR/issue-117789.rs:3:17 + --> $DIR/issue-117789.rs:1:17 | LL | auto trait Trait

{} | -----^^^ help: remove the parameters @@ -7,7 +7,7 @@ LL | auto trait Trait

{} | auto trait cannot have generic parameters error[E0658]: auto traits are experimental and possibly buggy - --> $DIR/issue-117789.rs:3:1 + --> $DIR/issue-117789.rs:1:1 | LL | auto trait Trait

{} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/auto-traits/issue-83857-ub.rs b/tests/ui/auto-traits/issue-83857-ub.rs index f9b47d2b0c670..20abfdd851a69 100644 --- a/tests/ui/auto-traits/issue-83857-ub.rs +++ b/tests/ui/auto-traits/issue-83857-ub.rs @@ -1,4 +1,3 @@ -#![allow(suspicious_auto_trait_impls)] // Tests that we don't incorrectly allow overlap between a builtin auto trait // impl and a user written one. See #83857 for more details diff --git a/tests/ui/auto-traits/issue-83857-ub.stderr b/tests/ui/auto-traits/issue-83857-ub.stderr index 6372bdfe762b0..20bfe7e36ca83 100644 --- a/tests/ui/auto-traits/issue-83857-ub.stderr +++ b/tests/ui/auto-traits/issue-83857-ub.stderr @@ -1,12 +1,12 @@ error[E0277]: `Foo` cannot be sent between threads safely - --> $DIR/issue-83857-ub.rs:22:38 + --> $DIR/issue-83857-ub.rs:21:38 | LL | fn generic(v: Foo, f: fn( as WithAssoc>::Output) -> i32) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Foo` cannot be sent between threads safely | = help: the trait `Send` is not implemented for `Foo`, which is required by `Foo: WithAssoc` note: required for `Foo` to implement `WithAssoc` - --> $DIR/issue-83857-ub.rs:15:15 + --> $DIR/issue-83857-ub.rs:14:15 | LL | impl WithAssoc for T { | ---- ^^^^^^^^^ ^ @@ -18,7 +18,7 @@ LL | fn generic(v: Foo, f: fn( as WithAssoc>::Output) -> i | +++++++++++++++++++++ error[E0277]: `Foo` cannot be sent between threads safely - --> $DIR/issue-83857-ub.rs:22:80 + --> $DIR/issue-83857-ub.rs:21:80 | LL | fn generic(v: Foo, f: fn( as WithAssoc>::Output) -> i32) { | ________________________________________________________________________________^ @@ -31,7 +31,7 @@ LL | | } | = help: the trait `Send` is not implemented for `Foo`, which is required by `Foo: WithAssoc` note: required for `Foo` to implement `WithAssoc` - --> $DIR/issue-83857-ub.rs:15:15 + --> $DIR/issue-83857-ub.rs:14:15 | LL | impl WithAssoc for T { | ---- ^^^^^^^^^ ^ @@ -43,7 +43,7 @@ LL | fn generic(v: Foo, f: fn( as WithAssoc>::Output) -> i | +++++++++++++++++++++ error[E0277]: `Foo` cannot be sent between threads safely - --> $DIR/issue-83857-ub.rs:25:11 + --> $DIR/issue-83857-ub.rs:24:11 | LL | f(foo(v)); | --- ^ `Foo` cannot be sent between threads safely @@ -52,7 +52,7 @@ LL | f(foo(v)); | = help: the trait `Send` is not implemented for `Foo` note: required by a bound in `foo` - --> $DIR/issue-83857-ub.rs:29:11 + --> $DIR/issue-83857-ub.rs:28:11 | LL | fn foo(x: T) -> ::Output { | ^^^^ required by this bound in `foo` diff --git a/tests/ui/auto-traits/suspicious-impls-lint.rs b/tests/ui/auto-traits/suspicious-impls-lint.rs deleted file mode 100644 index 7712e84f4a243..0000000000000 --- a/tests/ui/auto-traits/suspicious-impls-lint.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![deny(suspicious_auto_trait_impls)] - -use std::marker::PhantomData; - -struct MayImplementSendOk(T); -unsafe impl Send for MayImplementSendOk {} // ok - -struct MayImplementSendErr(T); -unsafe impl Send for MayImplementSendErr<&T> {} -//~^ ERROR -//~| WARNING this will change its meaning - -struct ContainsNonSendDirect(*const T); -unsafe impl Send for ContainsNonSendDirect<&T> {} // ok - -struct ContainsPtr(*const T); -struct ContainsIndirectNonSend(ContainsPtr); -unsafe impl Send for ContainsIndirectNonSend<&T> {} // ok - -struct ContainsVec(Vec); -unsafe impl Send for ContainsVec {} -//~^ ERROR -//~| WARNING this will change its meaning - -struct TwoParams(T, U); -unsafe impl Send for TwoParams {} // ok - -struct TwoParamsFlipped(T, U); -unsafe impl Send for TwoParamsFlipped {} // ok - -struct TwoParamsSame(T, U); -unsafe impl Send for TwoParamsSame {} -//~^ ERROR -//~| WARNING this will change its meaning - -pub struct WithPhantomDataNonSend(PhantomData<*const T>, U); -unsafe impl Send for WithPhantomDataNonSend {} // ok - -pub struct WithPhantomDataSend(PhantomData, U); -unsafe impl Send for WithPhantomDataSend<*const T, i8> {} -//~^ ERROR -//~| WARNING this will change its meaning - -pub struct WithLifetime<'a, T>(&'a (), T); -unsafe impl Send for WithLifetime<'static, T> {} // ok -unsafe impl Sync for WithLifetime<'static, Vec> {} -//~^ ERROR -//~| WARNING this will change its meaning - -fn main() {} diff --git a/tests/ui/auto-traits/suspicious-impls-lint.stderr b/tests/ui/auto-traits/suspicious-impls-lint.stderr deleted file mode 100644 index 9cd4e79f851eb..0000000000000 --- a/tests/ui/auto-traits/suspicious-impls-lint.stderr +++ /dev/null @@ -1,82 +0,0 @@ -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:9:1 - | -LL | unsafe impl Send for MayImplementSendErr<&T> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `&T` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:8:1 - | -LL | struct MayImplementSendErr(T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: the lint level is defined here - --> $DIR/suspicious-impls-lint.rs:1:9 - | -LL | #![deny(suspicious_auto_trait_impls)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:21:1 - | -LL | unsafe impl Send for ContainsVec {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `i32` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:20:1 - | -LL | struct ContainsVec(Vec); - | ^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:32:1 - | -LL | unsafe impl Send for TwoParamsSame {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `T` is mentioned multiple times -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:31:1 - | -LL | struct TwoParamsSame(T, U); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:40:1 - | -LL | unsafe impl Send for WithPhantomDataSend<*const T, i8> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `*const T` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:39:1 - | -LL | pub struct WithPhantomDataSend(PhantomData, U); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Sync`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:46:1 - | -LL | unsafe impl Sync for WithLifetime<'static, Vec> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `Vec` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:44:1 - | -LL | pub struct WithLifetime<'a, T>(&'a (), T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 5 previous errors - diff --git a/tests/ui/auto-traits/suspicious-negative-impls-lint.rs b/tests/ui/auto-traits/suspicious-negative-impls-lint.rs deleted file mode 100644 index 34842e5944b46..0000000000000 --- a/tests/ui/auto-traits/suspicious-negative-impls-lint.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![feature(negative_impls)] -#![deny(suspicious_auto_trait_impls)] - -use std::marker::PhantomData; - -struct ContainsVec(Vec); -impl !Send for ContainsVec {} -//~^ ERROR -//~| WARNING this will change its meaning - -pub struct WithPhantomDataSend(PhantomData, U); -impl !Send for WithPhantomDataSend<*const T, u8> {} -//~^ ERROR -//~| WARNING this will change its meaning - -pub struct WithLifetime<'a, T>(&'a (), T); -impl !Sync for WithLifetime<'static, Option> {} -//~^ ERROR -//~| WARNING this will change its meaning - -fn main() {} diff --git a/tests/ui/auto-traits/suspicious-negative-impls-lint.stderr b/tests/ui/auto-traits/suspicious-negative-impls-lint.stderr deleted file mode 100644 index ee03ea1255757..0000000000000 --- a/tests/ui/auto-traits/suspicious-negative-impls-lint.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-negative-impls-lint.rs:7:1 - | -LL | impl !Send for ContainsVec {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `u32` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-negative-impls-lint.rs:6:1 - | -LL | struct ContainsVec(Vec); - | ^^^^^^^^^^^^^^^^^^^^^ -note: the lint level is defined here - --> $DIR/suspicious-negative-impls-lint.rs:2:9 - | -LL | #![deny(suspicious_auto_trait_impls)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-negative-impls-lint.rs:12:1 - | -LL | impl !Send for WithPhantomDataSend<*const T, u8> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `*const T` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-negative-impls-lint.rs:11:1 - | -LL | pub struct WithPhantomDataSend(PhantomData, U); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Sync`, should not be specialized - --> $DIR/suspicious-negative-impls-lint.rs:17:1 - | -LL | impl !Sync for WithLifetime<'static, Option> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `Option` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-negative-impls-lint.rs:16:1 - | -LL | pub struct WithLifetime<'a, T>(&'a (), T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/coherence/coherence-conflicting-negative-trait-impl.rs b/tests/ui/coherence/coherence-conflicting-negative-trait-impl.rs index 76a57936e6985..24b878927530c 100644 --- a/tests/ui/coherence/coherence-conflicting-negative-trait-impl.rs +++ b/tests/ui/coherence/coherence-conflicting-negative-trait-impl.rs @@ -13,7 +13,5 @@ impl !Send for TestType {} //~ ERROR found both positive and nega unsafe impl Send for TestType {} //~ ERROR conflicting implementations impl !Send for TestType {} -//~^ WARNING -//~| WARNING this will change its meaning fn main() {} diff --git a/tests/ui/coherence/coherence-conflicting-negative-trait-impl.stderr b/tests/ui/coherence/coherence-conflicting-negative-trait-impl.stderr index 020199da99141..2463f38a92251 100644 --- a/tests/ui/coherence/coherence-conflicting-negative-trait-impl.stderr +++ b/tests/ui/coherence/coherence-conflicting-negative-trait-impl.stderr @@ -16,23 +16,7 @@ LL | unsafe impl Send for TestType {} LL | unsafe impl Send for TestType {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>` -warning: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/coherence-conflicting-negative-trait-impl.rs:15:1 - | -LL | impl !Send for TestType {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `i32` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/coherence-conflicting-negative-trait-impl.rs:7:1 - | -LL | struct TestType(::std::marker::PhantomData); - | ^^^^^^^^^^^^^^^^^^ - = note: `#[warn(suspicious_auto_trait_impls)]` on by default - -error: aborting due to 2 previous errors; 1 warning emitted +error: aborting due to 2 previous errors Some errors have detailed explanations: E0119, E0751. For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/coherence/coherence-fn-implied-bounds.rs b/tests/ui/coherence/coherence-fn-implied-bounds.rs index 4539af9a32e38..0ae5428410298 100644 --- a/tests/ui/coherence/coherence-fn-implied-bounds.rs +++ b/tests/ui/coherence/coherence-fn-implied-bounds.rs @@ -20,7 +20,7 @@ impl Trait for for<'a, 'b> fn(&'a &'b u32, &'b &'a u32) -> &'b u32 {} impl Trait for for<'c> fn(&'c &'c u32, &'c &'c u32) -> &'c u32 { //~^ ERROR conflicting implementations - //~| WARNING this was previously accepted by the compiler + //~| WARN the behavior may change in a future release } fn main() {} diff --git a/tests/ui/coherence/coherence-fn-implied-bounds.stderr b/tests/ui/coherence/coherence-fn-implied-bounds.stderr index b0dea74670925..ece3288989d74 100644 --- a/tests/ui/coherence/coherence-fn-implied-bounds.stderr +++ b/tests/ui/coherence/coherence-fn-implied-bounds.stderr @@ -7,7 +7,7 @@ LL | LL | impl Trait for for<'c> fn(&'c &'c u32, &'c &'c u32) -> &'c u32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a &'b u32, &'b &'a u32) -> &'b u32` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = warning: the behavior may change in a future release = note: for more information, see issue #56105 = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details note: the lint level is defined here diff --git a/tests/ui/coherence/coherence-free-vs-bound-region.rs b/tests/ui/coherence/coherence-free-vs-bound-region.rs index 2f5c49d293d5d..89d0005fb7969 100644 --- a/tests/ui/coherence/coherence-free-vs-bound-region.rs +++ b/tests/ui/coherence/coherence-free-vs-bound-region.rs @@ -15,7 +15,7 @@ impl<'a> TheTrait for fn(&'a u8) {} impl TheTrait for fn(&u8) { //~^ ERROR conflicting implementations of trait - //~| WARNING this was previously accepted by the compiler + //~| WARN the behavior may change in a future release } fn main() {} diff --git a/tests/ui/coherence/coherence-free-vs-bound-region.stderr b/tests/ui/coherence/coherence-free-vs-bound-region.stderr index c97b32e429d37..e45cf5ad3a4c5 100644 --- a/tests/ui/coherence/coherence-free-vs-bound-region.stderr +++ b/tests/ui/coherence/coherence-free-vs-bound-region.stderr @@ -7,7 +7,7 @@ LL | LL | impl TheTrait for fn(&u8) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `fn(&u8)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = warning: the behavior may change in a future release = note: for more information, see issue #56105 = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details note: the lint level is defined here diff --git a/tests/ui/coherence/coherence-orphan.rs b/tests/ui/coherence/coherence-orphan.rs index c06705133c801..9c96958f21a12 100644 --- a/tests/ui/coherence/coherence-orphan.rs +++ b/tests/ui/coherence/coherence-orphan.rs @@ -7,18 +7,16 @@ use lib::TheTrait; struct TheType; -impl TheTrait for isize { } +impl TheTrait for isize {} //~^ ERROR E0117 //~| ERROR not all trait items implemented -impl TheTrait for isize { } +impl TheTrait for isize {} //~^ ERROR not all trait items implemented -impl TheTrait for TheType { } +impl TheTrait for TheType {} //~^ ERROR not all trait items implemented -impl !Send for Vec { } //~ ERROR E0117 -//~^ WARNING -//~| WARNING this will change its meaning +impl !Send for Vec {} //~ ERROR E0117 -fn main() { } +fn main() {} diff --git a/tests/ui/coherence/coherence-orphan.stderr b/tests/ui/coherence/coherence-orphan.stderr index 78fad837647b4..b1bb75bfe5162 100644 --- a/tests/ui/coherence/coherence-orphan.stderr +++ b/tests/ui/coherence/coherence-orphan.stderr @@ -1,7 +1,7 @@ error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/coherence-orphan.rs:10:1 | -LL | impl TheTrait for isize { } +LL | impl TheTrait for isize {} | ^^^^^---------------^^^^^----- | | | | | | | `isize` is not defined in the current crate @@ -13,7 +13,7 @@ LL | impl TheTrait for isize { } error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/coherence-orphan.rs:20:1 | -LL | impl !Send for Vec { } +LL | impl !Send for Vec {} | ^^^^^^^^^^^^^^^---------- | | | | | `Vec` is not defined in the current crate @@ -21,23 +21,10 @@ LL | impl !Send for Vec { } | = note: define and implement a trait or new type instead -warning: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/coherence-orphan.rs:20:1 - | -LL | impl !Send for Vec { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `isize` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL - = note: `#[warn(suspicious_auto_trait_impls)]` on by default - error[E0046]: not all trait items implemented, missing: `the_fn` --> $DIR/coherence-orphan.rs:10:1 | -LL | impl TheTrait for isize { } +LL | impl TheTrait for isize {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `the_fn` in implementation | = help: implement the missing item: `fn the_fn(&self) { todo!() }` @@ -45,7 +32,7 @@ LL | impl TheTrait for isize { } error[E0046]: not all trait items implemented, missing: `the_fn` --> $DIR/coherence-orphan.rs:14:1 | -LL | impl TheTrait for isize { } +LL | impl TheTrait for isize {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `the_fn` in implementation | = help: implement the missing item: `fn the_fn(&self) { todo!() }` @@ -53,12 +40,12 @@ LL | impl TheTrait for isize { } error[E0046]: not all trait items implemented, missing: `the_fn` --> $DIR/coherence-orphan.rs:17:1 | -LL | impl TheTrait for TheType { } +LL | impl TheTrait for TheType {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `the_fn` in implementation | = help: implement the missing item: `fn the_fn(&self) { todo!() }` -error: aborting due to 5 previous errors; 1 warning emitted +error: aborting due to 5 previous errors Some errors have detailed explanations: E0046, E0117. For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/coherence/coherence-overlap-negative-impls.rs b/tests/ui/coherence/coherence-overlap-negative-impls.rs index 9a85d8c5a63b7..ffcd56817e5c2 100644 --- a/tests/ui/coherence/coherence-overlap-negative-impls.rs +++ b/tests/ui/coherence/coherence-overlap-negative-impls.rs @@ -15,16 +15,20 @@ struct Test; trait Fold {} -impl Fold for Cons // 0 +impl Fold for Cons +// 0 where T: Fold, -{} +{ +} -impl Fold for Cons // 1 +impl Fold for Cons +// 1 where T: Fold, private::Is: private::NotNil, -{} +{ +} impl Fold for Test {} // 2 @@ -34,7 +38,6 @@ mod private { pub struct Is(T); pub auto trait NotNil {} - #[allow(suspicious_auto_trait_impls)] impl !NotNil for Is {} } diff --git a/tests/ui/coherence/coherence-subtyping.rs b/tests/ui/coherence/coherence-subtyping.rs index da0cc2d026548..4365ad5c884b9 100644 --- a/tests/ui/coherence/coherence-subtyping.rs +++ b/tests/ui/coherence/coherence-subtyping.rs @@ -13,8 +13,8 @@ trait TheTrait { impl TheTrait for for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8 {} impl TheTrait for for<'a> fn(&'a u8, &'a u8) -> &'a u8 { - //~^ WARNING conflicting implementation - //~^^ WARNING this was previously accepted by the compiler but is being phased out + //~^ WARN conflicting implementation + //~| WARN the behavior may change in a future release } fn main() {} diff --git a/tests/ui/coherence/coherence-subtyping.stderr b/tests/ui/coherence/coherence-subtyping.stderr index 9d90019a50fd3..42f256ace78f4 100644 --- a/tests/ui/coherence/coherence-subtyping.stderr +++ b/tests/ui/coherence/coherence-subtyping.stderr @@ -7,7 +7,7 @@ LL | LL | impl TheTrait for for<'a> fn(&'a u8, &'a u8) -> &'a u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = warning: the behavior may change in a future release = note: for more information, see issue #56105 = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details = note: `#[warn(coherence_leak_check)]` on by default diff --git a/tests/ui/coherence/coherence-wasm-bindgen.rs b/tests/ui/coherence/coherence-wasm-bindgen.rs index ee09a72449be1..57daaa134d495 100644 --- a/tests/ui/coherence/coherence-wasm-bindgen.rs +++ b/tests/ui/coherence/coherence-wasm-bindgen.rs @@ -31,7 +31,7 @@ where R: ReturnWasmAbi, { //~^^^^^ ERROR conflicting implementation - //~| WARNING this was previously accepted + //~| WARN the behavior may change in a future release } fn main() {} diff --git a/tests/ui/coherence/coherence-wasm-bindgen.stderr b/tests/ui/coherence/coherence-wasm-bindgen.stderr index b3c3dac612dbd..939f1fce9a40a 100644 --- a/tests/ui/coherence/coherence-wasm-bindgen.stderr +++ b/tests/ui/coherence/coherence-wasm-bindgen.stderr @@ -13,7 +13,7 @@ LL | | A: RefFromWasmAbi, LL | | R: ReturnWasmAbi, | |_____________________^ conflicting implementation for `&dyn Fn(&_) -> _` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = warning: the behavior may change in a future release = note: for more information, see issue #56105 = note: downstream crates may implement trait `FromWasmAbi` for type `&_` = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details diff --git a/tests/ui/coherence/const-errs-dont-conflict-103369.rs b/tests/ui/coherence/const-errs-dont-conflict-103369.rs new file mode 100644 index 0000000000000..c7d46a8000d4f --- /dev/null +++ b/tests/ui/coherence/const-errs-dont-conflict-103369.rs @@ -0,0 +1,14 @@ +// #103369: don't complain about conflicting implementations with [const error] + +pub trait ConstGenericTrait {} + +impl ConstGenericTrait<{my_fn(1)}> for () {} + +impl ConstGenericTrait<{my_fn(2)}> for () {} + +const fn my_fn(v: u32) -> u32 { + panic!("Some error occurred"); //~ ERROR E0080 + //~| ERROR E0080 +} + +fn main() {} diff --git a/tests/ui/coherence/const-errs-dont-conflict-103369.stderr b/tests/ui/coherence/const-errs-dont-conflict-103369.stderr new file mode 100644 index 0000000000000..22066d6b6bdee --- /dev/null +++ b/tests/ui/coherence/const-errs-dont-conflict-103369.stderr @@ -0,0 +1,39 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/const-errs-dont-conflict-103369.rs:10:5 + | +LL | panic!("Some error occurred"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Some error occurred', $DIR/const-errs-dont-conflict-103369.rs:10:5 + | +note: inside `my_fn` + --> $DIR/const-errs-dont-conflict-103369.rs:10:5 + | +LL | panic!("Some error occurred"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: inside `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}` + --> $DIR/const-errs-dont-conflict-103369.rs:5:25 + | +LL | impl ConstGenericTrait<{my_fn(1)}> for () {} + | ^^^^^^^^ + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0080]: evaluation of constant value failed + --> $DIR/const-errs-dont-conflict-103369.rs:10:5 + | +LL | panic!("Some error occurred"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Some error occurred', $DIR/const-errs-dont-conflict-103369.rs:10:5 + | +note: inside `my_fn` + --> $DIR/const-errs-dont-conflict-103369.rs:10:5 + | +LL | panic!("Some error occurred"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: inside `<() as ConstGenericTrait<{my_fn(2)}>>::{constant#0}` + --> $DIR/const-errs-dont-conflict-103369.rs:7:25 + | +LL | impl ConstGenericTrait<{my_fn(2)}> for () {} + | ^^^^^^^^ + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.explicit.stderr b/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.explicit.stderr index 5368db293383c..832c56a45549b 100644 --- a/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.explicit.stderr +++ b/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.explicit.stderr @@ -6,7 +6,7 @@ LL | impl FnMarker for fn(T) {} LL | impl FnMarker for fn(&T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `fn(&_)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = warning: the behavior may change in a future release = note: for more information, see issue #56105 = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details note: the lint level is defined here diff --git a/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.rs b/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.rs index 7967002e02102..e487dcc3c0e8d 100644 --- a/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.rs +++ b/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.rs @@ -20,6 +20,6 @@ trait FnMarker {} impl FnMarker for fn(T) {} impl FnMarker for fn(&T) {} //[explicit]~^ ERROR conflicting implementations of trait `FnMarker` for type `fn(&_)` -//[explicit]~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! +//[explicit]~| WARN the behavior may change in a future release fn main() {} diff --git a/tests/ui/const-generics/invariant.rs b/tests/ui/const-generics/invariant.rs index 39d658be67d40..ee4ad4e7c4e7b 100644 --- a/tests/ui/const-generics/invariant.rs +++ b/tests/ui/const-generics/invariant.rs @@ -12,18 +12,16 @@ impl SadBee for for<'a> fn(&'a ()) { const ASSOC: usize = 0; } impl SadBee for fn(&'static ()) { - //~^ WARNING conflicting implementations of trait - //~| WARNING this was previously accepted + //~^ WARN conflicting implementations of trait + //~| WARN the behavior may change in a future release const ASSOC: usize = 100; } struct Foo([u8; ::ASSOC], PhantomData) where - [(); ::ASSOC]: ; + [(); ::ASSOC]:; -fn covariant( - v: &'static Foo fn(&'a ())> -) -> &'static Foo { +fn covariant(v: &'static Foo fn(&'a ())>) -> &'static Foo { v //~^ ERROR mismatched types } diff --git a/tests/ui/const-generics/invariant.stderr b/tests/ui/const-generics/invariant.stderr index f631e1311460f..b4e46e5526836 100644 --- a/tests/ui/const-generics/invariant.stderr +++ b/tests/ui/const-generics/invariant.stderr @@ -7,13 +7,13 @@ LL | impl SadBee for for<'a> fn(&'a ()) { LL | impl SadBee for fn(&'static ()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a> fn(&'a ())` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = warning: the behavior may change in a future release = note: for more information, see issue #56105 = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details = note: `#[warn(coherence_leak_check)]` on by default error[E0308]: mismatched types - --> $DIR/invariant.rs:27:5 + --> $DIR/invariant.rs:25:5 | LL | v | ^ one type is more general than the other diff --git a/tests/ui/generic-associated-types/issue-79636-1.rs b/tests/ui/generic-associated-types/issue-79636-1.rs index a05311d59c11c..3357afb9d4dce 100644 --- a/tests/ui/generic-associated-types/issue-79636-1.rs +++ b/tests/ui/generic-associated-types/issue-79636-1.rs @@ -15,7 +15,6 @@ where //~^ ERROR: missing generics for associated type `Monad::Wrapped` { outer.bind(|inner| inner) - //~^ ERROR type annotations needed } fn main() { diff --git a/tests/ui/generic-associated-types/issue-79636-1.stderr b/tests/ui/generic-associated-types/issue-79636-1.stderr index 743d8b7d46279..c31064dec6296 100644 --- a/tests/ui/generic-associated-types/issue-79636-1.stderr +++ b/tests/ui/generic-associated-types/issue-79636-1.stderr @@ -30,19 +30,8 @@ help: function arguments must have a statically known size, borrowed types alway LL | fn bind(&self, f: F) -> Self::Wrapped { | + -error[E0282]: type annotations needed - --> $DIR/issue-79636-1.rs:17:17 - | -LL | outer.bind(|inner| inner) - | ^^^^^ - | -help: consider giving this closure parameter an explicit type - | -LL | outer.bind(|inner: /* Type */| inner) - | ++++++++++++ - error[E0277]: the trait bound `Option>: Monad` is not satisfied - --> $DIR/issue-79636-1.rs:22:21 + --> $DIR/issue-79636-1.rs:21:21 | LL | assert_eq!(join(Some(Some(true))), Some(true)); | ---- ^^^^^^^^^^^^^^^^ the trait `Monad` is not implemented for `Option>` @@ -63,7 +52,7 @@ LL | where LL | MOuter: Monad, | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `join` -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0107, E0277, E0282. +Some errors have detailed explanations: E0107, E0277. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/impl-trait/where-allowed.rs b/tests/ui/impl-trait/where-allowed.rs index 505e2d6c171f1..72ce617693e40 100644 --- a/tests/ui/impl-trait/where-allowed.rs +++ b/tests/ui/impl-trait/where-allowed.rs @@ -59,7 +59,6 @@ fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() } fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() } //~^ ERROR `impl Trait` is not allowed in the parameters of `Fn` trait bounds //~| ERROR nested `impl Trait` is not allowed -//~| ERROR: type annotations needed // Allowed fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() } diff --git a/tests/ui/impl-trait/where-allowed.stderr b/tests/ui/impl-trait/where-allowed.stderr index c22312cce1970..f203f4cabc847 100644 --- a/tests/ui/impl-trait/where-allowed.stderr +++ b/tests/ui/impl-trait/where-allowed.stderr @@ -17,7 +17,7 @@ LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic | outer `impl Trait` error[E0658]: `impl Trait` in associated types is unstable - --> $DIR/where-allowed.rs:123:16 + --> $DIR/where-allowed.rs:122:16 | LL | type Out = impl Debug; | ^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | type Out = impl Debug; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: `impl Trait` in type aliases is unstable - --> $DIR/where-allowed.rs:160:23 + --> $DIR/where-allowed.rs:159:23 | LL | type InTypeAlias = impl Debug; | ^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | type InTypeAlias = impl Debug; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: `impl Trait` in type aliases is unstable - --> $DIR/where-allowed.rs:163:39 + --> $DIR/where-allowed.rs:162:39 | LL | type InReturnInTypeAlias = fn() -> impl Debug; | ^^^^^^^^^^ @@ -127,7 +127,7 @@ LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in the parameters of `Fn` trait bounds - --> $DIR/where-allowed.rs:69:38 + --> $DIR/where-allowed.rs:68:38 | LL | fn in_Fn_parameter_in_generics (_: F) { panic!() } | ^^^^^^^^^^ @@ -135,7 +135,7 @@ LL | fn in_Fn_parameter_in_generics (_: F) { panic!() } = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in the return type of `Fn` trait bounds - --> $DIR/where-allowed.rs:73:40 + --> $DIR/where-allowed.rs:72:40 | LL | fn in_Fn_return_in_generics impl Debug> (_: F) { panic!() } | ^^^^^^^^^^ @@ -143,7 +143,7 @@ LL | fn in_Fn_return_in_generics impl Debug> (_: F) { panic!() } = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in field types - --> $DIR/where-allowed.rs:87:32 + --> $DIR/where-allowed.rs:86:32 | LL | struct InBraceStructField { x: impl Debug } | ^^^^^^^^^^ @@ -151,7 +151,7 @@ LL | struct InBraceStructField { x: impl Debug } = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in field types - --> $DIR/where-allowed.rs:91:41 + --> $DIR/where-allowed.rs:90:41 | LL | struct InAdtInBraceStructField { x: Vec } | ^^^^^^^^^^ @@ -159,7 +159,7 @@ LL | struct InAdtInBraceStructField { x: Vec } = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in field types - --> $DIR/where-allowed.rs:95:27 + --> $DIR/where-allowed.rs:94:27 | LL | struct InTupleStructField(impl Debug); | ^^^^^^^^^^ @@ -167,7 +167,7 @@ LL | struct InTupleStructField(impl Debug); = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in field types - --> $DIR/where-allowed.rs:100:25 + --> $DIR/where-allowed.rs:99:25 | LL | InBraceVariant { x: impl Debug }, | ^^^^^^^^^^ @@ -175,7 +175,7 @@ LL | InBraceVariant { x: impl Debug }, = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in field types - --> $DIR/where-allowed.rs:102:20 + --> $DIR/where-allowed.rs:101:20 | LL | InTupleVariant(impl Debug), | ^^^^^^^^^^ @@ -183,7 +183,7 @@ LL | InTupleVariant(impl Debug), = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in `extern fn` parameters - --> $DIR/where-allowed.rs:144:33 + --> $DIR/where-allowed.rs:143:33 | LL | fn in_foreign_parameters(_: impl Debug); | ^^^^^^^^^^ @@ -191,7 +191,7 @@ LL | fn in_foreign_parameters(_: impl Debug); = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in `extern fn` return types - --> $DIR/where-allowed.rs:147:31 + --> $DIR/where-allowed.rs:146:31 | LL | fn in_foreign_return() -> impl Debug; | ^^^^^^^^^^ @@ -199,7 +199,7 @@ LL | fn in_foreign_return() -> impl Debug; = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in `fn` pointer return types - --> $DIR/where-allowed.rs:163:39 + --> $DIR/where-allowed.rs:162:39 | LL | type InReturnInTypeAlias = fn() -> impl Debug; | ^^^^^^^^^^ @@ -207,7 +207,7 @@ LL | type InReturnInTypeAlias = fn() -> impl Debug; = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in traits - --> $DIR/where-allowed.rs:168:16 + --> $DIR/where-allowed.rs:167:16 | LL | impl PartialEq for () { | ^^^^^^^^^^ @@ -215,7 +215,7 @@ LL | impl PartialEq for () { = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in impl headers - --> $DIR/where-allowed.rs:173:24 + --> $DIR/where-allowed.rs:172:24 | LL | impl PartialEq<()> for impl Debug { | ^^^^^^^^^^ @@ -223,7 +223,7 @@ LL | impl PartialEq<()> for impl Debug { = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in impl headers - --> $DIR/where-allowed.rs:178:6 + --> $DIR/where-allowed.rs:177:6 | LL | impl impl Debug { | ^^^^^^^^^^ @@ -231,7 +231,7 @@ LL | impl impl Debug { = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in impl headers - --> $DIR/where-allowed.rs:184:24 + --> $DIR/where-allowed.rs:183:24 | LL | impl InInherentImplAdt { | ^^^^^^^^^^ @@ -239,7 +239,7 @@ LL | impl InInherentImplAdt { = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in bounds - --> $DIR/where-allowed.rs:190:11 + --> $DIR/where-allowed.rs:189:11 | LL | where impl Debug: Debug | ^^^^^^^^^^ @@ -247,7 +247,7 @@ LL | where impl Debug: Debug = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in bounds - --> $DIR/where-allowed.rs:197:15 + --> $DIR/where-allowed.rs:196:15 | LL | where Vec: Debug | ^^^^^^^^^^ @@ -255,7 +255,7 @@ LL | where Vec: Debug = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in bounds - --> $DIR/where-allowed.rs:204:24 + --> $DIR/where-allowed.rs:203:24 | LL | where T: PartialEq | ^^^^^^^^^^ @@ -263,7 +263,7 @@ LL | where T: PartialEq = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in the parameters of `Fn` trait bounds - --> $DIR/where-allowed.rs:211:17 + --> $DIR/where-allowed.rs:210:17 | LL | where T: Fn(impl Debug) | ^^^^^^^^^^ @@ -271,7 +271,7 @@ LL | where T: Fn(impl Debug) = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in the return type of `Fn` trait bounds - --> $DIR/where-allowed.rs:218:22 + --> $DIR/where-allowed.rs:217:22 | LL | where T: Fn() -> impl Debug | ^^^^^^^^^^ @@ -279,7 +279,7 @@ LL | where T: Fn() -> impl Debug = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in generic parameter defaults - --> $DIR/where-allowed.rs:224:40 + --> $DIR/where-allowed.rs:223:40 | LL | struct InStructGenericParamDefault(T); | ^^^^^^^^^^ @@ -287,7 +287,7 @@ LL | struct InStructGenericParamDefault(T); = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in generic parameter defaults - --> $DIR/where-allowed.rs:228:36 + --> $DIR/where-allowed.rs:227:36 | LL | enum InEnumGenericParamDefault { Variant(T) } | ^^^^^^^^^^ @@ -295,7 +295,7 @@ LL | enum InEnumGenericParamDefault { Variant(T) } = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in generic parameter defaults - --> $DIR/where-allowed.rs:232:38 + --> $DIR/where-allowed.rs:231:38 | LL | trait InTraitGenericParamDefault {} | ^^^^^^^^^^ @@ -303,7 +303,7 @@ LL | trait InTraitGenericParamDefault {} = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in generic parameter defaults - --> $DIR/where-allowed.rs:236:41 + --> $DIR/where-allowed.rs:235:41 | LL | type InTypeAliasGenericParamDefault = T; | ^^^^^^^^^^ @@ -311,7 +311,7 @@ LL | type InTypeAliasGenericParamDefault = T; = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in generic parameter defaults - --> $DIR/where-allowed.rs:240:11 + --> $DIR/where-allowed.rs:239:11 | LL | impl T {} | ^^^^^^^^^^ @@ -319,7 +319,7 @@ LL | impl T {} = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in generic parameter defaults - --> $DIR/where-allowed.rs:247:40 + --> $DIR/where-allowed.rs:246:40 | LL | fn in_method_generic_param_default(_: T) {} | ^^^^^^^^^^ @@ -327,7 +327,7 @@ LL | fn in_method_generic_param_default(_: T) {} = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/where-allowed.rs:253:29 + --> $DIR/where-allowed.rs:252:29 | LL | let _in_local_variable: impl Fn() = || {}; | ^^^^^^^^^ @@ -335,7 +335,7 @@ LL | let _in_local_variable: impl Fn() = || {}; = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in closure return types - --> $DIR/where-allowed.rs:255:46 + --> $DIR/where-allowed.rs:254:46 | LL | let _in_return_in_local_variable = || -> impl Fn() { || {} }; | ^^^^^^^^^ @@ -343,7 +343,7 @@ LL | let _in_return_in_local_variable = || -> impl Fn() { || {} }; = note: `impl Trait` is only allowed in arguments and return types of functions and methods error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/where-allowed.rs:240:7 + --> $DIR/where-allowed.rs:239:7 | LL | impl T {} | ^^^^^^^^^^^^^^ @@ -353,7 +353,7 @@ LL | impl T {} = note: `#[deny(invalid_type_param_default)]` on by default error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/where-allowed.rs:247:36 + --> $DIR/where-allowed.rs:246:36 | LL | fn in_method_generic_param_default(_: T) {} | ^^^^^^^^^^^^^^ @@ -362,7 +362,7 @@ LL | fn in_method_generic_param_default(_: T) {} = note: for more information, see issue #36887 error[E0118]: no nominal type found for inherent implementation - --> $DIR/where-allowed.rs:240:1 + --> $DIR/where-allowed.rs:239:1 | LL | impl T {} | ^^^^^^^^^^^^^^^^^^^^^^^ impl requires a nominal type @@ -377,14 +377,8 @@ LL | fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic! | = note: cannot satisfy `_: Debug` -error[E0282]: type annotations needed - --> $DIR/where-allowed.rs:59:49 - | -LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() } - | ^^^^^^^^^^^^^^^^^^^ cannot infer type - error[E0283]: type annotations needed - --> $DIR/where-allowed.rs:65:46 + --> $DIR/where-allowed.rs:64:46 | LL | fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() } | ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type @@ -396,7 +390,7 @@ LL | fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { pani where Args: Tuple, F: Fn, A: Allocator, F: ?Sized; error[E0599]: no function or associated item named `into_vec` found for slice `[_]` in the current scope - --> $DIR/where-allowed.rs:82:5 + --> $DIR/where-allowed.rs:81:5 | LL | vec![vec![0; 10], vec![12; 7], vec![8; 3]] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `[_]` @@ -404,7 +398,7 @@ LL | vec![vec![0; 10], vec![12; 7], vec![8; 3]] = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0053]: method `in_trait_impl_return` has an incompatible type for trait - --> $DIR/where-allowed.rs:130:34 + --> $DIR/where-allowed.rs:129:34 | LL | type Out = impl Debug; | ---------- the expected opaque type @@ -416,7 +410,7 @@ LL | fn in_trait_impl_return() -> impl Debug { () } | help: change the output type to match the trait: `<() as DummyTrait>::Out` | note: type in trait - --> $DIR/where-allowed.rs:120:34 + --> $DIR/where-allowed.rs:119:34 | LL | fn in_trait_impl_return() -> Self::Out; | ^^^^^^^^^ @@ -425,14 +419,14 @@ LL | fn in_trait_impl_return() -> Self::Out; = note: distinct uses of `impl Trait` result in different opaque types error: unconstrained opaque type - --> $DIR/where-allowed.rs:123:16 + --> $DIR/where-allowed.rs:122:16 | LL | type Out = impl Debug; | ^^^^^^^^^^ | = note: `Out` must be used in combination with a concrete type within the same impl -error: aborting due to 51 previous errors +error: aborting due to 50 previous errors -Some errors have detailed explanations: E0053, E0118, E0282, E0283, E0562, E0599, E0658, E0666. +Some errors have detailed explanations: E0053, E0118, E0283, E0562, E0599, E0658, E0666. For more information about an error, try `rustc --explain E0053`. diff --git a/tests/ui/inference/issue-80409.no-compat.stderr b/tests/ui/inference/issue-80409.no-compat.stderr index 7bb4786db3a91..f9772b2d5a699 100644 --- a/tests/ui/inference/issue-80409.no-compat.stderr +++ b/tests/ui/inference/issue-80409.no-compat.stderr @@ -1,6 +1,16 @@ error: internal compiler error: error performing ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: ImpliedOutlivesBounds { ty: &'?2 mut StateContext<'?3, usize> } } + --> $DIR/issue-80409.rs:49:30 | - = query stack during panic: +LL | builder.state().on_entry(|_| {}); + | ^^^ + | +note: + --> $DIR/issue-80409.rs:49:30 + | +LL | builder.state().on_entry(|_| {}); + | ^^^ + +query stack during panic: end of query stack error: aborting due to 1 previous error diff --git a/tests/ui/inference/issue-80409.rs b/tests/ui/inference/issue-80409.rs index e54da78614fdf..dfb84563e6d80 100644 --- a/tests/ui/inference/issue-80409.rs +++ b/tests/ui/inference/issue-80409.rs @@ -8,6 +8,7 @@ //@[no-compat] check-fail //@[no-compat] known-bug: #80409 //@[no-compat] failure-status: 101 +//@[no-compat] normalize-stderr-test "delayed at.*" -> "" //@[no-compat] normalize-stderr-test "note: .*\n\n" -> "" //@[no-compat] normalize-stderr-test "thread 'rustc' panicked.*\n" -> "" //@[no-compat] normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: " diff --git a/tests/ui/issues/issue-106755.rs b/tests/ui/issues/issue-106755.rs index 40cb83fcabc0c..689b1d885ae60 100644 --- a/tests/ui/issues/issue-106755.rs +++ b/tests/ui/issues/issue-106755.rs @@ -15,7 +15,5 @@ impl !Send for TestType {} //~ ERROR found both positive and nega unsafe impl Send for TestType {} //~ ERROR conflicting implementations impl !Send for TestType {} -//~^ WARNING -//~| WARNING this will change its meaning fn main() {} diff --git a/tests/ui/issues/issue-106755.stderr b/tests/ui/issues/issue-106755.stderr index 6b3a8427e7738..543970340620d 100644 --- a/tests/ui/issues/issue-106755.stderr +++ b/tests/ui/issues/issue-106755.stderr @@ -16,23 +16,7 @@ LL | unsafe impl Send for TestType {} LL | unsafe impl Send for TestType {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>` -warning: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/issue-106755.rs:17:1 - | -LL | impl !Send for TestType {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `i32` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/issue-106755.rs:9:1 - | -LL | struct TestType(::std::marker::PhantomData); - | ^^^^^^^^^^^^^^^^^^ - = note: `#[warn(suspicious_auto_trait_impls)]` on by default - -error: aborting due to 2 previous errors; 1 warning emitted +error: aborting due to 2 previous errors Some errors have detailed explanations: E0119, E0751. For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.rs b/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.rs index a3f65146f75fb..71416eb531ac2 100644 --- a/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.rs +++ b/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.rs @@ -18,7 +18,6 @@ impl Foo for () { type Baz = impl Sized; //~^ ERROR type `Baz` has 1 type parameter but its trait declaration has 0 type parameters - //~| ERROR unconstrained opaque type fn test<'a>() -> Self::Bar<'a> { &() diff --git a/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.stderr b/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.stderr index 13f5d8b8ea6e2..e5a21ff8b4e87 100644 --- a/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.stderr +++ b/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.stderr @@ -7,14 +7,6 @@ LL | type Baz<'a>; LL | type Baz = impl Sized; | ^ found 1 type parameter -error: unconstrained opaque type - --> $DIR/impl-trait-in-type-alias-with-bad-substs.rs:19:19 - | -LL | type Baz = impl Sized; - | ^^^^^^^^^^ - | - = note: `Baz` must be used in combination with a concrete type within the same impl - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0049`. diff --git a/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs b/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs index 3e15e28b8fd61..ce0b60b64119f 100644 --- a/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs +++ b/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs @@ -1,5 +1,4 @@ //@ aux-build:tdticc_coherence_lib.rs -#![allow(suspicious_auto_trait_impls)] // Test that we do not consider associated types to be sendable without // some applicable trait bound (and we don't ICE). @@ -11,15 +10,15 @@ extern crate tdticc_coherence_lib as lib; use lib::DefaultedTrait; struct A; -impl DefaultedTrait for (A,) { } //~ ERROR E0117 +impl DefaultedTrait for (A,) {} //~ ERROR E0117 struct B; -impl !DefaultedTrait for (B,) { } //~ ERROR E0117 +impl !DefaultedTrait for (B,) {} //~ ERROR E0117 struct C; struct D(T); -impl DefaultedTrait for Box { } //~ ERROR E0321 -impl DefaultedTrait for lib::Something { } //~ ERROR E0117 -impl DefaultedTrait for D { } // OK +impl DefaultedTrait for Box {} //~ ERROR E0321 +impl DefaultedTrait for lib::Something {} //~ ERROR E0117 +impl DefaultedTrait for D {} // OK -fn main() { } +fn main() {} diff --git a/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr b/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr index fc3778b796745..32e6e88fc4834 100644 --- a/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr +++ b/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr @@ -1,7 +1,7 @@ error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:14:1 + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:13:1 | -LL | impl DefaultedTrait for (A,) { } +LL | impl DefaultedTrait for (A,) {} | ^^^^^^^^^^^^^^^^^^^^^^^^---- | | | | | this is not defined in the current crate because tuples are always foreign @@ -10,9 +10,9 @@ LL | impl DefaultedTrait for (A,) { } = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:17:1 + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:16:1 | -LL | impl !DefaultedTrait for (B,) { } +LL | impl !DefaultedTrait for (B,) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^---- | | | | | this is not defined in the current crate because tuples are always foreign @@ -21,15 +21,15 @@ LL | impl !DefaultedTrait for (B,) { } = note: define and implement a trait or new type instead error[E0321]: cross-crate traits with a default impl, like `DefaultedTrait`, can only be implemented for a struct/enum type defined in the current crate - --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:21:1 + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:20:1 | -LL | impl DefaultedTrait for Box { } +LL | impl DefaultedTrait for Box {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait for type in another crate error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate - --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:22:1 + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:21:1 | -LL | impl DefaultedTrait for lib::Something { } +LL | impl DefaultedTrait for lib::Something {} | ^^^^^^^^^^^^^^^^^^^^^^^^----------------- | | | | | `Something` is not defined in the current crate diff --git a/tests/ui/wf/issue-110157.rs b/tests/ui/wf/issue-110157.rs index 07e2c5d58c340..1a3d13e93b0de 100644 --- a/tests/ui/wf/issue-110157.rs +++ b/tests/ui/wf/issue-110157.rs @@ -1,8 +1,7 @@ struct NeedsDropTypes<'tcx, F>(std::marker::PhantomData<&'tcx F>); impl<'tcx, F, I> Iterator for NeedsDropTypes<'tcx, F> -//~^ ERROR type annotations needed -//~| ERROR not all trait items implemented +//~^ ERROR not all trait items implemented where F: Fn(&Missing) -> Result, //~^ ERROR cannot find type `Missing` in this scope diff --git a/tests/ui/wf/issue-110157.stderr b/tests/ui/wf/issue-110157.stderr index 16bd34a6d8e44..e750ea47d515c 100644 --- a/tests/ui/wf/issue-110157.stderr +++ b/tests/ui/wf/issue-110157.stderr @@ -1,37 +1,20 @@ error[E0412]: cannot find type `Missing` in this scope - --> $DIR/issue-110157.rs:7:12 + --> $DIR/issue-110157.rs:6:12 | LL | F: Fn(&Missing) -> Result, | ^^^^^^^ not found in this scope error[E0412]: cannot find type `Missing` in this scope - --> $DIR/issue-110157.rs:9:24 + --> $DIR/issue-110157.rs:8:24 | LL | I: Iterator, | ^^^^^^^ not found in this scope -error[E0283]: type annotations needed - --> $DIR/issue-110157.rs:3:31 - | -LL | impl<'tcx, F, I> Iterator for NeedsDropTypes<'tcx, F> - | ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `I` - | - = note: cannot satisfy `_: Iterator` -note: required for `NeedsDropTypes<'tcx, F>` to implement `Iterator` - --> $DIR/issue-110157.rs:3:18 - | -LL | impl<'tcx, F, I> Iterator for NeedsDropTypes<'tcx, F> - | ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | I: Iterator, - | ------------------------ unsatisfied trait bound introduced here - error[E0046]: not all trait items implemented, missing: `Item`, `next` --> $DIR/issue-110157.rs:3:1 | LL | / impl<'tcx, F, I> Iterator for NeedsDropTypes<'tcx, F> LL | | -LL | | LL | | where LL | | F: Fn(&Missing) -> Result, LL | | @@ -41,7 +24,7 @@ LL | | I: Iterator, = help: implement the missing item: `type Item = /* Type */;` = help: implement the missing item: `fn next(&mut self) -> Option<::Item> { todo!() }` -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0046, E0283, E0412. +Some errors have detailed explanations: E0046, E0412. For more information about an error, try `rustc --explain E0046`.