From 7afba2977d0d8a2a2148cbdc244a86258bb5d328 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Tue, 9 Dec 2025 09:49:50 +0100 Subject: [PATCH 1/4] Make attr path symbols rather than idents --- compiler/rustc_ast/src/attr/mod.rs | 42 +++++++++---------- compiler/rustc_ast_passes/src/feature_gate.rs | 2 +- .../rustc_attr_parsing/src/attributes/cfg.rs | 8 +--- .../src/attributes/cfg_select.rs | 7 +--- .../rustc_attr_parsing/src/attributes/util.rs | 3 +- compiler/rustc_attr_parsing/src/parser.rs | 2 +- compiler/rustc_attr_parsing/src/safety.rs | 2 +- .../rustc_attr_parsing/src/target_checking.rs | 2 +- .../rustc_attr_parsing/src/validate_attr.rs | 2 +- compiler/rustc_builtin_macros/src/cfg.rs | 4 +- compiler/rustc_builtin_macros/src/cfg_eval.rs | 5 +-- .../rustc_codegen_ssa/src/codegen_attrs.rs | 4 +- compiler/rustc_expand/src/expand.rs | 4 +- compiler/rustc_hir/src/hir.rs | 33 ++++++++------- compiler/rustc_hir_pretty/src/lib.rs | 8 +++- .../rustc_parse/src/parser/attr_wrapper.rs | 12 +++--- compiler/rustc_passes/src/check_attr.rs | 4 +- .../src/ich/impls_syntax.rs | 2 +- src/librustdoc/clean/cfg.rs | 4 +- src/librustdoc/clean/mod.rs | 4 +- src/librustdoc/passes/propagate_doc_cfg.rs | 4 +- .../src/attrs/allow_attributes.rs | 7 ++-- .../clippy/clippy_lints/src/attrs/mod.rs | 12 +++--- .../src/attrs/useless_attribute.rs | 2 +- .../clippy_lints/src/incompatible_msrv.rs | 2 +- .../clippy/clippy_lints/src/missing_doc.rs | 4 +- src/tools/clippy/clippy_utils/src/attrs.rs | 17 ++++---- .../clippy_utils/src/check_proc_macro.rs | 4 +- .../tests/ui/renamed_builtin_attr.stderr | 4 +- .../clippy/tests/ui/unknown_attribute.stderr | 4 +- src/tools/rustfmt/src/attr.rs | 4 +- 31 files changed, 103 insertions(+), 115 deletions(-) diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index c53188a22aedd..c0ed6e24e222d 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -96,11 +96,11 @@ impl AttributeExt for Attribute { } /// For a single-segment attribute, returns its name; otherwise, returns `None`. - fn ident(&self) -> Option { + fn name(&self) -> Option { match &self.kind { AttrKind::Normal(normal) => { if let [ident] = &*normal.item.path.segments { - Some(ident.ident) + Some(ident.ident.name) } else { None } @@ -109,9 +109,18 @@ impl AttributeExt for Attribute { } } - fn ident_path(&self) -> Option> { + fn symbol_path(&self) -> Option> { match &self.kind { - AttrKind::Normal(p) => Some(p.item.path.segments.iter().map(|i| i.ident).collect()), + AttrKind::Normal(p) => { + Some(p.item.path.segments.iter().map(|i| i.ident.name).collect()) + } + AttrKind::DocComment(_, _) => None, + } + } + + fn path_span(&self) -> Option { + match &self.kind { + AttrKind::Normal(attr) => Some(attr.item.path.span), AttrKind::DocComment(_, _) => None, } } @@ -794,9 +803,7 @@ pub trait AttributeExt: Debug { /// For a single-segment attribute (i.e., `#[attr]` and not `#[path::atrr]`), /// return the name of the attribute; otherwise, returns `None`. - fn name(&self) -> Option { - self.ident().map(|ident| ident.name) - } + fn name(&self) -> Option; /// Get the meta item list, `#[attr(meta item list)]` fn meta_item_list(&self) -> Option>; @@ -807,9 +814,6 @@ pub trait AttributeExt: Debug { /// Gets the span of the value literal, as string, when using `#[attr = value]` fn value_span(&self) -> Option; - /// For a single-segment attribute, returns its ident; otherwise, returns `None`. - fn ident(&self) -> Option; - /// Checks whether the path of this attribute matches the name. /// /// Matches one segment of the path to each element in `name` @@ -822,7 +826,7 @@ pub trait AttributeExt: Debug { #[inline] fn has_name(&self, name: Symbol) -> bool { - self.ident().map(|x| x.name == name).unwrap_or(false) + self.name().map(|x| x == name).unwrap_or(false) } #[inline] @@ -836,13 +840,13 @@ pub trait AttributeExt: Debug { fn is_word(&self) -> bool; fn path(&self) -> SmallVec<[Symbol; 1]> { - self.ident_path() - .map(|i| i.into_iter().map(|i| i.name).collect()) - .unwrap_or(smallvec![sym::doc]) + self.symbol_path().unwrap_or(smallvec![sym::doc]) } + fn path_span(&self) -> Option; + /// Returns None for doc comments - fn ident_path(&self) -> Option>; + fn symbol_path(&self) -> Option>; /// Returns the documentation if this is a doc comment or a sugared doc comment. /// * `///doc` returns `Some("doc")`. @@ -903,10 +907,6 @@ impl Attribute { AttributeExt::value_span(self) } - pub fn ident(&self) -> Option { - AttributeExt::ident(self) - } - pub fn path_matches(&self, name: &[Symbol]) -> bool { AttributeExt::path_matches(self, name) } @@ -938,10 +938,6 @@ impl Attribute { AttributeExt::path(self) } - pub fn ident_path(&self) -> Option> { - AttributeExt::ident_path(self) - } - pub fn doc_str(&self) -> Option { AttributeExt::doc_str(self) } diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index dbbd3906b5258..26eb8051df376 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -160,7 +160,7 @@ impl<'a> PostExpansionVisitor<'a> { impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { fn visit_attribute(&mut self, attr: &ast::Attribute) { - let attr_info = attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)); + let attr_info = attr.name().and_then(|name| BUILTIN_ATTRIBUTE_MAP.get(&name)); // Check feature gates for built-in attributes. if let Some(BuiltinAttribute { gate: AttributeGate::Gated { feature, message, check, notes, .. }, diff --git a/compiler/rustc_attr_parsing/src/attributes/cfg.rs b/compiler/rustc_attr_parsing/src/attributes/cfg.rs index 798cc10765415..66f0f8d391f6f 100644 --- a/compiler/rustc_attr_parsing/src/attributes/cfg.rs +++ b/compiler/rustc_attr_parsing/src/attributes/cfg.rs @@ -371,13 +371,7 @@ fn parse_cfg_attr_internal<'a>( attribute.span, attribute.get_normal_item().span(), attribute.style, - AttrPath { - segments: attribute - .ident_path() - .expect("cfg_attr is not a doc comment") - .into_boxed_slice(), - span: attribute.span, - }, + AttrPath { segments: attribute.path().into_boxed_slice(), span: attribute.span }, Some(attribute.get_normal_item().unsafety), ParsedDescription::Attribute, pred_span, diff --git a/compiler/rustc_attr_parsing/src/attributes/cfg_select.rs b/compiler/rustc_attr_parsing/src/attributes/cfg_select.rs index 00a2d12106e76..24b989e22a2bb 100644 --- a/compiler/rustc_attr_parsing/src/attributes/cfg_select.rs +++ b/compiler/rustc_attr_parsing/src/attributes/cfg_select.rs @@ -7,7 +7,7 @@ use rustc_hir::attrs::CfgEntry; use rustc_parse::exp; use rustc_parse::parser::Parser; use rustc_session::Session; -use rustc_span::{ErrorGuaranteed, Ident, Span}; +use rustc_span::{ErrorGuaranteed, Span, sym}; use crate::parser::MetaItemOrLitParser; use crate::{AttributeParser, ParsedDescription, ShouldEmit, parse_cfg_entry}; @@ -86,10 +86,7 @@ pub fn parse_cfg_select( cfg_span, cfg_span, AttrStyle::Inner, - AttrPath { - segments: vec![Ident::from_str("cfg_select")].into_boxed_slice(), - span: cfg_span, - }, + AttrPath { segments: vec![sym::cfg_select].into_boxed_slice(), span: cfg_span }, None, ParsedDescription::Macro, cfg_span, diff --git a/compiler/rustc_attr_parsing/src/attributes/util.rs b/compiler/rustc_attr_parsing/src/attributes/util.rs index 431ba539b2ba2..ebec8e8443fc8 100644 --- a/compiler/rustc_attr_parsing/src/attributes/util.rs +++ b/compiler/rustc_attr_parsing/src/attributes/util.rs @@ -28,8 +28,7 @@ pub fn parse_version(s: Symbol) -> Option { } pub fn is_builtin_attr(attr: &impl AttributeExt) -> bool { - attr.is_doc_comment().is_some() - || attr.ident().is_some_and(|ident| is_builtin_attr_name(ident.name)) + attr.is_doc_comment().is_some() || attr.name().is_some_and(|name| is_builtin_attr_name(name)) } /// Parse a single integer. diff --git a/compiler/rustc_attr_parsing/src/parser.rs b/compiler/rustc_attr_parsing/src/parser.rs index 9551744d5ec53..9c0fbe92d71b0 100644 --- a/compiler/rustc_attr_parsing/src/parser.rs +++ b/compiler/rustc_attr_parsing/src/parser.rs @@ -34,7 +34,7 @@ pub type RefPathParser<'p> = PathParser<&'p Path>; impl> PathParser

