diff --git a/compiler/rustc_attr_data_structures/src/attributes.rs b/compiler/rustc_attr_data_structures/src/attributes.rs index 8fafa7af6eed7..3febd4d7aef43 100644 --- a/compiler/rustc_attr_data_structures/src/attributes.rs +++ b/compiler/rustc_attr_data_structures/src/attributes.rs @@ -142,26 +142,16 @@ impl Deprecation { /// happen. /// /// For more docs, look in [`rustc_attr`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_attr/index.html) -// FIXME(jdonszelmann): rename to AttributeKind once hir::AttributeKind is dissolved #[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable)] pub enum AttributeKind { // tidy-alphabetical-start - Allow, AllowConstFnUnstable(ThinVec), - AllowInternalUnsafe, AllowInternalUnstable(ThinVec<(Symbol, Span)>), - AutoDiff, - AutomaticallyDerived, BodyStability { stability: DefaultBodyStability, /// Span of the `#[rustc_default_body_unstable(...)]` attribute span: Span, }, - Cfg, - CfgAttr, - CfiEncoding, // FIXME(cfi_encoding) - Cold, - CollapseDebuginfo, Confusables { symbols: ThinVec, // FIXME(jdonszelmann): remove when target validation code is moved @@ -173,14 +163,6 @@ pub enum AttributeKind { span: Span, }, ConstStabilityIndirect, - ConstTrait, - Coroutine, - Coverage, - CustomMir, - DebuggerVisualizer, - DefaultLibAllocator, - Deny, - DeprecatedSafe, // FIXME(deprecated_safe) Deprecation { deprecation: Deprecation, span: Span, @@ -196,57 +178,12 @@ pub enum AttributeKind { span: Span, comment: Symbol, }, - Expect, - ExportName, - FfiConst, - FfiPure, - Forbid, - Fundamental, - Ignore, - // TODO: must contain span for clippy - Inline, - InstructionSet, // broken on stable!!! - Lang, - Link, - Linkage, - LinkName, - LinkOrdinal, - LinkSection, - MacroExport, MacroTransparency(Transparency), - MacroUse, - Marker, - MayDangle, - MustNotSuspend, - MustUse, - NeedsAllocator, - NoImplicitPrelude, - NoLink, - NoMangle, - NonExhaustive, - NoSanitize, - OmitGdbPrettyPrinterSection, // FIXME(omit_gdb_pretty_printer_section) - PanicHandler, - PatchableFunctionEntry, // FIXME(patchable_function_entry) - Path, - Pointee, // FIXME(derive_smart_pointer) - PreludeImport, - ProcMacro, - ProcMacroAttribute, - ProcMacroDerive, Repr(ThinVec<(ReprAttr, Span)>), Stability { stability: Stability, /// Span of the `#[stable(...)]` or `#[unstable(...)]` attribute span: Span, }, - Start, - TargetFeature, - ThreadLocal, - TrackCaller, - Unstable, - Used, - Warn, - WindowsSubsystem, // broken on stable!!! - // tidy-alphabetical-end + // tidy-alphabetical-end } diff --git a/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs b/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs index 23ad550e60d2c..7c1108879c9cc 100644 --- a/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs +++ b/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs @@ -1,7 +1,7 @@ use std::iter; use rustc_attr_data_structures::AttributeKind; -use rustc_span::{sym, Span, Symbol}; +use rustc_span::{Span, Symbol, sym}; use super::{CombineAttributeGroup, ConvertFn}; use crate::context::AttributeAcceptContext; diff --git a/compiler/rustc_attr_parsing/src/attributes/cfg.rs b/compiler/rustc_attr_parsing/src/attributes/cfg.rs index 19da7bc294dc3..0d6d521b40c61 100644 --- a/compiler/rustc_attr_parsing/src/attributes/cfg.rs +++ b/compiler/rustc_attr_parsing/src/attributes/cfg.rs @@ -1,4 +1,3 @@ -// TODO: convert cfg properly.... And learn how cfg works I guess use rustc_ast::{LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, NodeId}; use rustc_ast_pretty::pprust; use rustc_attr_data_structures::RustcVersion; diff --git a/compiler/rustc_attr_parsing/src/attributes/confusables.rs b/compiler/rustc_attr_parsing/src/attributes/confusables.rs index e59759df3600e..6236e13cc6a87 100644 --- a/compiler/rustc_attr_parsing/src/attributes/confusables.rs +++ b/compiler/rustc_attr_parsing/src/attributes/confusables.rs @@ -1,4 +1,3 @@ - use rustc_attr_data_structures::AttributeKind; use rustc_span::{Span, Symbol, sym}; use thin_vec::ThinVec; @@ -17,7 +16,7 @@ pub(crate) struct ConfusablesGroup { impl AttributeGroup for ConfusablesGroup { const ATTRIBUTES: AttributeMapping = &[(&[sym::rustc_confusables], |this, cx, args| { let Some(list) = args.list() else { - // TODO: error when not a list? Bring validation code here. + // FIXME(jdonszelmann): error when not a list? Bring validation code here. // NOTE: currently subsequent attributes are silently ignored using // tcx.get_attr(). return; diff --git a/compiler/rustc_attr_parsing/src/attributes/deprecation.rs b/compiler/rustc_attr_parsing/src/attributes/deprecation.rs index c7f9d7d32c044..eecfbfaacb79d 100644 --- a/compiler/rustc_attr_parsing/src/attributes/deprecation.rs +++ b/compiler/rustc_attr_parsing/src/attributes/deprecation.rs @@ -41,10 +41,7 @@ fn get( } } else { // FIXME(jdonszelmann): suggestion? - cx.emit_err(session_diagnostics::IncorrectMetaItem { - span: param_span, - suggestion: None, - }); + cx.emit_err(session_diagnostics::IncorrectMetaItem { span: param_span, suggestion: None }); false } } diff --git a/compiler/rustc_attr_parsing/src/attributes/mod.rs b/compiler/rustc_attr_parsing/src/attributes/mod.rs index 15dd651907091..a71d0344598e2 100644 --- a/compiler/rustc_attr_parsing/src/attributes/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/mod.rs @@ -141,11 +141,6 @@ impl AttributeGroup for Combine { &[(T::PATH, |group: &mut Combine, cx, args| group.1.extend(T::extend(cx, args)))]; fn finalize(self, _cx: &AttributeGroupContext<'_>) -> Option { - if self.1.is_empty() { - None - } else { - // TODO: what filter here? - Some(T::CONVERT(self.1)) - } + if self.1.is_empty() { None } else { Some(T::CONVERT(self.1)) } } } diff --git a/compiler/rustc_attr_parsing/src/attributes/repr.rs b/compiler/rustc_attr_parsing/src/attributes/repr.rs index 828ed240b141f..cca8cb04802c3 100644 --- a/compiler/rustc_attr_parsing/src/attributes/repr.rs +++ b/compiler/rustc_attr_parsing/src/attributes/repr.rs @@ -41,9 +41,7 @@ impl CombineAttributeGroup for ReprGroup { for param in list.mixed() { if let Some(_) = param.lit() { - cx.emit_err(session_diagnostics::ReprIdent { - span: cx.attr_span, - }); + cx.emit_err(session_diagnostics::ReprIdent { span: cx.attr_span }); continue; } @@ -57,22 +55,21 @@ impl CombineAttributeGroup for ReprGroup { macro_rules! int_pat { () => { - sym::i8 - | sym::u8 - | sym::i16 - | sym::u16 - | sym::i32 - | sym::u32 - | sym::i64 - | sym::u64 - | sym::i128 - | sym::u128 - | sym::isize - | sym::usize + sym::i8 + | sym::u8 + | sym::i16 + | sym::u16 + | sym::i32 + | sym::u32 + | sym::i64 + | sym::u64 + | sym::i128 + | sym::u128 + | sym::isize + | sym::usize }; } -// TODO: inline fn int_type_of_word(s: Symbol) -> Option { use IntType::*; @@ -93,10 +90,7 @@ fn int_type_of_word(s: Symbol) -> Option { } } -fn parse_repr( - cx: &AttributeAcceptContext<'_>, - param: &MetaItemParser<'_>, -) -> Option { +fn parse_repr(cx: &AttributeAcceptContext<'_>, param: &MetaItemParser<'_>) -> Option { use ReprAttr::*; // FIXME(jdonszelmann): invert the parsing here to match on the word first and then the @@ -104,16 +98,18 @@ fn parse_repr( let (ident, args) = param.word_or_empty(); match (ident.name, args) { - (sym::align, ArgParser::NoArgs) => { + (sym::align, ArgParser::NoArgs) => { cx.emit_err(session_diagnostics::InvalidReprAlignNeedArg { span: ident.span }); None } (sym::align, ArgParser::List(l)) => parse_repr_align(cx, l, param.span(), AlignKind::Align), (sym::packed, ArgParser::NoArgs) => Some(ReprPacked(Align::ONE)), - (sym::packed, ArgParser::List(l)) => parse_repr_align(cx, l, param.span(), AlignKind::Packed), + (sym::packed, ArgParser::List(l)) => { + parse_repr_align(cx, l, param.span(), AlignKind::Packed) + } - (sym::align | sym::packed, ArgParser::NameValue(l)) => { + (sym::align | sym::packed, ArgParser::NameValue(l)) => { cx.emit_err(session_diagnostics::IncorrectReprFormatGeneric { span: param.span(), // FIXME(jdonszelmann) can just be a string in the diag type @@ -127,24 +123,19 @@ fn parse_repr( None } - (sym::Rust, ArgParser::NoArgs) => { - Some(ReprRust) - } - (sym::C, ArgParser::NoArgs) => { - Some(ReprC) - } - (sym::simd, ArgParser::NoArgs) => { - Some(ReprSimd) - } - (sym::transparent, ArgParser::NoArgs) => { - Some(ReprTransparent) - } - (i@int_pat!(), ArgParser::NoArgs) => { + (sym::Rust, ArgParser::NoArgs) => Some(ReprRust), + (sym::C, ArgParser::NoArgs) => Some(ReprC), + (sym::simd, ArgParser::NoArgs) => Some(ReprSimd), + (sym::transparent, ArgParser::NoArgs) => Some(ReprTransparent), + (i @ int_pat!(), ArgParser::NoArgs) => { // int_pat!() should make sure it always parses Some(ReprInt(int_type_of_word(i).unwrap())) } - (sym::Rust | sym::C | sym::simd | sym::transparent | int_pat!(), ArgParser::NameValue(_)) => { + ( + sym::Rust | sym::C | sym::simd | sym::transparent | int_pat!(), + ArgParser::NameValue(_), + ) => { cx.emit_err(session_diagnostics::InvalidReprHintNoValue { span: param.span(), name: ident.to_string(), @@ -168,10 +159,15 @@ fn parse_repr( enum AlignKind { Packed, - Align + Align, } -fn parse_repr_align(cx: &AttributeAcceptContext<'_>, list: &MetaItemListParser<'_>, param_span: Span, align_kind: AlignKind) -> Option { +fn parse_repr_align( + cx: &AttributeAcceptContext<'_>, + list: &MetaItemListParser<'_>, + param_span: Span, + align_kind: AlignKind, +) -> Option { use AlignKind::*; let Some(align) = list.single() else { @@ -180,14 +176,15 @@ fn parse_repr_align(cx: &AttributeAcceptContext<'_>, list: &MetaItemListParser<' cx.emit_err(session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg { span: param_span, }); - }, + } Align => { - cx.dcx() - .emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg { span: param_span }); + cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg { + span: param_span, + }); } } - return None + return None; }; let Some(lit) = align.lit() else { @@ -196,7 +193,7 @@ fn parse_repr_align(cx: &AttributeAcceptContext<'_>, list: &MetaItemListParser<' cx.emit_err(session_diagnostics::IncorrectReprFormatPackedExpectInteger { span: align.span(), }); - }, + } Align => { cx.emit_err(session_diagnostics::IncorrectReprFormatExpectInteger { span: align.span(), @@ -204,7 +201,7 @@ fn parse_repr_align(cx: &AttributeAcceptContext<'_>, list: &MetaItemListParser<' } } - return None + return None; }; match parse_alignment(&lit.kind) { diff --git a/compiler/rustc_attr_parsing/src/attributes/stability.rs b/compiler/rustc_attr_parsing/src/attributes/stability.rs index c5165200cfd10..656542a2d752e 100644 --- a/compiler/rustc_attr_parsing/src/attributes/stability.rs +++ b/compiler/rustc_attr_parsing/src/attributes/stability.rs @@ -1,7 +1,8 @@ use std::num::NonZero; use rustc_attr_data_structures::{ - AllowedThroughUnstableModules, AttributeKind, DefaultBodyStability, PartialConstStability, Stability, StabilityLevel, StableSince, UnstableReason, VERSION_PLACEHOLDER + AllowedThroughUnstableModules, AttributeKind, DefaultBodyStability, PartialConstStability, + Stability, StabilityLevel, StableSince, UnstableReason, VERSION_PLACEHOLDER, }; use rustc_span::{ErrorGuaranteed, Span, Symbol, sym}; @@ -16,7 +17,7 @@ macro_rules! reject_outside_std { // Emit errors for non-staged-api crates. if !$cx.features().staged_api() { $cx.emit_err(session_diagnostics::StabilityOutsideStd { span: $cx.attr_span }); - return + return; } }; } @@ -59,16 +60,24 @@ impl AttributeGroup for StabilityGroup { }), (&[sym::rustc_allowed_through_unstable_modules], |this, cx, args| { reject_outside_std!(cx); - this.allowed_through_unstable_modules = Some(match args.name_value().and_then(|i| i.value_as_str()) { - Some(msg) => AllowedThroughUnstableModules::WithDeprecation(msg), - None => AllowedThroughUnstableModules::WithoutDeprecation, - }); + this.allowed_through_unstable_modules = + Some(match args.name_value().and_then(|i| i.value_as_str()) { + Some(msg) => AllowedThroughUnstableModules::WithDeprecation(msg), + None => AllowedThroughUnstableModules::WithoutDeprecation, + }); }), ]; fn finalize(mut self, cx: &AttributeGroupContext<'_>) -> Option { if let Some(atum) = self.allowed_through_unstable_modules { - if let Some((Stability{level: StabilityLevel::Stable { ref mut allowed_through_unstable_modules, .. }, ..}, _)) = self.stability { + if let Some(( + Stability { + level: StabilityLevel::Stable { ref mut allowed_through_unstable_modules, .. }, + .. + }, + _, + )) = self.stability + { *allowed_through_unstable_modules = Some(atum); } else { cx.dcx().emit_err(session_diagnostics::RustcAllowedUnstablePairing { @@ -358,8 +367,8 @@ pub(crate) fn parse_unstability( None => Err(cx.emit_err(session_diagnostics::MissingFeature { span: cx.attr_span })), }; - let issue = issue - .ok_or_else(|| cx.emit_err(session_diagnostics::MissingIssue { span: cx.attr_span })); + let issue = + issue.ok_or_else(|| cx.emit_err(session_diagnostics::MissingIssue { span: cx.attr_span })); match (feature, issue) { (Ok(feature), Ok(_)) => { diff --git a/compiler/rustc_attr_parsing/src/attributes/transparency.rs b/compiler/rustc_attr_parsing/src/attributes/transparency.rs index b9f891f7b12e8..b0f843d2b2033 100644 --- a/compiler/rustc_attr_parsing/src/attributes/transparency.rs +++ b/compiler/rustc_attr_parsing/src/attributes/transparency.rs @@ -7,7 +7,7 @@ use crate::parser::ArgParser; pub(crate) struct TransparencyGroup; -// TODO: fix this but I don't want to rn +// FIXME(jdonszelmann): make these proper diagnostics #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] impl SingleAttributeGroup for TransparencyGroup { diff --git a/compiler/rustc_attr_parsing/src/attributes/util.rs b/compiler/rustc_attr_parsing/src/attributes/util.rs index 6b257c0425e1c..05a9029c59aa5 100644 --- a/compiler/rustc_attr_parsing/src/attributes/util.rs +++ b/compiler/rustc_attr_parsing/src/attributes/util.rs @@ -19,7 +19,6 @@ pub fn parse_version(s: Symbol) -> Option { Some(RustcVersion { major, minor, patch }) } -// TODO: create single word attribute map pub fn is_builtin_attr(attr: &impl AttributeExt) -> bool { attr.is_doc_comment() || attr.ident().is_some_and(|ident| is_builtin_attr_name(ident.name)) } diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index a5abd3cb45d76..e1d8bf3f86eb2 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -10,7 +10,7 @@ use rustc_feature::Features; use rustc_hir::{AttrArgs, AttrItem, AttrPath, Attribute, HashIgnoredAttrId}; use rustc_session::Session; use rustc_span::symbol::kw; -use rustc_span::{sym, ErrorGuaranteed, Span, Symbol, DUMMY_SP}; +use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym}; use crate::attributes::allow_unstable::{AllowConstFnUnstableGroup, AllowInternalUnstableGroup}; use crate::attributes::confusables::ConfusablesGroup; @@ -98,7 +98,8 @@ impl<'a> AttributeAcceptContext<'a> { if !self.limit_diagnostics { self.dcx().emit_err(diag) } else { - self.dcx().span_delayed_bug(self.attr_span, "diagnostic limited during attribute parsing") + self.dcx() + .span_delayed_bug(self.attr_span, "diagnostic limited during attribute parsing") } } } @@ -172,8 +173,14 @@ impl<'sess> AttributeParseContext<'sess> { target_span: Span, limit_diagnostics: bool, ) -> Option { - let mut parsed = Self { sess, features: None, tools: Vec::new(), parse_only: Some(sym), limit_diagnostics } - .parse_attribute_list(attrs, target_span, OmitDoc::Skip); + let mut parsed = Self { + sess, + features: None, + tools: Vec::new(), + parse_only: Some(sym), + limit_diagnostics, + } + .parse_attribute_list(attrs, target_span, OmitDoc::Skip); assert!(parsed.len() <= 1); diff --git a/compiler/rustc_attr_parsing/src/parser.rs b/compiler/rustc_attr_parsing/src/parser.rs index aec26842f9ecc..3941099d756ef 100644 --- a/compiler/rustc_attr_parsing/src/parser.rs +++ b/compiler/rustc_attr_parsing/src/parser.rs @@ -9,7 +9,7 @@ use rustc_ast_pretty::pprust; use rustc_errors::DiagCtxtHandle; use rustc_hir::{self as hir, AttrPath}; use rustc_span::symbol::{Ident, kw}; -use rustc_span::{ErrorGuaranteed, Span, Symbol, DUMMY_SP}; +use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol}; pub(crate) struct SegmentIterator<'a> { offset: usize, @@ -115,11 +115,13 @@ impl<'a> ArgParser<'a> { pub(crate) fn from_attr_args(value: &'a AttrArgs, dcx: DiagCtxtHandle<'a>) -> Self { match value { AttrArgs::Empty => Self::NoArgs, - AttrArgs::Delimited(args) if args.delim == Delimiter::Parenthesis => Self::List(MetaItemListParser::new(args, dcx)), + AttrArgs::Delimited(args) if args.delim == Delimiter::Parenthesis => { + Self::List(MetaItemListParser::new(args, dcx)) + } AttrArgs::Delimited(args) => { Self::List(MetaItemListParser { sub_parsers: vec![], span: args.dspan.entire() }) - }, - AttrArgs::Eq { eq_span, expr } => Self::NameValue( NameValueParser { + } + AttrArgs::Eq { eq_span, expr } => Self::NameValue(NameValueParser { eq_span: *eq_span, value: expr_to_lit(dcx, &expr), value_span: expr.span, @@ -135,7 +137,7 @@ impl<'a> ArgParser<'a> { /// - `#[rustfmt::skip::macros(target_macro_name)]`: `(target_macro_name)` is a list pub(crate) fn list(&self) -> Option<&MetaItemListParser<'a>> { match self { - Self::List(l) => Some(l), + Self::List(l) => Some(l), Self::NameValue(_) | Self::NoArgs => None, } } @@ -170,7 +172,7 @@ impl<'a> ArgParser<'a> { pub(crate) enum MetaItemOrLitParser<'a> { MetaItemParser(MetaItemParser<'a>), Lit(MetaItemLit), - Err(Span, ErrorGuaranteed) + Err(Span, ErrorGuaranteed), } impl<'a> MetaItemOrLitParser<'a> { @@ -428,9 +430,12 @@ impl<'a> MetaItemListParserContext<'a> { Some(x) => { // malformed attributes can get here. We can't crash, but somewhere else should've // already warned for this. - self.dcx.span_delayed_bug(x.span(), format!("unexpected token {x:?} in built-in attribute path")); + self.dcx.span_delayed_bug( + x.span(), + format!("unexpected token {x:?} in built-in attribute path"), + ); None - }, + } None => None, } } @@ -444,11 +449,9 @@ impl<'a> MetaItemListParserContext<'a> { } .value() } - Some(TokenTree::Token(ref token, _)) => if let Some(s) = MetaItemLit::from_token(token) { - Some(s) - } else { - None - }, + Some(TokenTree::Token(ref token, _)) => { + if let Some(s) = MetaItemLit::from_token(token) { Some(s) } else { None } + } x => unreachable!("{x:?}"), } } @@ -474,41 +477,46 @@ impl<'a> MetaItemListParserContext<'a> { } // or a path. - let path = if let Some(TokenTree::Token(Token { kind: token::Interpolated(nt), span, .. }, _)) = self.inside_delimiters.peek() - { - match &**nt { - // or maybe a full nt meta including the path but we return immediately - token::Nonterminal::NtMeta(item) => { - self.inside_delimiters.next(); + let path = + if let Some(TokenTree::Token(Token { kind: token::Interpolated(nt), span, .. }, _)) = + self.inside_delimiters.peek() + { + match &**nt { + // or maybe a full nt meta including the path but we return immediately + token::Nonterminal::NtMeta(item) => { + self.inside_delimiters.next(); - return Some(MetaItemOrLitParser::MetaItemParser(MetaItemParser { - path: PathParser::Ast(&item.path), - args: ArgParser::from_attr_args(&item.args, self.dcx), - dcx: self.dcx, - })) - } - // an already interpolated path from a macro expansion is a path, no need to parse - // one from tokens - token::Nonterminal::NtPath(path) => { - self.inside_delimiters.next(); + return Some(MetaItemOrLitParser::MetaItemParser(MetaItemParser { + path: PathParser::Ast(&item.path), + args: ArgParser::from_attr_args(&item.args, self.dcx), + dcx: self.dcx, + })); + } + // an already interpolated path from a macro expansion is a path, no need to parse + // one from tokens + token::Nonterminal::NtPath(path) => { + self.inside_delimiters.next(); - AttrPath::from_ast(path) - } - _ => { - self.inside_delimiters.next(); - // we go into this path if an expr ended up in an attribute that - // expansion did not turn into a literal. Say, `#[repr(align(macro!()))]` - // where the macro didn't expand to a literal. An error is already given - // for this at this point, and then we do continue. This makes this path - // reachable... - let e = self.dcx.span_delayed_bug(*span, "expr in place where literal is expected (builtin attr parsing)"); - - return Some(MetaItemOrLitParser::Err(*span, e)) + AttrPath::from_ast(path) + } + _ => { + self.inside_delimiters.next(); + // we go into this path if an expr ended up in an attribute that + // expansion did not turn into a literal. Say, `#[repr(align(macro!()))]` + // where the macro didn't expand to a literal. An error is already given + // for this at this point, and then we do continue. This makes this path + // reachable... + let e = self.dcx.span_delayed_bug( + *span, + "expr in place where literal is expected (builtin attr parsing)", + ); + + return Some(MetaItemOrLitParser::Err(*span, e)); + } } - } - } else { - self.next_path()? - }; + } else { + self.next_path()? + }; // Paths can be followed by: // - `(more meta items)` (another list) @@ -520,25 +528,37 @@ impl<'a> MetaItemListParserContext<'a> { MetaItemParser { path: PathParser::Attr(path), - args: ArgParser::List(MetaItemListParser::new_tts(inner_tokens.iter(), dspan.entire(), self.dcx)), + args: ArgParser::List(MetaItemListParser::new_tts( + inner_tokens.iter(), + dspan.entire(), + self.dcx, + )), dcx: self.dcx, } } Some(TokenTree::Delimited(span, ..)) => { self.inside_delimiters.next(); self.dcx.span_delayed_bug(span.entire(), "wrong delimiters"); - return None + return None; } Some(TokenTree::Token(Token { kind: token::Eq, span }, _)) => { self.inside_delimiters.next(); let value = self.value()?; MetaItemParser { path: PathParser::Attr(path), - args: ArgParser::NameValue(NameValueParser { eq_span: *span, value_span: value.span, value }), + args: ArgParser::NameValue(NameValueParser { + eq_span: *span, + value_span: value.span, + value, + }), dcx: self.dcx, } } - _ => MetaItemParser { path: PathParser::Attr(path), args: ArgParser::NoArgs, dcx: self.dcx }, + _ => MetaItemParser { + path: PathParser::Attr(path), + args: ArgParser::NoArgs, + dcx: self.dcx, + }, })) } @@ -555,9 +575,7 @@ impl<'a> MetaItemListParserContext<'a> { None | Some(TokenTree::Token(Token { kind: token::Comma, .. }, _)) => { self.inside_delimiters.next(); } - Some(_) => { - - } + Some(_) => {} } } @@ -577,11 +595,7 @@ impl<'a> MetaItemListParser<'a> { } fn new_tts(tts: TokenStreamIter<'a>, span: Span, dcx: DiagCtxtHandle<'a>) -> Self { - MetaItemListParserContext { - inside_delimiters: tts.peekable(), - dcx, - } - .parse(span) + MetaItemListParserContext { inside_delimiters: tts.peekable(), dcx }.parse(span) } /// Lets you pick and choose as what you want to parse each element in the list diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 05033da0ff074..4ce66cd1ae267 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -852,7 +852,8 @@ impl SyntaxExtension { .unwrap_or_default(); // FIXME(jdonszelman): allow_internal_unsafe isn't yet new-style // let allow_internal_unsafe = find_attr!(attrs, AttributeKind::AllowInternalUnsafe); - let allow_internal_unsafe = ast::attr::find_by_name(attrs, sym::allow_internal_unsafe).is_some(); + let allow_internal_unsafe = + ast::attr::find_by_name(attrs, sym::allow_internal_unsafe).is_some(); let local_inner_macros = ast::attr::find_by_name(attrs, sym::macro_export) .and_then(|macro_export| macro_export.meta_item_list()) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 5aa390e90c71f..4cff3dc5ba936 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -6,7 +6,8 @@ use rustc_ast::attr::AttributeExt; use rustc_ast::token::CommentKind; use rustc_ast::util::parser::{AssocOp, ExprPrecedence}; use rustc_ast::{ - self as ast, FloatTy, InlineAsmOptions, InlineAsmTemplatePiece, IntTy, Label, LitIntType, LitKind, TraitObjectSyntax, UintTy, UnsafeBinderCastKind + self as ast, FloatTy, InlineAsmOptions, InlineAsmTemplatePiece, IntTy, Label, LitIntType, + LitKind, TraitObjectSyntax, UintTy, UnsafeBinderCastKind, }; pub use rustc_ast::{ AttrId, AttrStyle, BinOp, BinOpKind, BindingMode, BorrowKind, BoundConstness, BoundPolarity, diff --git a/compiler/rustc_lint/src/expect.rs b/compiler/rustc_lint/src/expect.rs index f9e5192466af2..c0cfe15b972cd 100644 --- a/compiler/rustc_lint/src/expect.rs +++ b/compiler/rustc_lint/src/expect.rs @@ -40,10 +40,6 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option) { // We are an `eval_always` query, so looking at the attribute's `AttrId` is ok. let attr_id = tcx.hir().attrs(hir_id)[attr_index as usize].id(); - // TODO: we're only dealling with allow/deny/etc lint attributes. They can have an - // ID, while other attributes don't necessarily. however, how do we assert that - // nicely? - // let attr_id = todo!(); (attr_id, lint_index) } _ => panic!("fulfilled expectations must have a lint index"), diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 154e2611c3f55..b52b6f25dc056 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1538,7 +1538,10 @@ impl<'tcx> TyCtxt<'tcx> { max_align = max_align.max(Some(align)); ReprFlags::empty() } - attr::ReprEmpty => { /* skip these, they're just for diagnostics */ ReprFlags::empty() } + attr::ReprEmpty => { + /* skip these, they're just for diagnostics */ + ReprFlags::empty() + } }); } } @@ -1764,8 +1767,6 @@ impl<'tcx> TyCtxt<'tcx> { if let Some(did) = did.as_local() { self.hir().attrs(self.local_def_id_to_hir_id(did)).iter() } else { - // TODO: commented this check because we don't have the attr symbol from get_attrs here - // debug_assert!(rustc_feature::encode_cross_crate(attr)); self.attrs_for_def(did).iter() } } diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 9df9c05bafc6c..cf4bf87158514 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -117,19 +117,22 @@ impl<'tcx> CheckAttrVisitor<'tcx> { let mut seen = FxHashMap::default(); let attrs = self.tcx.hir().attrs(hir_id); for attr in attrs { - match attr { + match attr { Attribute::Parsed(AttributeKind::Confusables { first_span, .. }) => { self.check_confusables(*first_span, target); } Attribute::Parsed( AttributeKind::Stability { span, .. } - | AttributeKind::ConstStability { span, .. } - ) => { - self.check_stability_promotable(*span, target) - } - Attribute::Parsed(AttributeKind::AllowInternalUnstable(syms)) => { - self.check_allow_internal_unstable(hir_id, syms.first().unwrap().1, span, target, attrs) - } + | AttributeKind::ConstStability { span, .. }, + ) => self.check_stability_promotable(*span, target), + Attribute::Parsed(AttributeKind::AllowInternalUnstable(syms)) => self + .check_allow_internal_unstable( + hir_id, + syms.first().unwrap().1, + span, + target, + attrs, + ), _ => { match attr.path().as_slice() { [sym::diagnostic, sym::do_not_recommend, ..] => { @@ -357,9 +360,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } fn inline_attr_str_error_without_macro_def(&self, hir_id: HirId, attr_span: Span, sym: &str) { - self.tcx.emit_node_span_lint(UNUSED_ATTRIBUTES, hir_id, attr_span, errors::IgnoredAttr { - sym, - }); + self.tcx + .emit_node_span_lint(UNUSED_ATTRIBUTES, hir_id, attr_span, errors::IgnoredAttr { sym }); } /// Checks if `#[diagnostic::do_not_recommend]` is applied on a trait impl. @@ -1932,7 +1934,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { self.check_align_value(*align, *repr_span); } ReprAttr::ReprPacked(_) => { - // TODO: shouldn't we check the align here too? if target != Target::Struct && target != Target::Union { self.dcx().emit_err(errors::AttrApplication::StructUnion { hint_span: *repr_span, @@ -1978,7 +1979,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } // FIXME(jdonszelmann): move the diagnostic for unused repr attrs here, I think // it's a better place for it. - ReprAttr::ReprEmpty => { /* skip these, they're just for (other) diagnostics */ continue; } + ReprAttr::ReprEmpty => { + /* skip these, they're just for (other) diagnostics */ + continue; + } }; } @@ -2115,9 +2119,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { _ => {} } - self.tcx - .dcx() - .emit_err(errors::AllowInternalUnstable { attr_span, span }); + self.tcx.dcx().emit_err(errors::AllowInternalUnstable { attr_span, span }); } /// Checks if the items on the `#[debugger_visualizer]` attribute are valid. @@ -2275,10 +2277,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::Repr(reprs) => { for (r, span) in reprs { if let ReprAttr::ReprEmpty = r { - self.tcx.emit_node_span_lint(UNUSED_ATTRIBUTES, hir_id, *span, errors::Unused { - attr_span: *span, - note: errors::UnusedNote::EmptyList { name: sym::repr }, - }); + self.tcx.emit_node_span_lint( + UNUSED_ATTRIBUTES, + hir_id, + *span, + errors::Unused { + attr_span: *span, + note: errors::UnusedNote::EmptyList { name: sym::repr }, + }, + ); } } return; @@ -2288,19 +2295,17 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } // Warn on useless empty attributes. - let note = if ( - matches!( - attr.name_or_empty(), - sym::macro_use - | sym::allow - | sym::expect - | sym::warn - | sym::deny - | sym::forbid - | sym::feature - | sym::target_feature - ) - && attr.meta_item_list().is_some_and(|list| list.is_empty())) + let note = if (matches!( + attr.name_or_empty(), + sym::macro_use + | sym::allow + | sym::expect + | sym::warn + | sym::deny + | sym::forbid + | sym::feature + | sym::target_feature + ) && attr.meta_item_list().is_some_and(|list| list.is_empty())) { errors::UnusedNote::EmptyList { name: attr.name_or_empty() } } else if matches!( @@ -2646,7 +2651,9 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) { for attr in attrs { // FIXME(jdonszelmann): all attrs should be combined here cleaning this up some day. - let (span, name) = if let Some(a) = ATTRS_TO_CHECK.iter().find(|attr_to_check| attr.has_name(**attr_to_check)) { + let (span, name) = if let Some(a) = + ATTRS_TO_CHECK.iter().find(|attr_to_check| attr.has_name(**attr_to_check)) + { (attr.span(), *a) } else if let Attribute::Parsed(AttributeKind::Repr(r)) = attr { (r.first().unwrap().1, sym::repr) @@ -2671,11 +2678,7 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) { .span_to_snippet(span) .ok() .filter(|src| src.starts_with("#![")) - .map(|_| { - span - .with_lo(span.lo() + BytePos(1)) - .with_hi(span.lo() + BytePos(2)) - }), + .map(|_| span.with_lo(span.lo() + BytePos(1)).with_hi(span.lo() + BytePos(2))), name, item, }); diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index f40ec804a8602..476157294d0eb 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -1868,7 +1868,7 @@ pub(crate) struct NoSanitize<'a> { pub attr_str: &'a str, } -// TODO: move back to rustc_attr +// FIXME(jdonszelmann): move back to rustc_attr #[derive(Diagnostic)] #[diag(passes_rustc_const_stable_indirect_pairing)] pub(crate) struct RustcConstStableIndirectPairing { diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 4e67fac36c433..026e82aebdd10 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -5,8 +5,9 @@ use std::mem::replace; use std::num::NonZero; use rustc_attr_parsing::{ - self as attr, AttributeKind, ConstStability, DeprecatedSince, PartialConstStability, Stability, - StabilityLevel, StableSince, UnstableReason, VERSION_PLACEHOLDER, find_attr, AllowedThroughUnstableModules + self as attr, AllowedThroughUnstableModules, AttributeKind, ConstStability, DeprecatedSince, + PartialConstStability, Stability, StabilityLevel, StableSince, UnstableReason, + VERSION_PLACEHOLDER, find_attr, }; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::unord::{ExtendUnord, UnordMap, UnordSet}; @@ -186,7 +187,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { } if let Some(body_stab) = body_stab { - // TODO: check that this item can have body stability + // FIXME: check that this item can have body stability self.index.default_body_stab_map.insert(def_id, body_stab); debug!(?self.index.default_body_stab_map); @@ -800,8 +801,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { let features = self.tcx.features(); if features.staged_api() { let attrs = self.tcx.hir().attrs(item.hir_id()); - // TODO: check with https://github.com/rust-lang/rust/commit/e96808162ad7ff5906d7b58d32a25abe139e998c#diff-5f57ad10e1bdde3d046b258d390fd2ecc6f1511158aa130cebb72093da16ef29 - let stab = attr::find_attr!(attrs, AttributeKind::Stability{stability, span} => (*stability, *span)); // FIXME(jdonszelmann): make it impossible to miss the or_else in the typesystem