From: bors Date: Sun, 7 Nov 2021 20:04:54 +0000 (+0000) Subject: Auto merge of #90668 - matthiaskrgr:clippy_nov7, r=jyn514 X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=46b8e7488eae116722196e8390c1bd2ea2e396cf;hp=5c454551dae45563e7a33da7142377cf7d8dbcbf;p=rust.git Auto merge of #90668 - matthiaskrgr:clippy_nov7, r=jyn514 more clippy fixes --- diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index e2424e7d7ad..f9e19d30fcc 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2645,34 +2645,42 @@ fn default() -> FnHeader { } #[derive(Clone, Encodable, Decodable, Debug)] -pub struct TraitKind( - pub IsAuto, - pub Unsafe, - pub Generics, - pub GenericBounds, - pub Vec>, -); +pub struct Trait { + pub unsafety: Unsafe, + pub is_auto: IsAuto, + pub generics: Generics, + pub bounds: GenericBounds, + pub items: Vec>, +} #[derive(Clone, Encodable, Decodable, Debug)] -pub struct TyAliasKind(pub Defaultness, pub Generics, pub GenericBounds, pub Option>); +pub struct TyAlias { + pub defaultness: Defaultness, + pub generics: Generics, + pub bounds: GenericBounds, + pub ty: Option>, +} #[derive(Clone, Encodable, Decodable, Debug)] -pub struct ImplKind { - pub unsafety: Unsafe, - pub polarity: ImplPolarity, +pub struct Impl { pub defaultness: Defaultness, - pub constness: Const, + pub unsafety: Unsafe, pub generics: Generics, - + pub constness: Const, + pub polarity: ImplPolarity, /// The trait being implemented, if any. pub of_trait: Option, - pub self_ty: P, pub items: Vec>, } #[derive(Clone, Encodable, Decodable, Debug)] -pub struct FnKind(pub Defaultness, pub FnSig, pub Generics, pub Option>); +pub struct Fn { + pub defaultness: Defaultness, + pub generics: Generics, + pub sig: FnSig, + pub body: Option>, +} #[derive(Clone, Encodable, Decodable, Debug)] pub enum ItemKind { @@ -2695,7 +2703,7 @@ pub enum ItemKind { /// A function declaration (`fn`). /// /// E.g., `fn foo(bar: usize) -> usize { .. }`. - Fn(Box), + Fn(Box), /// A module declaration (`mod`). /// /// E.g., `mod foo;` or `mod foo { .. }`. @@ -2711,7 +2719,7 @@ pub enum ItemKind { /// A type alias (`type`). /// /// E.g., `type Foo = Bar;`. - TyAlias(Box), + TyAlias(Box), /// An enum definition (`enum`). /// /// E.g., `enum Foo { C, D }`. @@ -2727,7 +2735,7 @@ pub enum ItemKind { /// A trait declaration (`trait`). /// /// E.g., `trait Foo { .. }`, `trait Foo { .. }` or `auto trait Foo {}`. - Trait(Box), + Trait(Box), /// Trait alias /// /// E.g., `trait Foo = Bar + Quux;`. @@ -2735,7 +2743,7 @@ pub enum ItemKind { /// An implementation. /// /// E.g., `impl Foo { .. }` or `impl Trait for Foo { .. }`. - Impl(Box), + Impl(Box), /// A macro invocation. /// /// E.g., `foo!(..)`. @@ -2782,14 +2790,14 @@ pub fn descr(&self) -> &str { pub fn generics(&self) -> Option<&Generics> { match self { - Self::Fn(box FnKind(_, _, generics, _)) - | Self::TyAlias(box TyAliasKind(_, generics, ..)) + Self::Fn(box Fn { generics, .. }) + | Self::TyAlias(box TyAlias { generics, .. }) | Self::Enum(_, generics) | Self::Struct(_, generics) | Self::Union(_, generics) - | Self::Trait(box TraitKind(_, _, generics, ..)) + | Self::Trait(box Trait { generics, .. }) | Self::TraitAlias(generics, _) - | Self::Impl(box ImplKind { generics, .. }) => Some(generics), + | Self::Impl(box Impl { generics, .. }) => Some(generics), _ => None, } } @@ -2812,9 +2820,9 @@ pub enum AssocItemKind { /// If `def` is parsed, then the constant is provided, and otherwise required. Const(Defaultness, P, Option>), /// An associated function. - Fn(Box), + Fn(Box), /// An associated type. - TyAlias(Box), + TyAlias(Box), /// A macro expanding to associated items. MacCall(MacCall), } @@ -2825,9 +2833,9 @@ pub enum AssocItemKind { impl AssocItemKind { pub fn defaultness(&self) -> Defaultness { match *self { - Self::Const(def, ..) - | Self::Fn(box FnKind(def, ..)) - | Self::TyAlias(box TyAliasKind(def, ..)) => def, + Self::Const(defaultness, ..) + | Self::Fn(box Fn { defaultness, .. }) + | Self::TyAlias(box TyAlias { defaultness, .. }) => defaultness, Self::MacCall(..) => Defaultness::Final, } } @@ -2864,9 +2872,9 @@ pub enum ForeignItemKind { /// A foreign static item (`static FOO: u8`). Static(P, Mutability, Option>), /// An foreign function. - Fn(Box), + Fn(Box), /// An foreign type. - TyAlias(Box), + TyAlias(Box), /// A macro expanding to foreign items. MacCall(MacCall), } diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 74def2bab1b..fc5cc963992 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -459,7 +459,8 @@ pub fn noop_visit_ty(ty: &mut P, vis: &mut T) { vis.visit_mt(mt); } TyKind::BareFn(bft) => { - let BareFnTy { unsafety: _, ext: _, generic_params, decl } = bft.deref_mut(); + let BareFnTy { unsafety, ext: _, generic_params, decl } = bft.deref_mut(); + visit_unsafety(unsafety, vis); generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param)); vis.visit_fn_decl(decl); } @@ -488,7 +489,8 @@ pub fn noop_visit_ty(ty: &mut P, vis: &mut T) { } pub fn noop_visit_foreign_mod(foreign_mod: &mut ForeignMod, vis: &mut T) { - let ForeignMod { unsafety: _, abi: _, items } = foreign_mod; + let ForeignMod { unsafety, abi: _, items } = foreign_mod; + visit_unsafety(unsafety, vis); items.flat_map_in_place(|item| vis.flat_map_foreign_item(item)); } @@ -788,6 +790,38 @@ pub fn visit_interpolated(nt: &mut token::Nonterminal, vis: &mut } } +// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. +pub fn visit_defaultness(defaultness: &mut Defaultness, vis: &mut T) { + match defaultness { + Defaultness::Default(span) => vis.visit_span(span), + Defaultness::Final => {} + } +} + +// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. +pub fn visit_unsafety(unsafety: &mut Unsafe, vis: &mut T) { + match unsafety { + Unsafe::Yes(span) => vis.visit_span(span), + Unsafe::No => {} + } +} + +// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. +pub fn visit_polarity(polarity: &mut ImplPolarity, vis: &mut T) { + match polarity { + ImplPolarity::Positive => {} + ImplPolarity::Negative(span) => vis.visit_span(span), + } +} + +// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. +pub fn visit_constness(constness: &mut Const, vis: &mut T) { + match constness { + Const::Yes(span) => vis.visit_span(span), + Const::No => {} + } +} + pub fn noop_visit_asyncness(asyncness: &mut Async, vis: &mut T) { match asyncness { Async::Yes { span: _, closure_id, return_impl_trait_id } => { @@ -955,25 +989,35 @@ pub fn noop_visit_item_kind(kind: &mut ItemKind, vis: &mut T) { match kind { ItemKind::ExternCrate(_orig_name) => {} ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree), - ItemKind::Static(ty, _, expr) | ItemKind::Const(_, ty, expr) => { + ItemKind::Static(ty, _, expr) => { vis.visit_ty(ty); visit_opt(expr, |expr| vis.visit_expr(expr)); } - ItemKind::Fn(box FnKind(_, sig, generics, body)) => { + ItemKind::Const(defaultness, ty, expr) => { + visit_defaultness(defaultness, vis); + vis.visit_ty(ty); + visit_opt(expr, |expr| vis.visit_expr(expr)); + } + ItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { + visit_defaultness(defaultness, vis); visit_fn_sig(sig, vis); vis.visit_generics(generics); visit_opt(body, |body| vis.visit_block(body)); } - ItemKind::Mod(_unsafety, mod_kind) => match mod_kind { - ModKind::Loaded(items, _inline, inner_span) => { - vis.visit_span(inner_span); - items.flat_map_in_place(|item| vis.flat_map_item(item)); + ItemKind::Mod(unsafety, mod_kind) => { + visit_unsafety(unsafety, vis); + match mod_kind { + ModKind::Loaded(items, _inline, inner_span) => { + vis.visit_span(inner_span); + items.flat_map_in_place(|item| vis.flat_map_item(item)); + } + ModKind::Unloaded => {} } - ModKind::Unloaded => {} - }, + } ItemKind::ForeignMod(nm) => vis.visit_foreign_mod(nm), ItemKind::GlobalAsm(asm) => noop_visit_inline_asm(asm, vis), - ItemKind::TyAlias(box TyAliasKind(_, generics, bounds, ty)) => { + ItemKind::TyAlias(box TyAlias { defaultness, generics, bounds, ty }) => { + visit_defaultness(defaultness, vis); vis.visit_generics(generics); visit_bounds(bounds, vis); visit_opt(ty, |ty| vis.visit_ty(ty)); @@ -986,22 +1030,27 @@ pub fn noop_visit_item_kind(kind: &mut ItemKind, vis: &mut T) { vis.visit_variant_data(variant_data); vis.visit_generics(generics); } - ItemKind::Impl(box ImplKind { - unsafety: _, - polarity: _, - defaultness: _, - constness: _, + ItemKind::Impl(box Impl { + defaultness, + unsafety, generics, + constness, + polarity, of_trait, self_ty, items, }) => { + visit_defaultness(defaultness, vis); + visit_unsafety(unsafety, vis); vis.visit_generics(generics); + visit_constness(constness, vis); + visit_polarity(polarity, vis); visit_opt(of_trait, |trait_ref| vis.visit_trait_ref(trait_ref)); vis.visit_ty(self_ty); items.flat_map_in_place(|item| vis.flat_map_impl_item(item)); } - ItemKind::Trait(box TraitKind(.., generics, bounds, items)) => { + ItemKind::Trait(box Trait { unsafety, is_auto: _, generics, bounds, items }) => { + visit_unsafety(unsafety, vis); vis.visit_generics(generics); visit_bounds(bounds, vis); items.flat_map_in_place(|item| vis.flat_map_trait_item(item)); @@ -1025,16 +1074,19 @@ pub fn noop_flat_map_assoc_item( visitor.visit_vis(vis); visit_attrs(attrs, visitor); match kind { - AssocItemKind::Const(_, ty, expr) => { + AssocItemKind::Const(defaultness, ty, expr) => { + visit_defaultness(defaultness, visitor); visitor.visit_ty(ty); visit_opt(expr, |expr| visitor.visit_expr(expr)); } - AssocItemKind::Fn(box FnKind(_, sig, generics, body)) => { + AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { + visit_defaultness(defaultness, visitor); visitor.visit_generics(generics); visit_fn_sig(sig, visitor); visit_opt(body, |body| visitor.visit_block(body)); } - AssocItemKind::TyAlias(box TyAliasKind(_, generics, bounds, ty)) => { + AssocItemKind::TyAlias(box TyAlias { defaultness, generics, bounds, ty }) => { + visit_defaultness(defaultness, visitor); visitor.visit_generics(generics); visit_bounds(bounds, visitor); visit_opt(ty, |ty| visitor.visit_ty(ty)); @@ -1047,8 +1099,10 @@ pub fn noop_flat_map_assoc_item( } pub fn noop_visit_fn_header(header: &mut FnHeader, vis: &mut T) { - let FnHeader { unsafety: _, asyncness, constness: _, ext: _ } = header; + let FnHeader { unsafety, asyncness, constness, ext: _ } = header; + visit_constness(constness, vis); vis.visit_asyncness(asyncness); + visit_unsafety(unsafety, vis); } // FIXME: Avoid visiting the crate as a `Mod` item, flat map only the inner items if possible, @@ -1114,12 +1168,14 @@ pub fn noop_flat_map_foreign_item( visitor.visit_ty(ty); visit_opt(expr, |expr| visitor.visit_expr(expr)); } - ForeignItemKind::Fn(box FnKind(_, sig, generics, body)) => { + ForeignItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { + visit_defaultness(defaultness, visitor); visitor.visit_generics(generics); visit_fn_sig(sig, visitor); visit_opt(body, |body| visitor.visit_block(body)); } - ForeignItemKind::TyAlias(box TyAliasKind(_, generics, bounds, ty)) => { + ForeignItemKind::TyAlias(box TyAlias { defaultness, generics, bounds, ty }) => { + visit_defaultness(defaultness, visitor); visitor.visit_generics(generics); visit_bounds(bounds, visitor); visit_opt(ty, |ty| visitor.visit_ty(ty)); diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index b38031042e0..be794ed221a 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -285,7 +285,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { visitor.visit_ty(typ); walk_list!(visitor, visit_expr, expr); } - ItemKind::Fn(box FnKind(_, ref sig, ref generics, ref body)) => { + ItemKind::Fn(box Fn { defaultness: _, ref generics, ref sig, ref body }) => { visitor.visit_generics(generics); let kind = FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, body.as_deref()); visitor.visit_fn(kind, item.span, item.id) @@ -300,7 +300,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { walk_list!(visitor, visit_foreign_item, &foreign_module.items); } ItemKind::GlobalAsm(ref asm) => walk_inline_asm(visitor, asm), - ItemKind::TyAlias(box TyAliasKind(_, ref generics, ref bounds, ref ty)) => { + ItemKind::TyAlias(box TyAlias { defaultness: _, ref generics, ref bounds, ref ty }) => { visitor.visit_generics(generics); walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_ty, ty); @@ -309,12 +309,12 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { visitor.visit_generics(generics); visitor.visit_enum_def(enum_definition, generics, item.id, item.span) } - ItemKind::Impl(box ImplKind { - unsafety: _, - polarity: _, + ItemKind::Impl(box Impl { defaultness: _, - constness: _, + unsafety: _, ref generics, + constness: _, + polarity: _, ref of_trait, ref self_ty, ref items, @@ -329,7 +329,13 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { visitor.visit_generics(generics); visitor.visit_variant_data(struct_definition); } - ItemKind::Trait(box TraitKind(.., ref generics, ref bounds, ref items)) => { + ItemKind::Trait(box Trait { + unsafety: _, + is_auto: _, + ref generics, + ref bounds, + ref items, + }) => { visitor.visit_generics(generics); walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Trait); @@ -547,12 +553,12 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI visitor.visit_ty(ty); walk_list!(visitor, visit_expr, expr); } - ForeignItemKind::Fn(box FnKind(_, sig, generics, body)) => { + ForeignItemKind::Fn(box Fn { defaultness: _, ref generics, ref sig, ref body }) => { visitor.visit_generics(generics); let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, body.as_deref()); visitor.visit_fn(kind, span, id); } - ForeignItemKind::TyAlias(box TyAliasKind(_, generics, bounds, ty)) => { + ForeignItemKind::TyAlias(box TyAlias { defaultness: _, generics, bounds, ty }) => { visitor.visit_generics(generics); walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_ty, ty); @@ -653,12 +659,12 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem, visitor.visit_ty(ty); walk_list!(visitor, visit_expr, expr); } - AssocItemKind::Fn(box FnKind(_, sig, generics, body)) => { + AssocItemKind::Fn(box Fn { defaultness: _, ref generics, ref sig, ref body }) => { visitor.visit_generics(generics); let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, body.as_deref()); visitor.visit_fn(kind, span, id); } - AssocItemKind::TyAlias(box TyAliasKind(_, generics, bounds, ty)) => { + AssocItemKind::TyAlias(box TyAlias { defaultness: _, generics, bounds, ty }) => { visitor.visit_generics(generics); walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_ty, ty); diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index d0da88f1cc0..95997a37d84 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -4,7 +4,8 @@ use rustc_data_structures::fx::FxHashMap; use rustc_errors::struct_span_err; use rustc_hir as hir; -use rustc_span::{Span, Symbol}; +use rustc_session::parse::feature_err; +use rustc_span::{sym, Span, Symbol}; use rustc_target::asm; use std::collections::hash_map::Entry; use std::fmt::Write; @@ -18,6 +19,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { struct_span_err!(self.sess, sp, E0472, "inline assembly is unsupported on this target") .emit(); } + if let Some(asm_arch) = asm_arch { + // Inline assembly is currently only stable for these architectures. + let is_stable = matches!( + asm_arch, + asm::InlineAsmArch::X86 + | asm::InlineAsmArch::X86_64 + | asm::InlineAsmArch::Arm + | asm::InlineAsmArch::AArch64 + | asm::InlineAsmArch::RiscV32 + | asm::InlineAsmArch::RiscV64 + ); + if !is_stable && !self.sess.features_untracked().asm_experimental_arch { + feature_err( + &self.sess.parse_sess, + sym::asm_experimental_arch, + sp, + "inline assembly is not stable yet on this architecture", + ) + .emit(); + } + } if asm.options.contains(InlineAsmOptions::ATT_SYNTAX) && !matches!(asm_arch, Some(asm::InlineAsmArch::X86 | asm::InlineAsmArch::X86_64)) && !self.sess.opts.actually_rustdoc @@ -121,10 +143,30 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { out_expr: out_expr.as_ref().map(|expr| self.lower_expr_mut(expr)), } } - InlineAsmOperand::Const { ref anon_const } => hir::InlineAsmOperand::Const { - anon_const: self.lower_anon_const(anon_const), - }, + InlineAsmOperand::Const { ref anon_const } => { + if !self.sess.features_untracked().asm_const { + feature_err( + &self.sess.parse_sess, + sym::asm_const, + *op_sp, + "const operands for inline assembly are unstable", + ) + .emit(); + } + hir::InlineAsmOperand::Const { + anon_const: self.lower_anon_const(anon_const), + } + } InlineAsmOperand::Sym { ref expr } => { + if !self.sess.features_untracked().asm_sym { + feature_err( + &self.sess.parse_sess, + sym::asm_sym, + *op_sp, + "sym operands for inline assembly are unstable", + ) + .emit(); + } hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) } } }; diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 63b20cd320b..6a4571cf6d2 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -49,7 +49,7 @@ fn visit_item(&mut self, item: &'a Item) { self.lctx.with_parent_item_lifetime_defs(hir_id, |this| { let this = &mut ItemLowerer { lctx: this }; match item.kind { - ItemKind::Impl(box ImplKind { ref of_trait, .. }) => { + ItemKind::Impl(box Impl { ref of_trait, .. }) => { this.with_trait_impl_ref(of_trait, |this| visit::walk_item(this, item)); } _ => visit::walk_item(this, item), @@ -218,12 +218,12 @@ fn lower_item_kind( let (ty, body_id) = self.lower_const_item(t, span, e.as_deref()); hir::ItemKind::Const(ty, body_id) } - ItemKind::Fn(box FnKind( - _, - FnSig { ref decl, header, span: fn_sig_span }, + ItemKind::Fn(box Fn { + sig: FnSig { ref decl, header, span: fn_sig_span }, ref generics, ref body, - )) => { + .. + }) => { let fn_def_id = self.resolver.local_def_id(id); self.with_new_scopes(|this| { this.current_item = Some(ident.span); @@ -273,7 +273,7 @@ fn lower_item_kind( ItemKind::GlobalAsm(ref asm) => { hir::ItemKind::GlobalAsm(self.lower_inline_asm(span, asm)) } - ItemKind::TyAlias(box TyAliasKind(_, ref gen, _, Some(ref ty))) => { + ItemKind::TyAlias(box TyAlias { ref generics, ty: Some(ref ty), .. }) => { // We lower // // type Foo = impl Trait @@ -288,10 +288,10 @@ fn lower_item_kind( capturable_lifetimes: &mut FxHashSet::default(), }, ); - let generics = self.lower_generics(gen, ImplTraitContext::disallowed()); + let generics = self.lower_generics(generics, ImplTraitContext::disallowed()); hir::ItemKind::TyAlias(ty, generics) } - ItemKind::TyAlias(box TyAliasKind(_, ref generics, _, None)) => { + ItemKind::TyAlias(box TyAlias { ref generics, ty: None, .. }) => { let ty = self.arena.alloc(self.ty(span, hir::TyKind::Err)); let generics = self.lower_generics(generics, ImplTraitContext::disallowed()); hir::ItemKind::TyAlias(ty, generics) @@ -318,7 +318,7 @@ fn lower_item_kind( self.lower_generics(generics, ImplTraitContext::disallowed()), ) } - ItemKind::Impl(box ImplKind { + ItemKind::Impl(box Impl { unsafety, polarity, defaultness, @@ -384,13 +384,13 @@ fn lower_item_kind( items: new_impl_items, }) } - ItemKind::Trait(box TraitKind( + ItemKind::Trait(box Trait { is_auto, unsafety, ref generics, ref bounds, ref items, - )) => { + }) => { let bounds = self.lower_param_bounds(bounds, ImplTraitContext::disallowed()); let items = self .arena @@ -655,7 +655,7 @@ fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir def_id, ident: self.lower_ident(i.ident), kind: match i.kind { - ForeignItemKind::Fn(box FnKind(_, ref sig, ref generics, _)) => { + ForeignItemKind::Fn(box Fn { ref sig, ref generics, .. }) => { let fdec = &sig.decl; let (generics, (fn_dec, fn_args)) = self.add_in_band_defs( generics, @@ -772,13 +772,13 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> { let body = default.as_ref().map(|x| self.lower_const_body(i.span, Some(x))); (hir::Generics::empty(), hir::TraitItemKind::Const(ty, body)) } - AssocItemKind::Fn(box FnKind(_, ref sig, ref generics, None)) => { + AssocItemKind::Fn(box Fn { ref sig, ref generics, body: None, .. }) => { let names = self.lower_fn_params_to_names(&sig.decl); let (generics, sig) = self.lower_method_sig(generics, sig, trait_item_def_id, false, None); (generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names))) } - AssocItemKind::Fn(box FnKind(_, ref sig, ref generics, Some(ref body))) => { + AssocItemKind::Fn(box Fn { ref sig, ref generics, body: Some(ref body), .. }) => { let asyncness = sig.header.asyncness; let body_id = self.lower_maybe_async_body(i.span, &sig.decl, asyncness, Some(&body)); @@ -791,8 +791,8 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> { ); (generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id))) } - AssocItemKind::TyAlias(box TyAliasKind(_, ref generics, ref bounds, ref default)) => { - let ty = default.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::disallowed())); + AssocItemKind::TyAlias(box TyAlias { ref generics, ref bounds, ref ty, .. }) => { + let ty = ty.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::disallowed())); let generics = self.lower_generics(generics, ImplTraitContext::disallowed()); let kind = hir::TraitItemKind::Type( self.lower_param_bounds(bounds, ImplTraitContext::disallowed()), @@ -818,11 +818,11 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> { fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemRef { let (kind, has_default) = match &i.kind { AssocItemKind::Const(_, _, default) => (hir::AssocItemKind::Const, default.is_some()), - AssocItemKind::TyAlias(box TyAliasKind(_, _, _, default)) => { - (hir::AssocItemKind::Type, default.is_some()) + AssocItemKind::TyAlias(box TyAlias { ty, .. }) => { + (hir::AssocItemKind::Type, ty.is_some()) } - AssocItemKind::Fn(box FnKind(_, sig, _, default)) => { - (hir::AssocItemKind::Fn { has_self: sig.decl.has_self() }, default.is_some()) + AssocItemKind::Fn(box Fn { sig, body, .. }) => { + (hir::AssocItemKind::Fn { has_self: sig.decl.has_self() }, body.is_some()) } AssocItemKind::MacCall(..) => unimplemented!(), }; @@ -853,7 +853,7 @@ fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> { hir::ImplItemKind::Const(ty, self.lower_const_body(i.span, expr.as_deref())), ) } - AssocItemKind::Fn(box FnKind(_, sig, generics, body)) => { + AssocItemKind::Fn(box Fn { sig, generics, body, .. }) => { self.current_item = Some(i.span); let asyncness = sig.header.asyncness; let body_id = @@ -869,7 +869,7 @@ fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> { (generics, hir::ImplItemKind::Fn(sig, body_id)) } - AssocItemKind::TyAlias(box TyAliasKind(_, generics, _, ty)) => { + AssocItemKind::TyAlias(box TyAlias { generics, ty, .. }) => { let generics = self.lower_generics(generics, ImplTraitContext::disallowed()); let kind = match ty { None => { @@ -920,7 +920,7 @@ fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef { kind: match &i.kind { AssocItemKind::Const(..) => hir::AssocItemKind::Const, AssocItemKind::TyAlias(..) => hir::AssocItemKind::Type, - AssocItemKind::Fn(box FnKind(_, sig, ..)) => { + AssocItemKind::Fn(box Fn { sig, .. }) => { hir::AssocItemKind::Fn { has_self: sig.decl.has_self() } } AssocItemKind::MacCall(..) => unimplemented!(), diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 793f6504be6..1822ba6ec99 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -1064,7 +1064,7 @@ fn visit_item(&mut self, item: &'a Item) { } match item.kind { - ItemKind::Impl(box ImplKind { + ItemKind::Impl(box Impl { unsafety, polarity, defaultness: _, @@ -1111,7 +1111,7 @@ fn visit_item(&mut self, item: &'a Item) { }); return; // Avoid visiting again. } - ItemKind::Impl(box ImplKind { + ItemKind::Impl(box Impl { unsafety, polarity, defaultness, @@ -1152,8 +1152,8 @@ fn visit_item(&mut self, item: &'a Item) { .emit(); } } - ItemKind::Fn(box FnKind(def, ref sig, ref generics, ref body)) => { - self.check_defaultness(item.span, def); + ItemKind::Fn(box Fn { defaultness, ref sig, ref generics, ref body }) => { + self.check_defaultness(item.span, defaultness); if body.is_none() { let msg = "free function without a body"; @@ -1195,19 +1195,13 @@ fn visit_item(&mut self, item: &'a Item) { } } } - ItemKind::Trait(box TraitKind( - is_auto, - _, - ref generics, - ref bounds, - ref trait_items, - )) => { + ItemKind::Trait(box Trait { is_auto, ref generics, ref bounds, ref items, .. }) => { if is_auto == IsAuto::Yes { // Auto traits cannot have generics, super traits nor contain items. self.deny_generic_params(generics, item.ident.span); self.deny_super_traits(bounds, item.ident.span); self.deny_where_clause(&generics.where_clause, item.ident.span); - self.deny_items(trait_items, item.ident.span); + self.deny_items(items, item.ident.span); } self.no_questions_in_bounds(bounds, "supertraits", true); @@ -1217,7 +1211,7 @@ fn visit_item(&mut self, item: &'a Item) { self.visit_ident(item.ident); self.visit_generics(generics); self.with_banned_tilde_const(|this| walk_list!(this, visit_param_bound, bounds)); - walk_list!(self, visit_assoc_item, trait_items, AssocCtxt::Trait); + walk_list!(self, visit_assoc_item, items, AssocCtxt::Trait); walk_list!(self, visit_attribute, &item.attrs); return; } @@ -1278,9 +1272,9 @@ fn visit_item(&mut self, item: &'a Item) { let msg = "free static item without body"; self.error_item_without_body(item.span, "static", msg, " = ;"); } - ItemKind::TyAlias(box TyAliasKind(def, _, ref bounds, ref body)) => { - self.check_defaultness(item.span, def); - if body.is_none() { + ItemKind::TyAlias(box TyAlias { defaultness, ref bounds, ref ty, .. }) => { + self.check_defaultness(item.span, defaultness); + if ty.is_none() { let msg = "free type alias without body"; self.error_item_without_body(item.span, "type", msg, " = ;"); } @@ -1294,15 +1288,15 @@ fn visit_item(&mut self, item: &'a Item) { fn visit_foreign_item(&mut self, fi: &'a ForeignItem) { match &fi.kind { - ForeignItemKind::Fn(box FnKind(def, sig, _, body)) => { - self.check_defaultness(fi.span, *def); + ForeignItemKind::Fn(box Fn { defaultness, sig, body, .. }) => { + self.check_defaultness(fi.span, *defaultness); self.check_foreign_fn_bodyless(fi.ident, body.as_deref()); self.check_foreign_fn_headerless(fi.ident, fi.span, sig.header); self.check_foreign_item_ascii_only(fi.ident); } - ForeignItemKind::TyAlias(box TyAliasKind(def, generics, bounds, body)) => { - self.check_defaultness(fi.span, *def); - self.check_foreign_kind_bodyless(fi.ident, "type", body.as_ref().map(|b| b.span)); + ForeignItemKind::TyAlias(box TyAlias { defaultness, generics, bounds, ty, .. }) => { + self.check_defaultness(fi.span, *defaultness); + self.check_foreign_kind_bodyless(fi.ident, "type", ty.as_ref().map(|b| b.span)); self.check_type_no_bounds(bounds, "`extern` blocks"); self.check_foreign_ty_genericless(generics); self.check_foreign_item_ascii_only(fi.ident); @@ -1587,11 +1581,11 @@ fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) { AssocItemKind::Const(_, _, body) => { self.check_impl_item_provided(item.span, body, "constant", " = ;"); } - AssocItemKind::Fn(box FnKind(_, _, _, body)) => { + AssocItemKind::Fn(box Fn { body, .. }) => { self.check_impl_item_provided(item.span, body, "function", " { }"); } - AssocItemKind::TyAlias(box TyAliasKind(_, _, bounds, body)) => { - self.check_impl_item_provided(item.span, body, "type", " = ;"); + AssocItemKind::TyAlias(box TyAlias { bounds, ty, .. }) => { + self.check_impl_item_provided(item.span, ty, "type", " = ;"); self.check_type_no_bounds(bounds, "`impl`s"); } _ => {} @@ -1600,7 +1594,7 @@ fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) { if ctxt == AssocCtxt::Trait || self.in_trait_impl { self.invalid_visibility(&item.vis, None); - if let AssocItemKind::Fn(box FnKind(_, sig, _, _)) = &item.kind { + if let AssocItemKind::Fn(box Fn { sig, .. }) = &item.kind { self.check_trait_fn_not_const(sig.header.constness); self.check_trait_fn_not_async(item.span, sig.header.asyncness); } @@ -1611,7 +1605,7 @@ fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) { } match item.kind { - AssocItemKind::TyAlias(box TyAliasKind(_, ref generics, ref bounds, ref ty)) + AssocItemKind::TyAlias(box TyAlias { ref generics, ref bounds, ref ty, .. }) if ctxt == AssocCtxt::Trait => { self.visit_vis(&item.vis); @@ -1623,7 +1617,7 @@ fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) { }); walk_list!(self, visit_ty, ty); } - AssocItemKind::Fn(box FnKind(_, ref sig, ref generics, ref body)) + AssocItemKind::Fn(box Fn { ref sig, ref generics, ref body, .. }) if self.in_const_trait_impl || ctxt == AssocCtxt::Trait || matches!(sig.header.constness, Const::Yes(_)) => diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index b4edd1ad8fb..f45a79f026f 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -423,9 +423,7 @@ fn visit_item(&mut self, i: &'a ast::Item) { } } - ast::ItemKind::Impl(box ast::ImplKind { - polarity, defaultness, ref of_trait, .. - }) => { + ast::ItemKind::Impl(box ast::Impl { polarity, defaultness, ref of_trait, .. }) => { if let ast::ImplPolarity::Negative(span) = polarity { gate_feature_post!( &self, @@ -441,7 +439,7 @@ fn visit_item(&mut self, i: &'a ast::Item) { } } - ast::ItemKind::Trait(box ast::TraitKind(ast::IsAuto::Yes, ..)) => { + ast::ItemKind::Trait(box ast::Trait { is_auto: ast::IsAuto::Yes, .. }) => { gate_feature_post!( &self, auto_traits, @@ -459,7 +457,7 @@ fn visit_item(&mut self, i: &'a ast::Item) { gate_feature_post!(&self, decl_macro, i.span, msg); } - ast::ItemKind::TyAlias(box ast::TyAliasKind(_, _, _, Some(ref ty))) => { + ast::ItemKind::TyAlias(box ast::TyAlias { ty: Some(ref ty), .. }) => { self.check_impl_trait(&ty) } @@ -632,7 +630,7 @@ fn visit_assoc_ty_constraint(&mut self, constraint: &'a AssocTyConstraint) { fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) { let is_fn = match i.kind { ast::AssocItemKind::Fn(_) => true, - ast::AssocItemKind::TyAlias(box ast::TyAliasKind(_, ref generics, _, ref ty)) => { + ast::AssocItemKind::TyAlias(box ast::TyAlias { ref generics, ref ty, .. }) => { if let (Some(_), AssocCtxt::Trait) = (ty, ctxt) { gate_feature_post!( &self, diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index bc1314121da..b59e49926ad 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1044,15 +1044,27 @@ pub fn print_type(&mut self, ty: &ast::Ty) { self.maybe_print_comment(span.lo()); self.print_outer_attributes(attrs); match kind { - ast::ForeignItemKind::Fn(box ast::FnKind(def, sig, gen, body)) => { - self.print_fn_full(sig, ident, gen, vis, *def, body.as_deref(), attrs); + ast::ForeignItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => { + self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs); } ast::ForeignItemKind::Static(ty, mutbl, body) => { let def = ast::Defaultness::Final; self.print_item_const(ident, Some(*mutbl), ty, body.as_deref(), vis, def); } - ast::ForeignItemKind::TyAlias(box ast::TyAliasKind(def, generics, bounds, ty)) => { - self.print_associated_type(ident, generics, bounds, ty.as_deref(), vis, *def); + ast::ForeignItemKind::TyAlias(box ast::TyAlias { + defaultness, + generics, + bounds, + ty, + }) => { + self.print_associated_type( + ident, + generics, + bounds, + ty.as_deref(), + vis, + *defaultness, + ); } ast::ForeignItemKind::MacCall(m) => { self.print_mac(m); @@ -1156,9 +1168,17 @@ fn print_associated_type( ast::ItemKind::Const(def, ref ty, ref body) => { self.print_item_const(item.ident, None, ty, body.as_deref(), &item.vis, def); } - ast::ItemKind::Fn(box ast::FnKind(def, ref sig, ref gen, ref body)) => { + ast::ItemKind::Fn(box ast::Fn { defaultness, ref sig, ref generics, ref body }) => { let body = body.as_deref(); - self.print_fn_full(sig, item.ident, gen, &item.vis, def, body, &item.attrs); + self.print_fn_full( + sig, + item.ident, + generics, + &item.vis, + defaultness, + body, + &item.attrs, + ); } ast::ItemKind::Mod(unsafety, ref mod_kind) => { self.head(self.to_string(|s| { @@ -1203,9 +1223,21 @@ fn print_associated_type( self.print_inline_asm(asm); self.end(); } - ast::ItemKind::TyAlias(box ast::TyAliasKind(def, ref generics, ref bounds, ref ty)) => { + ast::ItemKind::TyAlias(box ast::TyAlias { + defaultness, + ref generics, + ref bounds, + ref ty, + }) => { let ty = ty.as_deref(); - self.print_associated_type(item.ident, generics, bounds, ty, &item.vis, def); + self.print_associated_type( + item.ident, + generics, + bounds, + ty, + &item.vis, + defaultness, + ); } ast::ItemKind::Enum(ref enum_definition, ref params) => { self.print_enum_def(enum_definition, params, item.ident, item.span, &item.vis); @@ -1218,7 +1250,7 @@ fn print_associated_type( self.head(visibility_qualified(&item.vis, "union")); self.print_struct(struct_def, generics, item.ident, item.span, true); } - ast::ItemKind::Impl(box ast::ImplKind { + ast::ItemKind::Impl(box ast::Impl { unsafety, polarity, defaultness, @@ -1261,13 +1293,14 @@ fn print_associated_type( } self.bclose(item.span); } - ast::ItemKind::Trait(box ast::TraitKind( + ast::ItemKind::Trait(box ast::Trait { is_auto, unsafety, ref generics, ref bounds, - ref trait_items, - )) => { + ref items, + .. + }) => { self.head(""); self.print_visibility(&item.vis); self.print_unsafety(unsafety); @@ -1290,7 +1323,7 @@ fn print_associated_type( self.s.word(" "); self.bopen(); self.print_inner_attributes(&item.attrs); - for trait_item in trait_items { + for trait_item in items { self.print_assoc_item(trait_item); } self.bclose(item.span); @@ -1479,14 +1512,21 @@ fn print_poly_trait_ref(&mut self, t: &ast::PolyTraitRef) { self.maybe_print_comment(span.lo()); self.print_outer_attributes(attrs); match kind { - ast::AssocItemKind::Fn(box ast::FnKind(def, sig, gen, body)) => { - self.print_fn_full(sig, ident, gen, vis, *def, body.as_deref(), attrs); + ast::AssocItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => { + self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs); } ast::AssocItemKind::Const(def, ty, body) => { self.print_item_const(ident, None, ty, body.as_deref(), vis, *def); } - ast::AssocItemKind::TyAlias(box ast::TyAliasKind(def, generics, bounds, ty)) => { - self.print_associated_type(ident, generics, bounds, ty.as_deref(), vis, *def); + ast::AssocItemKind::TyAlias(box ast::TyAlias { defaultness, generics, bounds, ty }) => { + self.print_associated_type( + ident, + generics, + bounds, + ty.as_deref(), + vis, + *defaultness, + ); } ast::AssocItemKind::MacCall(m) => { self.print_mac(m); diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index a225b328ab6..994a74a5a9b 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -557,12 +557,12 @@ fn create_derived_impl( tokens: None, }, attrs: Vec::new(), - kind: ast::AssocItemKind::TyAlias(Box::new(ast::TyAliasKind( - ast::Defaultness::Final, - Generics::default(), - Vec::new(), - Some(type_def.to_ty(cx, self.span, type_ident, generics)), - ))), + kind: ast::AssocItemKind::TyAlias(Box::new(ast::TyAlias { + defaultness: ast::Defaultness::Final, + generics: Generics::default(), + bounds: Vec::new(), + ty: Some(type_def.to_ty(cx, self.span, type_ident, generics)), + })), tokens: None, }) }); @@ -726,7 +726,7 @@ fn create_derived_impl( self.span, Ident::empty(), a, - ast::ItemKind::Impl(Box::new(ast::ImplKind { + ast::ItemKind::Impl(Box::new(ast::Impl { unsafety, polarity: ast::ImplPolarity::Positive, defaultness: ast::Defaultness::Final, @@ -955,7 +955,7 @@ fn create_method( decl: fn_decl, span: trait_.span, }; - let def = ast::Defaultness::Final; + let defaultness = ast::Defaultness::Final; // Create the method. P(ast::AssocItem { @@ -968,12 +968,12 @@ fn create_method( tokens: None, }, ident: method_ident, - kind: ast::AssocItemKind::Fn(Box::new(ast::FnKind( - def, + kind: ast::AssocItemKind::Fn(Box::new(ast::Fn { + defaultness, sig, - fn_generics, - Some(body_block), - ))), + generics: fn_generics, + body: Some(body_block), + })), tokens: None, }) } diff --git a/compiler/rustc_builtin_macros/src/deriving/mod.rs b/compiler/rustc_builtin_macros/src/deriving/mod.rs index fa389a51115..367a5aa7323 100644 --- a/compiler/rustc_builtin_macros/src/deriving/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/mod.rs @@ -2,7 +2,7 @@ use rustc_ast as ast; use rustc_ast::ptr::P; -use rustc_ast::{ImplKind, ItemKind, MetaItem}; +use rustc_ast::{Impl, ItemKind, MetaItem}; use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, MultiItemModifier}; use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::Span; @@ -180,7 +180,7 @@ fn inject_impl_of_structural_trait( span, Ident::empty(), attrs, - ItemKind::Impl(Box::new(ImplKind { + ItemKind::Impl(Box::new(Impl { unsafety: ast::Unsafe::No, polarity: ast::ImplPolarity::Positive, defaultness: ast::Defaultness::Final, diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs index 3f71ee6f489..a433876147f 100644 --- a/compiler/rustc_builtin_macros/src/global_allocator.rs +++ b/compiler/rustc_builtin_macros/src/global_allocator.rs @@ -5,7 +5,7 @@ }; use rustc_ast::ptr::P; use rustc_ast::{self as ast, Attribute, Expr, FnHeader, FnSig, Generics, Param, StmtKind}; -use rustc_ast::{FnKind, ItemKind, Mutability, Stmt, Ty, TyKind, Unsafe}; +use rustc_ast::{Fn, ItemKind, Mutability, Stmt, Ty, TyKind, Unsafe}; use rustc_expand::base::{Annotatable, ExtCtxt}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::Span; @@ -84,13 +84,13 @@ fn allocator_fn(&self, method: &AllocatorMethod) -> Stmt { let decl = self.cx.fn_decl(abi_args, ast::FnRetTy::Ty(output_ty)); let header = FnHeader { unsafety: Unsafe::Yes(self.span), ..FnHeader::default() }; let sig = FnSig { decl, header, span: self.span }; - let block = Some(self.cx.block_expr(output_expr)); - let kind = ItemKind::Fn(Box::new(FnKind( - ast::Defaultness::Final, + let body = Some(self.cx.block_expr(output_expr)); + let kind = ItemKind::Fn(Box::new(Fn { + defaultness: ast::Defaultness::Final, sig, - Generics::default(), - block, - ))); + generics: Generics::default(), + body, + })); let item = self.cx.item( self.span, Ident::from_str_and_span(&self.kind.fn_name(method.name), self.span), diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index bbca07085ea..d2629926b51 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -429,7 +429,7 @@ fn test_type(cx: &ExtCtxt<'_>) -> TestType { fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool { let has_should_panic_attr = cx.sess.contains_name(&i.attrs, sym::should_panic); let sd = &cx.sess.parse_sess.span_diagnostic; - if let ast::ItemKind::Fn(box ast::FnKind(_, ref sig, ref generics, _)) = i.kind { + if let ast::ItemKind::Fn(box ast::Fn { ref sig, ref generics, .. }) = i.kind { if let ast::Unsafe::Yes(span) = sig.header.unsafety { sd.struct_span_err(i.span, "unsafe functions cannot be used for tests") .span_label(span, "`unsafe` because of this") @@ -478,7 +478,7 @@ fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool { } fn has_bench_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool { - let has_sig = if let ast::ItemKind::Fn(box ast::FnKind(_, ref sig, _, _)) = i.kind { + let has_sig = if let ast::ItemKind::Fn(box ast::Fn { ref sig, .. }) = i.kind { // N.B., inadequate check, but we're running // well before resolve, can't get too deep. sig.decl.inputs.len() == 1 diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index d791677cb8e..64ccd4331e5 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -313,13 +313,13 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P { let decl = ecx.fn_decl(vec![], ast::FnRetTy::Ty(main_ret_ty)); let sig = ast::FnSig { decl, header: ast::FnHeader::default(), span: sp }; - let def = ast::Defaultness::Final; - let main = ast::ItemKind::Fn(Box::new(ast::FnKind( - def, + let defaultness = ast::Defaultness::Final; + let main = ast::ItemKind::Fn(Box::new(ast::Fn { + defaultness, sig, - ast::Generics::default(), - Some(main_body), - ))); + generics: ast::Generics::default(), + body: Some(main_body), + })); // Honor the reexport_test_harness_main attribute let main_id = match cx.reexport_test_harness_main { diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 1c6f1344e8a..0266b7844ba 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -692,6 +692,15 @@ pub fn set(&self, features: &mut Features, span: Span) { /// Tells rustdoc to automatically generate `#[doc(cfg(...))]`. (active, doc_auto_cfg, "1.58.0", Some(43781), None), + /// Allows using `const` operands in inline assembly. + (active, asm_const, "1.58.0", Some(72016), None), + + /// Allows using `sym` operands in inline assembly. + (active, asm_sym, "1.58.0", Some(72016), None), + + /// Enables experimental inline assembly support for additional architectures. + (active, asm_experimental_arch, "1.58.0", Some(72016), None), + // ------------------------------------------------------------------------- // feature-group-end: actual feature gates // ------------------------------------------------------------------------- diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index cffb087af18..94650237873 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -776,7 +776,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a, '_> { fn visit_item_kind(&mut self, i: &mut ast::ItemKind) { let is_const = match i { ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => true, - ast::ItemKind::Fn(box ast::FnKind(_, ref sig, _, _)) => Self::is_sig_const(sig), + ast::ItemKind::Fn(box ast::Fn { ref sig, .. }) => Self::is_sig_const(sig), _ => false, }; self.run(is_const, |s| noop_visit_item_kind(i, s)) @@ -785,7 +785,7 @@ fn visit_item_kind(&mut self, i: &mut ast::ItemKind) { fn flat_map_trait_item(&mut self, i: P) -> SmallVec<[P; 1]> { let is_const = match i.kind { ast::AssocItemKind::Const(..) => true, - ast::AssocItemKind::Fn(box ast::FnKind(_, ref sig, _, _)) => Self::is_sig_const(sig), + ast::AssocItemKind::Fn(box ast::Fn { ref sig, .. }) => Self::is_sig_const(sig), _ => false, }; self.run(is_const, |s| noop_flat_map_assoc_item(i, s)) diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 985574b195e..6548cdc0fdc 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -369,12 +369,12 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) { fn check_item(&mut self, cx: &EarlyContext<'_>, it: &ast::Item) { match it.kind { - ast::ItemKind::Trait(box ast::TraitKind(_, ast::Unsafe::Yes(_), ..)) => self + ast::ItemKind::Trait(box ast::Trait { unsafety: ast::Unsafe::Yes(_), .. }) => self .report_unsafe(cx, it.span, |lint| { lint.build("declaration of an `unsafe` trait").emit() }), - ast::ItemKind::Impl(box ast::ImplKind { unsafety: ast::Unsafe::Yes(_), .. }) => self + ast::ItemKind::Impl(box ast::Impl { unsafety: ast::Unsafe::Yes(_), .. }) => self .report_unsafe(cx, it.span, |lint| { lint.build("implementation of an `unsafe` trait").emit() }), @@ -921,7 +921,7 @@ fn check_trait_item(&mut self, cx: &EarlyContext<'_>, it: &ast::AssocItem) { // This is a hard error in future editions; avoid linting and erroring return; } - if let ast::AssocItemKind::Fn(box FnKind(_, ref sig, _, _)) = it.kind { + if let ast::AssocItemKind::Fn(box Fn { ref sig, .. }) = it.kind { for arg in sig.decl.inputs.iter() { if let ast::PatKind::Ident(_, ident, None) = arg.pat.kind { if ident.name == kw::Empty { diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index f64312761da..c64a67b6b9f 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -229,8 +229,7 @@ fn gen_args(segment: &PathSegment<'_>) -> String { impl EarlyLintPass for LintPassImpl { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) { - if let ast::ItemKind::Impl(box ast::ImplKind { of_trait: Some(lint_pass), .. }) = &item.kind - { + if let ast::ItemKind::Impl(box ast::Impl { of_trait: Some(lint_pass), .. }) = &item.kind { if let Some(last) = lint_pass.path.segments.last() { if last.ident.name == sym::LintPass { let expn_data = lint_pass.path.span.ctxt().outer_expn_data(); diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 95b74fd5306..eb0a693226c 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -29,6 +29,7 @@ use proc_macro::bridge::client::ProcMacro; use std::collections::BTreeMap; +use std::ops::Fn; use std::path::Path; use std::{cmp, env}; use tracing::{debug, info}; diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index d2167c7a5db..73ca809ab1d 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -220,7 +220,7 @@ fn parse_item_kind( } else if self.check_fn_front_matter(def_final) { // FUNCTION ITEM let (ident, sig, generics, body) = self.parse_fn(attrs, req_name, lo)?; - (ident, ItemKind::Fn(Box::new(FnKind(def(), sig, generics, body)))) + (ident, ItemKind::Fn(Box::new(Fn { defaultness: def(), sig, generics, body }))) } else if self.eat_keyword(kw::Extern) { if self.eat_keyword(kw::Crate) { // EXTERN CRATE @@ -560,7 +560,7 @@ fn parse_item_impl( }; let trait_ref = TraitRef { path, ref_id: ty_first.id }; - ItemKind::Impl(Box::new(ImplKind { + ItemKind::Impl(Box::new(Impl { unsafety, polarity, defaultness, @@ -573,7 +573,7 @@ fn parse_item_impl( } None => { // impl Type - ItemKind::Impl(Box::new(ImplKind { + ItemKind::Impl(Box::new(Impl { unsafety, polarity, defaultness, @@ -682,7 +682,7 @@ fn parse_item_trait(&mut self, attrs: &mut Vec, lo: Span) -> PResult< self.expect_keyword(kw::Trait)?; let ident = self.parse_ident()?; - let mut tps = self.parse_generics()?; + let mut generics = self.parse_generics()?; // Parse optional colon and supertrait bounds. let had_colon = self.eat(&token::Colon); @@ -702,7 +702,7 @@ fn parse_item_trait(&mut self, attrs: &mut Vec, lo: Span) -> PResult< } let bounds = self.parse_generic_bounds(None)?; - tps.where_clause = self.parse_where_clause()?; + generics.where_clause = self.parse_where_clause()?; self.expect_semi()?; let whole_span = lo.to(self.prev_token.span); @@ -717,12 +717,15 @@ fn parse_item_trait(&mut self, attrs: &mut Vec, lo: Span) -> PResult< self.sess.gated_spans.gate(sym::trait_alias, whole_span); - Ok((ident, ItemKind::TraitAlias(tps, bounds))) + Ok((ident, ItemKind::TraitAlias(generics, bounds))) } else { // It's a normal trait. - tps.where_clause = self.parse_where_clause()?; + generics.where_clause = self.parse_where_clause()?; let items = self.parse_item_list(attrs, |p| p.parse_trait_item(ForceCollect::No))?; - Ok((ident, ItemKind::Trait(Box::new(TraitKind(is_auto, unsafety, tps, bounds, items))))) + Ok(( + ident, + ItemKind::Trait(Box::new(Trait { is_auto, unsafety, generics, bounds, items })), + )) } } @@ -769,7 +772,7 @@ fn parse_assoc_item( /// TypeAlias = "type" Ident Generics {":" GenericBounds}? {"=" Ty}? ";" ; /// ``` /// The `"type"` has already been eaten. - fn parse_type_alias(&mut self, def: Defaultness) -> PResult<'a, ItemInfo> { + fn parse_type_alias(&mut self, defaultness: Defaultness) -> PResult<'a, ItemInfo> { let ident = self.parse_ident()?; let mut generics = self.parse_generics()?; @@ -778,10 +781,10 @@ fn parse_type_alias(&mut self, def: Defaultness) -> PResult<'a, ItemInfo> { if self.eat(&token::Colon) { self.parse_generic_bounds(None)? } else { Vec::new() }; generics.where_clause = self.parse_where_clause()?; - let default = if self.eat(&token::Eq) { Some(self.parse_ty()?) } else { None }; + let ty = if self.eat(&token::Eq) { Some(self.parse_ty()?) } else { None }; self.expect_semi()?; - Ok((ident, ItemKind::TyAlias(Box::new(TyAliasKind(def, generics, bounds, default))))) + Ok((ident, ItemKind::TyAlias(Box::new(TyAlias { defaultness, generics, bounds, ty })))) } /// Parses a `UseTree`. @@ -1039,9 +1042,7 @@ fn recover_const_impl( }; match impl_info.1 { - ItemKind::Impl(box ImplKind { - of_trait: Some(ref trai), ref mut constness, .. - }) => { + ItemKind::Impl(box Impl { of_trait: Some(ref trai), ref mut constness, .. }) => { *constness = Const::Yes(const_span); let before_trait = trai.path.span.shrink_to_lo(); diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 33af9884cbb..d77a70e5327 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -15,7 +15,7 @@ use rustc_ast::visit::{self, AssocCtxt, Visitor}; use rustc_ast::{self as ast, AssocItem, AssocItemKind, MetaItemKind, StmtKind}; -use rustc_ast::{Block, FnKind, ForeignItem, ForeignItemKind, ImplKind, Item, ItemKind, NodeId}; +use rustc_ast::{Block, Fn, ForeignItem, ForeignItemKind, Impl, Item, ItemKind, NodeId}; use rustc_ast_lowering::ResolverAstLowering; use rustc_attr as attr; use rustc_data_structures::sync::Lrc; @@ -880,7 +880,7 @@ fn build_reduced_graph_for_item(&mut self, item: &'b Item) { } // These items do not add names to modules. - ItemKind::Impl(box ImplKind { of_trait: Some(..), .. }) => { + ItemKind::Impl(box Impl { of_trait: Some(..), .. }) => { self.r.trait_impl_items.insert(local_def_id); } ItemKind::Impl { .. } | ItemKind::ForeignMod(..) | ItemKind::GlobalAsm(..) => {} @@ -1380,7 +1380,7 @@ fn visit_assoc_item(&mut self, item: &'b AssocItem, ctxt: AssocCtxt) { if ctxt == AssocCtxt::Trait { let (def_kind, ns) = match item.kind { AssocItemKind::Const(..) => (DefKind::AssocConst, ValueNS), - AssocItemKind::Fn(box FnKind(_, ref sig, _, _)) => { + AssocItemKind::Fn(box Fn { ref sig, .. }) => { if sig.decl.has_self() { self.r.has_self.insert(def_id); } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 0a24e00ee4b..e67f7f03516 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -498,8 +498,8 @@ fn visit_poly_trait_ref(&mut self, tref: &'ast PolyTraitRef, m: &'ast TraitBound } fn visit_foreign_item(&mut self, foreign_item: &'ast ForeignItem) { match foreign_item.kind { - ForeignItemKind::Fn(box FnKind(_, _, ref generics, _)) - | ForeignItemKind::TyAlias(box TyAliasKind(_, ref generics, ..)) => { + ForeignItemKind::Fn(box Fn { ref generics, .. }) + | ForeignItemKind::TyAlias(box TyAlias { ref generics, .. }) => { self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| { visit::walk_foreign_item(this, foreign_item); }); @@ -953,8 +953,8 @@ fn resolve_item(&mut self, item: &'ast Item) { debug!("(resolving item) resolving {} ({:?})", name, item.kind); match item.kind { - ItemKind::TyAlias(box TyAliasKind(_, ref generics, _, _)) - | ItemKind::Fn(box FnKind(_, _, ref generics, _)) => { + ItemKind::TyAlias(box TyAlias { ref generics, .. }) + | ItemKind::Fn(box Fn { ref generics, .. }) => { self.compute_num_lifetime_params(item.id, generics); self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| { visit::walk_item(this, item) @@ -968,7 +968,7 @@ fn resolve_item(&mut self, item: &'ast Item) { self.resolve_adt(item, generics); } - ItemKind::Impl(box ImplKind { + ItemKind::Impl(box Impl { ref generics, ref of_trait, ref self_ty, @@ -979,7 +979,7 @@ fn resolve_item(&mut self, item: &'ast Item) { self.resolve_implementation(generics, of_trait, &self_ty, item.id, impl_items); } - ItemKind::Trait(box TraitKind(.., ref generics, ref bounds, ref trait_items)) => { + ItemKind::Trait(box Trait { ref generics, ref bounds, ref items, .. }) => { self.compute_num_lifetime_params(item.id, generics); // Create a new rib for the trait-wide type parameters. self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| { @@ -994,8 +994,8 @@ fn resolve_item(&mut self, item: &'ast Item) { }); }; - this.with_trait_items(trait_items, |this| { - for item in trait_items { + this.with_trait_items(items, |this| { + for item in items { match &item.kind { AssocItemKind::Const(_, ty, default) => { this.visit_ty(ty); @@ -1015,10 +1015,10 @@ fn resolve_item(&mut self, item: &'ast Item) { ); } } - AssocItemKind::Fn(box FnKind(_, _, generics, _)) => { + AssocItemKind::Fn(box Fn { generics, .. }) => { walk_assoc_item(this, generics, item); } - AssocItemKind::TyAlias(box TyAliasKind(_, generics, _, _)) => { + AssocItemKind::TyAlias(box TyAlias { generics, .. }) => { walk_assoc_item(this, generics, item); } AssocItemKind::MacCall(_) => { @@ -1338,7 +1338,7 @@ fn resolve_implementation( }, ); } - AssocItemKind::Fn(box FnKind(.., generics, _)) => { + AssocItemKind::Fn(box Fn { generics, .. }) => { debug!("resolve_implementation AssocItemKind::Fn"); // We also need a new scope for the impl item type parameters. this.with_generic_param_rib( @@ -1363,12 +1363,9 @@ fn resolve_implementation( }, ); } - AssocItemKind::TyAlias(box TyAliasKind( - _, - generics, - _, - _, - )) => { + AssocItemKind::TyAlias(box TyAlias { + generics, .. + }) => { debug!("resolve_implementation AssocItemKind::TyAlias"); // We also need a new scope for the impl item type parameters. this.with_generic_param_rib( diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 489d5c40415..4acbb11b13f 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1235,9 +1235,7 @@ fn extract_node_id(t: &Ty) -> Option { if assoc_item.ident == ident { return Some(match &assoc_item.kind { ast::AssocItemKind::Const(..) => AssocSuggestion::AssocConst, - ast::AssocItemKind::Fn(box ast::FnKind(_, sig, ..)) - if sig.decl.has_self() => - { + ast::AssocItemKind::Fn(box ast::Fn { sig, .. }) if sig.decl.has_self() => { AssocSuggestion::MethodWithSelf } ast::AssocItemKind::Fn(..) => AssocSuggestion::AssocFn, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 52e2a8f48e2..b9730a1e420 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -327,6 +327,9 @@ as_ptr, as_str, asm, + asm_const, + asm_experimental_arch, + asm_sym, assert, assert_inhabited, assert_macro, diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 5f44087cabb..4b16a269f2d 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -193,6 +193,7 @@ #![feature(try_blocks)] #![feature(unboxed_closures)] #![feature(unsized_fn_params)] +#![cfg_attr(not(bootstrap), feature(asm_const))] // // Target features: #![feature(aarch64_target_feature)] diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs index 6f4863057ab..b99eb2e553f 100644 --- a/library/std/src/sys/unix/thread.rs +++ b/library/std/src/sys/unix/thread.rs @@ -275,6 +275,14 @@ pub fn available_parallelism() -> io::Result { target_os = "solaris", target_os = "illumos", ))] { + #[cfg(any(target_os = "android", target_os = "linux"))] + { + let mut set: libc::cpu_set_t = unsafe { mem::zeroed() }; + if unsafe { libc::sched_getaffinity(0, mem::size_of::(), &mut set) } == 0 { + let count = unsafe { libc::CPU_COUNT(&set) }; + return Ok(unsafe { NonZeroUsize::new_unchecked(count as usize) }); + } + } match unsafe { libc::sysconf(libc::_SC_NPROCESSORS_ONLN) } { -1 => Err(io::Error::last_os_error()), 0 => Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform")), diff --git a/src/doc/unstable-book/src/library-features/global-asm.md b/src/doc/unstable-book/src/library-features/global-asm.md index 146d17b4638..3f8e165841d 100644 --- a/src/doc/unstable-book/src/library-features/global-asm.md +++ b/src/doc/unstable-book/src/library-features/global-asm.md @@ -75,7 +75,7 @@ are concatenated into one or assembled separately. constants defined in Rust to be used in assembly code: ```rust,no_run -#![feature(global_asm)] +#![feature(global_asm, asm_const)] # #[cfg(any(target_arch="x86", target_arch="x86_64"))] # mod x86 { const C: i32 = 1234; @@ -96,7 +96,7 @@ override this by adding `options(att_syntax)` at the end of the macro arguments list: ```rust,no_run -#![feature(global_asm)] +#![feature(global_asm, asm_const)] # #[cfg(any(target_arch="x86", target_arch="x86_64"))] # mod x86 { global_asm!("movl ${}, %ecx", const 5, options(att_syntax)); diff --git a/src/test/assembly/asm/aarch64-types.rs b/src/test/assembly/asm/aarch64-types.rs index 66c39a48c6e..04b5f4aed9b 100644 --- a/src/test/assembly/asm/aarch64-types.rs +++ b/src/test/assembly/asm/aarch64-types.rs @@ -2,7 +2,7 @@ // compile-flags: --target aarch64-unknown-linux-gnu // needs-llvm-components: aarch64 -#![feature(no_core, lang_items, rustc_attrs, repr_simd)] +#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)] #![crate_type = "rlib"] #![no_core] #![allow(asm_sub_register, non_camel_case_types)] diff --git a/src/test/assembly/asm/arm-types.rs b/src/test/assembly/asm/arm-types.rs index c848e3284ff..0c57b1fc478 100644 --- a/src/test/assembly/asm/arm-types.rs +++ b/src/test/assembly/asm/arm-types.rs @@ -3,7 +3,7 @@ // compile-flags: -C target-feature=+neon // needs-llvm-components: arm -#![feature(no_core, lang_items, rustc_attrs, repr_simd)] +#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)] #![crate_type = "rlib"] #![no_core] #![allow(asm_sub_register, non_camel_case_types)] diff --git a/src/test/assembly/asm/bpf-types.rs b/src/test/assembly/asm/bpf-types.rs index 7271ef11287..3428d93fb12 100644 --- a/src/test/assembly/asm/bpf-types.rs +++ b/src/test/assembly/asm/bpf-types.rs @@ -3,7 +3,7 @@ // compile-flags: --target bpfel-unknown-none -C target_feature=+alu32 // needs-llvm-components: bpf -#![feature(no_core, lang_items, rustc_attrs, repr_simd)] +#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)] #![crate_type = "rlib"] #![no_core] #![allow(asm_sub_register, non_camel_case_types)] diff --git a/src/test/assembly/asm/global_asm.rs b/src/test/assembly/asm/global_asm.rs index 1c981040d60..7e48c386abc 100644 --- a/src/test/assembly/asm/global_asm.rs +++ b/src/test/assembly/asm/global_asm.rs @@ -2,7 +2,7 @@ // assembly-output: emit-asm // compile-flags: -C llvm-args=--x86-asm-syntax=intel -#![feature(asm, global_asm)] +#![feature(global_asm, asm_const)] #![crate_type = "rlib"] // CHECK: mov eax, eax diff --git a/src/test/assembly/asm/hexagon-types.rs b/src/test/assembly/asm/hexagon-types.rs index 2156d77233d..de310c78488 100644 --- a/src/test/assembly/asm/hexagon-types.rs +++ b/src/test/assembly/asm/hexagon-types.rs @@ -2,7 +2,7 @@ // compile-flags: --target hexagon-unknown-linux-musl // needs-llvm-components: hexagon -#![feature(no_core, lang_items, rustc_attrs, repr_simd)] +#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)] #![crate_type = "rlib"] #![no_core] #![allow(asm_sub_register, non_camel_case_types)] diff --git a/src/test/assembly/asm/mips-types.rs b/src/test/assembly/asm/mips-types.rs index eb6627639f1..04bf49a40ef 100644 --- a/src/test/assembly/asm/mips-types.rs +++ b/src/test/assembly/asm/mips-types.rs @@ -5,7 +5,7 @@ //[mips64] compile-flags: --target mips64-unknown-linux-gnuabi64 //[mips64] needs-llvm-components: mips -#![feature(no_core, lang_items, rustc_attrs, repr_simd)] +#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)] #![crate_type = "rlib"] #![no_core] #![allow(asm_sub_register, non_camel_case_types)] diff --git a/src/test/assembly/asm/nvptx-types.rs b/src/test/assembly/asm/nvptx-types.rs index cc816fd78f8..3ebd5b4b896 100644 --- a/src/test/assembly/asm/nvptx-types.rs +++ b/src/test/assembly/asm/nvptx-types.rs @@ -3,7 +3,7 @@ // compile-flags: --crate-type cdylib // needs-llvm-components: nvptx -#![feature(no_core, lang_items, rustc_attrs)] +#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch)] #![no_core] #[rustc_builtin_macro] diff --git a/src/test/assembly/asm/powerpc-types.rs b/src/test/assembly/asm/powerpc-types.rs index 34299824531..b8859c07e16 100644 --- a/src/test/assembly/asm/powerpc-types.rs +++ b/src/test/assembly/asm/powerpc-types.rs @@ -6,7 +6,7 @@ //[powerpc64] compile-flags: --target powerpc64-unknown-linux-gnu //[powerpc64] needs-llvm-components: powerpc -#![feature(no_core, lang_items, rustc_attrs, repr_simd)] +#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)] #![crate_type = "rlib"] #![no_core] #![allow(asm_sub_register, non_camel_case_types)] diff --git a/src/test/assembly/asm/riscv-types.rs b/src/test/assembly/asm/riscv-types.rs index c510689b42b..0f9f61bd6d9 100644 --- a/src/test/assembly/asm/riscv-types.rs +++ b/src/test/assembly/asm/riscv-types.rs @@ -6,7 +6,7 @@ //[riscv32] needs-llvm-components: riscv // compile-flags: -C target-feature=+d -#![feature(no_core, lang_items, rustc_attrs)] +#![feature(no_core, lang_items, rustc_attrs, asm_sym)] #![crate_type = "rlib"] #![no_core] #![allow(asm_sub_register)] diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs index b8a4ca08df1..6a12902a046 100644 --- a/src/test/assembly/asm/s390x-types.rs +++ b/src/test/assembly/asm/s390x-types.rs @@ -3,7 +3,7 @@ //[s390x] compile-flags: --target s390x-unknown-linux-gnu //[s390x] needs-llvm-components: systemz -#![feature(no_core, lang_items, rustc_attrs, repr_simd)] +#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)] #![crate_type = "rlib"] #![no_core] #![allow(asm_sub_register, non_camel_case_types)] diff --git a/src/test/assembly/asm/wasm-types.rs b/src/test/assembly/asm/wasm-types.rs index 4b2e83e69b1..3aa128c46ac 100644 --- a/src/test/assembly/asm/wasm-types.rs +++ b/src/test/assembly/asm/wasm-types.rs @@ -3,7 +3,7 @@ // compile-flags: --crate-type cdylib // needs-llvm-components: webassembly -#![feature(no_core, lang_items, rustc_attrs)] +#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch)] #![no_core] #[rustc_builtin_macro] diff --git a/src/test/assembly/asm/x86-types.rs b/src/test/assembly/asm/x86-types.rs index 81be79cbaac..e871535cfde 100644 --- a/src/test/assembly/asm/x86-types.rs +++ b/src/test/assembly/asm/x86-types.rs @@ -7,7 +7,7 @@ // compile-flags: -C llvm-args=--x86-asm-syntax=intel // compile-flags: -C target-feature=+avx512bw -#![feature(no_core, lang_items, rustc_attrs, repr_simd)] +#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)] #![crate_type = "rlib"] #![no_core] #![allow(asm_sub_register, non_camel_case_types)] diff --git a/src/test/codegen/asm-powerpc-clobbers.rs b/src/test/codegen/asm-powerpc-clobbers.rs index ce13a7ff938..10b20ba6beb 100644 --- a/src/test/codegen/asm-powerpc-clobbers.rs +++ b/src/test/codegen/asm-powerpc-clobbers.rs @@ -7,7 +7,7 @@ //[powerpc64le] needs-llvm-components: powerpc #![crate_type = "rlib"] -#![feature(no_core, rustc_attrs, lang_items)] +#![feature(no_core, rustc_attrs, lang_items, asm_experimental_arch)] #![no_core] #[lang = "sized"] diff --git a/src/test/run-make-fulldeps/print-cfg/Makefile b/src/test/run-make-fulldeps/print-cfg/Makefile index 013bf3baca4..5472baae3f2 100644 --- a/src/test/run-make-fulldeps/print-cfg/Makefile +++ b/src/test/run-make-fulldeps/print-cfg/Makefile @@ -1,3 +1,5 @@ +# needs-llvm-components: x86 arm + -include ../tools.mk all: default diff --git a/src/test/ui/asm/aarch64/bad-reg.rs b/src/test/ui/asm/aarch64/bad-reg.rs index 22d0499a1cc..4d7a7fd31fe 100644 --- a/src/test/ui/asm/aarch64/bad-reg.rs +++ b/src/test/ui/asm/aarch64/bad-reg.rs @@ -1,7 +1,7 @@ // only-aarch64 // compile-flags: -C target-feature=+fp -#![feature(asm)] +#![feature(asm, asm_const, asm_sym)] fn main() { let mut foo = 0; diff --git a/src/test/ui/asm/aarch64/const.rs b/src/test/ui/asm/aarch64/const.rs index 05165b2d46c..49fe48600c2 100644 --- a/src/test/ui/asm/aarch64/const.rs +++ b/src/test/ui/asm/aarch64/const.rs @@ -3,7 +3,7 @@ // revisions: mirunsafeck thirunsafeck // [thirunsafeck]compile-flags: -Z thir-unsafeck -#![feature(asm, global_asm)] +#![feature(asm, global_asm, asm_const)] fn const_generic() -> usize { unsafe { diff --git a/src/test/ui/asm/aarch64/parse-error.rs b/src/test/ui/asm/aarch64/parse-error.rs index faa5e37b781..e19c5cd13d3 100644 --- a/src/test/ui/asm/aarch64/parse-error.rs +++ b/src/test/ui/asm/aarch64/parse-error.rs @@ -1,6 +1,6 @@ // only-aarch64 -#![feature(asm, global_asm)] +#![feature(asm, global_asm, asm_const)] fn main() { let mut foo = 0; diff --git a/src/test/ui/asm/aarch64/sym.rs b/src/test/ui/asm/aarch64/sym.rs index 526555334cb..b0dd143a0a1 100644 --- a/src/test/ui/asm/aarch64/sym.rs +++ b/src/test/ui/asm/aarch64/sym.rs @@ -2,7 +2,7 @@ // only-linux // run-pass -#![feature(asm, thread_local)] +#![feature(asm, thread_local, asm_sym)] extern "C" fn f1() -> i32 { 111 @@ -75,5 +75,7 @@ fn main() { std::thread::spawn(|| { assert_eq!(static_addr!(S1), &S1 as *const u32); assert_eq!(static_tls_addr!(S2), &S2 as *const u32); - }).join().unwrap(); + }) + .join() + .unwrap(); } diff --git a/src/test/ui/asm/aarch64/type-check-2.rs b/src/test/ui/asm/aarch64/type-check-2.rs index cf25dcb930c..e1e8a91dda6 100644 --- a/src/test/ui/asm/aarch64/type-check-2.rs +++ b/src/test/ui/asm/aarch64/type-check-2.rs @@ -1,6 +1,6 @@ // only-aarch64 -#![feature(asm, repr_simd, never_type)] +#![feature(asm, repr_simd, never_type, asm_sym)] #[repr(simd)] #[derive(Clone, Copy)] diff --git a/src/test/ui/asm/aarch64/type-check-3.rs b/src/test/ui/asm/aarch64/type-check-3.rs index d0d5954ca4a..fc1831a520a 100644 --- a/src/test/ui/asm/aarch64/type-check-3.rs +++ b/src/test/ui/asm/aarch64/type-check-3.rs @@ -1,13 +1,13 @@ // only-aarch64 // compile-flags: -C target-feature=+neon -#![feature(asm, global_asm, repr_simd, stdsimd)] +#![feature(asm, global_asm, repr_simd, stdsimd, asm_const)] use std::arch::aarch64::float64x2_t; #[repr(simd)] #[derive(Copy, Clone)] -struct Simd256bit(f64, f64,f64, f64); +struct Simd256bit(f64, f64, f64, f64); fn main() { let f64x2: float64x2_t = unsafe { std::mem::transmute(0i128) }; @@ -42,7 +42,6 @@ fn main() { asm!("{:b}", in(vreg) 0u64); asm!("{:d}", in(vreg_low16) f64x2); - // Template modifier suggestions for sub-registers asm!("{}", in(reg) 0u8); diff --git a/src/test/ui/asm/aarch64/type-check-3.stderr b/src/test/ui/asm/aarch64/type-check-3.stderr index c31a62ae791..ed9d3147b9f 100644 --- a/src/test/ui/asm/aarch64/type-check-3.stderr +++ b/src/test/ui/asm/aarch64/type-check-3.stderr @@ -1,5 +1,5 @@ warning: formatting may not be suitable for sub-register argument - --> $DIR/type-check-3.rs:48:15 + --> $DIR/type-check-3.rs:47:15 | LL | asm!("{}", in(reg) 0u8); | ^^ --- for this argument @@ -9,7 +9,7 @@ LL | asm!("{}", in(reg) 0u8); = help: or use the `x` modifier to keep the default formatting of `x0` warning: formatting may not be suitable for sub-register argument - --> $DIR/type-check-3.rs:50:15 + --> $DIR/type-check-3.rs:49:15 | LL | asm!("{}", in(reg) 0u16); | ^^ ---- for this argument @@ -18,7 +18,7 @@ LL | asm!("{}", in(reg) 0u16); = help: or use the `x` modifier to keep the default formatting of `x0` warning: formatting may not be suitable for sub-register argument - --> $DIR/type-check-3.rs:52:15 + --> $DIR/type-check-3.rs:51:15 | LL | asm!("{}", in(reg) 0i32); | ^^ ---- for this argument @@ -27,7 +27,7 @@ LL | asm!("{}", in(reg) 0i32); = help: or use the `x` modifier to keep the default formatting of `x0` warning: formatting may not be suitable for sub-register argument - --> $DIR/type-check-3.rs:54:15 + --> $DIR/type-check-3.rs:53:15 | LL | asm!("{}", in(reg) 0f32); | ^^ ---- for this argument @@ -36,7 +36,7 @@ LL | asm!("{}", in(reg) 0f32); = help: or use the `x` modifier to keep the default formatting of `x0` warning: formatting may not be suitable for sub-register argument - --> $DIR/type-check-3.rs:57:15 + --> $DIR/type-check-3.rs:56:15 | LL | asm!("{}", in(vreg) 0i16); | ^^ ---- for this argument @@ -45,7 +45,7 @@ LL | asm!("{}", in(vreg) 0i16); = help: or use the `v` modifier to keep the default formatting of `v0` warning: formatting may not be suitable for sub-register argument - --> $DIR/type-check-3.rs:59:15 + --> $DIR/type-check-3.rs:58:15 | LL | asm!("{}", in(vreg) 0f32); | ^^ ---- for this argument @@ -54,7 +54,7 @@ LL | asm!("{}", in(vreg) 0f32); = help: or use the `v` modifier to keep the default formatting of `v0` warning: formatting may not be suitable for sub-register argument - --> $DIR/type-check-3.rs:61:15 + --> $DIR/type-check-3.rs:60:15 | LL | asm!("{}", in(vreg) 0f64); | ^^ ---- for this argument @@ -63,7 +63,7 @@ LL | asm!("{}", in(vreg) 0f64); = help: or use the `v` modifier to keep the default formatting of `v0` warning: formatting may not be suitable for sub-register argument - --> $DIR/type-check-3.rs:63:15 + --> $DIR/type-check-3.rs:62:15 | LL | asm!("{}", in(vreg_low16) 0f64); | ^^ ---- for this argument @@ -72,7 +72,7 @@ LL | asm!("{}", in(vreg_low16) 0f64); = help: or use the `v` modifier to keep the default formatting of `v0` warning: formatting may not be suitable for sub-register argument - --> $DIR/type-check-3.rs:66:15 + --> $DIR/type-check-3.rs:65:15 | LL | asm!("{0} {0}", in(reg) 0i16); | ^^^ ^^^ ---- for this argument @@ -81,7 +81,7 @@ LL | asm!("{0} {0}", in(reg) 0i16); = help: or use the `x` modifier to keep the default formatting of `x0` warning: formatting may not be suitable for sub-register argument - --> $DIR/type-check-3.rs:68:15 + --> $DIR/type-check-3.rs:67:15 | LL | asm!("{0} {0:x}", in(reg) 0i16); | ^^^ ---- for this argument @@ -90,7 +90,7 @@ LL | asm!("{0} {0:x}", in(reg) 0i16); = help: or use the `x` modifier to keep the default formatting of `x0` error: type `i128` cannot be used with this register class - --> $DIR/type-check-3.rs:73:28 + --> $DIR/type-check-3.rs:72:28 | LL | asm!("{}", in(reg) 0i128); | ^^^^^ @@ -98,7 +98,7 @@ LL | asm!("{}", in(reg) 0i128); = note: register class `reg` supports these types: i8, i16, i32, i64, f32, f64 error: type `float64x2_t` cannot be used with this register class - --> $DIR/type-check-3.rs:75:28 + --> $DIR/type-check-3.rs:74:28 | LL | asm!("{}", in(reg) f64x2); | ^^^^^ @@ -106,7 +106,7 @@ LL | asm!("{}", in(reg) f64x2); = note: register class `reg` supports these types: i8, i16, i32, i64, f32, f64 error: type `Simd256bit` cannot be used with this register class - --> $DIR/type-check-3.rs:77:29 + --> $DIR/type-check-3.rs:76:29 | LL | asm!("{}", in(vreg) f64x4); | ^^^^^ @@ -114,7 +114,7 @@ LL | asm!("{}", in(vreg) f64x4); = note: register class `vreg` supports these types: i8, i16, i32, i64, f32, f64, i8x8, i16x4, i32x2, i64x1, f32x2, f64x1, i8x16, i16x8, i32x4, i64x2, f32x4, f64x2 error: incompatible types for asm inout argument - --> $DIR/type-check-3.rs:88:33 + --> $DIR/type-check-3.rs:87:33 | LL | asm!("{:x}", inout(reg) 0u32 => val_f32); | ^^^^ ^^^^^^^ type `f32` @@ -124,7 +124,7 @@ LL | asm!("{:x}", inout(reg) 0u32 => val_f32); = note: asm inout arguments must have the same type, unless they are both pointers or integers of the same size error: incompatible types for asm inout argument - --> $DIR/type-check-3.rs:90:33 + --> $DIR/type-check-3.rs:89:33 | LL | asm!("{:x}", inout(reg) 0u32 => val_ptr); | ^^^^ ^^^^^^^ type `*mut u8` @@ -134,7 +134,7 @@ LL | asm!("{:x}", inout(reg) 0u32 => val_ptr); = note: asm inout arguments must have the same type, unless they are both pointers or integers of the same size error: incompatible types for asm inout argument - --> $DIR/type-check-3.rs:92:33 + --> $DIR/type-check-3.rs:91:33 | LL | asm!("{:x}", inout(reg) main => val_u32); | ^^^^ ^^^^^^^ type `u32` @@ -144,7 +144,7 @@ LL | asm!("{:x}", inout(reg) main => val_u32); = note: asm inout arguments must have the same type, unless they are both pointers or integers of the same size error[E0013]: constants cannot refer to statics - --> $DIR/type-check-3.rs:108:25 + --> $DIR/type-check-3.rs:107:25 | LL | global_asm!("{}", const S); | ^ @@ -152,7 +152,7 @@ LL | global_asm!("{}", const S); = help: consider extracting the value of the `static` to a `const`, and referring to that error[E0013]: constants cannot refer to statics - --> $DIR/type-check-3.rs:111:35 + --> $DIR/type-check-3.rs:110:35 | LL | global_asm!("{}", const const_foo(S)); | ^ @@ -160,7 +160,7 @@ LL | global_asm!("{}", const const_foo(S)); = help: consider extracting the value of the `static` to a `const`, and referring to that error[E0013]: constants cannot refer to statics - --> $DIR/type-check-3.rs:114:35 + --> $DIR/type-check-3.rs:113:35 | LL | global_asm!("{}", const const_bar(S)); | ^ diff --git a/src/test/ui/asm/bad-template.rs b/src/test/ui/asm/bad-template.rs index fca77e7aa71..b062c45e6ea 100644 --- a/src/test/ui/asm/bad-template.rs +++ b/src/test/ui/asm/bad-template.rs @@ -10,7 +10,7 @@ // [aarch64_thirunsafeck] needs-llvm-components: aarch64 // [aarch64_mirunsafeck] needs-llvm-components: aarch64 -#![feature(no_core, lang_items, rustc_attrs)] +#![feature(no_core, lang_items, rustc_attrs, asm_const)] #![no_core] #[rustc_builtin_macro] diff --git a/src/test/ui/asm/issue-89305.rs b/src/test/ui/asm/issue-89305.rs index bdcf3f305eb..a4b22e21028 100644 --- a/src/test/ui/asm/issue-89305.rs +++ b/src/test/ui/asm/issue-89305.rs @@ -2,6 +2,7 @@ // as both unused and possibly-uninitialized. // check-pass +// needs-asm-support #![feature(asm)] #![warn(unused)] diff --git a/src/test/ui/asm/issue-89305.stderr b/src/test/ui/asm/issue-89305.stderr index 9cc127b44d0..3fb1526183b 100644 --- a/src/test/ui/asm/issue-89305.stderr +++ b/src/test/ui/asm/issue-89305.stderr @@ -1,11 +1,11 @@ warning: unused variable: `x` - --> $DIR/issue-89305.rs:11:13 + --> $DIR/issue-89305.rs:12:13 | LL | let x: () = asm!("nop"); | ^ help: if this is intentional, prefix it with an underscore: `_x` | note: the lint level is defined here - --> $DIR/issue-89305.rs:7:9 + --> $DIR/issue-89305.rs:8:9 | LL | #![warn(unused)] | ^^^^^^ diff --git a/src/test/ui/asm/naked-functions.rs b/src/test/ui/asm/naked-functions.rs index 803311d4235..7154ce26efc 100644 --- a/src/test/ui/asm/naked-functions.rs +++ b/src/test/ui/asm/naked-functions.rs @@ -7,11 +7,15 @@ #![feature(llvm_asm)] #![feature(naked_functions)] #![feature(or_patterns)] +#![feature(asm_const, asm_sym)] #![crate_type = "lib"] #![allow(deprecated)] // llvm_asm! #[repr(C)] -pub struct P { x: u8, y: u16 } +pub struct P { + x: u8, + y: u16, +} #[naked] pub unsafe extern "C" fn patterns( @@ -143,21 +147,27 @@ pub unsafe fn default_abi() { } #[naked] -pub unsafe extern "Rust" fn rust_abi() { +pub unsafe fn rust_abi() { //~^ WARN Rust ABI is unsupported in naked functions asm!("", options(noreturn)); } #[naked] pub extern "C" fn valid_a() -> T { - unsafe { asm!("", options(noreturn)); } + unsafe { + asm!("", options(noreturn)); + } } #[naked] pub extern "C" fn valid_b() { - unsafe { { { - asm!("", options(noreturn)); ; ; ; - } ; } ; } + unsafe { + { + { + asm!("", options(noreturn)); + }; + }; + } } #[naked] diff --git a/src/test/ui/asm/naked-functions.stderr b/src/test/ui/asm/naked-functions.stderr index 465db634aa2..e4ddb97ca27 100644 --- a/src/test/ui/asm/naked-functions.stderr +++ b/src/test/ui/asm/naked-functions.stderr @@ -1,35 +1,35 @@ error: asm with the `pure` option must have at least one output - --> $DIR/naked-functions.rs:131:14 + --> $DIR/naked-functions.rs:135:14 | LL | asm!("", options(readonly, nostack), options(pure)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ error: patterns not allowed in naked function parameters - --> $DIR/naked-functions.rs:18:5 + --> $DIR/naked-functions.rs:22:5 | LL | mut a: u32, | ^^^^^ error: patterns not allowed in naked function parameters - --> $DIR/naked-functions.rs:20:5 + --> $DIR/naked-functions.rs:24:5 | LL | &b: &i32, | ^^ error: patterns not allowed in naked function parameters - --> $DIR/naked-functions.rs:22:6 + --> $DIR/naked-functions.rs:26:6 | LL | (None | Some(_)): Option>, | ^^^^^^^^^^^^^^ error: patterns not allowed in naked function parameters - --> $DIR/naked-functions.rs:24:5 + --> $DIR/naked-functions.rs:28:5 | LL | P { x, y }: P, | ^^^^^^^^^^ error: referencing function parameters is not allowed in naked functions - --> $DIR/naked-functions.rs:34:5 + --> $DIR/naked-functions.rs:38:5 | LL | a + 1 | ^ @@ -37,7 +37,7 @@ LL | a + 1 = help: follow the calling convention in asm block to use parameters warning: naked functions must contain a single asm block - --> $DIR/naked-functions.rs:31:1 + --> $DIR/naked-functions.rs:35:1 | LL | / pub unsafe extern "C" fn inc(a: u32) -> u32 { LL | | @@ -53,7 +53,7 @@ LL | | } = note: for more information, see issue #32408 error: referencing function parameters is not allowed in naked functions - --> $DIR/naked-functions.rs:40:31 + --> $DIR/naked-functions.rs:44:31 | LL | asm!("/* {0} */", in(reg) a, options(noreturn)); | ^ @@ -61,7 +61,7 @@ LL | asm!("/* {0} */", in(reg) a, options(noreturn)); = help: follow the calling convention in asm block to use parameters warning: only `const` and `sym` operands are supported in naked functions - --> $DIR/naked-functions.rs:40:23 + --> $DIR/naked-functions.rs:44:23 | LL | asm!("/* {0} */", in(reg) a, options(noreturn)); | ^^^^^^^^^ @@ -70,7 +70,7 @@ LL | asm!("/* {0} */", in(reg) a, options(noreturn)); = note: for more information, see issue #32408 warning: naked functions must contain a single asm block - --> $DIR/naked-functions.rs:47:1 + --> $DIR/naked-functions.rs:51:1 | LL | / pub unsafe extern "C" fn inc_closure(a: u32) -> u32 { LL | | @@ -84,7 +84,7 @@ LL | | } = note: for more information, see issue #32408 warning: only `const` and `sym` operands are supported in naked functions - --> $DIR/naked-functions.rs:67:10 + --> $DIR/naked-functions.rs:71:10 | LL | in(reg) a, | ^^^^^^^^^ @@ -102,7 +102,7 @@ LL | out(reg) e, = note: for more information, see issue #32408 warning: asm in naked functions must use `noreturn` option - --> $DIR/naked-functions.rs:64:5 + --> $DIR/naked-functions.rs:68:5 | LL | / asm!("/* {0} {1} {2} {3} {4} {5} {6} */", LL | | @@ -117,7 +117,7 @@ LL | | ); = note: for more information, see issue #32408 warning: naked functions must contain a single asm block - --> $DIR/naked-functions.rs:54:1 + --> $DIR/naked-functions.rs:58:1 | LL | / pub unsafe extern "C" fn unsupported_operands() { LL | | @@ -141,7 +141,7 @@ LL | | } = note: for more information, see issue #32408 warning: naked functions must contain a single asm block - --> $DIR/naked-functions.rs:80:1 + --> $DIR/naked-functions.rs:84:1 | LL | / pub extern "C" fn missing_assembly() { LL | | @@ -153,7 +153,7 @@ LL | | } = note: for more information, see issue #32408 warning: asm in naked functions must use `noreturn` option - --> $DIR/naked-functions.rs:89:5 + --> $DIR/naked-functions.rs:93:5 | LL | asm!(""); | ^^^^^^^^ @@ -162,7 +162,7 @@ LL | asm!(""); = note: for more information, see issue #32408 warning: asm in naked functions must use `noreturn` option - --> $DIR/naked-functions.rs:92:5 + --> $DIR/naked-functions.rs:96:5 | LL | asm!(""); | ^^^^^^^^ @@ -171,7 +171,7 @@ LL | asm!(""); = note: for more information, see issue #32408 warning: asm in naked functions must use `noreturn` option - --> $DIR/naked-functions.rs:95:5 + --> $DIR/naked-functions.rs:99:5 | LL | asm!(""); | ^^^^^^^^ @@ -180,7 +180,7 @@ LL | asm!(""); = note: for more information, see issue #32408 warning: naked functions must contain a single asm block - --> $DIR/naked-functions.rs:86:1 + --> $DIR/naked-functions.rs:90:1 | LL | / pub extern "C" fn too_many_asm_blocks() { LL | | @@ -202,7 +202,7 @@ LL | | } = note: for more information, see issue #32408 error: referencing function parameters is not allowed in naked functions - --> $DIR/naked-functions.rs:106:11 + --> $DIR/naked-functions.rs:110:11 | LL | *&y | ^ @@ -210,7 +210,7 @@ LL | *&y = help: follow the calling convention in asm block to use parameters warning: naked functions must contain a single asm block - --> $DIR/naked-functions.rs:103:5 + --> $DIR/naked-functions.rs:107:5 | LL | / pub extern "C" fn inner(y: usize) -> usize { LL | | @@ -225,7 +225,7 @@ LL | | } = note: for more information, see issue #32408 warning: the LLVM-style inline assembly is unsupported in naked functions - --> $DIR/naked-functions.rs:116:5 + --> $DIR/naked-functions.rs:120:5 | LL | llvm_asm!(""); | ^^^^^^^^^^^^^ @@ -236,7 +236,7 @@ LL | llvm_asm!(""); = note: this warning originates in the macro `llvm_asm` (in Nightly builds, run with -Z macro-backtrace for more info) warning: naked functions must contain a single asm block - --> $DIR/naked-functions.rs:113:1 + --> $DIR/naked-functions.rs:117:1 | LL | / unsafe extern "C" fn llvm() -> ! { LL | | @@ -252,7 +252,7 @@ LL | | } = note: for more information, see issue #32408 warning: asm options unsupported in naked functions: `nomem`, `preserves_flags` - --> $DIR/naked-functions.rs:124:5 + --> $DIR/naked-functions.rs:128:5 | LL | asm!("", options(nomem, preserves_flags, noreturn)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -261,7 +261,7 @@ LL | asm!("", options(nomem, preserves_flags, noreturn)); = note: for more information, see issue #32408 warning: asm options unsupported in naked functions: `nostack`, `pure`, `readonly` - --> $DIR/naked-functions.rs:131:5 + --> $DIR/naked-functions.rs:135:5 | LL | asm!("", options(readonly, nostack), options(pure)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -270,7 +270,7 @@ LL | asm!("", options(readonly, nostack), options(pure)); = note: for more information, see issue #32408 warning: asm in naked functions must use `noreturn` option - --> $DIR/naked-functions.rs:131:5 + --> $DIR/naked-functions.rs:135:5 | LL | asm!("", options(readonly, nostack), options(pure)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -279,7 +279,7 @@ LL | asm!("", options(readonly, nostack), options(pure)); = note: for more information, see issue #32408 warning: Rust ABI is unsupported in naked functions - --> $DIR/naked-functions.rs:140:15 + --> $DIR/naked-functions.rs:144:15 | LL | pub unsafe fn default_abi() { | ^^^^^^^^^^^ @@ -287,13 +287,13 @@ LL | pub unsafe fn default_abi() { = note: `#[warn(undefined_naked_function_abi)]` on by default warning: Rust ABI is unsupported in naked functions - --> $DIR/naked-functions.rs:146:29 + --> $DIR/naked-functions.rs:150:15 | -LL | pub unsafe extern "Rust" fn rust_abi() { - | ^^^^^^^^ +LL | pub unsafe fn rust_abi() { + | ^^^^^^^^ warning: naked functions cannot be inlined - --> $DIR/naked-functions.rs:180:1 + --> $DIR/naked-functions.rs:190:1 | LL | #[inline] | ^^^^^^^^^ @@ -302,7 +302,7 @@ LL | #[inline] = note: for more information, see issue #32408 warning: naked functions cannot be inlined - --> $DIR/naked-functions.rs:188:1 + --> $DIR/naked-functions.rs:198:1 | LL | #[inline(always)] | ^^^^^^^^^^^^^^^^^ @@ -311,7 +311,7 @@ LL | #[inline(always)] = note: for more information, see issue #32408 warning: naked functions cannot be inlined - --> $DIR/naked-functions.rs:196:1 + --> $DIR/naked-functions.rs:206:1 | LL | #[inline(never)] | ^^^^^^^^^^^^^^^^ @@ -320,7 +320,7 @@ LL | #[inline(never)] = note: for more information, see issue #32408 warning: naked functions cannot be inlined - --> $DIR/naked-functions.rs:204:1 + --> $DIR/naked-functions.rs:214:1 | LL | #[inline] | ^^^^^^^^^ @@ -329,7 +329,7 @@ LL | #[inline] = note: for more information, see issue #32408 warning: naked functions cannot be inlined - --> $DIR/naked-functions.rs:207:1 + --> $DIR/naked-functions.rs:217:1 | LL | #[inline(always)] | ^^^^^^^^^^^^^^^^^ @@ -338,7 +338,7 @@ LL | #[inline(always)] = note: for more information, see issue #32408 warning: naked functions cannot be inlined - --> $DIR/naked-functions.rs:210:1 + --> $DIR/naked-functions.rs:220:1 | LL | #[inline(never)] | ^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/asm/named-asm-labels.rs b/src/test/ui/asm/named-asm-labels.rs index 82c47945a7b..c87188e46a2 100644 --- a/src/test/ui/asm/named-asm-labels.rs +++ b/src/test/ui/asm/named-asm-labels.rs @@ -11,7 +11,7 @@ // which causes less readable LLVM errors and in the worst cases causes ICEs // or segfaults based on system dependent behavior and codegen flags. -#![feature(asm, global_asm, naked_functions)] +#![feature(asm, global_asm, naked_functions, asm_const)] #[no_mangle] pub static FOO: usize = 42; diff --git a/src/test/ui/asm/type-check-1.rs b/src/test/ui/asm/type-check-1.rs index bbbe798d155..1e463107b18 100644 --- a/src/test/ui/asm/type-check-1.rs +++ b/src/test/ui/asm/type-check-1.rs @@ -3,7 +3,7 @@ // ignore-spirv // ignore-wasm32 -#![feature(asm, global_asm)] +#![feature(asm, global_asm, asm_const)] fn main() { unsafe { diff --git a/src/test/ui/asm/x86_64/bad-reg.rs b/src/test/ui/asm/x86_64/bad-reg.rs index 91d0f8c33f9..ba4e95db46a 100644 --- a/src/test/ui/asm/x86_64/bad-reg.rs +++ b/src/test/ui/asm/x86_64/bad-reg.rs @@ -1,7 +1,7 @@ // only-x86_64 // compile-flags: -C target-feature=+avx2 -#![feature(asm)] +#![feature(asm, asm_const, asm_sym)] fn main() { let mut foo = 0; diff --git a/src/test/ui/asm/x86_64/const.rs b/src/test/ui/asm/x86_64/const.rs index dbf17755720..c1e4cdbb928 100644 --- a/src/test/ui/asm/x86_64/const.rs +++ b/src/test/ui/asm/x86_64/const.rs @@ -3,7 +3,7 @@ // revisions: mirunsafeck thirunsafeck // [thirunsafeck]compile-flags: -Z thir-unsafeck -#![feature(asm, global_asm)] +#![feature(asm, global_asm, asm_const)] fn const_generic() -> usize { unsafe { diff --git a/src/test/ui/asm/x86_64/parse-error.rs b/src/test/ui/asm/x86_64/parse-error.rs index fa14c52cf0a..e7f3804c588 100644 --- a/src/test/ui/asm/x86_64/parse-error.rs +++ b/src/test/ui/asm/x86_64/parse-error.rs @@ -1,6 +1,6 @@ // only-x86_64 -#![feature(asm, global_asm)] +#![feature(asm, global_asm, asm_const)] fn main() { let mut foo = 0; diff --git a/src/test/ui/asm/x86_64/sym.rs b/src/test/ui/asm/x86_64/sym.rs index 188d03e298e..958dbbdd376 100644 --- a/src/test/ui/asm/x86_64/sym.rs +++ b/src/test/ui/asm/x86_64/sym.rs @@ -3,7 +3,7 @@ // only-linux // run-pass -#![feature(asm, thread_local)] +#![feature(asm, thread_local, asm_sym)] extern "C" fn f1() -> i32 { 111 @@ -76,5 +76,7 @@ fn main() { std::thread::spawn(|| { assert_eq!(static_addr!(S1), &S1 as *const u32); assert_eq!(static_tls_addr!(S2), &S2 as *const u32); - }).join().unwrap(); + }) + .join() + .unwrap(); } diff --git a/src/test/ui/asm/x86_64/type-check-2.rs b/src/test/ui/asm/x86_64/type-check-2.rs index 2311f86d340..94aadcf09f4 100644 --- a/src/test/ui/asm/x86_64/type-check-2.rs +++ b/src/test/ui/asm/x86_64/type-check-2.rs @@ -1,6 +1,6 @@ // only-x86_64 -#![feature(asm, repr_simd, never_type)] +#![feature(asm, repr_simd, never_type, asm_sym)] #[repr(simd)] struct SimdNonCopy(f32, f32, f32, f32); diff --git a/src/test/ui/asm/x86_64/type-check-3.rs b/src/test/ui/asm/x86_64/type-check-3.rs index c2c1885ff16..83674cf8204 100644 --- a/src/test/ui/asm/x86_64/type-check-3.rs +++ b/src/test/ui/asm/x86_64/type-check-3.rs @@ -1,7 +1,7 @@ // only-x86_64 // compile-flags: -C target-feature=+avx512f -#![feature(asm, global_asm)] +#![feature(asm, global_asm, asm_const)] use std::arch::x86_64::{_mm256_setzero_ps, _mm_setzero_ps}; diff --git a/src/test/ui/consts/inline_asm.rs b/src/test/ui/consts/inline_asm.rs index fa9542f93a3..b46ca6ba6df 100644 --- a/src/test/ui/consts/inline_asm.rs +++ b/src/test/ui/consts/inline_asm.rs @@ -1,3 +1,5 @@ +// needs-asm-support + #![feature(asm)] const _: () = unsafe { asm!("nop") }; diff --git a/src/test/ui/consts/inline_asm.stderr b/src/test/ui/consts/inline_asm.stderr index f38044a290b..65a828d118c 100644 --- a/src/test/ui/consts/inline_asm.stderr +++ b/src/test/ui/consts/inline_asm.stderr @@ -1,5 +1,5 @@ error[E0015]: inline assembly is not allowed in constants - --> $DIR/inline_asm.rs:3:24 + --> $DIR/inline_asm.rs:5:24 | LL | const _: () = unsafe { asm!("nop") }; | ^^^^^^^^^^^ diff --git a/src/test/ui/feature-gates/feature-gate-asm_const.rs b/src/test/ui/feature-gates/feature-gate-asm_const.rs new file mode 100644 index 00000000000..c152b54c669 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-asm_const.rs @@ -0,0 +1,10 @@ +// only-x86_64 + +#![feature(asm)] + +fn main() { + unsafe { + asm!("mov eax, {}", const 123); + //~^ ERROR const operands for inline assembly are unstable + } +} diff --git a/src/test/ui/feature-gates/feature-gate-asm_const.stderr b/src/test/ui/feature-gates/feature-gate-asm_const.stderr new file mode 100644 index 00000000000..2851a9b0ae6 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-asm_const.stderr @@ -0,0 +1,12 @@ +error[E0658]: const operands for inline assembly are unstable + --> $DIR/feature-gate-asm_const.rs:7:29 + | +LL | asm!("mov eax, {}", const 123); + | ^^^^^^^^^ + | + = note: see issue #72016 for more information + = help: add `#![feature(asm_const)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/feature-gates/feature-gate-asm_experimental_arch.rs b/src/test/ui/feature-gates/feature-gate-asm_experimental_arch.rs new file mode 100644 index 00000000000..53e2a4d132c --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-asm_experimental_arch.rs @@ -0,0 +1,21 @@ +// compile-flags: --target mips-unknown-linux-gnu +// needs-llvm-components: mips + +#![feature(no_core, lang_items, rustc_attrs)] +#![crate_type = "rlib"] +#![no_core] + +#[rustc_builtin_macro] +macro_rules! asm { + () => {}; +} + +#[lang = "sized"] +trait Sized {} +#[lang = "copy"] +trait Copy {} + +unsafe fn main() { + asm!(""); + //~^ ERROR inline assembly is not stable yet on this architecture +} diff --git a/src/test/ui/feature-gates/feature-gate-asm_experimental_arch.stderr b/src/test/ui/feature-gates/feature-gate-asm_experimental_arch.stderr new file mode 100644 index 00000000000..1b4188ae1ad --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-asm_experimental_arch.stderr @@ -0,0 +1,12 @@ +error[E0658]: inline assembly is not stable yet on this architecture + --> $DIR/feature-gate-asm_experimental_arch.rs:19:5 + | +LL | asm!(""); + | ^^^^^^^^ + | + = note: see issue #72016 for more information + = help: add `#![feature(asm_experimental_arch)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/feature-gates/feature-gate-asm_sym.rs b/src/test/ui/feature-gates/feature-gate-asm_sym.rs new file mode 100644 index 00000000000..d89c7dd0ef4 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-asm_sym.rs @@ -0,0 +1,10 @@ +// only-x86_64 + +#![feature(asm)] + +fn main() { + unsafe { + asm!("mov eax, {}", sym main); + //~^ ERROR sym operands for inline assembly are unstable + } +} diff --git a/src/test/ui/feature-gates/feature-gate-asm_sym.stderr b/src/test/ui/feature-gates/feature-gate-asm_sym.stderr new file mode 100644 index 00000000000..99b61b829fb --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-asm_sym.stderr @@ -0,0 +1,12 @@ +error[E0658]: sym operands for inline assembly are unstable + --> $DIR/feature-gate-asm_sym.rs:7:29 + | +LL | asm!("mov eax, {}", sym main); + | ^^^^^^^^ + | + = note: see issue #72016 for more information + = help: add `#![feature(asm_sym)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/tools/clippy/clippy_lints/src/doc.rs b/src/tools/clippy/clippy_lints/src/doc.rs index 87ad5178ff0..d4ba072807f 100644 --- a/src/tools/clippy/clippy_lints/src/doc.rs +++ b/src/tools/clippy/clippy_lints/src/doc.rs @@ -5,7 +5,7 @@ use clippy_utils::{is_entrypoint_fn, is_expn_of, match_panic_def_id, method_chain_args, return_ty}; use if_chain::if_chain; use itertools::Itertools; -use rustc_ast::ast::{Async, AttrKind, Attribute, FnKind, FnRetTy, ItemKind}; +use rustc_ast::ast::{Async, AttrKind, Attribute, Fn, FnRetTy, ItemKind}; use rustc_ast::token::CommentKind; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; @@ -639,7 +639,7 @@ fn has_needless_main(code: String, edition: Edition) -> bool { | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) => return false, // We found a main function ... - ItemKind::Fn(box FnKind(_, sig, _, Some(block))) if item.ident.name == sym::main => { + ItemKind::Fn(box Fn { sig, body: Some(block), .. }) if item.ident.name == sym::main => { let is_async = matches!(sig.header.asyncness, Async::Yes { .. }); let returns_nothing = match &sig.decl.output { FnRetTy::Default(..) => true, diff --git a/src/tools/clippy/clippy_lints/src/excessive_bools.rs b/src/tools/clippy/clippy_lints/src/excessive_bools.rs index 476e6d23f12..09b6e200838 100644 --- a/src/tools/clippy/clippy_lints/src/excessive_bools.rs +++ b/src/tools/clippy/clippy_lints/src/excessive_bools.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::in_macro; -use rustc_ast::ast::{AssocItemKind, Extern, FnKind, FnSig, ImplKind, Item, ItemKind, TraitKind, Ty, TyKind}; +use rustc_ast::ast::{AssocItemKind, Extern, Fn, FnSig, Impl, Item, ItemKind, Trait, Ty, TyKind}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{sym, Span}; @@ -162,17 +162,17 @@ fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { ); } }, - ItemKind::Impl(box ImplKind { + ItemKind::Impl(box Impl { of_trait: None, items, .. }) - | ItemKind::Trait(box TraitKind(.., items)) => { + | ItemKind::Trait(box Trait { items, .. }) => { for item in items { - if let AssocItemKind::Fn(box FnKind(_, fn_sig, _, _)) = &item.kind { - self.check_fn_sig(cx, fn_sig, item.span); + if let AssocItemKind::Fn(box Fn { sig, .. }) = &item.kind { + self.check_fn_sig(cx, sig, item.span); } } }, - ItemKind::Fn(box FnKind(_, fn_sig, _, _)) => self.check_fn_sig(cx, fn_sig, item.span), + ItemKind::Fn(box Fn { sig, .. }) => self.check_fn_sig(cx, sig, item.span), _ => (), } } diff --git a/src/tools/clippy/clippy_lints/src/non_expressive_names.rs b/src/tools/clippy/clippy_lints/src/non_expressive_names.rs index 5b254bc8133..e28cc49bf2a 100644 --- a/src/tools/clippy/clippy_lints/src/non_expressive_names.rs +++ b/src/tools/clippy/clippy_lints/src/non_expressive_names.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; use rustc_ast::ast::{ - Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, FnKind, Item, ItemKind, Local, Pat, PatKind, + self, Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, Pat, PatKind, }; use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor}; use rustc_lint::{EarlyContext, EarlyLintPass}; @@ -357,7 +357,7 @@ fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { return; } - if let ItemKind::Fn(box FnKind(_, ref sig, _, Some(ref blk))) = item.kind { + if let ItemKind::Fn(box ast::Fn { ref sig, body: Some(ref blk), .. }) = item.kind { do_check(self, cx, &item.attrs, &sig.decl, blk); } } @@ -367,7 +367,7 @@ fn check_impl_item(&mut self, cx: &EarlyContext<'_>, item: &AssocItem) { return; } - if let AssocItemKind::Fn(box FnKind(_, ref sig, _, Some(ref blk))) = item.kind { + if let AssocItemKind::Fn(box ast::Fn { ref sig, body: Some(ref blk), .. }) = item.kind { do_check(self, cx, &item.attrs, &sig.decl, blk); } } diff --git a/src/tools/clippy/clippy_lints/src/write.rs b/src/tools/clippy/clippy_lints/src/write.rs index 85d1f65c51f..b412e15ae4f 100644 --- a/src/tools/clippy/clippy_lints/src/write.rs +++ b/src/tools/clippy/clippy_lints/src/write.rs @@ -4,7 +4,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::{snippet_opt, snippet_with_applicability}; -use rustc_ast::ast::{Expr, ExprKind, ImplKind, Item, ItemKind, MacCall, Path, StrLit, StrStyle}; +use rustc_ast::ast::{Expr, ExprKind, Impl, Item, ItemKind, MacCall, Path, StrLit, StrStyle}; use rustc_ast::token::{self, LitKind}; use rustc_ast::tokenstream::TokenStream; use rustc_errors::Applicability; @@ -243,7 +243,7 @@ pub struct Write { impl EarlyLintPass for Write { fn check_item(&mut self, _: &EarlyContext<'_>, item: &Item) { - if let ItemKind::Impl(box ImplKind { + if let ItemKind::Impl(box Impl { of_trait: Some(trait_ref), .. }) = &item.kind diff --git a/src/tools/clippy/clippy_utils/src/ast_utils.rs b/src/tools/clippy/clippy_utils/src/ast_utils.rs index 2fa98831c77..1b05a8a3504 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils.rs @@ -250,7 +250,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { (Use(l), Use(r)) => eq_use_tree(l, r), (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => { + (Fn(box ast::Fn { defaultness: ld, sig: lf, generics: lg, body: lb }), + Fn(box ast::Fn { defaultness: rd, sig: rf, generics: rg, body: rb })) => { eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) }, (Mod(lu, lmk), Mod(ru, rmk)) => { @@ -266,7 +267,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { (ForeignMod(l), ForeignMod(r)) => { both(&l.abi, &r.abi, eq_str_lit) && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_foreign_item_kind)) }, - (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => { + (TyAlias(box ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt }), + TyAlias(box ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, ty: rt })) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) @@ -276,7 +278,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { (Struct(lv, lg), Struct(rv, rg)) | (Union(lv, lg), Union(rv, rg)) => { eq_variant_data(lv, rv) && eq_generics(lg, rg) }, - (Trait(box TraitKind(la, lu, lg, lb, li)), Trait(box TraitKind(ra, ru, rg, rb, ri))) => { + (Trait(box ast::Trait { is_auto: la, unsafety: lu, generics: lg, bounds: lb, items: li }), + Trait(box ast::Trait { is_auto: ra, unsafety: ru, generics: rg, bounds: rb, items: ri })) => { la == ra && matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No) && eq_generics(lg, rg) @@ -285,7 +288,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { }, (TraitAlias(lg, lb), TraitAlias(rg, rb)) => eq_generics(lg, rg) && over(lb, rb, eq_generic_bound), ( - Impl(box ImplKind { + Impl(box ast::Impl { unsafety: lu, polarity: lp, defaultness: ld, @@ -295,7 +298,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { self_ty: lst, items: li, }), - Impl(box ImplKind { + Impl(box ast::Impl { unsafety: ru, polarity: rp, defaultness: rd, @@ -325,10 +328,12 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { use ForeignItemKind::*; match (l, r) { (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => { + (Fn(box ast::Fn { defaultness: ld, sig: lf, generics: lg, body: lb }), + Fn(box ast::Fn { defaultness: rd, sig: rf, generics: rg, body: rb })) => { eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) }, - (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => { + (TyAlias(box ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt }), + TyAlias(box ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, ty: rt })) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) @@ -343,10 +348,12 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { use AssocItemKind::*; match (l, r) { (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => { + (Fn(box ast::Fn { defaultness: ld, sig: lf, generics: lg, body: lb }), + Fn(box ast::Fn { defaultness: rd, sig: rf, generics: rg, body: rb })) => { eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) }, - (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => { + (TyAlias(box ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt }), + TyAlias(box ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, ty: rt })) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs index d03c21dc508..6ca145a58e9 100644 --- a/src/tools/compiletest/src/util.rs +++ b/src/tools/compiletest/src/util.rs @@ -133,8 +133,10 @@ ]; static ASM_SUPPORTED_ARCHS: &[&str] = &[ - "x86", "x86_64", "arm", "aarch64", "riscv32", "riscv64", "nvptx64", "hexagon", "mips", - "mips64", "spirv", "wasm32", + "x86", "x86_64", "arm", "aarch64", "riscv32", + "riscv64", + // These targets require an additional asm_experimental_arch feature. + // "nvptx64", "hexagon", "mips", "mips64", "spirv", "wasm32", ]; pub fn has_asm_support(triple: &str) -> bool { diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index 1cb1a2701c3..c828798d933 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/src/items.rs @@ -622,7 +622,7 @@ fn both_opaque( fn need_empty_line(a: &ast::AssocItemKind, b: &ast::AssocItemKind) -> bool { match (a, b) { (TyAlias(lty), TyAlias(rty)) - if both_type(<y.3, &rty.3) || both_opaque(<y.3, &rty.3) => + if both_type(<y.ty, &rty.ty) || both_opaque(<y.ty, &rty.ty) => { false } @@ -633,7 +633,7 @@ fn need_empty_line(a: &ast::AssocItemKind, b: &ast::AssocItemKind) -> bool { buffer.sort_by(|(_, a), (_, b)| match (&a.kind, &b.kind) { (TyAlias(lty), TyAlias(rty)) - if both_type(<y.3, &rty.3) || both_opaque(<y.3, &rty.3) => + if both_type(<y.ty, &rty.ty) || both_opaque(<y.ty, &rty.ty) => { a.ident.as_str().cmp(&b.ident.as_str()) } @@ -641,8 +641,8 @@ fn need_empty_line(a: &ast::AssocItemKind, b: &ast::AssocItemKind) -> bool { a.ident.as_str().cmp(&b.ident.as_str()) } (Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()), - (TyAlias(ty), _) if is_type(&ty.3) => Ordering::Less, - (_, TyAlias(ty)) if is_type(&ty.3) => Ordering::Greater, + (TyAlias(ty), _) if is_type(&ty.ty) => Ordering::Less, + (_, TyAlias(ty)) if is_type(&ty.ty) => Ordering::Greater, (TyAlias(..), _) => Ordering::Less, (_, TyAlias(..)) => Ordering::Greater, (Const(..), _) => Ordering::Less, @@ -679,7 +679,7 @@ pub(crate) fn format_impl( offset: Indent, ) -> Option { if let ast::ItemKind::Impl(impl_kind) = &item.kind { - let ast::ImplKind { + let ast::Impl { ref generics, ref self_ty, ref items, @@ -833,7 +833,7 @@ fn format_impl_ref_and_type( offset: Indent, ) -> Option { if let ast::ItemKind::Impl(impl_kind) = &item.kind { - let ast::ImplKind { + let ast::Impl { unsafety, polarity, defaultness, @@ -1029,8 +1029,13 @@ pub(crate) fn format_trait( offset: Indent, ) -> Option { if let ast::ItemKind::Trait(trait_kind) = &item.kind { - let ast::TraitKind(is_auto, unsafety, ref generics, ref generic_bounds, ref trait_items) = - **trait_kind; + let ast::Trait { + is_auto, + unsafety, + ref generics, + ref bounds, + ref items, + } = **trait_kind; let mut result = String::with_capacity(128); let header = format!( "{}{}{}trait ", @@ -1048,11 +1053,11 @@ pub(crate) fn format_trait( result.push_str(&generics_str); // FIXME(#2055): rustfmt fails to format when there are comments between trait bounds. - if !generic_bounds.is_empty() { + if !bounds.is_empty() { let ident_hi = context .snippet_provider .span_after(item.span, &item.ident.as_str()); - let bound_hi = generic_bounds.last().unwrap().span().hi(); + let bound_hi = bounds.last().unwrap().span().hi(); let snippet = context.snippet(mk_sp(ident_hi, bound_hi)); if contains_comment(snippet) { return None; @@ -1061,7 +1066,7 @@ pub(crate) fn format_trait( result = rewrite_assign_rhs_with( context, result + ":", - generic_bounds, + bounds, shape, RhsTactics::ForceNextLineWithoutIndent, )?; @@ -1072,10 +1077,10 @@ pub(crate) fn format_trait( let where_on_new_line = context.config.indent_style() != IndentStyle::Block; let where_budget = context.budget(last_line_width(&result)); - let pos_before_where = if generic_bounds.is_empty() { + let pos_before_where = if bounds.is_empty() { generics.where_clause.span.lo() } else { - generic_bounds[generic_bounds.len() - 1].span().hi() + bounds[bounds.len() - 1].span().hi() }; let option = WhereClauseOption::snuggled(&generics_str); let where_clause_str = rewrite_where_clause( @@ -1134,7 +1139,7 @@ pub(crate) fn format_trait( BraceStyle::PreferSameLine => result.push(' '), BraceStyle::SameLineWhere => { if result.contains('\n') - || (!generics.where_clause.predicates.is_empty() && !trait_items.is_empty()) + || (!generics.where_clause.predicates.is_empty() && !items.is_empty()) { result.push_str(&offset.to_string_with_newline(context.config)); } else { @@ -1149,12 +1154,12 @@ pub(crate) fn format_trait( let open_pos = snippet.find_uncommented("{")? + 1; let outer_indent_str = offset.block_only().to_string_with_newline(context.config); - if !trait_items.is_empty() || contains_comment(&snippet[open_pos..]) { + if !items.is_empty() || contains_comment(&snippet[open_pos..]) { let mut visitor = FmtVisitor::from_context(context); visitor.block_indent = offset.block_only().block_indent(context.config); visitor.last_pos = block_span.lo() + BytePos(open_pos as u32); - for item in trait_items { + for item in items { visitor.visit_trait_item(item); } @@ -3125,17 +3130,22 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option let item_str = match self.kind { ast::ForeignItemKind::Fn(ref fn_kind) => { - let ast::FnKind(defaultness, ref fn_sig, ref generics, ref block) = **fn_kind; - if let Some(ref body) = block { + let ast::Fn { + defaultness, + ref sig, + ref generics, + ref body, + } = **fn_kind; + if let Some(ref body) = body { let mut visitor = FmtVisitor::from_context(context); visitor.block_indent = shape.indent; visitor.last_pos = self.span.lo(); let inner_attrs = inner_attributes(&self.attrs); let fn_ctxt = visit::FnCtxt::Foreign; visitor.visit_fn( - visit::FnKind::Fn(fn_ctxt, self.ident, &fn_sig, &self.vis, Some(body)), + visit::FnKind::Fn(fn_ctxt, self.ident, &sig, &self.vis, Some(body)), generics, - &fn_sig.decl, + &sig.decl, self.span, defaultness, Some(&inner_attrs), @@ -3146,7 +3156,7 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option context, shape.indent, self.ident, - &FnSig::from_method_sig(&fn_sig, generics, &self.vis), + &FnSig::from_method_sig(&sig, generics, &self.vis), span, FnBraceStyle::None, ) @@ -3168,16 +3178,20 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option rewrite_assign_rhs(context, prefix, &**ty, shape.sub_width(1)?).map(|s| s + ";") } ast::ForeignItemKind::TyAlias(ref ty_alias_kind) => { - let ast::TyAliasKind(_, ref generics, ref generic_bounds, ref type_default) = - **ty_alias_kind; + let ast::TyAlias { + ref generics, + ref bounds, + ref ty, + .. + } = **ty_alias_kind; rewrite_type( &context, shape.indent, self.ident, &self.vis, generics, - Some(generic_bounds), - type_default.as_ref(), + Some(bounds), + ty.as_ref(), self.span, ) } diff --git a/src/tools/rustfmt/src/visitor.rs b/src/tools/rustfmt/src/visitor.rs index d854d90b40b..2cfd4e3f15c 100644 --- a/src/tools/rustfmt/src/visitor.rs +++ b/src/tools/rustfmt/src/visitor.rs @@ -540,24 +540,22 @@ pub(crate) fn visit_item(&mut self, item: &ast::Item) { self.visit_static(&StaticParts::from_item(item)); } ast::ItemKind::Fn(ref fn_kind) => { - let ast::FnKind(defaultness, ref fn_signature, ref generics, ref block) = - **fn_kind; - if let Some(ref body) = block { + let ast::Fn { + defaultness, + ref sig, + ref generics, + ref body, + } = **fn_kind; + if let Some(ref body) = body { let inner_attrs = inner_attributes(&item.attrs); - let fn_ctxt = match fn_signature.header.ext { + let fn_ctxt = match sig.header.ext { ast::Extern::None => visit::FnCtxt::Free, _ => visit::FnCtxt::Foreign, }; self.visit_fn( - visit::FnKind::Fn( - fn_ctxt, - item.ident, - &fn_signature, - &item.vis, - Some(body), - ), + visit::FnKind::Fn(fn_ctxt, item.ident, &sig, &item.vis, Some(body)), generics, - &fn_signature.decl, + &sig.decl, item.span, defaultness, Some(&inner_attrs), @@ -565,19 +563,18 @@ pub(crate) fn visit_item(&mut self, item: &ast::Item) { } else { let indent = self.block_indent; let rewrite = self.rewrite_required_fn( - indent, - item.ident, - &fn_signature, - &item.vis, - generics, - item.span, + indent, item.ident, &sig, &item.vis, generics, item.span, ); self.push_rewrite(item.span, rewrite); } } ast::ItemKind::TyAlias(ref alias_kind) => { - let ast::TyAliasKind(_, ref generics, ref generic_bounds, ref ty) = - **alias_kind; + let ast::TyAlias { + ref generics, + ref bounds, + ref ty, + .. + } = **alias_kind; match ty { Some(ty) => { let rewrite = rewrite_type( @@ -586,7 +583,7 @@ pub(crate) fn visit_item(&mut self, item: &ast::Item) { item.ident, &item.vis, generics, - Some(generic_bounds), + Some(bounds), Some(&*ty), item.span, ); @@ -597,7 +594,7 @@ pub(crate) fn visit_item(&mut self, item: &ast::Item) { &self.get_context(), self.block_indent, item.ident, - generic_bounds, + bounds, generics, &item.vis, item.span, @@ -639,8 +636,13 @@ pub(crate) fn visit_trait_item(&mut self, ti: &ast::AssocItem) { match ti.kind { ast::AssocItemKind::Const(..) => self.visit_static(&StaticParts::from_trait_item(ti)), ast::AssocItemKind::Fn(ref fn_kind) => { - let ast::FnKind(defaultness, ref sig, ref generics, ref block) = **fn_kind; - if let Some(ref body) = block { + let ast::Fn { + defaultness, + ref sig, + ref generics, + ref body, + } = **fn_kind; + if let Some(ref body) = body { let inner_attrs = inner_attributes(&ti.attrs); let fn_ctxt = visit::FnCtxt::Assoc(visit::AssocCtxt::Trait); self.visit_fn( @@ -659,16 +661,20 @@ pub(crate) fn visit_trait_item(&mut self, ti: &ast::AssocItem) { } } ast::AssocItemKind::TyAlias(ref ty_alias_kind) => { - let ast::TyAliasKind(_, ref generics, ref generic_bounds, ref type_default) = - **ty_alias_kind; + let ast::TyAlias { + ref generics, + ref bounds, + ref ty, + .. + } = **ty_alias_kind; let rewrite = rewrite_type( &self.get_context(), self.block_indent, ti.ident, &ti.vis, generics, - Some(generic_bounds), - type_default.as_ref(), + Some(bounds), + ty.as_ref(), ti.span, ); self.push_rewrite(ti.span, rewrite); @@ -689,8 +695,13 @@ pub(crate) fn visit_impl_item(&mut self, ii: &ast::AssocItem) { match ii.kind { ast::AssocItemKind::Fn(ref fn_kind) => { - let ast::FnKind(defaultness, ref sig, ref generics, ref block) = **fn_kind; - if let Some(ref body) = block { + let ast::Fn { + defaultness, + ref sig, + ref generics, + ref body, + } = **fn_kind; + if let Some(ref body) = body { let inner_attrs = inner_attributes(&ii.attrs); let fn_ctxt = visit::FnCtxt::Assoc(visit::AssocCtxt::Impl); self.visit_fn( @@ -710,7 +721,12 @@ pub(crate) fn visit_impl_item(&mut self, ii: &ast::AssocItem) { } ast::AssocItemKind::Const(..) => self.visit_static(&StaticParts::from_impl_item(ii)), ast::AssocItemKind::TyAlias(ref ty_alias_kind) => { - let ast::TyAliasKind(defaultness, ref generics, _, ref ty) = **ty_alias_kind; + let ast::TyAlias { + defaultness, + ref generics, + ref ty, + .. + } = **ty_alias_kind; self.push_rewrite( ii.span, rewrite_impl_type(