{ pub fn get_attribute_path(&self) -> hir::AttrPath { AttrPath { - segments: self.segments().copied().collect::>().into_boxed_slice(), + segments: self.segments().map(|s| s.name).collect::>().into_boxed_slice(), span: self.span(), } } diff --git a/compiler/rustc_attr_parsing/src/safety.rs b/compiler/rustc_attr_parsing/src/safety.rs index 817785108a1ed..68aeca2bbda92 100644 --- a/compiler/rustc_attr_parsing/src/safety.rs +++ b/compiler/rustc_attr_parsing/src/safety.rs @@ -22,7 +22,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> { return; } - let name = (attr_path.segments.len() == 1).then_some(attr_path.segments[0].name); + let name = (attr_path.segments.len() == 1).then_some(attr_path.segments[0]); if let Some(name) = name && [sym::cfg_trace, sym::cfg_attr_trace].contains(&name) { diff --git a/compiler/rustc_attr_parsing/src/target_checking.rs b/compiler/rustc_attr_parsing/src/target_checking.rs index 88efb910c1601..e86ecb451fc28 100644 --- a/compiler/rustc_attr_parsing/src/target_checking.rs +++ b/compiler/rustc_attr_parsing/src/target_checking.rs @@ -104,7 +104,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> { let (applied, only) = allowed_targets_applied(allowed_targets, target, cx.features); let name = cx.attr_path.clone(); - let lint = if name.segments[0].name == sym::deprecated + let lint = if name.segments[0] == sym::deprecated && ![ Target::Closure, Target::Expression, diff --git a/compiler/rustc_attr_parsing/src/validate_attr.rs b/compiler/rustc_attr_parsing/src/validate_attr.rs index e69ed0eea6b01..4879646a11072 100644 --- a/compiler/rustc_attr_parsing/src/validate_attr.rs +++ b/compiler/rustc_attr_parsing/src/validate_attr.rs @@ -27,7 +27,7 @@ pub fn check_attr(psess: &ParseSess, attr: &Attribute) { return; } - let builtin_attr_info = attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)); + let builtin_attr_info = attr.name().and_then(|name| BUILTIN_ATTRIBUTE_MAP.get(&name)); // Check input tokens for built-in and key-value attributes. match builtin_attr_info { diff --git a/compiler/rustc_builtin_macros/src/cfg.rs b/compiler/rustc_builtin_macros/src/cfg.rs index 7bc9080ba0229..557daa94b98ee 100644 --- a/compiler/rustc_builtin_macros/src/cfg.rs +++ b/compiler/rustc_builtin_macros/src/cfg.rs @@ -13,7 +13,7 @@ use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpa use rustc_hir::AttrPath; use rustc_hir::attrs::CfgEntry; use rustc_parse::exp; -use rustc_span::{ErrorGuaranteed, Ident, Span}; +use rustc_span::{ErrorGuaranteed, Span, sym}; use crate::errors; @@ -47,7 +47,7 @@ fn parse_cfg(cx: &ExtCtxt<'_>, span: Span, tts: TokenStream) -> Result bool { impl<'ast> visit::Visitor<'ast> for CfgFinder { type Result = ControlFlow<()>; fn visit_attribute(&mut self, attr: &'ast Attribute) -> ControlFlow<()> { - if attr - .ident() - .is_some_and(|ident| ident.name == sym::cfg || ident.name == sym::cfg_attr) - { + if attr.name().is_some_and(|name| name == sym::cfg || name == sym::cfg_attr) { ControlFlow::Break(()) } else { ControlFlow::Continue(()) diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 8135fd43dd93f..93043c69579af 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -18,7 +18,7 @@ use rustc_middle::span_bug; use rustc_middle::ty::{self as ty, Instance, TyCtxt}; use rustc_session::lint; use rustc_session::parse::feature_err; -use rustc_span::{Ident, Span, Symbol, sym}; +use rustc_span::{Span, Symbol, sym}; use rustc_target::spec::Os; use crate::errors; @@ -357,7 +357,7 @@ fn process_builtin_attrs( } } - let Some(Ident { name, .. }) = attr.ident() else { + let Some(name) = attr.name() else { continue; }; diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 6422779e13c9b..52b7339e01408 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -2110,7 +2110,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { let mut attr_pos = None; for (pos, attr) in item.attrs().iter().enumerate() { if !attr.is_doc_comment() && !self.cx.expanded_inert_attrs.is_marked(attr) { - let name = attr.ident().map(|ident| ident.name); + let name = attr.name(); if name == Some(sym::cfg) || name == Some(sym::cfg_attr) { cfg_pos = Some(pos); // a cfg attr found, no need to search anymore break; @@ -2187,7 +2187,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { } else if rustc_attr_parsing::is_builtin_attr(attr) && !AttributeParser::::is_parsed_attribute(&attr.path()) { - let attr_name = attr.ident().unwrap().name; + let attr_name = attr.name().unwrap(); // `#[cfg]` and `#[cfg_attr]` are special - they are // eagerly evaluated. if attr_name != sym::cfg_trace && attr_name != sym::cfg_attr_trace { diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index c60471848c892..483e864f69d43 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1182,7 +1182,7 @@ pub enum AttrArgs { #[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable)] pub struct AttrPath { - pub segments: Box<[Ident]>, + pub segments: Box<[Symbol]>, pub span: Span, } @@ -1198,7 +1198,7 @@ impl AttrPath { segments: path .segments .iter() - .map(|i| Ident { name: i.ident.name, span: lower_span(i.ident.span) }) + .map(|i| i.ident.name) .collect::>() .into_boxed_slice(), span: lower_span(path.span), @@ -1208,7 +1208,11 @@ impl AttrPath { impl fmt::Display for AttrPath { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", join_path_idents(&self.segments)) + write!( + f, + "{}", + join_path_idents(self.segments.iter().map(|i| Ident { name: *i, span: DUMMY_SP })) + ) } } @@ -1313,7 +1317,7 @@ impl AttributeExt for Attribute { /// For a single-segment attribute, returns its name; otherwise, returns `None`. #[inline] - fn ident(&self) -> Option { + fn name(&self) -> Option { match &self { Attribute::Unparsed(n) => { if let [ident] = n.path.segments.as_ref() { @@ -1329,7 +1333,7 @@ impl AttributeExt for Attribute { #[inline] fn path_matches(&self, name: &[Symbol]) -> bool { match &self { - Attribute::Unparsed(n) => n.path.segments.iter().map(|ident| &ident.name).eq(name), + Attribute::Unparsed(n) => n.path.segments.iter().eq(name), _ => false, } } @@ -1365,13 +1369,20 @@ impl AttributeExt for Attribute { } #[inline] - fn ident_path(&self) -> Option> { + fn symbol_path(&self) -> Option> { match &self { Attribute::Unparsed(n) => Some(n.path.segments.iter().copied().collect()), _ => None, } } + fn path_span(&self) -> Option { + match &self { + Attribute::Unparsed(attr) => Some(attr.path.span), + Attribute::Parsed(_) => None, + } + } + #[inline] fn doc_str(&self) -> Option { match &self { @@ -1451,11 +1462,6 @@ impl Attribute { AttributeExt::value_span(self) } - #[inline] - pub fn ident(&self) -> Option { - AttributeExt::ident(self) - } - #[inline] pub fn path_matches(&self, name: &[Symbol]) -> bool { AttributeExt::path_matches(self, name) @@ -1491,11 +1497,6 @@ impl Attribute { AttributeExt::path(self) } - #[inline] - pub fn ident_path(&self) -> Option> { - AttributeExt::ident_path(self) - } - #[inline] pub fn doc_str(&self) -> Option { AttributeExt::doc_str(self) diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index b3b416955230f..80e8bcb9a93a6 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -22,7 +22,7 @@ use rustc_hir::{ TyPatKind, }; use rustc_span::source_map::SourceMap; -use rustc_span::{FileName, Ident, Span, Symbol, kw, sym}; +use rustc_span::{DUMMY_SP, FileName, Ident, Span, Symbol, kw, sym}; use {rustc_ast as ast, rustc_hir as hir}; pub fn id_to_string(cx: &dyn rustc_hir::intravisit::HirTyCtxt<'_>, hir_id: HirId) -> String { @@ -136,7 +136,11 @@ impl<'a> State<'a> { .path .segments .iter() - .map(|i| ast::PathSegment { ident: *i, args: None, id: DUMMY_NODE_ID }) + .map(|i| ast::PathSegment { + ident: Ident { name: *i, span: DUMMY_SP }, + args: None, + id: DUMMY_NODE_ID, + }) .collect(), tokens: None, }; diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index 44fdf146f9c73..e04178645fdd8 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -86,9 +86,9 @@ fn has_cfg_or_cfg_attr(attrs: &[Attribute]) -> bool { // NOTE: Builtin attributes like `cfg` and `cfg_attr` cannot be renamed via imports. // Therefore, the absence of a literal `cfg` or `cfg_attr` guarantees that // we don't need to do any eager expansion. - attrs.iter().any(|attr| { - attr.ident().is_some_and(|ident| ident.name == sym::cfg || ident.name == sym::cfg_attr) - }) + attrs + .iter() + .any(|attr| attr.name().is_some_and(|ident| ident == sym::cfg || ident == sym::cfg_attr)) } impl<'a> Parser<'a> { @@ -398,10 +398,8 @@ impl<'a> Parser<'a> { /// - any single-segment, non-builtin attributes are present, e.g. `derive`, /// `test`, `global_allocator`. fn needs_tokens(attrs: &[ast::Attribute]) -> bool { - attrs.iter().any(|attr| match attr.ident() { + attrs.iter().any(|attr| match attr.name() { None => !attr.is_doc_comment(), - Some(ident) => { - ident.name == sym::cfg_attr || !rustc_feature::is_builtin_attr_name(ident.name) - } + Some(name) => name == sym::cfg_attr || !rustc_feature::is_builtin_attr_name(name), }) } diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 7822614a05cb1..eb551201b083f 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -388,7 +388,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { attr.path .segments .first() - .and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)) + .and_then(|name| BUILTIN_ATTRIBUTE_MAP.get(&name)) { match attr.style { ast::AttrStyle::Outer => { @@ -425,7 +425,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { if let Attribute::Unparsed(unparsed_attr) = attr && let Some(BuiltinAttribute { duplicates, .. }) = - attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)) + attr.name().and_then(|name| BUILTIN_ATTRIBUTE_MAP.get(&name)) { check_duplicates( self.tcx, diff --git a/compiler/rustc_query_system/src/ich/impls_syntax.rs b/compiler/rustc_query_system/src/ich/impls_syntax.rs index 118229ffc9902..fe6fb3d651946 100644 --- a/compiler/rustc_query_system/src/ich/impls_syntax.rs +++ b/compiler/rustc_query_system/src/ich/impls_syntax.rs @@ -24,7 +24,7 @@ impl<'a> HashStable> for [hir::Attribute] { .filter(|attr| { attr.is_doc_comment().is_none() // FIXME(jdonszelmann) have a better way to handle ignored attrs - && !attr.ident().is_some_and(|ident| hcx.is_ignored_attr(ident.name)) + && !attr.name().is_some_and(|ident| hcx.is_ignored_attr(ident)) }) .collect(); diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index 7ab2a72d75b5c..61ebc73182c0d 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -859,8 +859,8 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator } continue; } else if !cfg_info.parent_is_doc_cfg - && let Some(ident) = attr.ident() - && matches!(ident.name, sym::cfg | sym::cfg_trace) + && let Some(name) = attr.name() + && matches!(name, sym::cfg | sym::cfg_trace) && let Some(attr) = single(attr.meta_item_list()?) && let Ok(new_cfg) = Cfg::parse(&attr) { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 764b3a0acdb6f..72996cc4f21e9 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2673,8 +2673,8 @@ fn add_without_unwanted_attributes<'hir>( import_parent, )); } - hir::Attribute::Unparsed(normal) if let [ident] = &*normal.path.segments => { - if is_inline || ident.name != sym::cfg_trace { + hir::Attribute::Unparsed(normal) if let [name] = &*normal.path.segments => { + if is_inline || *name != sym::cfg_trace { // If it's not a `cfg()` attribute, we keep it. attrs.push((Cow::Borrowed(attr), import_parent)); } diff --git a/src/librustdoc/passes/propagate_doc_cfg.rs b/src/librustdoc/passes/propagate_doc_cfg.rs index 95f5537f394c0..d4bf74c295142 100644 --- a/src/librustdoc/passes/propagate_doc_cfg.rs +++ b/src/librustdoc/passes/propagate_doc_cfg.rs @@ -40,8 +40,8 @@ fn add_only_cfg_attributes(attrs: &mut Vec, new_attrs: &[Attribute]) new_attr.cfg = d.cfg.clone(); attrs.push(Attribute::Parsed(AttributeKind::Doc(Box::new(new_attr)))); } else if let Attribute::Unparsed(normal) = attr - && let [ident] = &*normal.path.segments - && ident.name == sym::cfg_trace + && let [name] = &*normal.path.segments + && *name == sym::cfg_trace { // If it's a `cfg()` attribute, we keep it. attrs.push(attr.clone()); diff --git a/src/tools/clippy/clippy_lints/src/attrs/allow_attributes.rs b/src/tools/clippy/clippy_lints/src/attrs/allow_attributes.rs index 53d9725703c3d..84b65d3185e35 100644 --- a/src/tools/clippy/clippy_lints/src/attrs/allow_attributes.rs +++ b/src/tools/clippy/clippy_lints/src/attrs/allow_attributes.rs @@ -4,18 +4,19 @@ use clippy_utils::is_from_proc_macro; use rustc_ast::{AttrStyle, Attribute}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, LintContext}; +use rustc_ast::attr::AttributeExt; // Separate each crate's features. pub fn check<'cx>(cx: &EarlyContext<'cx>, attr: &'cx Attribute) { if !attr.span.in_external_macro(cx.sess().source_map()) && let AttrStyle::Outer = attr.style - && let Some(ident) = attr.ident() + && let Some(path_span) = attr.path_span() && !is_from_proc_macro(cx, attr) { #[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")] - span_lint_and_then(cx, ALLOW_ATTRIBUTES, ident.span, "#[allow] attribute found", |diag| { + span_lint_and_then(cx, ALLOW_ATTRIBUTES, path_span, "#[allow] attribute found", |diag| { diag.span_suggestion( - ident.span, + path_span, "replace it with", "expect", Applicability::MachineApplicable, diff --git a/src/tools/clippy/clippy_lints/src/attrs/mod.rs b/src/tools/clippy/clippy_lints/src/attrs/mod.rs index 91c2dc7f3dc6c..679ccfb8de3a1 100644 --- a/src/tools/clippy/clippy_lints/src/attrs/mod.rs +++ b/src/tools/clippy/clippy_lints/src/attrs/mod.rs @@ -574,16 +574,16 @@ impl EarlyLintPass for PostExpansionEarlyAttributes { fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) { if let Some(items) = &attr.meta_item_list() - && let Some(ident) = attr.ident() + && let Some(name) = attr.name() { - if matches!(ident.name, sym::allow) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) { + if matches!(name, sym::allow) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) { allow_attributes::check(cx, attr); } - if matches!(ident.name, sym::allow | sym::expect) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) { - allow_attributes_without_reason::check(cx, ident.name, items, attr); + if matches!(name, sym::allow | sym::expect) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) { + allow_attributes_without_reason::check(cx, name, items, attr); } - if is_lint_level(ident.name, attr.id) { - blanket_clippy_restriction_lints::check(cx, ident.name, items); + if is_lint_level(name, attr.id) { + blanket_clippy_restriction_lints::check(cx, name, items); } if items.is_empty() || !attr.has_name(sym::deprecated) { return; diff --git a/src/tools/clippy/clippy_lints/src/attrs/useless_attribute.rs b/src/tools/clippy/clippy_lints/src/attrs/useless_attribute.rs index 1cebc18edc90a..aa9a6654bee32 100644 --- a/src/tools/clippy/clippy_lints/src/attrs/useless_attribute.rs +++ b/src/tools/clippy/clippy_lints/src/attrs/useless_attribute.rs @@ -15,7 +15,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) { return; } if let Some(lint_list) = &attr.meta_item_list() - && attr.ident().is_some_and(|ident| is_lint_level(ident.name, attr.id)) + && attr.name().is_some_and(|name| is_lint_level(name, attr.id)) { for lint in lint_list { match item.kind { diff --git a/src/tools/clippy/clippy_lints/src/incompatible_msrv.rs b/src/tools/clippy/clippy_lints/src/incompatible_msrv.rs index c3bc9048c23a8..28ea2e4fa1f0a 100644 --- a/src/tools/clippy/clippy_lints/src/incompatible_msrv.rs +++ b/src/tools/clippy/clippy_lints/src/incompatible_msrv.rs @@ -270,7 +270,7 @@ fn is_under_cfg_attribute(cx: &LateContext<'_>, hir_id: HirId) -> bool { cx.tcx.hir_parent_id_iter(hir_id).any(|id| { cx.tcx.hir_attrs(id).iter().any(|attr| { matches!( - attr.ident().map(|ident| ident.name), + attr.name(), Some(sym::cfg_trace | sym::cfg_attr_trace) ) }) diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs index ac221743cfd64..375b275cd113a 100644 --- a/src/tools/clippy/clippy_lints/src/missing_doc.rs +++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs @@ -287,8 +287,8 @@ fn is_doc_attr(attr: &Attribute) -> bool { match attr { Attribute::Parsed(AttributeKind::DocComment { .. }) => true, Attribute::Unparsed(attr) - if let [ident] = &*attr.path.segments - && ident.name == sym::doc => + if let [name] = &*attr.path.segments + && *name == sym::doc => { matches!(attr.args, AttrArgs::Eq { .. }) }, diff --git a/src/tools/clippy/clippy_utils/src/attrs.rs b/src/tools/clippy/clippy_utils/src/attrs.rs index 2fd773b06781d..94e4ede140486 100644 --- a/src/tools/clippy/clippy_utils/src/attrs.rs +++ b/src/tools/clippy/clippy_utils/src/attrs.rs @@ -20,10 +20,11 @@ pub fn get_builtin_attr<'a, A: AttributeExt + 'a>( name: Symbol, ) -> impl Iterator { attrs.iter().filter(move |attr| { - if let Some([clippy, segment2]) = attr.ident_path().as_deref() - && clippy.name == sym::clippy + if let [clippy, segment2] = &*attr.path() + && *clippy == sym::clippy { - let new_name = match segment2.name { + let path_span = attr.path_span().expect("Clippy attributes are unparsed and have a span"); + let new_name = match *segment2 { sym::cyclomatic_complexity => Some("cognitive_complexity"), sym::author | sym::version @@ -35,7 +36,7 @@ pub fn get_builtin_attr<'a, A: AttributeExt + 'a>( | sym::has_significant_drop | sym::format_args => None, _ => { - sess.dcx().span_err(segment2.span, "usage of unknown attribute"); + sess.dcx().span_err(path_span, "usage of unknown attribute"); return false; }, }; @@ -43,17 +44,17 @@ pub fn get_builtin_attr<'a, A: AttributeExt + 'a>( match new_name { Some(new_name) => { sess.dcx() - .struct_span_err(segment2.span, "usage of deprecated attribute") + .struct_span_err(path_span, "usage of deprecated attribute") .with_span_suggestion( - segment2.span, + path_span, "consider using", - new_name, + format!("clippy::{}", new_name), Applicability::MachineApplicable, ) .emit(); false }, - None => segment2.name == name, + None => *segment2 == name, } } else { false diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index d9254fca9453d..7fb8616072a59 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -348,9 +348,9 @@ fn fn_kind_pat(tcx: TyCtxt<'_>, kind: &FnKind<'_>, body: &Body<'_>, hir_id: HirI fn attr_search_pat(attr: &Attribute) -> (Pat, Pat) { match attr.kind { AttrKind::Normal(..) => { - if let Some(ident) = attr.ident() { + if let Some(name) = attr.name() { // NOTE: This will likely have false positives, like `allow = 1` - let ident_string = ident.to_string(); + let ident_string = name.to_string(); if attr.style == AttrStyle::Outer { ( Pat::OwnedMultiStr(vec!["#[".to_owned() + &ident_string, ident_string]), diff --git a/src/tools/clippy/tests/ui/renamed_builtin_attr.stderr b/src/tools/clippy/tests/ui/renamed_builtin_attr.stderr index fb51313dab69a..0ebc43739d6b7 100644 --- a/src/tools/clippy/tests/ui/renamed_builtin_attr.stderr +++ b/src/tools/clippy/tests/ui/renamed_builtin_attr.stderr @@ -1,8 +1,8 @@ error: usage of deprecated attribute - --> tests/ui/renamed_builtin_attr.rs:3:11 + --> tests/ui/renamed_builtin_attr.rs:3:3 | LL | #[clippy::cyclomatic_complexity = "1"] - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `cognitive_complexity` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `clippy::cognitive_complexity` error: aborting due to 1 previous error diff --git a/src/tools/clippy/tests/ui/unknown_attribute.stderr b/src/tools/clippy/tests/ui/unknown_attribute.stderr index b306abe0a9d1f..1d4d50ffc02a4 100644 --- a/src/tools/clippy/tests/ui/unknown_attribute.stderr +++ b/src/tools/clippy/tests/ui/unknown_attribute.stderr @@ -1,8 +1,8 @@ error: usage of unknown attribute - --> tests/ui/unknown_attribute.rs:3:11 + --> tests/ui/unknown_attribute.rs:3:3 | LL | #[clippy::unknown] - | ^^^^^^^ + | ^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/src/tools/rustfmt/src/attr.rs b/src/tools/rustfmt/src/attr.rs index 381c938ae8062..d03d33514046e 100644 --- a/src/tools/rustfmt/src/attr.rs +++ b/src/tools/rustfmt/src/attr.rs @@ -336,8 +336,8 @@ impl Rewrite for ast::Attribute { rewrite_doc_comment(snippet, shape.comment(context.config), context.config) } else { let should_skip = self - .ident() - .map(|s| context.skip_context.attributes.skip(s.name.as_str())) + .name() + .map(|s| context.skip_context.attributes.skip(s.as_str())) .unwrap_or(false); let prefix = attr_prefix(self); From 5c5c1ff6dbe84e1d9eddd158116f6e40b941ed03 Mon Sep 17 00:00:00 2001 From: reddevilmidzy Date: Thu, 25 Dec 2025 23:29:35 +0900 Subject: [PATCH 2/4] moved some test delete tests/ui/issues/issue-22426.rs duplicated of tests/ui/match/guards.rs --- .../associated-type-const-nomalization.rs} | 0 .../ui/{issues/issue-2428.rs => cast/cast-enum-const.rs} | 0 .../ui/{issues/issue-22403.rs => cast/cast-to-box-arr.rs} | 0 .../issue-41998.rs => cast/cast-to-char-compare.rs} | 0 .../const-static-ref-to-closure.rs} | 0 .../derive-debug-generic-with-lifetime.rs} | 0 .../derive-debug-newtype-unsized-slice.rs} | 0 .../call-unit-struct-impl-fn-once.rs} | 0 .../fn-trait-explicit-call.rs} | 0 tests/ui/issues/issue-22426.rs | 8 -------- tests/ui/{issues => resolve}/auxiliary/i8.rs | 0 .../const-iter-no-conflict-for-loop.rs} | 0 .../issue-20427.rs => resolve/shadow-primitives.rs} | 0 .../self-in-method-body-resolves.rs} | 0 .../bound/recursive-trait-bound-on-type-param.rs} | 0 .../tuple-ref-order-distinct-impls.rs} | 0 .../issue-20676.rs => ufcs/ufcs-trait-object-format.rs} | 0 17 files changed, 8 deletions(-) rename tests/ui/{issues/issue-26614.rs => associated-types/associated-type-const-nomalization.rs} (100%) rename tests/ui/{issues/issue-2428.rs => cast/cast-enum-const.rs} (100%) rename tests/ui/{issues/issue-22403.rs => cast/cast-to-box-arr.rs} (100%) rename tests/ui/{issues/issue-41998.rs => cast/cast-to-char-compare.rs} (100%) rename tests/ui/{issues/issue-25180.rs => consts/const-static-ref-to-closure.rs} (100%) rename tests/ui/{issues/issue-29030.rs => derives/derive-debug-generic-with-lifetime.rs} (100%) rename tests/ui/{issues/issue-25394.rs => derives/derive-debug-newtype-unsized-slice.rs} (100%) rename tests/ui/{issues/issue-33687.rs => fn_traits/call-unit-struct-impl-fn-once.rs} (100%) rename tests/ui/{issues/issue-20847.rs => fn_traits/fn-trait-explicit-call.rs} (100%) delete mode 100644 tests/ui/issues/issue-22426.rs rename tests/ui/{issues => resolve}/auxiliary/i8.rs (100%) rename tests/ui/{issues/issue-27639.rs => resolve/const-iter-no-conflict-for-loop.rs} (100%) rename tests/ui/{issues/issue-20427.rs => resolve/shadow-primitives.rs} (100%) rename tests/ui/{issues/issue-24389.rs => self/self-in-method-body-resolves.rs} (100%) rename tests/ui/{issues/issue-19601.rs => traits/bound/recursive-trait-bound-on-type-param.rs} (100%) rename tests/ui/{issues/issue-11384.rs => typeck/tuple-ref-order-distinct-impls.rs} (100%) rename tests/ui/{issues/issue-20676.rs => ufcs/ufcs-trait-object-format.rs} (100%) diff --git a/tests/ui/issues/issue-26614.rs b/tests/ui/associated-types/associated-type-const-nomalization.rs similarity index 100% rename from tests/ui/issues/issue-26614.rs rename to tests/ui/associated-types/associated-type-const-nomalization.rs diff --git a/tests/ui/issues/issue-2428.rs b/tests/ui/cast/cast-enum-const.rs similarity index 100% rename from tests/ui/issues/issue-2428.rs rename to tests/ui/cast/cast-enum-const.rs diff --git a/tests/ui/issues/issue-22403.rs b/tests/ui/cast/cast-to-box-arr.rs similarity index 100% rename from tests/ui/issues/issue-22403.rs rename to tests/ui/cast/cast-to-box-arr.rs diff --git a/tests/ui/issues/issue-41998.rs b/tests/ui/cast/cast-to-char-compare.rs similarity index 100% rename from tests/ui/issues/issue-41998.rs rename to tests/ui/cast/cast-to-char-compare.rs diff --git a/tests/ui/issues/issue-25180.rs b/tests/ui/consts/const-static-ref-to-closure.rs similarity index 100% rename from tests/ui/issues/issue-25180.rs rename to tests/ui/consts/const-static-ref-to-closure.rs diff --git a/tests/ui/issues/issue-29030.rs b/tests/ui/derives/derive-debug-generic-with-lifetime.rs similarity index 100% rename from tests/ui/issues/issue-29030.rs rename to tests/ui/derives/derive-debug-generic-with-lifetime.rs diff --git a/tests/ui/issues/issue-25394.rs b/tests/ui/derives/derive-debug-newtype-unsized-slice.rs similarity index 100% rename from tests/ui/issues/issue-25394.rs rename to tests/ui/derives/derive-debug-newtype-unsized-slice.rs diff --git a/tests/ui/issues/issue-33687.rs b/tests/ui/fn_traits/call-unit-struct-impl-fn-once.rs similarity index 100% rename from tests/ui/issues/issue-33687.rs rename to tests/ui/fn_traits/call-unit-struct-impl-fn-once.rs diff --git a/tests/ui/issues/issue-20847.rs b/tests/ui/fn_traits/fn-trait-explicit-call.rs similarity index 100% rename from tests/ui/issues/issue-20847.rs rename to tests/ui/fn_traits/fn-trait-explicit-call.rs diff --git a/tests/ui/issues/issue-22426.rs b/tests/ui/issues/issue-22426.rs deleted file mode 100644 index 0857ac9dfb4d1..0000000000000 --- a/tests/ui/issues/issue-22426.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ run-pass - -fn main() { - match 42 { - x if x < 7 => (), - _ => () - } -} diff --git a/tests/ui/issues/auxiliary/i8.rs b/tests/ui/resolve/auxiliary/i8.rs similarity index 100% rename from tests/ui/issues/auxiliary/i8.rs rename to tests/ui/resolve/auxiliary/i8.rs diff --git a/tests/ui/issues/issue-27639.rs b/tests/ui/resolve/const-iter-no-conflict-for-loop.rs similarity index 100% rename from tests/ui/issues/issue-27639.rs rename to tests/ui/resolve/const-iter-no-conflict-for-loop.rs diff --git a/tests/ui/issues/issue-20427.rs b/tests/ui/resolve/shadow-primitives.rs similarity index 100% rename from tests/ui/issues/issue-20427.rs rename to tests/ui/resolve/shadow-primitives.rs diff --git a/tests/ui/issues/issue-24389.rs b/tests/ui/self/self-in-method-body-resolves.rs similarity index 100% rename from tests/ui/issues/issue-24389.rs rename to tests/ui/self/self-in-method-body-resolves.rs diff --git a/tests/ui/issues/issue-19601.rs b/tests/ui/traits/bound/recursive-trait-bound-on-type-param.rs similarity index 100% rename from tests/ui/issues/issue-19601.rs rename to tests/ui/traits/bound/recursive-trait-bound-on-type-param.rs diff --git a/tests/ui/issues/issue-11384.rs b/tests/ui/typeck/tuple-ref-order-distinct-impls.rs similarity index 100% rename from tests/ui/issues/issue-11384.rs rename to tests/ui/typeck/tuple-ref-order-distinct-impls.rs diff --git a/tests/ui/issues/issue-20676.rs b/tests/ui/ufcs/ufcs-trait-object-format.rs similarity index 100% rename from tests/ui/issues/issue-20676.rs rename to tests/ui/ufcs/ufcs-trait-object-format.rs From 93f8ad99507ecb851ace4b1d4e3e7c5cd67ed80c Mon Sep 17 00:00:00 2001 From: reddevilmidzy Date: Fri, 26 Dec 2025 00:13:11 +0900 Subject: [PATCH 3/4] cleaned up some tests cleaned up cast-enum-const.rs cleaned up ufcs-trait-object-format.rs add comment to cast-to-box-arr.rs add comment to shadow-primitives.rs add comment to associated-type-const-nomalization.rs add comment to fn-trait-explicit-call.rs add comment to call-unit-struct-impl-fn-once.rs add comment to cast-to-char-compare.rs add comment to self-in-method-body-resolves.rs add comment to derive-debug-newtype-unsized-slice.rs add comment to tuple-ref-order-distinct-impls.rs add comment to derive-debug-generic-with-lifetime.rs add comment to recursive-trait-bound-on-type-param.rs cleaned up const-static-ref-to-closure.rs add comment to const-iter-no-conflict-for-loop.rs --- .../associated-type-const-nomalization.rs | 1 + tests/ui/cast/cast-enum-const.rs | 12 +++---- tests/ui/cast/cast-to-box-arr.rs | 1 + tests/ui/cast/cast-to-char-compare.rs | 2 +- .../ui/consts/const-static-ref-to-closure.rs | 4 +-- .../derive-debug-generic-with-lifetime.rs | 1 + .../derive-debug-newtype-unsized-slice.rs | 1 + .../call-unit-struct-impl-fn-once.rs | 1 + tests/ui/fn_traits/fn-trait-explicit-call.rs | 1 + .../const-iter-no-conflict-for-loop.rs | 4 +++ tests/ui/resolve/shadow-primitives.rs | 33 ++++++++++--------- tests/ui/self/self-in-method-body-resolves.rs | 9 +++-- .../recursive-trait-bound-on-type-param.rs | 8 ++++- .../typeck/tuple-ref-order-distinct-impls.rs | 5 ++- tests/ui/ufcs/ufcs-trait-object-format.rs | 9 ++--- 15 files changed, 59 insertions(+), 33 deletions(-) diff --git a/tests/ui/associated-types/associated-type-const-nomalization.rs b/tests/ui/associated-types/associated-type-const-nomalization.rs index 576c7545924b3..b7951ba9a435c 100644 --- a/tests/ui/associated-types/associated-type-const-nomalization.rs +++ b/tests/ui/associated-types/associated-type-const-nomalization.rs @@ -1,3 +1,4 @@ +//! regression test for //@ check-pass trait Mirror { diff --git a/tests/ui/cast/cast-enum-const.rs b/tests/ui/cast/cast-enum-const.rs index 9cb02460f35b7..cfad40c07b0e5 100644 --- a/tests/ui/cast/cast-enum-const.rs +++ b/tests/ui/cast/cast-enum-const.rs @@ -1,14 +1,12 @@ +//! regression test for //@ run-pass -#![allow(non_upper_case_globals)] - -pub fn main() { - let _foo = 100; - const quux: isize = 5; +fn main() { + const QUUX: isize = 5; enum Stuff { - Bar = quux + Bar = QUUX, } - assert_eq!(Stuff::Bar as isize, quux); + assert_eq!(Stuff::Bar as isize, QUUX); } diff --git a/tests/ui/cast/cast-to-box-arr.rs b/tests/ui/cast/cast-to-box-arr.rs index 89c956913f932..1a9004cd074ef 100644 --- a/tests/ui/cast/cast-to-box-arr.rs +++ b/tests/ui/cast/cast-to-box-arr.rs @@ -1,3 +1,4 @@ +//! regression test for //@ run-pass fn main() { let x = Box::new([1, 2, 3]); diff --git a/tests/ui/cast/cast-to-char-compare.rs b/tests/ui/cast/cast-to-char-compare.rs index 303bf7a575138..159b8ee04e028 100644 --- a/tests/ui/cast/cast-to-char-compare.rs +++ b/tests/ui/cast/cast-to-char-compare.rs @@ -1,6 +1,6 @@ +//! regression test for //@ check-pass - fn main() { if ('x' as char) < ('y' as char) { print!("x"); diff --git a/tests/ui/consts/const-static-ref-to-closure.rs b/tests/ui/consts/const-static-ref-to-closure.rs index 339aca0375465..06b5ca5a935ca 100644 --- a/tests/ui/consts/const-static-ref-to-closure.rs +++ b/tests/ui/consts/const-static-ref-to-closure.rs @@ -1,7 +1,7 @@ +//! regression test for //@ check-pass #![allow(dead_code)] -#![allow(non_upper_case_globals)] -const x: &'static dyn Fn() = &|| println!("ICE here"); +const X: &'static dyn Fn() = &|| println!("ICE here"); fn main() {} diff --git a/tests/ui/derives/derive-debug-generic-with-lifetime.rs b/tests/ui/derives/derive-debug-generic-with-lifetime.rs index c92853fb5dc2f..430ade071795d 100644 --- a/tests/ui/derives/derive-debug-generic-with-lifetime.rs +++ b/tests/ui/derives/derive-debug-generic-with-lifetime.rs @@ -1,3 +1,4 @@ +//! regression test for //@ check-pass #![allow(dead_code)] #[derive(Debug)] diff --git a/tests/ui/derives/derive-debug-newtype-unsized-slice.rs b/tests/ui/derives/derive-debug-newtype-unsized-slice.rs index 689c9f33af029..c735d9f039d2d 100644 --- a/tests/ui/derives/derive-debug-newtype-unsized-slice.rs +++ b/tests/ui/derives/derive-debug-newtype-unsized-slice.rs @@ -1,3 +1,4 @@ +//! regression test for //@ check-pass #![allow(dead_code)] #[derive(Debug)] diff --git a/tests/ui/fn_traits/call-unit-struct-impl-fn-once.rs b/tests/ui/fn_traits/call-unit-struct-impl-fn-once.rs index a5693b3aca8e4..15554482931b7 100644 --- a/tests/ui/fn_traits/call-unit-struct-impl-fn-once.rs +++ b/tests/ui/fn_traits/call-unit-struct-impl-fn-once.rs @@ -1,3 +1,4 @@ +//! regression test for //@ run-pass #![feature(unboxed_closures)] #![feature(fn_traits)] diff --git a/tests/ui/fn_traits/fn-trait-explicit-call.rs b/tests/ui/fn_traits/fn-trait-explicit-call.rs index 364b07bf6922f..f37e0a558baa6 100644 --- a/tests/ui/fn_traits/fn-trait-explicit-call.rs +++ b/tests/ui/fn_traits/fn-trait-explicit-call.rs @@ -1,3 +1,4 @@ +//! regression test for //@ run-pass #![feature(fn_traits)] diff --git a/tests/ui/resolve/const-iter-no-conflict-for-loop.rs b/tests/ui/resolve/const-iter-no-conflict-for-loop.rs index 95edcb8695e21..ddbba64e5a31f 100644 --- a/tests/ui/resolve/const-iter-no-conflict-for-loop.rs +++ b/tests/ui/resolve/const-iter-no-conflict-for-loop.rs @@ -1,3 +1,7 @@ +//! regression test for +//! Ensure that a constant named `iter` does not +//! interfere with the name resolution of the `iter` methods used internally +//! by `for` loops //@ run-pass #![allow(dead_code)] #![allow(non_upper_case_globals)] diff --git a/tests/ui/resolve/shadow-primitives.rs b/tests/ui/resolve/shadow-primitives.rs index 4018043c371ee..17da0cd0530c2 100644 --- a/tests/ui/resolve/shadow-primitives.rs +++ b/tests/ui/resolve/shadow-primitives.rs @@ -1,3 +1,4 @@ +//! regression test for //@ run-pass #![allow(dead_code)] #![allow(unused_variables)] @@ -31,17 +32,10 @@ mod char { mod char_ {} mod str { - use super::i8 as i8; - use super::i32_ as i32; - use super::i64_ as i64; - use super::u8_ as u8; - use super::f_ as f64; - use super::u16_ as u16; - use super::u32_ as u32; - use super::u64_ as u64; - use super::bool_ as bool; - use super::{bool_ as str}; - use super::char_ as char; + use super::{ + bool_ as bool, bool_ as str, char_ as char, f_ as f64, i8, i32_ as i32, i64_ as i64, + u8_ as u8, u16_ as u16, u32_ as u32, u64_ as u64, + }; } } @@ -49,7 +43,9 @@ trait isize_ { type isize; } -fn usize<'usize>(usize: &'usize usize) -> &'usize usize { usize } +fn usize<'usize>(usize: &'usize usize) -> &'usize usize { + usize +} mod reuse { use std::mem::size_of; @@ -68,9 +64,10 @@ mod reuse { mod guard { pub fn check() { use std::u8; // bring module u8 in scope - fn f() -> u8 { // OK, resolves to primitive u8, not to std::u8 + fn f() -> u8 { + // OK, resolves to primitive u8, not to std::u8 u8::max_value() // OK, resolves to associated function ::max_value, - // not to non-existent std::u8::max_value + // not to non-existent std::u8::max_value } assert_eq!(f(), u8::MAX); // OK, resolves to std::u8::MAX } @@ -79,7 +76,13 @@ mod guard { fn main() { let bool = true; let _ = match bool { - str @ true => if str { i32 as i64 } else { i64 }, + str @ true => { + if str { + i32 as i64 + } else { + i64 + } + } false => i64, }; diff --git a/tests/ui/self/self-in-method-body-resolves.rs b/tests/ui/self/self-in-method-body-resolves.rs index 95bb2af9b25c5..636922cd87ce6 100644 --- a/tests/ui/self/self-in-method-body-resolves.rs +++ b/tests/ui/self/self-in-method-body-resolves.rs @@ -1,11 +1,16 @@ +//! regression test for //@ check-pass #![allow(dead_code)] struct Foo; impl Foo { - fn new() -> Self { Foo } - fn bar() { Self::new(); } + fn new() -> Self { + Foo + } + fn bar() { + Self::new(); + } } fn main() {} diff --git a/tests/ui/traits/bound/recursive-trait-bound-on-type-param.rs b/tests/ui/traits/bound/recursive-trait-bound-on-type-param.rs index e97819e4122da..41ae91afad49a 100644 --- a/tests/ui/traits/bound/recursive-trait-bound-on-type-param.rs +++ b/tests/ui/traits/bound/recursive-trait-bound-on-type-param.rs @@ -1,6 +1,12 @@ +//! regression test for //@ check-pass trait A {} -struct B where B: A> { t: T } +struct B +where + B: A>, +{ + t: T, +} fn main() {} diff --git a/tests/ui/typeck/tuple-ref-order-distinct-impls.rs b/tests/ui/typeck/tuple-ref-order-distinct-impls.rs index ad0affa4b0d25..fdede8a1d9c44 100644 --- a/tests/ui/typeck/tuple-ref-order-distinct-impls.rs +++ b/tests/ui/typeck/tuple-ref-order-distinct-impls.rs @@ -1,6 +1,9 @@ +//! regression test for //@ check-pass -trait Common { fn dummy(&self) { } } +trait Common { + fn dummy(&self) {} +} impl<'t, T> Common for (T, &'t T) {} diff --git a/tests/ui/ufcs/ufcs-trait-object-format.rs b/tests/ui/ufcs/ufcs-trait-object-format.rs index 2059365c7d628..7d50a24448069 100644 --- a/tests/ui/ufcs/ufcs-trait-object-format.rs +++ b/tests/ui/ufcs/ufcs-trait-object-format.rs @@ -1,8 +1,9 @@ //@ run-pass -// Regression test for #20676. Error was that we didn't support -// UFCS-style calls to a method in `Trait` where `Self` was bound to a -// trait object of type `Trait`. See also `ufcs-trait-object.rs`. - +//! Regression test for . +//! Error was that we didn't support +//! UFCS-style calls to a method in `Trait` where `Self` was bound to a +//! trait object of type `Trait`. +//! See also . use std::fmt; From 3d6a2c5ae1685cda3a1ec8357a21fc7f76c7c6be Mon Sep 17 00:00:00 2001 From: Marijn Schouten Date: Mon, 5 Jan 2026 12:05:23 +0000 Subject: [PATCH 4/4] relate.rs: tiny cleanup: eliminate temp vars 2 --- compiler/rustc_type_ir/src/relate.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_type_ir/src/relate.rs b/compiler/rustc_type_ir/src/relate.rs index 9e14bf6b60ad5..3610605462ba9 100644 --- a/compiler/rustc_type_ir/src/relate.rs +++ b/compiler/rustc_type_ir/src/relate.rs @@ -216,11 +216,7 @@ impl Relate for ty::AliasTy { b: ty::AliasTy, ) -> RelateResult> { if a.def_id != b.def_id { - Err(TypeError::ProjectionMismatched({ - let a = a.def_id; - let b = b.def_id; - ExpectedFound::new(a, b) - })) + Err(TypeError::ProjectionMismatched(ExpectedFound::new(a.def_id, b.def_id))) } else { let cx = relation.cx(); let args = if let Some(variances) = cx.opt_alias_variances(a.kind(cx), a.def_id) { @@ -240,11 +236,7 @@ impl Relate for ty::AliasTerm { b: ty::AliasTerm, ) -> RelateResult> { if a.def_id != b.def_id { - Err(TypeError::ProjectionMismatched({ - let a = a.def_id; - let b = b.def_id; - ExpectedFound::new(a, b) - })) + Err(TypeError::ProjectionMismatched(ExpectedFound::new(a.def_id, b.def_id))) } else { let args = match a.kind(relation.cx()) { ty::AliasTermKind::OpaqueTy => relate_args_with_variances( @@ -275,11 +267,7 @@ impl Relate for ty::ExistentialProjection { b: ty::ExistentialProjection, ) -> RelateResult> { if a.def_id != b.def_id { - Err(TypeError::ProjectionMismatched({ - let a = a.def_id; - let b = b.def_id; - ExpectedFound::new(a, b) - })) + Err(TypeError::ProjectionMismatched(ExpectedFound::new(a.def_id, b.def_id))) } else { let term = relation.relate_with_variance( ty::Invariant,