Skip to content

Commit eb9d3ca

Browse files
committed
Auto merge of #154253 - JonathanBrouwer:rollup-LLZUsz2, r=JonathanBrouwer
Rollup of 13 pull requests Successful merges: - #154241 (`rust-analyzer` subtree update) - #153686 (`std`: include `dlmalloc` for all non-wasi Wasm targets) - #154105 (bootstrap: Pass `--features=rustc` to rustc_transmute) - #153069 ([BPF] add target feature allows-misaligned-mem-access) - #154085 (Parenthesize or-patterns in prefix pattern positions in pretty printer) - #154191 (refactor RangeFromIter overflow-checks impl) - #154207 (Refactor query loading) - #153540 (drop derive helpers during attribute parsing) - #154140 (Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.) - #154161 (On E0277 tweak help when single type impls traits) - #154218 (interpret/validity: remove unreachable error kind) - #154225 (diagnostics: avoid ICE in confusable_method_name for associated functions) - #154228 (Improve inline assembly error messages)
2 parents 13e2aba + 1448ab9 commit eb9d3ca

166 files changed

Lines changed: 3935 additions & 1594 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::hash_map::Entry;
2-
use std::fmt::Write;
32

43
use rustc_ast::*;
54
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
@@ -124,13 +123,9 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
124123
self.dcx().emit_err(ClobberAbiNotSupported { abi_span: *abi_span });
125124
}
126125
Err(supported_abis) => {
127-
let mut abis = format!("`{}`", supported_abis[0]);
128-
for m in &supported_abis[1..] {
129-
let _ = write!(abis, ", `{m}`");
130-
}
131126
self.dcx().emit_err(InvalidAbiClobberAbi {
132127
abi_span: *abi_span,
133-
supported_abis: abis,
128+
supported_abis: supported_abis.to_vec().into(),
134129
});
135130
}
136131
}
@@ -164,15 +159,12 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
164159
asm::InlineAsmRegOrRegClass::RegClass(if let Some(asm_arch) = asm_arch {
165160
asm::InlineAsmRegClass::parse(asm_arch, reg_class).unwrap_or_else(
166161
|supported_register_classes| {
167-
let mut register_classes =
168-
format!("`{}`", supported_register_classes[0]);
169-
for m in &supported_register_classes[1..] {
170-
let _ = write!(register_classes, ", `{m}`");
171-
}
172162
self.dcx().emit_err(InvalidRegisterClass {
173163
op_span: *op_sp,
174164
reg_class,
175-
supported_register_classes: register_classes,
165+
supported_register_classes: supported_register_classes
166+
.to_vec()
167+
.into(),
176168
});
177169
asm::InlineAsmRegClass::Err
178170
},
@@ -272,23 +264,20 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
272264
}
273265
let valid_modifiers = class.valid_modifiers(asm_arch.unwrap());
274266
if !valid_modifiers.contains(&modifier) {
275-
let sub = if !valid_modifiers.is_empty() {
276-
let mut mods = format!("`{}`", valid_modifiers[0]);
277-
for m in &valid_modifiers[1..] {
278-
let _ = write!(mods, ", `{m}`");
279-
}
280-
InvalidAsmTemplateModifierRegClassSub::SupportModifier {
267+
let sub = if valid_modifiers.is_empty() {
268+
InvalidAsmTemplateModifierRegClassSub::DoesNotSupportModifier {
281269
class_name: class.name(),
282-
modifiers: mods,
283270
}
284271
} else {
285-
InvalidAsmTemplateModifierRegClassSub::DoesNotSupportModifier {
272+
InvalidAsmTemplateModifierRegClassSub::SupportModifier {
286273
class_name: class.name(),
274+
modifiers: valid_modifiers.to_vec().into(),
287275
}
288276
};
289277
self.dcx().emit_err(InvalidAsmTemplateModifierRegClass {
290278
placeholder_span,
291279
op_span: op_sp,
280+
modifier: modifier.to_string(),
292281
sub,
293282
});
294283
}

compiler/rustc_ast_lowering/src/errors.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use rustc_errors::DiagArgFromDisplay;
21
use rustc_errors::codes::*;
2+
use rustc_errors::{DiagArgFromDisplay, DiagSymbolList};
33
use rustc_macros::{Diagnostic, Subdiagnostic};
44
use rustc_span::{Ident, Span, Symbol};
55

@@ -191,10 +191,10 @@ pub(crate) struct ClobberAbiNotSupported {
191191
#[derive(Diagnostic)]
192192
#[note("the following ABIs are supported on this target: {$supported_abis}")]
193193
#[diag("invalid ABI for `clobber_abi`")]
194-
pub(crate) struct InvalidAbiClobberAbi {
194+
pub(crate) struct InvalidAbiClobberAbi<'a> {
195195
#[primary_span]
196196
pub abi_span: Span,
197-
pub supported_abis: String,
197+
pub supported_abis: DiagSymbolList<&'a str>,
198198
}
199199

200200
#[derive(Diagnostic)]
@@ -215,17 +215,18 @@ pub(crate) struct InvalidRegisterClass {
215215
#[primary_span]
216216
pub op_span: Span,
217217
pub reg_class: Symbol,
218-
pub supported_register_classes: String,
218+
pub supported_register_classes: DiagSymbolList<Symbol>,
219219
}
220220

221221
#[derive(Diagnostic)]
222-
#[diag("invalid asm template modifier for this register class")]
222+
#[diag("invalid asm template modifier `{$modifier}` for this register class")]
223223
pub(crate) struct InvalidAsmTemplateModifierRegClass {
224224
#[primary_span]
225225
#[label("template modifier")]
226226
pub placeholder_span: Span,
227227
#[label("argument")]
228228
pub op_span: Span,
229+
pub modifier: String,
229230
#[subdiagnostic]
230231
pub sub: InvalidAsmTemplateModifierRegClassSub,
231232
}
@@ -235,7 +236,7 @@ pub(crate) enum InvalidAsmTemplateModifierRegClassSub {
235236
#[note(
236237
"the `{$class_name}` register class supports the following template modifiers: {$modifiers}"
237238
)]
238-
SupportModifier { class_name: Symbol, modifiers: String },
239+
SupportModifier { class_name: Symbol, modifiers: DiagSymbolList<char> },
239240
#[note("the `{$class_name}` register class does not support template modifiers")]
240241
DoesNotSupportModifier { class_name: Symbol },
241242
}

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,23 @@ impl<'a> State<'a> {
17861786
}
17871787
}
17881788

1789+
/// Print a pattern, parenthesizing it if it is an or-pattern (`A | B`).
1790+
///
1791+
/// Or-patterns have the lowest precedence among patterns, so they need
1792+
/// parentheses when nested inside `@` bindings, `&` references, or `box`
1793+
/// patterns — otherwise `x @ A | B` parses as `(x @ A) | B`, `&A | B`
1794+
/// parses as `(&A) | B`, etc.
1795+
fn print_pat_paren_if_or(&mut self, pat: &ast::Pat) {
1796+
let needs_paren = matches!(pat.kind, PatKind::Or(..));
1797+
if needs_paren {
1798+
self.popen();
1799+
}
1800+
self.print_pat(pat);
1801+
if needs_paren {
1802+
self.pclose();
1803+
}
1804+
}
1805+
17891806
fn print_pat(&mut self, pat: &ast::Pat) {
17901807
self.maybe_print_comment(pat.span.lo());
17911808
self.ann.pre(self, AnnNode::Pat(pat));
@@ -1813,7 +1830,7 @@ impl<'a> State<'a> {
18131830
if let Some(p) = sub {
18141831
self.space();
18151832
self.word_space("@");
1816-
self.print_pat(p);
1833+
self.print_pat_paren_if_or(p);
18171834
}
18181835
}
18191836
PatKind::TupleStruct(qself, path, elts) => {
@@ -1885,7 +1902,7 @@ impl<'a> State<'a> {
18851902
}
18861903
PatKind::Box(inner) => {
18871904
self.word("box ");
1888-
self.print_pat(inner);
1905+
self.print_pat_paren_if_or(inner);
18891906
}
18901907
PatKind::Deref(inner) => {
18911908
self.word("deref!");
@@ -1909,7 +1926,7 @@ impl<'a> State<'a> {
19091926
self.print_pat(inner);
19101927
self.pclose();
19111928
} else {
1912-
self.print_pat(inner);
1929+
self.print_pat_paren_if_or(inner);
19131930
}
19141931
}
19151932
PatKind::Expr(e) => self.print_expr(e, FixupContext::default()),
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use rustc_errors::MultiSpan;
2+
use rustc_macros::{Diagnostic, Subdiagnostic};
3+
use rustc_span::{Span, Symbol};
4+
5+
#[derive(Diagnostic)]
6+
#[diag("`{$name}` attribute cannot be used at crate level")]
7+
pub(crate) struct InvalidAttrAtCrateLevel {
8+
#[primary_span]
9+
pub span: Span,
10+
#[suggestion(
11+
"perhaps you meant to use an outer attribute",
12+
code = "#[",
13+
applicability = "machine-applicable",
14+
style = "verbose"
15+
)]
16+
pub pound_to_opening_bracket: Span,
17+
pub name: Symbol,
18+
#[subdiagnostic]
19+
pub item: Option<ItemFollowingInnerAttr>,
20+
}
21+
22+
#[derive(Clone, Copy, Subdiagnostic)]
23+
#[label("the inner attribute doesn't annotate this item")]
24+
pub(crate) struct ItemFollowingInnerAttr {
25+
#[primary_span]
26+
pub span: Span,
27+
}
28+
29+
#[derive(Diagnostic)]
30+
#[diag("most attributes are not supported in `where` clauses")]
31+
#[help("only `#[cfg]` and `#[cfg_attr]` are supported")]
32+
pub(crate) struct UnsupportedAttributesInWhere {
33+
#[primary_span]
34+
pub span: MultiSpan,
35+
}

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
269269
mut emit_lint: impl FnMut(LintId, Span, AttributeLintKind),
270270
) -> Vec<Attribute> {
271271
let mut attributes = Vec::new();
272+
// We store the attributes we intend to discard at the end of this function in order to
273+
// check they are applied to the right target and error out if necessary. In practice, we
274+
// end up dropping only derive attributes and derive helpers, both being fully processed
275+
// at macro expansion.
276+
let mut dropped_attributes = Vec::new();
272277
let mut attr_paths: Vec<RefPathParser<'_>> = Vec::new();
273278
let mut early_parsed_state = EarlyParsedState::default();
274279

@@ -304,7 +309,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
304309
kind: DocFragmentKind::Sugared(*comment_kind),
305310
span: attr_span,
306311
comment: *symbol,
307-
}))
312+
}));
308313
}
309314
ast::AttrKind::Normal(n) => {
310315
attr_paths.push(PathParser(&n.item.path));
@@ -393,29 +398,33 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
393398
Self::check_target(&accept.allowed_targets, target, &mut cx);
394399
}
395400
} else {
396-
// If we're here, we must be compiling a tool attribute... Or someone
397-
// forgot to parse their fancy new attribute. Let's warn them in any case.
398-
// If you are that person, and you really think your attribute should
399-
// remain unparsed, carefully read the documentation in this module and if
400-
// you still think so you can add an exception to this assertion.
401-
402-
// FIXME(jdonszelmann): convert other attributes, and check with this that
403-
// we caught em all
404-
// const FIXME_TEMPORARY_ATTR_ALLOWLIST: &[Symbol] = &[sym::cfg];
405-
// assert!(
406-
// self.tools.contains(&parts[0]) || true,
407-
// // || FIXME_TEMPORARY_ATTR_ALLOWLIST.contains(&parts[0]),
408-
// "attribute {path} wasn't parsed and isn't a know tool attribute",
409-
// );
410-
411-
attributes.push(Attribute::Unparsed(Box::new(AttrItem {
401+
let attr = AttrItem {
412402
path: attr_path.clone(),
413403
args: self
414404
.lower_attr_args(n.item.args.unparsed_ref().unwrap(), lower_span),
415405
id: HashIgnoredAttrId { attr_id: attr.id },
416406
style: attr.style,
417407
span: attr_span,
418-
})));
408+
};
409+
410+
if !matches!(self.stage.should_emit(), ShouldEmit::Nothing)
411+
&& target == Target::Crate
412+
{
413+
self.check_invalid_crate_level_attr_item(&attr, n.item.span());
414+
}
415+
416+
let attr = Attribute::Unparsed(Box::new(attr));
417+
418+
if self.tools.contains(&parts[0])
419+
// FIXME: this can be removed once #152369 has been merged.
420+
// https://github.com/rust-lang/rust/pull/152369
421+
|| [sym::allow, sym::deny, sym::expect, sym::forbid, sym::warn]
422+
.contains(&parts[0])
423+
{
424+
attributes.push(attr);
425+
} else {
426+
dropped_attributes.push(attr);
427+
}
419428
}
420429
}
421430
}
@@ -431,6 +440,12 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
431440
}
432441
}
433442

443+
if !matches!(self.stage.should_emit(), ShouldEmit::Nothing)
444+
&& target == Target::WherePredicate
445+
{
446+
self.check_invalid_where_predicate_attrs(attributes.iter().chain(&dropped_attributes));
447+
}
448+
434449
attributes
435450
}
436451

compiler/rustc_attr_parsing/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
// tidy-alphabetical-start
8080
#![feature(decl_macro)]
8181
#![feature(iter_intersperse)]
82+
#![feature(try_blocks)]
8283
#![recursion_limit = "256"]
8384
// tidy-alphabetical-end
8485

@@ -99,6 +100,7 @@ mod interface;
99100
pub mod parser;
100101

101102
mod early_parsed;
103+
mod errors;
102104
mod safety;
103105
mod session_diagnostics;
104106
mod target_checking;

0 commit comments

Comments
 (0)