Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
72b6825
test `#[naked]` with `#[link_section = "..."]` on windows
folkertdev Mar 30, 2026
edad629
Remove `BuiltinLintDiag::ElidedLifetimesInPaths` variant
GuillaumeGomez Apr 6, 2026
e03e00f
Remove `BuiltinLintDiag::UnusedImports` variant
GuillaumeGomez Apr 6, 2026
12457f8
Remove `BuiltinLintDiag::NamedArgumentUsedPositionally` variant
GuillaumeGomez Apr 6, 2026
caeaf19
Remove `BuiltinLintDiag`
GuillaumeGomez Apr 6, 2026
aa9da4b
Hexagon inline asm: add reg_pair, vreg, vreg_pair, and qreg register …
androm3da Apr 2, 2026
574d877
Parenthesize block-like expressions in index base of pretty printer
aytey Mar 18, 2026
56f43b5
Parenthesize block-like expressions in call callee of pretty printer
aytey Apr 8, 2026
27e3d26
rename test
aytey Apr 8, 2026
1e8c6f0
Nooooo my workflow relied on programs using `niko` as an identifier
jdonszelmann Apr 6, 2026
fbdcd19
make `expected_literal` positive
jdonszelmann Apr 6, 2026
092f0ca
Clarify that `core::range::RangeInclusive` does not have special syntax
shepmaster Apr 8, 2026
eef4363
Clarify that `core::range::{Range,RangeFrom,RangeToInclusive}` do not…
shepmaster Apr 8, 2026
1d0d172
Rollup merge of #154912 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer
JonathanBrouwer Apr 8, 2026
b040d54
Rollup merge of #154598 - folkertdev:windows-naked-link-section, r=ma…
JonathanBrouwer Apr 8, 2026
3fb712c
Rollup merge of #154719 - androm3da:hexagon-inline-asm-register-class…
JonathanBrouwer Apr 8, 2026
8be4c46
Rollup merge of #154057 - aytey:fix-block-index-paren, r=fmease
JonathanBrouwer Apr 8, 2026
83e8133
Rollup merge of #154893 - jdonszelmann:expected-literal-positive, r=J…
JonathanBrouwer Apr 8, 2026
efa9224
Rollup merge of #155002 - shepmaster:clarify-new-range, r=tgross35
JonathanBrouwer Apr 8, 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
13 changes: 11 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,15 @@ impl<'a> State<'a> {
// In order to call a named field, needs parens: `(self.fun)()`
// But not for an unnamed field: `self.0()`
ast::ExprKind::Field(_, name) => !name.is_numeric(),
_ => func_fixup.precedence(func) < ExprPrecedence::Unambiguous,
// Block-like expressions (block, match, if, loop, ...) never
// parse as the callee of a call, regardless of context: the
// closing brace ends the expression and `(args)` becomes a
// separate tuple. Parenthesize them so the call survives a
// pretty-print round trip.
_ => {
func_fixup.precedence(func) < ExprPrecedence::Unambiguous
|| classify::expr_is_complete(func)
}
};

