diff --git a/.mailmap b/.mailmap index f476926832158..d3e400e5f9061 100644 --- a/.mailmap +++ b/.mailmap @@ -148,6 +148,7 @@ Jorge Aparicio Joseph Martin Joseph T. Lyons Joseph T. Lyons +Joshua Nelson jumbatm <30644300+jumbatm@users.noreply.github.com> Junyoung Cho Jyun-Yan You diff --git a/Cargo.lock b/Cargo.lock index 928d19b1e2c3f..b5abab7ba965d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3802,7 +3802,7 @@ dependencies = [ "rustc_target", "rustc_trait_selection", "rustc_traits", - "rustc_ty", + "rustc_ty_utils", "rustc_typeck", "smallvec 1.4.2", "tempfile", @@ -4240,7 +4240,7 @@ dependencies = [ ] [[package]] -name = "rustc_ty" +name = "rustc_ty_utils" version = "0.0.0" dependencies = [ "rustc_data_structures", diff --git a/compiler/rustc_builtin_macros/src/cfg_accessible.rs b/compiler/rustc_builtin_macros/src/cfg_accessible.rs index 75f4b077640d4..09ed1af345675 100644 --- a/compiler/rustc_builtin_macros/src/cfg_accessible.rs +++ b/compiler/rustc_builtin_macros/src/cfg_accessible.rs @@ -1,7 +1,7 @@ //! Implementation of the `#[cfg_accessible(path)]` attribute macro. use rustc_ast as ast; -use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, MultiItemModifier}; +use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier}; use rustc_feature::AttributeTemplate; use rustc_parse::validate_attr; use rustc_span::symbol::sym; @@ -31,7 +31,7 @@ impl MultiItemModifier for Expander { fn expand( &self, ecx: &mut ExtCtxt<'_>, - _span: Span, + span: Span, meta_item: &ast::MetaItem, item: Annotatable, ) -> ExpandResult, Annotatable> { @@ -49,11 +49,14 @@ impl MultiItemModifier for Expander { None => return ExpandResult::Ready(Vec::new()), }; - let failure_msg = "cannot determine whether the path is accessible or not"; match ecx.resolver.cfg_accessible(ecx.current_expansion.id, path) { Ok(true) => ExpandResult::Ready(vec![item]), Ok(false) => ExpandResult::Ready(Vec::new()), - Err(_) => ExpandResult::Retry(item, failure_msg.into()), + Err(Indeterminate) if ecx.force_mode => { + ecx.span_err(span, "cannot determine whether the path is accessible or not"); + ExpandResult::Ready(vec![item]) + } + Err(Indeterminate) => ExpandResult::Retry(item), } } } diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 0642edff6b678..a767de53dae1f 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -407,13 +407,7 @@ impl<'a> TraitDef<'a> { _ => false, }) } - _ => { - // Non-ADT derive is an error, but it should have been - // set earlier; see - // librustc_expand/expand.rs:MacroExpander::fully_expand_fragment() - // librustc_expand/base.rs:Annotatable::derive_allowed() - return; - } + _ => unreachable!(), }; let container_id = cx.current_expansion.id.expn_data().parent; let always_copy = has_no_type_params && cx.resolver.has_derive_copy(container_id); @@ -475,12 +469,7 @@ impl<'a> TraitDef<'a> { ); push(Annotatable::Item(P(ast::Item { attrs, ..(*newitem).clone() }))) } - _ => { - // Non-Item derive is an error, but it should have been - // set earlier; see - // librustc_expand/expand.rs:MacroExpander::fully_expand_fragment() - // librustc_expand/base.rs:Annotatable::derive_allowed() - } + _ => unreachable!(), } } diff --git a/compiler/rustc_builtin_macros/src/deriving/mod.rs b/compiler/rustc_builtin_macros/src/deriving/mod.rs index bf95093492880..72d94af4694ab 100644 --- a/compiler/rustc_builtin_macros/src/deriving/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/mod.rs @@ -98,13 +98,7 @@ fn inject_impl_of_structural_trait( ) { let item = match *item { Annotatable::Item(ref item) => item, - _ => { - // Non-Item derive is an error, but it should have been - // set earlier; see - // librustc_expand/expand.rs:MacroExpander::fully_expand_fragment() - // librustc_expand/base.rs:Annotatable::derive_allowed() - return; - } + _ => unreachable!(), }; let generics = match item.kind { diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index b435def87ac84..1c76c31e1a7ff 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -251,8 +251,7 @@ pub enum ExpandResult { /// Expansion produced a result (possibly dummy). Ready(T), /// Expansion could not produce a result and needs to be retried. - /// The string is an explanation that will be printed if we are stuck in an infinite retry loop. - Retry(U, String), + Retry(U), } // `meta_item` is the attribute, and `item` is the item being modified. @@ -889,8 +888,10 @@ pub trait ResolverExpand { /// Some parent node that is close enough to the given macro call. fn lint_node_id(&mut self, expn_id: ExpnId) -> NodeId; + // Resolver interfaces for specific built-in macros. + /// Does `#[derive(...)]` attribute with the given `ExpnId` have built-in `Copy` inside it? fn has_derive_copy(&self, expn_id: ExpnId) -> bool; - fn add_derive_copy(&mut self, expn_id: ExpnId); + /// Path resolution logic for `#[cfg_accessible(path)]`. fn cfg_accessible(&mut self, expn_id: ExpnId, path: &ast::Path) -> Result; } @@ -919,6 +920,9 @@ pub struct ExtCtxt<'a> { pub root_path: PathBuf, pub resolver: &'a mut dyn ResolverExpand, pub current_expansion: ExpansionData, + /// Error recovery mode entered when expansion is stuck + /// (or during eager expansion, but that's a hack). + pub force_mode: bool, pub expansions: FxHashMap>, /// Called directly after having parsed an external `mod foo;` in expansion. pub(super) extern_mod_loaded: Option<&'a dyn Fn(&ast::Crate)>, @@ -945,6 +949,7 @@ impl<'a> ExtCtxt<'a> { directory_ownership: DirectoryOwnership::Owned { relative: None }, prior_type_ascription: None, }, + force_mode: false, expansions: FxHashMap::default(), } } diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs index cccbdf778edcc..563783c5b795d 100644 --- a/compiler/rustc_expand/src/config.rs +++ b/compiler/rustc_expand/src/config.rs @@ -1,5 +1,7 @@ //! Conditional compilation stripping. +use crate::base::Annotatable; + use rustc_ast::attr::HasAttrs; use rustc_ast::mut_visit::*; use rustc_ast::ptr::P; @@ -496,6 +498,49 @@ impl<'a> StripUnconfigured<'a> { pub fn configure_fn_decl(&mut self, fn_decl: &mut ast::FnDecl) { fn_decl.inputs.flat_map_in_place(|arg| self.configure(arg)); } + + pub fn fully_configure(&mut self, item: Annotatable) -> Annotatable { + // Since the item itself has already been configured by the InvocationCollector, + // we know that fold result vector will contain exactly one element + match item { + Annotatable::Item(item) => Annotatable::Item(self.flat_map_item(item).pop().unwrap()), + Annotatable::TraitItem(item) => { + Annotatable::TraitItem(self.flat_map_trait_item(item).pop().unwrap()) + } + Annotatable::ImplItem(item) => { + Annotatable::ImplItem(self.flat_map_impl_item(item).pop().unwrap()) + } + Annotatable::ForeignItem(item) => { + Annotatable::ForeignItem(self.flat_map_foreign_item(item).pop().unwrap()) + } + Annotatable::Stmt(stmt) => { + Annotatable::Stmt(stmt.map(|stmt| self.flat_map_stmt(stmt).pop().unwrap())) + } + Annotatable::Expr(mut expr) => Annotatable::Expr({ + self.visit_expr(&mut expr); + expr + }), + Annotatable::Arm(arm) => Annotatable::Arm(self.flat_map_arm(arm).pop().unwrap()), + Annotatable::Field(field) => { + Annotatable::Field(self.flat_map_field(field).pop().unwrap()) + } + Annotatable::FieldPat(fp) => { + Annotatable::FieldPat(self.flat_map_field_pattern(fp).pop().unwrap()) + } + Annotatable::GenericParam(param) => { + Annotatable::GenericParam(self.flat_map_generic_param(param).pop().unwrap()) + } + Annotatable::Param(param) => { + Annotatable::Param(self.flat_map_param(param).pop().unwrap()) + } + Annotatable::StructField(sf) => { + Annotatable::StructField(self.flat_map_struct_field(sf).pop().unwrap()) + } + Annotatable::Variant(v) => { + Annotatable::Variant(self.flat_map_variant(v).pop().unwrap()) + } + } + } } impl<'a> MutVisitor for StripUnconfigured<'a> { diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 1b31bd6a30510..5be2fee8b38fa 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -209,6 +209,28 @@ impl AstFragmentKind { self.make_from(DummyResult::any(span)).expect("couldn't create a dummy AST fragment") } + /// Fragment supports macro expansion and not just inert attributes, `cfg` and `cfg_attr`. + pub fn supports_macro_expansion(self) -> bool { + match self { + AstFragmentKind::OptExpr + | AstFragmentKind::Expr + | AstFragmentKind::Pat + | AstFragmentKind::Ty + | AstFragmentKind::Stmts + | AstFragmentKind::Items + | AstFragmentKind::TraitItems + | AstFragmentKind::ImplItems + | AstFragmentKind::ForeignItems => true, + AstFragmentKind::Arms + | AstFragmentKind::Fields + | AstFragmentKind::FieldPats + | AstFragmentKind::GenericParams + | AstFragmentKind::Params + | AstFragmentKind::StructFields + | AstFragmentKind::Variants => false, + } + } + fn expect_from_annotatables>( self, items: I, @@ -404,6 +426,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { // Recursively expand all macro invocations in this AST fragment. pub fn fully_expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragment { let orig_expansion_data = self.cx.current_expansion.clone(); + let orig_force_mode = self.cx.force_mode; self.cx.current_expansion.depth = 0; // Collect all macro invocations and replace them with placeholders. @@ -432,6 +455,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> { } invocations = mem::take(&mut undetermined_invocations); force = !mem::replace(&mut progress, false); + if force && self.monotonic { + self.cx.sess.delay_span_bug( + invocations.last().unwrap().0.span(), + "expansion entered force mode without producing any errors", + ); + } continue; }; @@ -460,18 +489,19 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let ExpansionData { depth, id: expn_id, .. } = invoc.expansion_data; self.cx.current_expansion = invoc.expansion_data.clone(); + self.cx.force_mode = force; // FIXME(jseyfried): Refactor out the following logic + let fragment_kind = invoc.fragment_kind; let (expanded_fragment, new_invocations) = match res { InvocationRes::Single(ext) => match self.expand_invoc(invoc, &ext.kind) { ExpandResult::Ready(fragment) => self.collect_invocations(fragment, &[]), - ExpandResult::Retry(invoc, explanation) => { + ExpandResult::Retry(invoc) => { if force { - // We are stuck, stop retrying and produce a dummy fragment. - let span = invoc.span(); - self.cx.span_err(span, &explanation); - let fragment = invoc.fragment_kind.dummy(span); - self.collect_invocations(fragment, &[]) + self.cx.span_bug( + invoc.span(), + "expansion entered force mode but is still stuck", + ); } else { // Cannot expand, will retry this invocation later. undetermined_invocations @@ -483,36 +513,45 @@ impl<'a, 'b> MacroExpander<'a, 'b> { InvocationRes::DeriveContainer(_exts) => { // FIXME: Consider using the derive resolutions (`_exts`) immediately, // instead of enqueuing the derives to be resolved again later. - let (derives, item) = match invoc.kind { + let (derives, mut item) = match invoc.kind { InvocationKind::DeriveContainer { derives, item } => (derives, item), _ => unreachable!(), }; - if !item.derive_allowed() { + let (item, derive_placeholders) = if !item.derive_allowed() { self.error_derive_forbidden_on_non_adt(&derives, &item); - } + item.visit_attrs(|attrs| attrs.retain(|a| !a.has_name(sym::derive))); + (item, Vec::new()) + } else { + let mut item = StripUnconfigured { + sess: self.cx.sess, + features: self.cx.ecfg.features, + } + .fully_configure(item); + item.visit_attrs(|attrs| attrs.retain(|a| !a.has_name(sym::derive))); + + invocations.reserve(derives.len()); + let derive_placeholders = derives + .into_iter() + .map(|path| { + let expn_id = ExpnId::fresh(None); + invocations.push(( + Invocation { + kind: InvocationKind::Derive { path, item: item.clone() }, + fragment_kind, + expansion_data: ExpansionData { + id: expn_id, + ..self.cx.current_expansion.clone() + }, + }, + None, + )); + NodeId::placeholder_from_expn_id(expn_id) + }) + .collect::>(); + (item, derive_placeholders) + }; - let mut item = self.fully_configure(item); - item.visit_attrs(|attrs| attrs.retain(|a| !a.has_name(sym::derive))); - - let mut derive_placeholders = Vec::with_capacity(derives.len()); - invocations.reserve(derives.len()); - for path in derives { - let expn_id = ExpnId::fresh(None); - derive_placeholders.push(NodeId::placeholder_from_expn_id(expn_id)); - invocations.push(( - Invocation { - kind: InvocationKind::Derive { path, item: item.clone() }, - fragment_kind: invoc.fragment_kind, - expansion_data: ExpansionData { - id: expn_id, - ..invoc.expansion_data.clone() - }, - }, - None, - )); - } - let fragment = - invoc.fragment_kind.expect_from_annotatables(::std::iter::once(item)); + let fragment = fragment_kind.expect_from_annotatables(::std::iter::once(item)); self.collect_invocations(fragment, &derive_placeholders) } }; @@ -526,6 +565,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { } self.cx.current_expansion = orig_expansion_data; + self.cx.force_mode = orig_force_mode; // Finally incorporate all the expanded macros into the input AST fragment. let mut placeholder_expander = PlaceholderExpander::new(self.cx, self.monotonic); @@ -601,48 +641,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> { (fragment, invocations) } - fn fully_configure(&mut self, item: Annotatable) -> Annotatable { - let mut cfg = StripUnconfigured { sess: &self.cx.sess, features: self.cx.ecfg.features }; - // Since the item itself has already been configured by the InvocationCollector, - // we know that fold result vector will contain exactly one element - match item { - Annotatable::Item(item) => Annotatable::Item(cfg.flat_map_item(item).pop().unwrap()), - Annotatable::TraitItem(item) => { - Annotatable::TraitItem(cfg.flat_map_trait_item(item).pop().unwrap()) - } - Annotatable::ImplItem(item) => { - Annotatable::ImplItem(cfg.flat_map_impl_item(item).pop().unwrap()) - } - Annotatable::ForeignItem(item) => { - Annotatable::ForeignItem(cfg.flat_map_foreign_item(item).pop().unwrap()) - } - Annotatable::Stmt(stmt) => { - Annotatable::Stmt(stmt.map(|stmt| cfg.flat_map_stmt(stmt).pop().unwrap())) - } - Annotatable::Expr(mut expr) => Annotatable::Expr({ - cfg.visit_expr(&mut expr); - expr - }), - Annotatable::Arm(arm) => Annotatable::Arm(cfg.flat_map_arm(arm).pop().unwrap()), - Annotatable::Field(field) => { - Annotatable::Field(cfg.flat_map_field(field).pop().unwrap()) - } - Annotatable::FieldPat(fp) => { - Annotatable::FieldPat(cfg.flat_map_field_pattern(fp).pop().unwrap()) - } - Annotatable::GenericParam(param) => { - Annotatable::GenericParam(cfg.flat_map_generic_param(param).pop().unwrap()) - } - Annotatable::Param(param) => { - Annotatable::Param(cfg.flat_map_param(param).pop().unwrap()) - } - Annotatable::StructField(sf) => { - Annotatable::StructField(cfg.flat_map_struct_field(sf).pop().unwrap()) - } - Annotatable::Variant(v) => Annotatable::Variant(cfg.flat_map_variant(v).pop().unwrap()), - } - } - fn error_recursion_limit_reached(&mut self) { let expn_data = self.cx.current_expansion.id.expn_data(); let suggested_limit = self.cx.ecfg.recursion_limit * 2; @@ -735,20 +733,17 @@ impl<'a, 'b> MacroExpander<'a, 'b> { Ok(meta) => { let items = match expander.expand(self.cx, span, &meta, item) { ExpandResult::Ready(items) => items, - ExpandResult::Retry(item, explanation) => { + ExpandResult::Retry(item) => { // Reassemble the original invocation for retrying. - return ExpandResult::Retry( - Invocation { - kind: InvocationKind::Attr { - attr, - item, - derives, - after_derive, - }, - ..invoc + return ExpandResult::Retry(Invocation { + kind: InvocationKind::Attr { + attr, + item, + derives, + after_derive, }, - explanation, - ); + ..invoc + }); } }; fragment_kind.expect_from_annotatables(items) @@ -772,24 +767,18 @@ impl<'a, 'b> MacroExpander<'a, 'b> { InvocationKind::Derive { path, item } => match ext { SyntaxExtensionKind::Derive(expander) | SyntaxExtensionKind::LegacyDerive(expander) => { - if !item.derive_allowed() { - return ExpandResult::Ready(fragment_kind.dummy(span)); - } if let SyntaxExtensionKind::Derive(..) = ext { self.gate_proc_macro_input(&item); } let meta = ast::MetaItem { kind: ast::MetaItemKind::Word, span, path }; let items = match expander.expand(self.cx, span, &meta, item) { ExpandResult::Ready(items) => items, - ExpandResult::Retry(item, explanation) => { + ExpandResult::Retry(item) => { // Reassemble the original invocation for retrying. - return ExpandResult::Retry( - Invocation { - kind: InvocationKind::Derive { path: meta.path, item }, - ..invoc - }, - explanation, - ); + return ExpandResult::Retry(Invocation { + kind: InvocationKind::Derive { path: meta.path, item }, + ..invoc + }); } }; fragment_kind.expect_from_annotatables(items) @@ -1034,11 +1023,9 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { fn collect_attr( &mut self, - attr: Option, - derives: Vec, + (attr, derives, after_derive): (Option, Vec, bool), item: Annotatable, kind: AstFragmentKind, - after_derive: bool, ) -> AstFragment { self.collect( kind, @@ -1054,7 +1041,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { attrs: &mut Vec, after_derive: &mut bool, ) -> Option { - let attr = attrs + attrs .iter() .position(|a| { if a.has_name(sym::derive) { @@ -1062,29 +1049,14 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { } !self.cx.sess.is_attr_known(a) && !is_builtin_attr(a) }) - .map(|i| attrs.remove(i)); - if let Some(attr) = &attr { - if !self.cx.ecfg.custom_inner_attributes() - && attr.style == ast::AttrStyle::Inner - && !attr.has_name(sym::test) - { - feature_err( - &self.cx.sess.parse_sess, - sym::custom_inner_attributes, - attr.span, - "non-builtin inner attributes are unstable", - ) - .emit(); - } - } - attr + .map(|i| attrs.remove(i)) } /// If `item` is an attr invocation, remove and return the macro attribute and derive traits. - fn classify_item( + fn take_first_attr( &mut self, item: &mut impl HasAttrs, - ) -> (Option, Vec, /* after_derive */ bool) { + ) -> Option<(Option, Vec, /* after_derive */ bool)> { let (mut attr, mut traits, mut after_derive) = (None, Vec::new(), false); item.visit_attrs(|mut attrs| { @@ -1092,23 +1064,23 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { traits = collect_derives(&mut self.cx, &mut attrs); }); - (attr, traits, after_derive) + if attr.is_some() || !traits.is_empty() { Some((attr, traits, after_derive)) } else { None } } - /// Alternative to `classify_item()` that ignores `#[derive]` so invocations fallthrough + /// Alternative to `take_first_attr()` that ignores `#[derive]` so invocations fallthrough /// to the unused-attributes lint (making it an error on statements and expressions /// is a breaking change) - fn classify_nonitem( + fn take_first_attr_no_derive( &mut self, nonitem: &mut impl HasAttrs, - ) -> (Option, /* after_derive */ bool) { + ) -> Option<(Option, Vec, /* after_derive */ bool)> { let (mut attr, mut after_derive) = (None, false); nonitem.visit_attrs(|mut attrs| { attr = self.find_attr_invoc(&mut attrs, &mut after_derive); }); - (attr, after_derive) + attr.map(|attr| (Some(attr), Vec::new(), after_derive)) } fn configure(&mut self, node: T) -> Option { @@ -1152,23 +1124,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { visit_clobber(expr.deref_mut(), |mut expr| { self.cfg.configure_expr_kind(&mut expr.kind); - // ignore derives so they remain unused - let (attr, after_derive) = self.classify_nonitem(&mut expr); - - if let Some(ref attr_value) = attr { + if let Some(attr) = self.take_first_attr_no_derive(&mut expr) { // Collect the invoc regardless of whether or not attributes are permitted here // expansion will eat the attribute so it won't error later. - self.cfg.maybe_emit_expr_attr_err(attr_value); + attr.0.as_ref().map(|attr| self.cfg.maybe_emit_expr_attr_err(attr)); // AstFragmentKind::Expr requires the macro to emit an expression. return self - .collect_attr( - attr, - vec![], - Annotatable::Expr(P(expr)), - AstFragmentKind::Expr, - after_derive, - ) + .collect_attr(attr, Annotatable::Expr(P(expr)), AstFragmentKind::Expr) .make_expr() .into_inner(); } @@ -1186,16 +1149,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> { let mut arm = configure!(self, arm); - let (attr, traits, after_derive) = self.classify_item(&mut arm); - if attr.is_some() || !traits.is_empty() { + if let Some(attr) = self.take_first_attr(&mut arm) { return self - .collect_attr( - attr, - traits, - Annotatable::Arm(arm), - AstFragmentKind::Arms, - after_derive, - ) + .collect_attr(attr, Annotatable::Arm(arm), AstFragmentKind::Arms) .make_arms(); } @@ -1205,16 +1161,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { fn flat_map_field(&mut self, field: ast::Field) -> SmallVec<[ast::Field; 1]> { let mut field = configure!(self, field); - let (attr, traits, after_derive) = self.classify_item(&mut field); - if attr.is_some() || !traits.is_empty() { + if let Some(attr) = self.take_first_attr(&mut field) { return self - .collect_attr( - attr, - traits, - Annotatable::Field(field), - AstFragmentKind::Fields, - after_derive, - ) + .collect_attr(attr, Annotatable::Field(field), AstFragmentKind::Fields) .make_fields(); } @@ -1224,16 +1173,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { fn flat_map_field_pattern(&mut self, fp: ast::FieldPat) -> SmallVec<[ast::FieldPat; 1]> { let mut fp = configure!(self, fp); - let (attr, traits, after_derive) = self.classify_item(&mut fp); - if attr.is_some() || !traits.is_empty() { + if let Some(attr) = self.take_first_attr(&mut fp) { return self - .collect_attr( - attr, - traits, - Annotatable::FieldPat(fp), - AstFragmentKind::FieldPats, - after_derive, - ) + .collect_attr(attr, Annotatable::FieldPat(fp), AstFragmentKind::FieldPats) .make_field_patterns(); } @@ -1243,16 +1185,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { fn flat_map_param(&mut self, p: ast::Param) -> SmallVec<[ast::Param; 1]> { let mut p = configure!(self, p); - let (attr, traits, after_derive) = self.classify_item(&mut p); - if attr.is_some() || !traits.is_empty() { + if let Some(attr) = self.take_first_attr(&mut p) { return self - .collect_attr( - attr, - traits, - Annotatable::Param(p), - AstFragmentKind::Params, - after_derive, - ) + .collect_attr(attr, Annotatable::Param(p), AstFragmentKind::Params) .make_params(); } @@ -1262,16 +1197,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { fn flat_map_struct_field(&mut self, sf: ast::StructField) -> SmallVec<[ast::StructField; 1]> { let mut sf = configure!(self, sf); - let (attr, traits, after_derive) = self.classify_item(&mut sf); - if attr.is_some() || !traits.is_empty() { + if let Some(attr) = self.take_first_attr(&mut sf) { return self - .collect_attr( - attr, - traits, - Annotatable::StructField(sf), - AstFragmentKind::StructFields, - after_derive, - ) + .collect_attr(attr, Annotatable::StructField(sf), AstFragmentKind::StructFields) .make_struct_fields(); } @@ -1281,16 +1209,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { fn flat_map_variant(&mut self, variant: ast::Variant) -> SmallVec<[ast::Variant; 1]> { let mut variant = configure!(self, variant); - let (attr, traits, after_derive) = self.classify_item(&mut variant); - if attr.is_some() || !traits.is_empty() { + if let Some(attr) = self.take_first_attr(&mut variant) { return self - .collect_attr( - attr, - traits, - Annotatable::Variant(variant), - AstFragmentKind::Variants, - after_derive, - ) + .collect_attr(attr, Annotatable::Variant(variant), AstFragmentKind::Variants) .make_variants(); } @@ -1302,20 +1223,11 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { expr.filter_map(|mut expr| { self.cfg.configure_expr_kind(&mut expr.kind); - // Ignore derives so they remain unused. - let (attr, after_derive) = self.classify_nonitem(&mut expr); - - if let Some(ref attr_value) = attr { - self.cfg.maybe_emit_expr_attr_err(attr_value); + if let Some(attr) = self.take_first_attr_no_derive(&mut expr) { + attr.0.as_ref().map(|attr| self.cfg.maybe_emit_expr_attr_err(attr)); return self - .collect_attr( - attr, - vec![], - Annotatable::Expr(P(expr)), - AstFragmentKind::OptExpr, - after_derive, - ) + .collect_attr(attr, Annotatable::Expr(P(expr)), AstFragmentKind::OptExpr) .make_opt_expr() .map(|expr| expr.into_inner()); } @@ -1354,25 +1266,13 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { // we'll expand attributes on expressions separately if !stmt.is_expr() { - let (attr, derives, after_derive) = if stmt.is_item() { - // FIXME: Handle custom attributes on statements (#15701) - (None, vec![], false) - } else { - // ignore derives on non-item statements so it falls through - // to the unused-attributes lint - let (attr, after_derive) = self.classify_nonitem(&mut stmt); - (attr, vec![], after_derive) - }; + // FIXME: Handle custom attributes on statements (#15701). + let attr = + if stmt.is_item() { None } else { self.take_first_attr_no_derive(&mut stmt) }; - if attr.is_some() || !derives.is_empty() { + if let Some(attr) = attr { return self - .collect_attr( - attr, - derives, - Annotatable::Stmt(P(stmt)), - AstFragmentKind::Stmts, - after_derive, - ) + .collect_attr(attr, Annotatable::Stmt(P(stmt)), AstFragmentKind::Stmts) .make_stmts(); } } @@ -1412,16 +1312,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { let mut item = configure!(self, item); - let (attr, traits, after_derive) = self.classify_item(&mut item); - if attr.is_some() || !traits.is_empty() { + if let Some(attr) = self.take_first_attr(&mut item) { return self - .collect_attr( - attr, - traits, - Annotatable::Item(item), - AstFragmentKind::Items, - after_derive, - ) + .collect_attr(attr, Annotatable::Item(item), AstFragmentKind::Items) .make_items(); } @@ -1515,16 +1408,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { fn flat_map_trait_item(&mut self, item: P) -> SmallVec<[P; 1]> { let mut item = configure!(self, item); - let (attr, traits, after_derive) = self.classify_item(&mut item); - if attr.is_some() || !traits.is_empty() { + if let Some(attr) = self.take_first_attr(&mut item) { return self - .collect_attr( - attr, - traits, - Annotatable::TraitItem(item), - AstFragmentKind::TraitItems, - after_derive, - ) + .collect_attr(attr, Annotatable::TraitItem(item), AstFragmentKind::TraitItems) .make_trait_items(); } @@ -1545,16 +1431,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { fn flat_map_impl_item(&mut self, item: P) -> SmallVec<[P; 1]> { let mut item = configure!(self, item); - let (attr, traits, after_derive) = self.classify_item(&mut item); - if attr.is_some() || !traits.is_empty() { + if let Some(attr) = self.take_first_attr(&mut item) { return self - .collect_attr( - attr, - traits, - Annotatable::ImplItem(item), - AstFragmentKind::ImplItems, - after_derive, - ) + .collect_attr(attr, Annotatable::ImplItem(item), AstFragmentKind::ImplItems) .make_impl_items(); } @@ -1595,16 +1474,12 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { &mut self, mut foreign_item: P, ) -> SmallVec<[P; 1]> { - let (attr, traits, after_derive) = self.classify_item(&mut foreign_item); - - if attr.is_some() || !traits.is_empty() { + if let Some(attr) = self.take_first_attr(&mut foreign_item) { return self .collect_attr( attr, - traits, Annotatable::ForeignItem(foreign_item), AstFragmentKind::ForeignItems, - after_derive, ) .make_foreign_items(); } @@ -1639,15 +1514,12 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { ) -> SmallVec<[ast::GenericParam; 1]> { let mut param = configure!(self, param); - let (attr, traits, after_derive) = self.classify_item(&mut param); - if attr.is_some() || !traits.is_empty() { + if let Some(attr) = self.take_first_attr(&mut param) { return self .collect_attr( attr, - traits, Annotatable::GenericParam(param), AstFragmentKind::GenericParams, - after_derive, ) .make_generic_params(); } @@ -1830,7 +1702,4 @@ impl<'feat> ExpansionConfig<'feat> { fn proc_macro_hygiene(&self) -> bool { self.features.map_or(false, |features| features.proc_macro_hygiene) } - fn custom_inner_attributes(&self) -> bool { - self.features.map_or(false, |features| features.custom_inner_attributes) - } } diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs index 4c95f19b96dc6..dea167740edca 100644 --- a/compiler/rustc_expand/src/proc_macro.rs +++ b/compiler/rustc_expand/src/proc_macro.rs @@ -75,38 +75,9 @@ impl MultiItemModifier for ProcMacroDerive { item: Annotatable, ) -> ExpandResult, Annotatable> { let item = match item { - Annotatable::Arm(..) - | Annotatable::Field(..) - | Annotatable::FieldPat(..) - | Annotatable::GenericParam(..) - | Annotatable::Param(..) - | Annotatable::StructField(..) - | Annotatable::Variant(..) => panic!("unexpected annotatable"), - Annotatable::Item(item) => item, - Annotatable::ImplItem(_) - | Annotatable::TraitItem(_) - | Annotatable::ForeignItem(_) - | Annotatable::Stmt(_) - | Annotatable::Expr(_) => { - ecx.span_err( - span, - "proc-macro derives may only be applied to a struct, enum, or union", - ); - return ExpandResult::Ready(Vec::new()); - } + Annotatable::Item(item) => token::NtItem(item), + _ => unreachable!(), }; - match item.kind { - ItemKind::Struct(..) | ItemKind::Enum(..) | ItemKind::Union(..) => {} - _ => { - ecx.span_err( - span, - "proc-macro derives may only be applied to a struct, enum, or union", - ); - return ExpandResult::Ready(Vec::new()); - } - } - - let item = token::NtItem(item); let input = if item.pretty_printing_compatibility_hack() { TokenTree::token(token::Interpolated(Lrc::new(item)), DUMMY_SP).into() } else { diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 298cfcc254c86..4ede9d67b741f 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -39,6 +39,9 @@ pub enum NonMacroAttrKind { Tool, /// Single-segment custom attribute registered by a derive macro (`#[serde(default)]`). DeriveHelper, + /// Single-segment custom attribute registered by a derive macro + /// but used before that derive macro was expanded (deprecated). + DeriveHelperCompat, /// Single-segment custom attribute registered with `#[register_attr]`. Registered, } @@ -370,7 +373,9 @@ impl NonMacroAttrKind { match self { NonMacroAttrKind::Builtin => "built-in attribute", NonMacroAttrKind::Tool => "tool attribute", - NonMacroAttrKind::DeriveHelper => "derive helper attribute", + NonMacroAttrKind::DeriveHelper | NonMacroAttrKind::DeriveHelperCompat => { + "derive helper attribute" + } NonMacroAttrKind::Registered => "explicitly registered attribute", } } @@ -385,7 +390,9 @@ impl NonMacroAttrKind { /// Users of some attributes cannot mark them as used, so they are considered always used. pub fn is_used(self) -> bool { match self { - NonMacroAttrKind::Tool | NonMacroAttrKind::DeriveHelper => true, + NonMacroAttrKind::Tool + | NonMacroAttrKind::DeriveHelper + | NonMacroAttrKind::DeriveHelperCompat => true, NonMacroAttrKind::Builtin | NonMacroAttrKind::Registered => false, } } diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs index 8d0100440a8a5..61fad8863e7c4 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs @@ -131,7 +131,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { } pub(super) fn asyncness(&self, local_def_id: LocalDefId) -> Option { - // similar to the asyncness fn in rustc_ty::ty + // similar to the asyncness fn in rustc_ty_utils::ty let hir_id = self.tcx().hir().local_def_id_to_hir_id(local_def_id); let node = self.tcx().hir().get(hir_id); let fn_like = rustc_middle::hir::map::blocks::FnLikeNode::from_node(node)?; diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index e214493a567b8..2481a27dee795 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -41,7 +41,7 @@ rustc_plugin_impl = { path = "../rustc_plugin_impl" } rustc_privacy = { path = "../rustc_privacy" } rustc_resolve = { path = "../rustc_resolve" } rustc_trait_selection = { path = "../rustc_trait_selection" } -rustc_ty = { path = "../rustc_ty" } +rustc_ty_utils = { path = "../rustc_ty_utils" } tempfile = "3.0.5" [target.'cfg(windows)'.dependencies] diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 82cf4ab7f5c08..5fd560d7effb3 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -699,7 +699,7 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy = SyncLazy::new(|| { rustc_passes::provide(providers); rustc_resolve::provide(providers); rustc_traits::provide(providers); - rustc_ty::provide(providers); + rustc_ty_utils::provide(providers); rustc_metadata::provide(providers); rustc_lint::provide(providers); rustc_symbol_mangling::provide(providers); diff --git a/compiler/rustc_mir/src/transform/validate.rs b/compiler/rustc_mir/src/transform/validate.rs index 75399e9c32cc7..919e4a90a1716 100644 --- a/compiler/rustc_mir/src/transform/validate.rs +++ b/compiler/rustc_mir/src/transform/validate.rs @@ -38,9 +38,7 @@ pub struct Validator { impl<'tcx> MirPass<'tcx> for Validator { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let def_id = body.source.def_id(); - // We need to param_env_reveal_all_normalized, as some optimizations - // change types in ways that require unfolding opaque types. - let param_env = tcx.param_env_reveal_all_normalized(def_id); + let param_env = tcx.param_env(def_id); let mir_phase = self.mir_phase; let always_live_locals = AlwaysLiveLocals::new(body); @@ -81,6 +79,7 @@ pub fn equal_up_to_regions( } // Normalize lifetimes away on both sides, then compare. + let param_env = param_env.with_reveal_all_normalized(tcx); let normalize = |ty: Ty<'tcx>| { tcx.normalize_erasing_regions( param_env, @@ -168,14 +167,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { return true; } // Normalize projections and things like that. - let src = self.tcx.normalize_erasing_regions(self.param_env, src); - let dest = self.tcx.normalize_erasing_regions(self.param_env, dest); + // FIXME: We need to reveal_all, as some optimizations change types in ways + // that require unfolding opaque types. + let param_env = self.param_env.with_reveal_all_normalized(self.tcx); + let src = self.tcx.normalize_erasing_regions(param_env, src); + let dest = self.tcx.normalize_erasing_regions(param_env, dest); // Type-changing assignments can happen when subtyping is used. While // all normal lifetimes are erased, higher-ranked types with their // late-bound lifetimes are still around and can lead to type // differences. So we compare ignoring lifetimes. - equal_up_to_regions(self.tcx, self.param_env, src, dest) + equal_up_to_regions(self.tcx, param_env, src, dest) } } @@ -363,7 +365,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { } TerminatorKind::Call { func, args, destination, cleanup, .. } => { let func_ty = func.ty(&self.body.local_decls, self.tcx); - let func_ty = self.tcx.normalize_erasing_regions(self.param_env, func_ty); match func_ty.kind() { ty::FnPtr(..) | ty::FnDef(..) => {} _ => self.fail( diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index 3738fbaeac84f..41985757b57af 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -312,14 +312,13 @@ impl<'a> Parser<'a> { } pub fn maybe_needs_tokens(attrs: &[ast::Attribute]) -> bool { + // One of the attributes may either itself be a macro, or apply derive macros (`derive`), + // or expand to macro attributes (`cfg_attr`). attrs.iter().any(|attr| { - if let Some(ident) = attr.ident() { + attr.ident().map_or(true, |ident| { ident.name == sym::derive - // This might apply a custom attribute/derive - || ident.name == sym::cfg_attr - || !rustc_feature::is_builtin_attr_name(ident.name) - } else { - true - } + || ident.name == sym::cfg_attr + || !rustc_feature::is_builtin_attr_name(ident.name) + }) }) } diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index acd88af1806ca..2cca1a6ee5979 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -609,7 +609,7 @@ impl<'a> Resolver<'a> { } } Scope::DeriveHelpersCompat => { - let res = Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper); + let res = Res::NonMacroAttr(NonMacroAttrKind::DeriveHelperCompat); if filter_fn(res) { for derive in parent_scope.derives { let parent_scope = &ParentScope { derives: &[], ..*parent_scope }; diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 21e43be20456b..1ee96f81e4fab 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -12,24 +12,24 @@ use rustc_ast_pretty::pprust; use rustc_attr::StabilityLevel; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::ptr_key::PtrKey; +use rustc_data_structures::sync::Lrc; use rustc_errors::struct_span_err; use rustc_expand::base::{Indeterminate, InvocationRes, ResolverExpand, SyntaxExtension}; use rustc_expand::compile_declarative_macro; -use rustc_expand::expand::{AstFragment, AstFragmentKind, Invocation, InvocationKind}; +use rustc_expand::expand::{AstFragment, Invocation, InvocationKind}; use rustc_feature::is_builtin_attr_name; use rustc_hir::def::{self, DefKind, NonMacroAttrKind}; use rustc_hir::def_id; use rustc_middle::middle::stability; use rustc_middle::ty; use rustc_session::lint::builtin::UNUSED_MACROS; +use rustc_session::parse::feature_err; use rustc_session::Session; use rustc_span::edition::Edition; use rustc_span::hygiene::{self, ExpnData, ExpnId, ExpnKind}; +use rustc_span::hygiene::{AstPass, MacroKind}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; - -use rustc_data_structures::sync::Lrc; -use rustc_span::hygiene::{AstPass, MacroKind}; use std::cell::Cell; use std::{mem, ptr}; @@ -241,15 +241,20 @@ impl<'a> ResolverExpand for Resolver<'a> { } }; - let (path, kind, derives, after_derive) = match invoc.kind { + let (path, kind, inner_attr, derives, after_derive) = match invoc.kind { InvocationKind::Attr { ref attr, ref derives, after_derive, .. } => ( &attr.get_normal_item().path, MacroKind::Attr, + attr.style == ast::AttrStyle::Inner, self.arenas.alloc_ast_paths(derives), after_derive, ), - InvocationKind::Bang { ref mac, .. } => (&mac.path, MacroKind::Bang, &[][..], false), - InvocationKind::Derive { ref path, .. } => (path, MacroKind::Derive, &[][..], false), + InvocationKind::Bang { ref mac, .. } => { + (&mac.path, MacroKind::Bang, false, &[][..], false) + } + InvocationKind::Derive { ref path, .. } => { + (path, MacroKind::Derive, false, &[][..], false) + } InvocationKind::DeriveContainer { ref derives, .. } => { // Block expansion of the container until we resolve all derives in it. // This is required for two reasons: @@ -281,7 +286,7 @@ impl<'a> ResolverExpand for Resolver<'a> { ext.helper_attrs.iter().map(|name| Ident::new(*name, span)), ); if ext.is_derive_copy { - self.add_derive_copy(invoc_id); + self.containers_deriving_copy.insert(invoc_id); } ext } @@ -299,8 +304,17 @@ impl<'a> ResolverExpand for Resolver<'a> { // Derives are not included when `invocations` are collected, so we have to add them here. let parent_scope = &ParentScope { derives, ..parent_scope }; + let require_inert = !invoc.fragment_kind.supports_macro_expansion(); let node_id = self.lint_node_id(eager_expansion_root); - let (ext, res) = self.smart_resolve_macro_path(path, kind, parent_scope, node_id, force)?; + let (ext, res) = self.smart_resolve_macro_path( + path, + kind, + require_inert, + inner_attr, + parent_scope, + node_id, + force, + )?; let span = invoc.span(); invoc_id.set_expn_data(ext.expn_data( @@ -318,29 +332,6 @@ impl<'a> ResolverExpand for Resolver<'a> { self.definitions.add_parent_module_of_macro_def(invoc_id, normal_module_def_id); } - match invoc.fragment_kind { - AstFragmentKind::Arms - | AstFragmentKind::Fields - | AstFragmentKind::FieldPats - | AstFragmentKind::GenericParams - | AstFragmentKind::Params - | AstFragmentKind::StructFields - | AstFragmentKind::Variants => { - if let Res::Def(..) = res { - self.session.span_err( - span, - &format!( - "expected an inert attribute, found {} {}", - res.article(), - res.descr() - ), - ); - return Ok(InvocationRes::Single(self.dummy_ext(kind))); - } - } - _ => {} - } - Ok(InvocationRes::Single(ext)) } @@ -360,10 +351,6 @@ impl<'a> ResolverExpand for Resolver<'a> { self.containers_deriving_copy.contains(&expn_id) } - fn add_derive_copy(&mut self, expn_id: ExpnId) { - self.containers_deriving_copy.insert(expn_id); - } - // The function that implements the resolution logic of `#[cfg_accessible(path)]`. // Returns true if the path can certainly be resolved in one of three namespaces, // returns false if the path certainly cannot be resolved in any of the three namespaces. @@ -403,10 +390,14 @@ impl<'a> ResolverExpand for Resolver<'a> { impl<'a> Resolver<'a> { /// Resolve macro path with error reporting and recovery. + /// Uses dummy syntax extensions for unresolved macros or macros with unexpected resolutions + /// for better error recovery. fn smart_resolve_macro_path( &mut self, path: &ast::Path, kind: MacroKind, + require_inert: bool, + inner_attr: bool, parent_scope: &ParentScope<'a>, node_id: NodeId, force: bool, @@ -414,7 +405,6 @@ impl<'a> Resolver<'a> { let (ext, res) = match self.resolve_macro_path(path, Some(kind), parent_scope, true, force) { Ok((Some(ext), res)) => (ext, res), - // Use dummy syntax extensions for unresolved macros for better recovery. Ok((None, res)) => (self.dummy_ext(kind), res), Err(Determinacy::Determined) => (self.dummy_ext(kind), Res::Err), Err(Determinacy::Undetermined) => return Err(Indeterminate), @@ -451,19 +441,43 @@ impl<'a> Resolver<'a> { self.check_stability_and_deprecation(&ext, path, node_id); - Ok(if ext.macro_kind() != kind { - let expected = kind.descr_expected(); + let unexpected_res = if ext.macro_kind() != kind { + Some((kind.article(), kind.descr_expected())) + } else if require_inert && matches!(res, Res::Def(..)) { + Some(("a", "non-macro attribute")) + } else { + None + }; + if let Some((article, expected)) = unexpected_res { let path_str = pprust::path_to_string(path); let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path_str); self.session .struct_span_err(path.span, &msg) - .span_label(path.span, format!("not {} {}", kind.article(), expected)) + .span_label(path.span, format!("not {} {}", article, expected)) .emit(); - // Use dummy syntax extensions for unexpected macro kinds for better recovery. - (self.dummy_ext(kind), Res::Err) - } else { - (ext, res) - }) + return Ok((self.dummy_ext(kind), Res::Err)); + } + + // We are trying to avoid reporting this error if other related errors were reported. + if inner_attr + && !self.session.features_untracked().custom_inner_attributes + && path != &sym::test + && res != Res::Err + { + feature_err( + &self.session.parse_sess, + sym::custom_inner_attributes, + path.span, + match res { + Res::Def(..) => "inner macro attributes are unstable", + Res::NonMacroAttr(..) => "custom inner attributes are unstable", + _ => unreachable!(), + }, + ) + .emit(); + } + + Ok((ext, res)) } pub fn resolve_macro_path( @@ -568,10 +582,9 @@ impl<'a> Resolver<'a> { struct Flags: u8 { const MACRO_RULES = 1 << 0; const MODULE = 1 << 1; - const DERIVE_HELPER_COMPAT = 1 << 2; - const MISC_SUGGEST_CRATE = 1 << 3; - const MISC_SUGGEST_SELF = 1 << 4; - const MISC_FROM_PRELUDE = 1 << 5; + const MISC_SUGGEST_CRATE = 1 << 2; + const MISC_SUGGEST_SELF = 1 << 3; + const MISC_FROM_PRELUDE = 1 << 4; } } @@ -646,14 +659,11 @@ impl<'a> Resolver<'a> { ) { Ok((Some(ext), _)) => { if ext.helper_attrs.contains(&ident.name) { - let binding = ( - Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper), - ty::Visibility::Public, + result = ok( + Res::NonMacroAttr(NonMacroAttrKind::DeriveHelperCompat), derive.span, - ExpnId::root(), - ) - .to_name_binding(this.arenas); - result = Ok((binding, Flags::DERIVE_HELPER_COMPAT)); + this.arenas, + ); break; } } @@ -799,17 +809,15 @@ impl<'a> Resolver<'a> { let (res, innermost_res) = (binding.res(), innermost_binding.res()); if res != innermost_res { let builtin = Res::NonMacroAttr(NonMacroAttrKind::Builtin); - let is_derive_helper_compat = |res, flags: Flags| { - res == Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper) - && flags.contains(Flags::DERIVE_HELPER_COMPAT) - }; + let derive_helper_compat = + Res::NonMacroAttr(NonMacroAttrKind::DeriveHelperCompat); let ambiguity_error_kind = if is_import { Some(AmbiguityKind::Import) } else if innermost_res == builtin || res == builtin { Some(AmbiguityKind::BuiltinAttr) - } else if is_derive_helper_compat(innermost_res, innermost_flags) - || is_derive_helper_compat(res, flags) + } else if innermost_res == derive_helper_compat + || res == derive_helper_compat { Some(AmbiguityKind::DeriveHelper) } else if innermost_flags.contains(Flags::MACRO_RULES) diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index dead795c6afe7..df472e6ed7e9d 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -997,7 +997,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( // type. // // NOTE: This should be kept in sync with the similar code in - // `rustc_ty::instance::resolve_associated_item()`. + // `rustc_ty_utils::instance::resolve_associated_item()`. let node_item = assoc_ty_def(selcx, impl_data.impl_def_id, obligation.predicate.item_def_id) .map_err(|ErrorReported| ())?; diff --git a/compiler/rustc_ty/Cargo.toml b/compiler/rustc_ty_utils/Cargo.toml similarity index 95% rename from compiler/rustc_ty/Cargo.toml rename to compiler/rustc_ty_utils/Cargo.toml index acb011b2dc063..5020437bcf9cc 100644 --- a/compiler/rustc_ty/Cargo.toml +++ b/compiler/rustc_ty_utils/Cargo.toml @@ -1,6 +1,6 @@ [package] authors = ["The Rust Project Developers"] -name = "rustc_ty" +name = "rustc_ty_utils" version = "0.0.0" edition = "2018" diff --git a/compiler/rustc_ty/src/common_traits.rs b/compiler/rustc_ty_utils/src/common_traits.rs similarity index 100% rename from compiler/rustc_ty/src/common_traits.rs rename to compiler/rustc_ty_utils/src/common_traits.rs diff --git a/compiler/rustc_ty/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs similarity index 100% rename from compiler/rustc_ty/src/instance.rs rename to compiler/rustc_ty_utils/src/instance.rs diff --git a/compiler/rustc_ty/src/lib.rs b/compiler/rustc_ty_utils/src/lib.rs similarity index 100% rename from compiler/rustc_ty/src/lib.rs rename to compiler/rustc_ty_utils/src/lib.rs diff --git a/compiler/rustc_ty/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs similarity index 100% rename from compiler/rustc_ty/src/needs_drop.rs rename to compiler/rustc_ty_utils/src/needs_drop.rs diff --git a/compiler/rustc_ty/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs similarity index 100% rename from compiler/rustc_ty/src/ty.rs rename to compiler/rustc_ty_utils/src/ty.rs diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index cafb002c01a11..706f865b4d14f 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -69,7 +69,8 @@ impl IntoIter { /// Returns an immutable slice of all elements that have not been yielded /// yet. - fn as_slice(&self) -> &[T] { + #[unstable(feature = "array_value_iter_slice", issue = "65798")] + pub fn as_slice(&self) -> &[T] { // SAFETY: We know that all elements within `alive` are properly initialized. unsafe { let slice = self.data.get_unchecked(self.alive.clone()); @@ -78,7 +79,8 @@ impl IntoIter { } /// Returns a mutable slice of all elements that have not been yielded yet. - fn as_mut_slice(&mut self) -> &mut [T] { + #[unstable(feature = "array_value_iter_slice", issue = "65798")] + pub fn as_mut_slice(&mut self) -> &mut [T] { // SAFETY: We know that all elements within `alive` are properly initialized. unsafe { let slice = self.data.get_unchecked_mut(self.alive.clone()); diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 79ae1d5829a24..c50aa18caf69a 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -2724,6 +2724,7 @@ impl [T] { /// /// [`clone_from_slice`]: #method.clone_from_slice /// [`split_at_mut`]: #method.split_at_mut + #[doc(alias = "memcpy")] #[stable(feature = "copy_from_slice", since = "1.9.0")] pub fn copy_from_slice(&mut self, src: &[T]) where diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index d48c02bf59c64..9d2045990570b 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -47,9 +47,16 @@ //! //! * PowerPC and MIPS platforms with 32-bit pointers do not have `AtomicU64` or //! `AtomicI64` types. -//! * ARM platforms like `armv5te` that aren't for Linux do not have any atomics -//! at all. -//! * ARM targets with `thumbv6m` do not have atomic operations at all. +//! * ARM platforms like `armv5te` that aren't for Linux only provide `load` +//! and `store` operations, and do not support Compare and Swap (CAS) +//! operations, such as `swap`, `fetch_add`, etc. Additionally on Linux, +//! these CAS operations are implemented via [operating system support], which +//! may come with a performance penalty. +//! * ARM targets with `thumbv6m` only provide `load` and `store` operations, +//! and do not support Compare and Swap (CAS) operations, such as `swap`, +//! `fetch_add`, etc. +//! +//! [operating system support]: https://www.kernel.org/doc/Documentation/arm/kernel_user_helpers.txt //! //! Note that future platforms may be added that also do not have support for //! some atomic operations. Maximally portable code will want to be careful diff --git a/library/core/tests/num/i128.rs b/library/core/tests/num/i128.rs new file mode 100644 index 0000000000000..72c0b225991f6 --- /dev/null +++ b/library/core/tests/num/i128.rs @@ -0,0 +1 @@ +int_module!(i128, i128); diff --git a/library/core/tests/num/int_macros.rs b/library/core/tests/num/int_macros.rs index fcb0d6031be62..90c476567844e 100644 --- a/library/core/tests/num/int_macros.rs +++ b/library/core/tests/num/int_macros.rs @@ -131,9 +131,9 @@ macro_rules! int_module { assert_eq!(B.rotate_left(0), B); assert_eq!(C.rotate_left(0), C); // Rotating by a multiple of word size should also have no effect - assert_eq!(A.rotate_left(64), A); - assert_eq!(B.rotate_left(64), B); - assert_eq!(C.rotate_left(64), C); + assert_eq!(A.rotate_left(128), A); + assert_eq!(B.rotate_left(128), B); + assert_eq!(C.rotate_left(128), C); } #[test] diff --git a/library/core/tests/num/mod.rs b/library/core/tests/num/mod.rs index 49e5cc0eaa544..012ab4ea5c573 100644 --- a/library/core/tests/num/mod.rs +++ b/library/core/tests/num/mod.rs @@ -11,6 +11,7 @@ use core::str::FromStr; #[macro_use] mod int_macros; +mod i128; mod i16; mod i32; mod i64; @@ -19,6 +20,7 @@ mod i8; #[macro_use] mod uint_macros; +mod u128; mod u16; mod u32; mod u64; diff --git a/library/core/tests/num/u128.rs b/library/core/tests/num/u128.rs new file mode 100644 index 0000000000000..716d1836f2c0e --- /dev/null +++ b/library/core/tests/num/u128.rs @@ -0,0 +1 @@ +uint_module!(u128, u128); diff --git a/library/core/tests/num/uint_macros.rs b/library/core/tests/num/uint_macros.rs index 952ec188dc138..445f8fb350eeb 100644 --- a/library/core/tests/num/uint_macros.rs +++ b/library/core/tests/num/uint_macros.rs @@ -96,9 +96,9 @@ macro_rules! uint_module { assert_eq!(B.rotate_left(0), B); assert_eq!(C.rotate_left(0), C); // Rotating by a multiple of word size should also have no effect - assert_eq!(A.rotate_left(64), A); - assert_eq!(B.rotate_left(64), B); - assert_eq!(C.rotate_left(64), C); + assert_eq!(A.rotate_left(128), A); + assert_eq!(B.rotate_left(128), B); + assert_eq!(C.rotate_left(128), C); } #[test] diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 60808dcba6144..e087e2b8ff153 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -484,10 +484,13 @@ impl Step for CompiletestTest { let host = self.host; let compiler = builder.compiler(0, host); + // We need `ToolStd` for the locally-built sysroot because + // compiletest uses unstable features of the `test` crate. + builder.ensure(compile::Std { compiler, target: host }); let cargo = tool::prepare_tool_cargo( builder, compiler, - Mode::ToolBootstrap, + Mode::ToolStd, host, "test", "src/tools/compiletest", diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 28f7a4d316248..147a8d33765af 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1194,6 +1194,16 @@ fn write_minify( } } +fn write_srclink(cx: &Context, item: &clean::Item, buf: &mut Buffer, cache: &Cache) { + if let Some(l) = cx.src_href(item, cache) { + write!( + buf, + "[src]", + l, "goto source code" + ) + } +} + #[derive(Debug, Eq, PartialEq, Hash)] struct ItemEntry { url: String, @@ -1706,13 +1716,7 @@ fn print_item(cx: &Context, item: &clean::Item, buf: &mut Buffer, cache: &Cache) // this page, and this link will be auto-clicked. The `id` attribute is // used to find the link to auto-click. if cx.shared.include_sources && !item.is_primitive() { - if let Some(l) = cx.src_href(item, cache) { - write!( - buf, - "[src]", - l, "goto source code" - ); - } + write_srclink(cx, item, buf, cache); } write!(buf, ""); // out-of-band @@ -2624,7 +2628,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait, write!(w, "{}Loading content...", extra_content) } - fn trait_item(w: &mut Buffer, cx: &Context, m: &clean::Item, t: &clean::Item) { + fn trait_item(w: &mut Buffer, cx: &Context, m: &clean::Item, t: &clean::Item, cache: &Cache) { let name = m.name.as_ref().unwrap(); info!("Documenting {} on {}", name, t.name.as_deref().unwrap_or_default()); let item_type = m.type_(); @@ -2633,6 +2637,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait, render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl); write!(w, ""); render_stability_since(w, m, t); + write_srclink(cx, m, w, cache); write!(w, ""); document(w, cx, m, Some(t)); } @@ -2644,8 +2649,8 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait, "Associated Types", "
", ); - for t in &types { - trait_item(w, cx, *t, it); + for t in types { + trait_item(w, cx, t, it, cache); } write_loading_content(w, "
"); } @@ -2657,8 +2662,8 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait, "Associated Constants", "
", ); - for t in &consts { - trait_item(w, cx, *t, it); + for t in consts { + trait_item(w, cx, t, it, cache); } write_loading_content(w, "
"); } @@ -2671,8 +2676,8 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait, "Required methods", "
", ); - for m in &required { - trait_item(w, cx, *m, it); + for m in required { + trait_item(w, cx, m, it, cache); } write_loading_content(w, "
"); } @@ -2683,8 +2688,8 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait, "Provided methods", "
", ); - for m in &provided { - trait_item(w, cx, *m, it); + for m in provided { + trait_item(w, cx, m, it, cache); } write_loading_content(w, "
"); } @@ -3693,13 +3698,7 @@ fn render_impl( StabilityLevel::Unstable { .. } => None, }); render_stability_since_raw(w, since.as_deref(), outer_version); - if let Some(l) = cx.src_href(&i.impl_item, cache) { - write!( - w, - "[src]", - l, "goto source code" - ); - } + write_srclink(cx, &i.impl_item, w, cache); write!(w, ""); if trait_.is_some() { @@ -3765,13 +3764,7 @@ fn render_impl( render_assoc_item(w, item, link.anchor(&id), ItemType::Impl); write!(w, ""); render_stability_since_raw(w, item.stable_since().as_deref(), outer_version); - if let Some(l) = cx.src_href(item, cache) { - write!( - w, - "[src]", - l, "goto source code" - ); - } + write_srclink(cx, item, w, cache); write!(w, ""); } } @@ -3787,13 +3780,7 @@ fn render_impl( assoc_const(w, item, ty, default.as_ref(), link.anchor(&id), ""); write!(w, ""); render_stability_since_raw(w, item.stable_since().as_deref(), outer_version); - if let Some(l) = cx.src_href(item, cache) { - write!( - w, - "[src]", - l, "goto source code" - ); - } + write_srclink(cx, item, w, cache); write!(w, ""); } clean::AssocTypeItem(ref bounds, ref default) => { diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 7eccb09b07367..7d22913b99de9 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -659,7 +659,7 @@ a { text-decoration: underline; } -.invisible > .srclink, h4 > code + .srclink { +.invisible > .srclink, h4 > code + .srclink, h3 > code + .srclink { position: absolute; top: 0; right: 0; @@ -857,25 +857,25 @@ body.blur > :not(#help) { top: 0; } -.impl-items .since, .impl .since { +.impl-items .since, .impl .since, .methods .since { flex-grow: 0; padding-left: 12px; padding-right: 2px; position: initial; } -.impl-items .srclink, .impl .srclink { +.impl-items .srclink, .impl .srclink, .methods .srclink { flex-grow: 0; /* Override header settings otherwise it's too bold */ font-size: 17px; font-weight: normal; } -.impl-items code, .impl code { +.impl-items code, .impl code, .methods code { flex-grow: 1; } -.impl-items h4, h4.impl, h3.impl { +.impl-items h4, h4.impl, h3.impl, .methods h3 { display: flex; flex-basis: 100%; font-size: 16px; diff --git a/src/test/rustdoc/trait-src-link.rs b/src/test/rustdoc/trait-src-link.rs new file mode 100644 index 0000000000000..77116695690fc --- /dev/null +++ b/src/test/rustdoc/trait-src-link.rs @@ -0,0 +1,26 @@ +#![crate_name = "quix"] +pub trait Foo { + // @has quix/trait.Foo.html '//a[@href="../src/quix/trait-src-link.rs.html#4"]' '[src]' + fn required(); + + // @has quix/trait.Foo.html '//a[@href="../src/quix/trait-src-link.rs.html#7"]' '[src]' + fn provided() {} +} + +pub struct Bar; + +impl Foo for Bar { + // @has quix/struct.Bar.html '//a[@href="../src/quix/trait-src-link.rs.html#14"]' '[src]' + fn required() {} + // @has quix/struct.Bar.html '//a[@href="../src/quix/trait-src-link.rs.html#7"]' '[src]' +} + +pub struct Baz; + +impl Foo for Baz { + // @has quix/struct.Baz.html '//a[@href="../src/quix/trait-src-link.rs.html#22"]' '[src]' + fn required() {} + + // @has quix/struct.Baz.html '//a[@href="../src/quix/trait-src-link.rs.html#25"]' '[src]' + fn provided() {} +} diff --git a/src/test/ui/attrs-resolution-errors.rs b/src/test/ui/attrs-resolution-errors.rs index a38b3cfa6665e..8770fb1ded8eb 100644 --- a/src/test/ui/attrs-resolution-errors.rs +++ b/src/test/ui/attrs-resolution-errors.rs @@ -1,12 +1,12 @@ enum FooEnum { #[test] - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro Bar(i32), } struct FooStruct { #[test] - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro bar: i32, } @@ -21,20 +21,20 @@ fn main() { match foo_struct { FooStruct { #[test] bar - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro } => {} } match 1 { 0 => {} #[test] - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro _ => {} } let _another_foo_strunct = FooStruct { #[test] - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro bar: 1, }; } diff --git a/src/test/ui/attrs-resolution-errors.stderr b/src/test/ui/attrs-resolution-errors.stderr index 31f2a74edb333..883f96e5c1931 100644 --- a/src/test/ui/attrs-resolution-errors.stderr +++ b/src/test/ui/attrs-resolution-errors.stderr @@ -1,32 +1,32 @@ -error: expected an inert attribute, found an attribute macro - --> $DIR/attrs-resolution-errors.rs:2:5 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/attrs-resolution-errors.rs:2:7 | LL | #[test] - | ^^^^^^^ + | ^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/attrs-resolution-errors.rs:8:5 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/attrs-resolution-errors.rs:8:7 | LL | #[test] - | ^^^^^^^ + | ^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/attrs-resolution-errors.rs:23:13 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/attrs-resolution-errors.rs:23:15 | LL | #[test] bar - | ^^^^^^^ + | ^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/attrs-resolution-errors.rs:30:9 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/attrs-resolution-errors.rs:30:11 | LL | #[test] - | ^^^^^^^ + | ^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/attrs-resolution-errors.rs:36:9 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/attrs-resolution-errors.rs:36:11 | LL | #[test] - | ^^^^^^^ + | ^^^^ not a non-macro attribute error: aborting due to 5 previous errors diff --git a/src/test/ui/conditional-compilation/cfg_accessible-stuck.rs b/src/test/ui/conditional-compilation/cfg_accessible-stuck.rs index 8bc93fa324378..50504a44c9518 100644 --- a/src/test/ui/conditional-compilation/cfg_accessible-stuck.rs +++ b/src/test/ui/conditional-compilation/cfg_accessible-stuck.rs @@ -1,6 +1,6 @@ #![feature(cfg_accessible)] -#[cfg_accessible(Z)] //~ ERROR cannot determine whether the path is accessible or not +#[cfg_accessible(Z)] // OK, recovered after the other `cfg_accessible` produces an error. struct S; #[cfg_accessible(S)] //~ ERROR cannot determine whether the path is accessible or not diff --git a/src/test/ui/conditional-compilation/cfg_accessible-stuck.stderr b/src/test/ui/conditional-compilation/cfg_accessible-stuck.stderr index 9641441a819b0..33af7d62548ec 100644 --- a/src/test/ui/conditional-compilation/cfg_accessible-stuck.stderr +++ b/src/test/ui/conditional-compilation/cfg_accessible-stuck.stderr @@ -4,11 +4,5 @@ error: cannot determine whether the path is accessible or not LL | #[cfg_accessible(S)] | ^^^^^^^^^^^^^^^^^^^^ -error: cannot determine whether the path is accessible or not - --> $DIR/cfg_accessible-stuck.rs:3:1 - | -LL | #[cfg_accessible(Z)] - | ^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors +error: aborting due to previous error diff --git a/src/test/ui/destructuring-assignment/drop-order.rs b/src/test/ui/destructuring-assignment/drop-order.rs new file mode 100644 index 0000000000000..d06b31c7f2702 --- /dev/null +++ b/src/test/ui/destructuring-assignment/drop-order.rs @@ -0,0 +1,44 @@ +// run-pass + +//! Test that let bindings and destructuring assignments have consistent drop orders + +#![feature(destructuring_assignment)] +#![allow(unused_variables, unused_assignments)] + +use std::cell::RefCell; + +thread_local! { + static DROP_ORDER: RefCell> = RefCell::new(Vec::new()); +} + +struct DropRecorder(usize); +impl Drop for DropRecorder { + fn drop(&mut self) { + DROP_ORDER.with(|d| d.borrow_mut().push(self.0)); + } +} + +fn main() { + let expected_drop_order = vec![1, 4, 5, 3, 2]; + // Check the drop order for let bindings: + { + let _ = DropRecorder(1); + let _val = DropRecorder(2); + let (x, _) = (DropRecorder(3), DropRecorder(4)); + drop(DropRecorder(5)); + } + DROP_ORDER.with(|d| { + assert_eq!(&*d.borrow(), &expected_drop_order); + d.borrow_mut().clear(); + }); + // Check that the drop order for destructuring assignment is the same: + { + let _val; + let x; + _ = DropRecorder(1); + _val = DropRecorder(2); + (x, _) = (DropRecorder(3), DropRecorder(4)); + drop(DropRecorder(5)); + } + DROP_ORDER.with(|d| assert_eq!(&*d.borrow(), &expected_drop_order)); +} diff --git a/src/test/ui/issues/issue-36617.rs b/src/test/ui/issues/issue-36617.rs index 58f44f42524bc..1102f3c4640a1 100644 --- a/src/test/ui/issues/issue-36617.rs +++ b/src/test/ui/issues/issue-36617.rs @@ -1,5 +1,4 @@ #![derive(Copy)] //~ ERROR `derive` may only be applied to structs, enums and unions //~| ERROR cannot determine resolution for the derive macro `Copy` - //~| ERROR cannot determine resolution for the derive macro `Copy` fn main() {} diff --git a/src/test/ui/issues/issue-36617.stderr b/src/test/ui/issues/issue-36617.stderr index 586dcf2cea675..dc6ef16925913 100644 --- a/src/test/ui/issues/issue-36617.stderr +++ b/src/test/ui/issues/issue-36617.stderr @@ -12,14 +12,6 @@ LL | #![derive(Copy)] | = note: import resolution is stuck, try simplifying macro imports -error: cannot determine resolution for the derive macro `Copy` - --> $DIR/issue-36617.rs:1:11 - | -LL | #![derive(Copy)] - | ^^^^ - | - = note: import resolution is stuck, try simplifying macro imports - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0774`. diff --git a/src/test/ui/issues/issue-49934-errors.rs b/src/test/ui/issues/issue-49934-errors.rs index 6fa5f01ffd926..bf95f8fa7e1ec 100644 --- a/src/test/ui/issues/issue-49934-errors.rs +++ b/src/test/ui/issues/issue-49934-errors.rs @@ -1,10 +1,8 @@ fn foo<#[derive(Debug)] T>() { //~^ ERROR `derive` may only be applied to structs, enums and unions -//~| ERROR expected an inert attribute, found a derive macro match 0 { #[derive(Debug)] //~^ ERROR `derive` may only be applied to structs, enums and unions - //~| ERROR expected an inert attribute, found a derive macro _ => (), } } diff --git a/src/test/ui/issues/issue-49934-errors.stderr b/src/test/ui/issues/issue-49934-errors.stderr index 3befb38a20882..71cd2d3034243 100644 --- a/src/test/ui/issues/issue-49934-errors.stderr +++ b/src/test/ui/issues/issue-49934-errors.stderr @@ -4,24 +4,12 @@ error[E0774]: `derive` may only be applied to structs, enums and unions LL | fn foo<#[derive(Debug)] T>() { | ^^^^^^^^^^^^^^^^ -error: expected an inert attribute, found a derive macro - --> $DIR/issue-49934-errors.rs:1:17 - | -LL | fn foo<#[derive(Debug)] T>() { - | ^^^^^ - error[E0774]: `derive` may only be applied to structs, enums and unions - --> $DIR/issue-49934-errors.rs:5:9 + --> $DIR/issue-49934-errors.rs:4:9 | LL | #[derive(Debug)] | ^^^^^^^^^^^^^^^^ -error: expected an inert attribute, found a derive macro - --> $DIR/issue-49934-errors.rs:5:18 - | -LL | #[derive(Debug)] - | ^^^^^ - -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0774`. diff --git a/src/test/ui/issues/issue-50865-private-impl-trait/auxiliary/lib.rs b/src/test/ui/issues/issue-50865-private-impl-trait/auxiliary/lib.rs index f3a51b415faca..fb4bf2b8b44e7 100644 --- a/src/test/ui/issues/issue-50865-private-impl-trait/auxiliary/lib.rs +++ b/src/test/ui/issues/issue-50865-private-impl-trait/auxiliary/lib.rs @@ -1,3 +1,7 @@ +// revisions: default miropt +//[miropt]compile-flags: -Z mir-opt-level=2 +// ~^ This flag is for #77668, it used to be ICE. + #![crate_type = "lib"] pub fn bar

( // Error won't happen if "bar" is not generic diff --git a/src/test/ui/malformed/issue-69341-malformed-derive-inert.rs b/src/test/ui/malformed/issue-69341-malformed-derive-inert.rs index 24692f7cf52e1..1fd7cddc7c937 100644 --- a/src/test/ui/malformed/issue-69341-malformed-derive-inert.rs +++ b/src/test/ui/malformed/issue-69341-malformed-derive-inert.rs @@ -4,7 +4,6 @@ struct CLI { #[derive(parse())] //~^ ERROR traits in `#[derive(...)]` don't accept arguments //~| ERROR cannot find derive macro `parse` in this scope - //~| ERROR cannot find derive macro `parse` in this scope path: (), //~^ ERROR `derive` may only be applied to structs, enums and unions } diff --git a/src/test/ui/malformed/issue-69341-malformed-derive-inert.stderr b/src/test/ui/malformed/issue-69341-malformed-derive-inert.stderr index c4532a375a75e..db40ce0753045 100644 --- a/src/test/ui/malformed/issue-69341-malformed-derive-inert.stderr +++ b/src/test/ui/malformed/issue-69341-malformed-derive-inert.stderr @@ -5,7 +5,7 @@ LL | #[derive(parse())] | ^^ help: remove the arguments error[E0774]: `derive` may only be applied to structs, enums and unions - --> $DIR/issue-69341-malformed-derive-inert.rs:8:5 + --> $DIR/issue-69341-malformed-derive-inert.rs:7:5 | LL | path: (), | ^^^^^^^^ @@ -16,12 +16,6 @@ error: cannot find derive macro `parse` in this scope LL | #[derive(parse())] | ^^^^^ -error: cannot find derive macro `parse` in this scope - --> $DIR/issue-69341-malformed-derive-inert.rs:4:14 - | -LL | #[derive(parse())] - | ^^^^^ - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0774`. diff --git a/src/test/ui/mir/mir-inlining/ice-issue-77306-1.rs b/src/test/ui/mir/mir-inlining/ice-issue-77306-1.rs index ccb279f7fa212..4d083bf232155 100644 --- a/src/test/ui/mir/mir-inlining/ice-issue-77306-1.rs +++ b/src/test/ui/mir/mir-inlining/ice-issue-77306-1.rs @@ -1,27 +1,17 @@ -// Regression test for various issues related to normalization & inlining. -// * #68347, #77306, #77668 - missed normalization during inlining. -// * #78442 - missed normalization in validator after inlining. -// -// build-pass +// run-pass // compile-flags:-Zmir-opt-level=2 +// Previously ICEd because we did not normalize during inlining, +// see https://github.com/rust-lang/rust/pull/77306 for more discussion. + pub fn write() { create()() } -pub fn write_generic(_t: T) { - hide()(); -} - pub fn create() -> impl FnOnce() { || () } -pub fn hide() -> impl Fn() { - write -} - fn main() { write(); - write_generic(()); } diff --git a/src/test/ui/proc-macro/proc-macro-gates.rs b/src/test/ui/proc-macro/proc-macro-gates.rs index b3b677fa7ffed..4c72ecbfc03a8 100644 --- a/src/test/ui/proc-macro/proc-macro-gates.rs +++ b/src/test/ui/proc-macro/proc-macro-gates.rs @@ -7,11 +7,11 @@ extern crate test_macros; fn _test_inner() { - #![empty_attr] //~ ERROR: non-builtin inner attributes are unstable + #![empty_attr] //~ ERROR: inner macro attributes are unstable } mod _test2_inner { - #![empty_attr] //~ ERROR: non-builtin inner attributes are unstable + #![empty_attr] //~ ERROR: inner macro attributes are unstable } #[empty_attr = "y"] //~ ERROR: key-value macro attributes are not supported diff --git a/src/test/ui/proc-macro/proc-macro-gates.stderr b/src/test/ui/proc-macro/proc-macro-gates.stderr index c034349553177..33a808037eea5 100644 --- a/src/test/ui/proc-macro/proc-macro-gates.stderr +++ b/src/test/ui/proc-macro/proc-macro-gates.stderr @@ -1,17 +1,17 @@ -error[E0658]: non-builtin inner attributes are unstable - --> $DIR/proc-macro-gates.rs:10:5 +error[E0658]: inner macro attributes are unstable + --> $DIR/proc-macro-gates.rs:10:8 | LL | #![empty_attr] - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^ | = note: see issue #54726 for more information = help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable -error[E0658]: non-builtin inner attributes are unstable - --> $DIR/proc-macro-gates.rs:14:5 +error[E0658]: inner macro attributes are unstable + --> $DIR/proc-macro-gates.rs:14:8 | LL | #![empty_attr] - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^ | = note: see issue #54726 for more information = help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable diff --git a/src/test/ui/proc-macro/proc-macro-gates2.rs b/src/test/ui/proc-macro/proc-macro-gates2.rs index 2fd5efd71f041..38fbd4733d5cb 100644 --- a/src/test/ui/proc-macro/proc-macro-gates2.rs +++ b/src/test/ui/proc-macro/proc-macro-gates2.rs @@ -10,11 +10,11 @@ extern crate test_macros; // should either require a feature gate or not be allowed on stable. fn _test6<#[empty_attr] T>() {} -//~^ ERROR: expected an inert attribute, found an attribute macro +//~^ ERROR: expected non-macro attribute, found attribute macro fn _test7() { match 1 { - #[empty_attr] //~ ERROR: expected an inert attribute, found an attribute macro + #[empty_attr] //~ ERROR: expected non-macro attribute, found attribute macro 0 => {} _ => {} } diff --git a/src/test/ui/proc-macro/proc-macro-gates2.stderr b/src/test/ui/proc-macro/proc-macro-gates2.stderr index fd271da61553a..64df34e7ce390 100644 --- a/src/test/ui/proc-macro/proc-macro-gates2.stderr +++ b/src/test/ui/proc-macro/proc-macro-gates2.stderr @@ -1,14 +1,14 @@ -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-gates2.rs:12:11 +error: expected non-macro attribute, found attribute macro `empty_attr` + --> $DIR/proc-macro-gates2.rs:12:13 | LL | fn _test6<#[empty_attr] T>() {} - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-gates2.rs:17:9 +error: expected non-macro attribute, found attribute macro `empty_attr` + --> $DIR/proc-macro-gates2.rs:17:11 | LL | #[empty_attr] - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^ not a non-macro attribute error: aborting due to 2 previous errors diff --git a/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.rs b/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.rs index bf09171c9a12a..6403b3f55c40c 100644 --- a/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.rs +++ b/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.rs @@ -3,7 +3,7 @@ extern "C" { /// Foo //~^ ERROR documentation comments cannot be applied to function #[test] a: i32, - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro /// Bar //~^ ERROR documentation comments cannot be applied to function #[must_use] @@ -19,7 +19,7 @@ type FnType = fn( /// Foo //~^ ERROR documentation comments cannot be applied to function #[test] a: u32, - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro /// Bar //~^ ERROR documentation comments cannot be applied to function #[must_use] @@ -34,7 +34,7 @@ pub fn foo( /// Foo //~^ ERROR documentation comments cannot be applied to function #[test] a: u32, - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro /// Bar //~^ ERROR documentation comments cannot be applied to function #[must_use] @@ -54,7 +54,7 @@ impl SelfStruct { /// Bar //~^ ERROR documentation comments cannot be applied to function #[test] a: i32, - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro /// Baz //~^ ERROR documentation comments cannot be applied to function #[must_use] @@ -69,7 +69,7 @@ impl SelfStruct { /// Foo //~^ ERROR documentation comments cannot be applied to function #[test] a: i32, - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro /// Baz //~^ ERROR documentation comments cannot be applied to function #[must_use] @@ -90,7 +90,7 @@ impl RefStruct { /// Bar //~^ ERROR documentation comments cannot be applied to function #[test] a: i32, - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro /// Baz //~^ ERROR documentation comments cannot be applied to function #[must_use] @@ -109,7 +109,7 @@ trait RefTrait { /// Bar //~^ ERROR documentation comments cannot be applied to function #[test] a: i32, - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro /// Baz //~^ ERROR documentation comments cannot be applied to function #[must_use] @@ -124,7 +124,7 @@ trait RefTrait { /// Foo //~^ ERROR documentation comments cannot be applied to function #[test] a: i32, - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro /// Baz //~^ ERROR documentation comments cannot be applied to function #[must_use] @@ -144,7 +144,7 @@ impl RefTrait for RefStruct { /// Bar //~^ ERROR documentation comments cannot be applied to function #[test] a: i32, - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro /// Baz //~^ ERROR documentation comments cannot be applied to function #[must_use] @@ -161,7 +161,7 @@ fn main() { /// Foo //~^ ERROR documentation comments cannot be applied to function #[test] a: u32, - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro /// Bar //~^ ERROR documentation comments cannot be applied to function #[must_use] diff --git a/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr b/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr index 4d0349e8765f0..edca8cea68d72 100644 --- a/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr +++ b/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr @@ -1,62 +1,62 @@ -error: expected an inert attribute, found an attribute macro - --> $DIR/param-attrs-builtin-attrs.rs:5:9 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/param-attrs-builtin-attrs.rs:5:11 | LL | #[test] a: i32, - | ^^^^^^^ + | ^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/param-attrs-builtin-attrs.rs:21:5 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/param-attrs-builtin-attrs.rs:21:7 | LL | #[test] a: u32, - | ^^^^^^^ + | ^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/param-attrs-builtin-attrs.rs:36:5 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/param-attrs-builtin-attrs.rs:36:7 | LL | #[test] a: u32, - | ^^^^^^^ + | ^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/param-attrs-builtin-attrs.rs:56:9 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/param-attrs-builtin-attrs.rs:56:11 | LL | #[test] a: i32, - | ^^^^^^^ + | ^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/param-attrs-builtin-attrs.rs:71:9 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/param-attrs-builtin-attrs.rs:71:11 | LL | #[test] a: i32, - | ^^^^^^^ + | ^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/param-attrs-builtin-attrs.rs:92:9 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/param-attrs-builtin-attrs.rs:92:11 | LL | #[test] a: i32, - | ^^^^^^^ + | ^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/param-attrs-builtin-attrs.rs:111:9 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/param-attrs-builtin-attrs.rs:111:11 | LL | #[test] a: i32, - | ^^^^^^^ + | ^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/param-attrs-builtin-attrs.rs:126:9 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/param-attrs-builtin-attrs.rs:126:11 | LL | #[test] a: i32, - | ^^^^^^^ + | ^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/param-attrs-builtin-attrs.rs:146:9 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/param-attrs-builtin-attrs.rs:146:11 | LL | #[test] a: i32, - | ^^^^^^^ + | ^^^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/param-attrs-builtin-attrs.rs:163:9 +error: expected non-macro attribute, found attribute macro `test` + --> $DIR/param-attrs-builtin-attrs.rs:163:11 | LL | #[test] a: u32, - | ^^^^^^^ + | ^^^^ not a non-macro attribute error: documentation comments cannot be applied to function parameters --> $DIR/param-attrs-builtin-attrs.rs:3:9 diff --git a/src/test/ui/rfc-2565-param-attrs/proc-macro-cannot-be-used.rs b/src/test/ui/rfc-2565-param-attrs/proc-macro-cannot-be-used.rs index be9085d5878cb..fcfa610ec8554 100644 --- a/src/test/ui/rfc-2565-param-attrs/proc-macro-cannot-be-used.rs +++ b/src/test/ui/rfc-2565-param-attrs/proc-macro-cannot-be-used.rs @@ -8,58 +8,58 @@ use ident_mac::id; struct W(u8); extern "C" { fn ffi(#[id] arg1: i32, #[id] ...); } -//~^ ERROR expected an inert attribute, found an attribute macro -//~| ERROR expected an inert attribute, found an attribute macro +//~^ ERROR expected non-macro attribute, found attribute macro +//~| ERROR expected non-macro attribute, found attribute macro unsafe extern "C" fn cvar(arg1: i32, #[id] mut args: ...) {} -//~^ ERROR expected an inert attribute, found an attribute macro +//~^ ERROR expected non-macro attribute, found attribute macro type Alias = extern "C" fn(#[id] u8, #[id] ...); - //~^ ERROR expected an inert attribute, found an attribute macro - //~| ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro + //~| ERROR expected non-macro attribute, found attribute macro fn free(#[id] arg1: u8) { - //~^ ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro let lam = |#[id] W(x), #[id] y: usize| (); - //~^ ERROR expected an inert attribute, found an attribute macro - //~| ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro + //~| ERROR expected non-macro attribute, found attribute macro } impl W { fn inherent1(#[id] self, #[id] arg1: u8) {} - //~^ ERROR expected an inert attribute, found an attribute macro - //~| ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro + //~| ERROR expected non-macro attribute, found attribute macro fn inherent2(#[id] &self, #[id] arg1: u8) {} - //~^ ERROR expected an inert attribute, found an attribute macro - //~| ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro + //~| ERROR expected non-macro attribute, found attribute macro fn inherent3<'a>(#[id] &'a mut self, #[id] arg1: u8) {} - //~^ ERROR expected an inert attribute, found an attribute macro - //~| ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro + //~| ERROR expected non-macro attribute, found attribute macro fn inherent4<'a>(#[id] self: Box, #[id] arg1: u8) {} - //~^ ERROR expected an inert attribute, found an attribute macro - //~| ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro + //~| ERROR expected non-macro attribute, found attribute macro fn issue_64682_associated_fn<'a>(#[id] arg1: u8, #[id] arg2: u8) {} - //~^ ERROR expected an inert attribute, found an attribute macro - //~| ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro + //~| ERROR expected non-macro attribute, found attribute macro } trait A { fn trait1(#[id] self, #[id] arg1: u8); - //~^ ERROR expected an inert attribute, found an attribute macro - //~| ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro + //~| ERROR expected non-macro attribute, found attribute macro fn trait2(#[id] &self, #[id] arg1: u8); - //~^ ERROR expected an inert attribute, found an attribute macro - //~| ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro + //~| ERROR expected non-macro attribute, found attribute macro fn trait3<'a>(#[id] &'a mut self, #[id] arg1: u8); - //~^ ERROR expected an inert attribute, found an attribute macro - //~| ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro + //~| ERROR expected non-macro attribute, found attribute macro fn trait4<'a>(#[id] self: Box, #[id] arg1: u8, #[id] Vec); - //~^ ERROR expected an inert attribute, found an attribute macro - //~| ERROR expected an inert attribute, found an attribute macro - //~| ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro + //~| ERROR expected non-macro attribute, found attribute macro + //~| ERROR expected non-macro attribute, found attribute macro fn issue_64682_associated_fn<'a>(#[id] arg1: u8, #[id] arg2: u8); - //~^ ERROR expected an inert attribute, found an attribute macro - //~| ERROR expected an inert attribute, found an attribute macro + //~^ ERROR expected non-macro attribute, found attribute macro + //~| ERROR expected non-macro attribute, found attribute macro } fn main() {} diff --git a/src/test/ui/rfc-2565-param-attrs/proc-macro-cannot-be-used.stderr b/src/test/ui/rfc-2565-param-attrs/proc-macro-cannot-be-used.stderr index 1cc3c3d82281b..38c5050f3428d 100644 --- a/src/test/ui/rfc-2565-param-attrs/proc-macro-cannot-be-used.stderr +++ b/src/test/ui/rfc-2565-param-attrs/proc-macro-cannot-be-used.stderr @@ -1,176 +1,176 @@ -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:10:21 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:10:23 | LL | extern "C" { fn ffi(#[id] arg1: i32, #[id] ...); } - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:10:38 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:10:40 | LL | extern "C" { fn ffi(#[id] arg1: i32, #[id] ...); } - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:14:38 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:14:40 | LL | unsafe extern "C" fn cvar(arg1: i32, #[id] mut args: ...) {} - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:17:28 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:17:30 | LL | type Alias = extern "C" fn(#[id] u8, #[id] ...); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:17:38 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:17:40 | LL | type Alias = extern "C" fn(#[id] u8, #[id] ...); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:21:9 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:21:11 | LL | fn free(#[id] arg1: u8) { - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:23:16 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:23:18 | LL | let lam = |#[id] W(x), #[id] y: usize| (); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:23:28 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:23:30 | LL | let lam = |#[id] W(x), #[id] y: usize| (); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:29:18 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:29:20 | LL | fn inherent1(#[id] self, #[id] arg1: u8) {} - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:29:30 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:29:32 | LL | fn inherent1(#[id] self, #[id] arg1: u8) {} - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:32:18 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:32:20 | LL | fn inherent2(#[id] &self, #[id] arg1: u8) {} - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:32:31 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:32:33 | LL | fn inherent2(#[id] &self, #[id] arg1: u8) {} - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:35:22 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:35:24 | LL | fn inherent3<'a>(#[id] &'a mut self, #[id] arg1: u8) {} - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:35:42 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:35:44 | LL | fn inherent3<'a>(#[id] &'a mut self, #[id] arg1: u8) {} - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:38:22 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:38:24 | LL | fn inherent4<'a>(#[id] self: Box, #[id] arg1: u8) {} - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:38:45 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:38:47 | LL | fn inherent4<'a>(#[id] self: Box, #[id] arg1: u8) {} - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:41:38 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:41:40 | LL | fn issue_64682_associated_fn<'a>(#[id] arg1: u8, #[id] arg2: u8) {} - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:41:54 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:41:56 | LL | fn issue_64682_associated_fn<'a>(#[id] arg1: u8, #[id] arg2: u8) {} - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:47:15 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:47:17 | LL | fn trait1(#[id] self, #[id] arg1: u8); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:47:27 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:47:29 | LL | fn trait1(#[id] self, #[id] arg1: u8); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:50:15 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:50:17 | LL | fn trait2(#[id] &self, #[id] arg1: u8); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:50:28 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:50:30 | LL | fn trait2(#[id] &self, #[id] arg1: u8); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:53:19 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:53:21 | LL | fn trait3<'a>(#[id] &'a mut self, #[id] arg1: u8); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:53:39 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:53:41 | LL | fn trait3<'a>(#[id] &'a mut self, #[id] arg1: u8); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:56:19 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:56:21 | LL | fn trait4<'a>(#[id] self: Box, #[id] arg1: u8, #[id] Vec); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:56:42 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:56:44 | LL | fn trait4<'a>(#[id] self: Box, #[id] arg1: u8, #[id] Vec); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:56:58 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:56:60 | LL | fn trait4<'a>(#[id] self: Box, #[id] arg1: u8, #[id] Vec); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:60:38 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:60:40 | LL | fn issue_64682_associated_fn<'a>(#[id] arg1: u8, #[id] arg2: u8); - | ^^^^^ + | ^^ not a non-macro attribute -error: expected an inert attribute, found an attribute macro - --> $DIR/proc-macro-cannot-be-used.rs:60:54 +error: expected non-macro attribute, found attribute macro `id` + --> $DIR/proc-macro-cannot-be-used.rs:60:56 | LL | fn issue_64682_associated_fn<'a>(#[id] arg1: u8, #[id] arg2: u8); - | ^^^^^ + | ^^ not a non-macro attribute error: aborting due to 29 previous errors diff --git a/src/test/ui/span/issue-36530.rs b/src/test/ui/span/issue-36530.rs index 4776740d8de90..70e04bf7ee6e8 100644 --- a/src/test/ui/span/issue-36530.rs +++ b/src/test/ui/span/issue-36530.rs @@ -6,7 +6,7 @@ #[foo] mod foo { - #![foo] //~ ERROR non-builtin inner attributes are unstable + #![foo] //~ ERROR custom inner attributes are unstable } fn main() {} diff --git a/src/test/ui/span/issue-36530.stderr b/src/test/ui/span/issue-36530.stderr index 79b12590fc538..a998d7217a13f 100644 --- a/src/test/ui/span/issue-36530.stderr +++ b/src/test/ui/span/issue-36530.stderr @@ -1,8 +1,8 @@ -error[E0658]: non-builtin inner attributes are unstable - --> $DIR/issue-36530.rs:9:5 +error[E0658]: custom inner attributes are unstable + --> $DIR/issue-36530.rs:9:8 | LL | #![foo] - | ^^^^^^^ + | ^^^ | = note: see issue #54726 for more information = help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable diff --git a/src/test/ui/span/issue-43927-non-ADT-derive.rs b/src/test/ui/span/issue-43927-non-ADT-derive.rs index 89b8eba1e95e7..8f1599a5abcb0 100644 --- a/src/test/ui/span/issue-43927-non-ADT-derive.rs +++ b/src/test/ui/span/issue-43927-non-ADT-derive.rs @@ -5,9 +5,6 @@ //~| ERROR cannot determine resolution for the derive macro `Debug` //~| ERROR cannot determine resolution for the derive macro `PartialEq` //~| ERROR cannot determine resolution for the derive macro `Eq` -//~| ERROR cannot determine resolution for the derive macro `Debug` -//~| ERROR cannot determine resolution for the derive macro `PartialEq` -//~| ERROR cannot determine resolution for the derive macro `Eq` struct DerivedOn; fn main() {} diff --git a/src/test/ui/span/issue-43927-non-ADT-derive.stderr b/src/test/ui/span/issue-43927-non-ADT-derive.stderr index b160a4e5877d5..85beac535c965 100644 --- a/src/test/ui/span/issue-43927-non-ADT-derive.stderr +++ b/src/test/ui/span/issue-43927-non-ADT-derive.stderr @@ -28,30 +28,6 @@ LL | #![derive(Debug, PartialEq, Eq)] // should be an outer attribute! | = note: import resolution is stuck, try simplifying macro imports -error: cannot determine resolution for the derive macro `Eq` - --> $DIR/issue-43927-non-ADT-derive.rs:3:29 - | -LL | #![derive(Debug, PartialEq, Eq)] // should be an outer attribute! - | ^^ - | - = note: import resolution is stuck, try simplifying macro imports - -error: cannot determine resolution for the derive macro `PartialEq` - --> $DIR/issue-43927-non-ADT-derive.rs:3:18 - | -LL | #![derive(Debug, PartialEq, Eq)] // should be an outer attribute! - | ^^^^^^^^^ - | - = note: import resolution is stuck, try simplifying macro imports - -error: cannot determine resolution for the derive macro `Debug` - --> $DIR/issue-43927-non-ADT-derive.rs:3:11 - | -LL | #![derive(Debug, PartialEq, Eq)] // should be an outer attribute! - | ^^^^^ - | - = note: import resolution is stuck, try simplifying macro imports - -error: aborting due to 7 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0774`.