Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a755d0f
Add an edge-case test for `--remap-path-prefix` for `rustc` & `rustdoc`
Urgau Apr 18, 2026
72c56ed
remove `deriving-via-extension-*.rs` tests
cyrgani Apr 22, 2026
f2657b8
create `derives/coercepointee`
cyrgani Apr 22, 2026
674eb8a
create `derives/debug`
cyrgani Apr 22, 2026
87a26ec
create `derives/default`
cyrgani Apr 22, 2026
818e511
create `derives/eq-ord`
cyrgani Apr 22, 2026
b0b5b12
create `derives/clone-copy`
cyrgani Apr 22, 2026
e908aa8
delete some no-longer-meaningful tests
cyrgani Apr 22, 2026
11ba127
move remaining files from `deriving` to `derives`
cyrgani Apr 22, 2026
9c49112
Lint doc comments in cfg_select branches
qaijuang Apr 24, 2026
4bb2b07
test with multi-line doc comment
qaijuang Apr 24, 2026
9aa431c
Add a simpler, harder to misuse, attribute parsing API
scrabsha Apr 13, 2026
067ef3d
Add documentation for higher-level attribute parsing API
scrabsha Apr 20, 2026
45b4e3c
Fix ICE of trying to get span from all attrs
chenyukang Apr 4, 2026
ff73b8a
triagebot.toml: Ping Enselic when tests/debuginfo/basic-stepping.rs c…
Enselic Apr 25, 2026
4d8bb1d
Rollup merge of #154803 - chenyukang:yukang-fix-154801-cfg-attr-span,…
JonathanBrouwer Apr 25, 2026
8202e27
Rollup merge of #155485 - Urgau:remap-edge-case-test, r=GuillaumeGomez
JonathanBrouwer Apr 25, 2026
46c8bae
Rollup merge of #155659 - cyrgani:deriving-2, r=Kivooeo
JonathanBrouwer Apr 25, 2026
ed7298a
Rollup merge of #155696 - scrabsha:push-kxqstpltlwzn, r=JonathanBrouwer
JonathanBrouwer Apr 25, 2026
054e0eb
Rollup merge of #155734 - qaijuang:cfg-select-doc-comment, r=Jonathan…
JonathanBrouwer Apr 25, 2026
1237cfc
Rollup merge of #155769 - Enselic:ping-enselic, r=Urgau
JonathanBrouwer Apr 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn parse_unstable<S: Stage>(
) -> impl IntoIterator<Item = Symbol> {
let mut res = Vec::new();

let Some(list) = args.list() else {
let Some(list) = args.as_list() else {
cx.emit_err(session_diagnostics::ExpectsFeatureList {
span: cx.attr_span,
name: symbol.to_ident_string(),
Expand Down
12 changes: 4 additions & 8 deletions compiler/rustc_attr_parsing/src/attributes/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,9 @@ pub fn parse_cfg<S: Stage>(
cx: &mut AcceptContext<'_, '_, S>,
args: &ArgParser,
) -> Option<CfgEntry> {
let ArgParser::List(list) = args else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
return None;
};
let list = cx.expect_list(args, cx.attr_span)?;

let Some(single) = list.single() else {
let Some(single) = list.as_single() else {
let target = cx.target;
let mut adcx = cx.adcx();
if list.is_empty() {
Expand Down Expand Up @@ -93,7 +89,7 @@ pub fn parse_cfg_entry<S: Stage>(
MetaItemOrLitParser::MetaItemParser(meta) => match meta.args() {
ArgParser::List(list) => match meta.path().word_sym() {
Some(sym::not) => {
let Some(single) = list.single() else {
let Some(single) = list.as_single() else {
return Err(cx.adcx().expected_single_argument(list.span, list.len()));
};
CfgEntry::Not(Box::new(parse_cfg_entry(cx, single)?), list.span)
Expand Down Expand Up @@ -136,7 +132,7 @@ fn parse_cfg_entry_version<S: Stage>(
meta_span: Span,
) -> Result<CfgEntry, ErrorGuaranteed> {
try_gate_cfg(sym::version, meta_span, cx.sess(), cx.features_option());
let Some(version) = list.single() else {
let Some(version) = list.as_single() else {
return Err(
cx.emit_err(session_diagnostics::ExpectedSingleVersionLiteral { span: list.span })
);
Expand Down
45 changes: 42 additions & 3 deletions compiler/rustc_attr_parsing/src/attributes/cfg_select.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use rustc_ast::token::Token;
use rustc_ast::token::{CommentKind, Token};
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::{AttrStyle, NodeId, token};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::Diagnostic;
use rustc_errors::{DiagDecorator, Diagnostic};
use rustc_feature::{AttributeTemplate, Features};
use rustc_hir::attrs::CfgEntry;
use rustc_hir::{AttrPath, Target};
use rustc_parse::exp;
use rustc_parse::parser::{Parser, Recovery};
use rustc_session::Session;
use rustc_session::lint::builtin::UNREACHABLE_CFG_SELECT_PREDICATES;
use rustc_session::lint::builtin::{UNREACHABLE_CFG_SELECT_PREDICATES, UNUSED_DOC_COMMENTS};
use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};

use crate::attributes::AttributeSafety;
Expand Down Expand Up @@ -78,12 +78,15 @@ pub fn parse_cfg_select(
let mut branches = CfgSelectBranches::default();

while p.token != token::Eof {
let doc_comment = eat_outer_doc_comments(p);

if p.eat_keyword(exp!(Underscore)) {
let underscore = p.prev_token;
p.expect(exp!(FatArrow)).map_err(|e| e.emit())?;

let tts = p.parse_delimited_token_tree().map_err(|e| e.emit())?;
let span = underscore.span.to(p.token.span);
lint_unused_doc_comment(p, doc_comment, lint_node_id);

match branches.wildcard {
None => branches.wildcard = Some((underscore, tts, span)),
Expand Down Expand Up @@ -123,6 +126,7 @@ pub fn parse_cfg_select(

let tts = p.parse_delimited_token_tree().map_err(|e| e.emit())?;
let span = cfg_span.to(p.token.span);
lint_unused_doc_comment(p, doc_comment, lint_node_id);

match branches.wildcard {
None => branches.reachable.push((cfg, tts, span)),
Expand All @@ -143,6 +147,41 @@ pub fn parse_cfg_select(
Ok(branches)
}

fn eat_outer_doc_comments(p: &mut Parser<'_>) -> Option<(Span, CommentKind)> {
let mut doc_comment: Option<(Span, CommentKind)> = None;

while let token::DocComment(comment_kind, AttrStyle::Outer, _) = p.token.kind {
let span = p.token.span;
doc_comment = Some(match doc_comment {
Some((prev_span, _)) => (prev_span.with_hi(span.hi()), comment_kind),
None => (span, comment_kind),
});
p.bump();
}

doc_comment
}

fn lint_unused_doc_comment(
p: &mut Parser<'_>,
doc_comment: Option<(Span, CommentKind)>,
lint_node_id: NodeId,
) {
let Some((span, comment_kind)) = doc_comment else { return };
let help = match comment_kind {
CommentKind::Line => "use `//` for a plain comment",
CommentKind::Block => "use `/* */` for a plain comment",
};
p.psess.buffer_lint(
UNUSED_DOC_COMMENTS,
span,
lint_node_id,
DiagDecorator(move |diag| {
diag.primary_message("unused doc comment").help(help);
}),
);
}

fn lint_unreachable(
p: &mut Parser<'_>,
predicates: impl Iterator<Item = CfgSelectPredicate>,
Expand Down
23 changes: 6 additions & 17 deletions compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
const TEMPLATE: AttributeTemplate = template!(List: &["size", "speed", "none"]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let single = cx.single_element_list(args, cx.attr_span)?;
let single = cx.expect_single_element_list(args, cx.attr_span)?;

let res = match single.meta_item().and_then(|i| i.path().word().map(|i| i.name)) {
Some(sym::size) => OptimizeAttr::Size,
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
const TEMPLATE: AttributeTemplate = template!(OneOf: &[sym::off, sym::on]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let arg = cx.single_element_list(args, cx.attr_span)?;
let arg = cx.expect_single_element_list(args, cx.attr_span)?;

let mut fail_incorrect_argument =
|span| cx.adcx().expected_specific_argument(span, &[sym::on, sym::off]);
Expand Down Expand Up @@ -371,8 +371,7 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
let used_by = match args {
ArgParser::NoArgs => UsedBy::Default,
ArgParser::List(list) => {
let Some(l) = list.single() else {
cx.adcx().expected_single_argument(list.span, list.len());
let Some(l) = cx.expect_single(list) else {
return;
};

Expand Down Expand Up @@ -463,9 +462,7 @@ fn parse_tf_attribute<S: Stage>(
args: &ArgParser,
) -> impl IntoIterator<Item = (Symbol, Span)> {
let mut features = Vec::new();
let ArgParser::List(list) = args else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
let Some(list) = cx.expect_list(args, cx.attr_span) else {
return features;
};
if list.is_empty() {
Expand Down Expand Up @@ -588,11 +585,7 @@ impl<S: Stage> SingleAttributeParser<S> for SanitizeParser {
]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let Some(list) = args.list() else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
return None;
};
let list = cx.expect_list(args, cx.attr_span)?;

let mut on_set = SanitizerSet::empty();
let mut off_set = SanitizerSet::empty();
Expand Down Expand Up @@ -719,11 +712,7 @@ impl<S: Stage> SingleAttributeParser<S> for PatchableFunctionEntryParser {
const TEMPLATE: AttributeTemplate = template!(List: &["prefix_nops = m, entry_nops = n"]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let Some(meta_item_list) = args.list() else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
return None;
};
let meta_item_list = cx.expect_list(args, cx.attr_span)?;

let mut prefix = None;
let mut entry = None;
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_attr_parsing/src/attributes/confusables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ impl<S: Stage> AttributeParser<S> for ConfusablesParser {
&[sym::rustc_confusables],
template!(List: &[r#""name1", "name2", ..."#]),
|this, cx, args| {
let Some(list) = args.list() else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
return;
};
let Some(list) = cx.expect_list(args, cx.attr_span) else { return };

if list.is_empty() {
cx.emit_err(EmptyConfusables { span: cx.attr_span });
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_attr_parsing/src/attributes/crate_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,7 @@ impl<S: Stage> CombineAttributeParser<S> for FeatureParser {
cx: &mut AcceptContext<'_, '_, S>,
args: &ArgParser,
) -> impl IntoIterator<Item = Self::Item> {
let ArgParser::List(list) = args else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
let Some(list) = cx.expect_list(args, cx.attr_span) else {
return Vec::new();
};

Expand Down Expand Up @@ -362,9 +360,7 @@ impl<S: Stage> CombineAttributeParser<S> for RegisterToolParser {
cx: &mut AcceptContext<'_, '_, S>,
args: &ArgParser,
) -> impl IntoIterator<Item = Self::Item> {
let ArgParser::List(list) = args else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
let Some(list) = cx.expect_list(args, cx.attr_span) else {
return Vec::new();
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<S: Stage> CombineAttributeParser<S> for DebuggerViualizerParser {
cx: &mut AcceptContext<'_, '_, S>,
args: &ArgParser,
) -> impl IntoIterator<Item = Self::Item> {
let single = cx.single_element_list(args, cx.attr_span)?;
let single = cx.expect_single_element_list(args, cx.attr_span)?;
let Some(mi) = single.meta_item() else {
cx.adcx().expected_name_value(single.span(), None);
return None;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ fn parse_directive_items<'p, S: Stage>(
}
(Mode::RustcOnUnimplemented, sym::on) => {
if is_root {
let items = or_malformed!(item.args().list()?);
let items = or_malformed!(item.args().as_list()?);
let mut iter = items.mixed();
let condition: &MetaItemOrLitParser = match iter.next() {
Some(c) => c,
Expand Down Expand Up @@ -554,7 +554,7 @@ fn parse_predicate(input: &MetaItemOrLitParser) -> Result<Predicate, InvalidOnCl
sym::any => Ok(Predicate::Any(parse_predicate_sequence(mis)?)),
sym::all => Ok(Predicate::All(parse_predicate_sequence(mis)?)),
sym::not => {
if let Some(single) = mis.single() {
if let Some(single) = mis.as_single() {
Ok(Predicate::Not(Box::new(parse_predicate(single)?)))
} else {
Err(InvalidOnClause::ExpectedOnePredInNot { span: mis.span })
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl DocParser {
self.attribute.no_crate_inject = Some(path.span())
}
Some(sym::attr) => {
let Some(list) = args.list() else {
let Some(list) = args.as_list() else {
// FIXME: remove this method once merged and uncomment the line below instead.
// cx.expected_list(cx.attr_span, args);
let span = cx.attr_span;
Expand Down Expand Up @@ -587,7 +587,7 @@ impl DocParser {
}),
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
Some(sym::test) => {
let Some(list) = args.list() else {
let Some(list) = args.as_list() else {
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
|dcx, level| DocTestTakesList.into_diag(dcx, level),
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_attr_parsing/src/attributes/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
match args {
ArgParser::NoArgs => Some(AttributeKind::Inline(InlineAttr::Hint, cx.attr_span)),
ArgParser::List(list) => {
let Some(l) = list.single() else {
cx.adcx().expected_single_argument(list.span, list.len());
return None;
};
let l = cx.expect_single(list)?;

match l.meta_item().and_then(|i| i.path().word_sym()) {
Some(sym::always) => {
Expand Down Expand Up @@ -78,10 +75,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcForceInlineParser {
let reason = match args {
ArgParser::NoArgs => None,
ArgParser::List(list) => {
let Some(l) = list.single() else {
cx.adcx().expected_single_argument(list.span, list.len());
return None;
};
let l = cx.expect_single(list)?;

let Some(reason) = l.lit().and_then(|i| i.kind.str()) else {
cx.adcx().expected_string_literal(l.span(), l.lit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl<S: Stage> SingleAttributeParser<S> for InstructionSetParser {
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
const POSSIBLE_SYMBOLS: &[Symbol] = &[sym::arm_a32, sym::arm_t32];
const POSSIBLE_ARM_SYMBOLS: &[Symbol] = &[sym::a32, sym::t32];
let maybe_meta_item = cx.single_element_list(args, cx.attr_span)?;
let maybe_meta_item = cx.expect_single_element_list(args, cx.attr_span)?;

let Some(meta_item) = maybe_meta_item.meta_item() else {
cx.adcx().expected_specific_argument(maybe_meta_item.span(), POSSIBLE_SYMBOLS);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/link_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl LinkParser {
cx.adcx().duplicate_key(item.span(), sym::cfg);
return true;
}
let Some(link_cfg) = cx.single_element_list(item.args(), item.span()) else {
let Some(link_cfg) = cx.expect_single_element_list(item.args(), item.span()) else {
return true;
};
if !features.link_cfg() {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<S: Stage> SingleAttributeParser<S> for MacroExportParser {
let local_inner_macros = match args {
ArgParser::NoArgs => false,
ArgParser::List(list) => {
let Some(l) = list.single() else {
let Some(l) = list.as_single() else {
cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS);
return None;
};
Expand Down Expand Up @@ -174,7 +174,7 @@ impl<S: Stage> SingleAttributeParser<S> for CollapseDebugInfoParser {
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::MacroDef)]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let single = cx.single_element_list(args, cx.attr_span)?;
let single = cx.expect_single_element_list(args, cx.attr_span)?;
let Some(mi) = single.meta_item() else {
cx.adcx().expected_not_literal(single.span());
return None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn parse_derive_like<S: Stage>(
args: &ArgParser,
trait_name_mandatory: bool,
) -> Option<(Option<Symbol>, ThinVec<Symbol>)> {
let Some(list) = args.list() else {
let Some(list) = args.as_list() else {
// For #[rustc_builtin_macro], it is permitted to leave out the trait name
if args.no_args().is_ok() && !trait_name_mandatory {
return Some((None, ThinVec::new()));
Expand Down Expand Up @@ -101,10 +101,7 @@ fn parse_derive_like<S: Stage>(
cx.adcx().expected_specific_argument(attrs.span(), &[sym::attributes]);
return None;
}
let Some(attr_list) = attr_list.args().list() else {
cx.adcx().expected_list(attrs.span(), attr_list.args());
return None;
};
let attr_list = cx.expect_list(attr_list.args(), attrs.span())?;

// Parse item in `attributes(...)` argument
for attr in attr_list.mixed() {
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_attr_parsing/src/attributes/prototype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ impl<S: Stage> SingleAttributeParser<S> for CustomMirParser {
const TEMPLATE: AttributeTemplate = template!(List: &[r#"dialect = "...", phase = "...""#]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let Some(list) = args.list() else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
return None;
};
let list = cx.expect_list(args, cx.attr_span)?;

let mut dialect = None;
let mut phase = None;
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_attr_parsing/src/attributes/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ impl<S: Stage> CombineAttributeParser<S> for ReprParser {
) -> impl IntoIterator<Item = Self::Item> {
let mut reprs = Vec::new();

let Some(list) = args.list() else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
let Some(list) = cx.expect_list(args, cx.attr_span) else {
return reprs;
};

Expand Down Expand Up @@ -197,7 +195,7 @@ fn parse_repr_align<S: Stage>(
) -> Option<ReprAttr> {
use AlignKind::*;

let Some(align) = list.single() else {
let Some(align) = list.as_single() else {
match align_kind {
Packed => {
cx.emit_err(session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
Expand Down Expand Up @@ -296,8 +294,7 @@ impl RustcAlignParser {
cx.adcx().expected_list(attr_span, args);
}
ArgParser::List(list) => {
let Some(align) = list.single() else {
cx.adcx().expected_single_argument(list.span, list.len());
let Some(align) = cx.expect_single(list) else {
return;
};

Expand Down
Loading
Loading