self.print_expr_cond_paren(func, needs_paren, func_fixup);
Expand Down Expand Up @@ -677,7 +685,8 @@ impl<'a> State<'a> {
let expr_fixup = fixup.leftmost_subexpression_with_operator(true);
self.print_expr_cond_paren(
expr,
expr_fixup.precedence(expr) < ExprPrecedence::Unambiguous,
expr_fixup.precedence(expr) < ExprPrecedence::Unambiguous
|| classify::expr_is_complete(expr),
expr_fixup,
);
self.word("[");
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/deprecation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecatedParser {
ArgParser::List(list) => {
for param in list.mixed() {
let Some(param) = param.meta_item() else {
cx.adcx().unexpected_literal(param.span());
cx.adcx().expected_not_literal(param.span());
return None;
};

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 @@ -93,7 +93,7 @@ impl<S: Stage> CombineAttributeParser<S> for LinkParser {
let mut import_name_type = None;
for item in items.mixed() {
let Some(item) = item.meta_item() else {
cx.adcx().unexpected_literal(item.span());
cx.adcx().expected_not_literal(item.span());
continue;
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl<S: Stage> SingleAttributeParser<S> for CollapseDebugInfoParser {
return None;
};
let Some(mi) = single.meta_item() else {
cx.adcx().unexpected_literal(single.span());
cx.adcx().expected_not_literal(single.span());
return None;
};
if let Err(err) = mi.args().no_args() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn parse_derive_like<S: Stage>(
return None;
};
let Some(trait_attr) = trait_attr.meta_item() else {
cx.adcx().unexpected_literal(trait_attr.span());
cx.adcx().expected_not_literal(trait_attr.span());
return None;
};
let Some(trait_ident) = trait_attr.path().word() else {
Expand All @@ -98,7 +98,7 @@ fn parse_derive_like<S: Stage>(
let mut attributes = ThinVec::new();
if let Some(attrs) = items.next() {
let Some(attr_list) = attrs.meta_item() else {
cx.adcx().unexpected_literal(attrs.span());
cx.adcx().expected_not_literal(attrs.span());
return None;
};
if !attr_list.path().word_is(sym::attributes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ impl<S: Stage> CombineAttributeParser<S> for RustcLayoutParser {
let mut result = Vec::new();
for item in items.mixed() {
let Some(arg) = item.meta_item() else {
cx.adcx().unexpected_literal(item.span());
cx.adcx().expected_not_literal(item.span());
continue;
};
let Some(ident) = arg.ident() else {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ pub(crate) fn parse_stability<S: Stage>(
for param in list.mixed() {
let param_span = param.span();
let Some(param) = param.meta_item() else {
cx.adcx().unexpected_literal(param.span());
cx.adcx().expected_not_literal(param.span());
return None;
};

Expand Down Expand Up @@ -390,7 +390,7 @@ pub(crate) fn parse_unstability<S: Stage>(

for param in list.mixed() {
let Some(param) = param.meta_item() else {
cx.adcx().unexpected_literal(param.span());
cx.adcx().expected_not_literal(param.span());
return None;
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/test_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<S: Stage> SingleAttributeParser<S> for TestRunnerParser {
};

let Some(meta) = single.meta_item() else {
cx.adcx().unexpected_literal(single.span());
cx.adcx().expected_not_literal(single.span());
return None;
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcSkipDuringMethodDispatchParser
}
for arg in args.mixed() {
let Some(arg) = arg.meta_item() else {
cx.adcx().unexpected_literal(arg.span());
cx.adcx().expected_not_literal(arg.span());
continue;
};
if let Err(span) = arg.args().no_args() {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ where

/// An error that should be emitted when a [`MetaItemOrLitParser`](crate::parser::MetaItemOrLitParser)
/// was expected *not* to be a literal, but instead a meta item.
pub(crate) fn unexpected_literal(&mut self, span: Span) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::UnexpectedLiteral)
pub(crate) fn expected_not_literal(&mut self, span: Span) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedNotLiteral)
}

pub(crate) fn expected_single_argument(&mut self, span: Span) -> ErrorGuaranteed {
Expand Down
18 changes: 3 additions & 15 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_hir::attrs::AttributeKind;
use rustc_hir::lints::AttributeLintKind;
use rustc_hir::{AttrArgs, AttrItem, AttrPath, Attribute, HashIgnoredAttrId, Target};
use rustc_session::Session;
use rustc_session::lint::{BuiltinLintDiag, LintId};
use rustc_session::lint::LintId;
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym};

use crate::context::{AcceptContext, FinalizeContext, FinalizeFn, SharedContext, Stage};
Expand Down Expand Up @@ -124,14 +124,7 @@ impl<'sess> AttributeParser<'sess, Early> {
target,
OmitDoc::Skip,
std::convert::identity,
|lint_id, span, kind| {
sess.psess.buffer_lint(
lint_id.lint,
span,
target_node_id,
BuiltinLintDiag::AttributeLint(kind),
)
},
|lint_id, span, kind| sess.psess.buffer_lint(lint_id.lint, span, target_node_id, kind),
)
}

Expand Down Expand Up @@ -230,12 +223,7 @@ impl<'sess> AttributeParser<'sess, Early> {
let mut parser =
Self { features, tools: None, parse_only: None, sess, stage: Early { emit_errors } };
let mut emit_lint = |lint_id: LintId, span: Span, kind: AttributeLintKind| {
sess.psess.buffer_lint(
lint_id.lint,
span,
target_node_id,
BuiltinLintDiag::AttributeLint(kind),
)
sess.psess.buffer_lint(lint_id.lint, span, target_node_id, kind)
};
if let Some(safety) = attr_safety {
parser.check_attribute_safety(&attr_path, inner_span, safety, &mut emit_lint)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ pub(crate) enum AttributeParseErrorReason<'a> {
},
ExpectedNameValueOrNoArgs,
ExpectedNonEmptyStringLiteral,
UnexpectedLiteral,
ExpectedNotLiteral,
ExpectedNameValue(Option<Symbol>),
DuplicateKey(Symbol),
ExpectedSpecificArgument {
Expand Down Expand Up @@ -799,7 +799,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError<'_> {
diag.span_label(self.span, format!("found `{key}` used as a key more than once"));
diag.code(E0538);
}
AttributeParseErrorReason::UnexpectedLiteral => {
AttributeParseErrorReason::ExpectedNotLiteral => {
diag.span_label(self.span, "didn't expect a literal here");
diag.code(E0565);
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_attr_parsing/src/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use rustc_hir::AttrPath;
use rustc_hir::lints::AttributeLintKind;
use rustc_parse::parse_in;
use rustc_session::errors::report_lit_error;
use rustc_session::lint::BuiltinLintDiag;
use rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT;
use rustc_session::parse::ParseSess;
use rustc_span::{Span, Symbol, sym};
Expand Down Expand Up @@ -187,11 +186,11 @@ pub fn emit_malformed_attribute(
ILL_FORMED_ATTRIBUTE_INPUT,
span,
ast::CRATE_NODE_ID,
BuiltinLintDiag::AttributeLint(AttributeLintKind::IllFormedAttributeInput {
AttributeLintKind::IllFormedAttributeInput {
suggestions: suggestions.clone(),
docs: template.docs,
help: None,
}),
},
);
} else {
suggestions.sort();
Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_builtin_macros/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,3 +1141,22 @@ pub(crate) struct EiiMacroExpectedMaxOneArgument {
pub span: Span,
pub name: String,
}

#[derive(Diagnostic)]
#[diag("named argument `{$named_arg_name}` is not used by name")]
pub(crate) struct NamedArgumentUsedPositionally {
#[label("this named argument is referred to by position in formatting string")]
pub named_arg_sp: Span,
#[label("this formatting argument uses named argument `{$named_arg_name}` by position")]
pub position_label_sp: Option<Span>,
#[suggestion(
"use the named argument by name to avoid ambiguity",
style = "verbose",
code = "{name}",
applicability = "maybe-incorrect"
)]
pub suggestion: Option<Span>,

pub name: String,
pub named_arg_name: String,
}
47 changes: 36 additions & 11 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use rustc_ast::{
};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{
Applicability, BufferedEarlyLint, Diag, MultiSpan, PResult, SingleLabelManySpans, listify,
pluralize,
Applicability, BufferedEarlyLint, DecorateDiagCompat, Diag, Diagnostic, MultiSpan, PResult,
SingleLabelManySpans, listify, pluralize,
};
use rustc_expand::base::*;
use rustc_lint_defs::LintId;
use rustc_lint_defs::builtin::NAMED_ARGUMENTS_USED_POSITIONALLY;
use rustc_lint_defs::{BuiltinLintDiag, LintId};
use rustc_parse::exp;
use rustc_parse_format as parse;
use rustc_span::{BytePos, ErrorGuaranteed, Ident, InnerSpan, Span, Symbol};
Expand Down Expand Up @@ -611,14 +611,39 @@ fn make_format_args(
span: Some(arg_name.span.into()),
node_id: rustc_ast::CRATE_NODE_ID,
lint_id: LintId::of(NAMED_ARGUMENTS_USED_POSITIONALLY),
diagnostic: BuiltinLintDiag::NamedArgumentUsedPositionally {
position_sp_to_replace,
position_sp_for_msg,
named_arg_sp: arg_name.span,
named_arg_name: arg_name.name.to_string(),
is_formatting_arg: matches!(used_as, Width | Precision),
}
.into(),
diagnostic: DecorateDiagCompat::Dynamic(Box::new(move |dcx, level, sess| {
let (suggestion, name) =
if let Some(positional_arg_to_replace) = position_sp_to_replace {
let mut name = arg_name.name.to_string();
let is_formatting_arg = matches!(used_as, Width | Precision);
if is_formatting_arg {
name.push('$')
};
let span_to_replace = if let Ok(positional_arg_content) = sess
.downcast_ref::<rustc_session::Session>()
.expect("expected a `Session`")
.source_map()
.span_to_snippet(positional_arg_to_replace)
&& positional_arg_content.starts_with(':')
{
positional_arg_to_replace.shrink_to_lo()
} else {
positional_arg_to_replace
};
(Some(span_to_replace), name)
} else {
(None, String::new())
};

errors::NamedArgumentUsedPositionally {
named_arg_sp: arg_name.span,
position_label_sp: position_sp_for_msg,
suggestion,
name,
named_arg_name: arg_name.name.to_string(),
}
.into_diag(dcx, level)
})),
});
}
}
Expand Down
16 changes: 16 additions & 0 deletions compiler/rustc_codegen_gcc/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,15 @@ fn reg_class_to_gcc(reg_class: InlineAsmRegClass) -> &'static str {
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => "r",
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg_pair) => "r",
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
unreachable!("clobber-only")
}
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::vreg) => "v",
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::vreg_pair) => "v",
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::qreg) => {
unreachable!("clobber-only")
}
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => "r",
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => "f",
InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg) => "r",
Expand Down Expand Up @@ -779,9 +785,19 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
cx.type_vector(cx.type_i64(), 2)
}
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => cx.type_i32(),
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg_pair) => cx.type_i64(),
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
unreachable!("clobber-only")
}
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::vreg) => {
cx.type_vector(cx.type_i32(), 16)
}
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::vreg_pair) => {
cx.type_vector(cx.type_i32(), 32)
}
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::qreg) => {
unreachable!("clobber-only")
}
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => cx.type_i32(),
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => cx.type_f32(),
InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg) => cx.type_i32(),
Expand Down
Loading
Loading