Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
9b6afcf
Fix indent for convert_closure_to_fn
A4-Tacks Sep 2, 2025
9bc8e4e
Add applicable on LetExpr for unwrap_tuple
A4-Tacks Sep 3, 2025
293e8d3
Fix not applicable on empty struct for no_such_field
A4-Tacks Sep 5, 2025
04b232a
Add wrap multiple attr for wrap_unwrap_cfg_attr
A4-Tacks Sep 7, 2025
2b3e319
Add nested lifetime support for add_lifetime_to_type
A4-Tacks Sep 8, 2025
5cd99fb
Add fixes for non_exhaustive_let diagnostic
A4-Tacks Sep 29, 2025
c55a224
Support unmap macro expansion
A4-Tacks Oct 26, 2025
440cb96
Support WhileExpr and ForExpr for add_label_to_loop
A4-Tacks Nov 7, 2025
f4334bb
stdx indent and dedent utils
A4-Tacks Dec 23, 2025
ad4e1c2
Fix postfix completion indentation compensation
A4-Tacks Dec 23, 2025
430468f
Fix tuple struct pat expected type
A4-Tacks Dec 25, 2025
e04b950
change test_name placeholder to executable_arg
dfireBird Jan 3, 2026
b21e115
Add a test for parsing BuildData and RunnableData json
cormacrelf Jan 9, 2026
557df27
Privatise some fields and structs in project_json
cormacrelf Jan 8, 2026
b801b88
Add unknown runnable kind for forwards compatibility
cormacrelf Jan 8, 2026
f8455e2
A comment to help ProjectJsonData stay backwards-compatible
cormacrelf Jan 8, 2026
ff365fd
Refactor the runnable_args implementation to be more compact
cormacrelf Jan 9, 2026
91819d0
Restore a deleted comment that was quite informative
cormacrelf Jan 8, 2026
f8d046d
Support more runnable kinds for project json
cormacrelf Jan 9, 2026
8ec0c96
Add partial selection for merge_imports
A4-Tacks Aug 29, 2025
529c83d
Add applicable on let-else branch for unwrap_block
A4-Tacks Jan 15, 2026
f62b2f3
[BPF] add target feature allows-misaligned-mem-access
clairechingching Feb 23, 2026
8788034
feat: complete block .let in closure expression
A4-Tacks Mar 5, 2026
835c745
internal: shortcuit simple current parameter
A4-Tacks Mar 6, 2026
923582c
fix: add ident_pat qualifier to fully fn param
A4-Tacks Mar 6, 2026
80fa2b5
feat: offer on let-expr for inline_local_variable
A4-Tacks Mar 7, 2026
901cb4c
fix: implement ir_print debug for next-solver predicate types
Albab-Hasan Mar 7, 2026
e4e8ae7
fix: qualify NormalizesTo and CoercePredicate in ir_print debug output
Albab-Hasan Mar 8, 2026
0adea80
Fix other predicate for replace_is_method_with_if_let_method
A4-Tacks Mar 9, 2026
005a1ed
internal: Fix test_loading_rust_analyzer when rust-project.json is pr…
Wilfred Mar 10, 2026
e108da9
`std`: include `dlmalloc` for all non-wasi Wasm targets
Twey Mar 11, 2026
e2923eb
`std`: don't depend on `dlmalloc` when `cfg(unix)`
Twey Mar 11, 2026
201bbb3
fix: offer on const like path-expr for 'extract_variable'
A4-Tacks Mar 13, 2026
5e62d4f
Bump undici from 6.21.3 to 6.24.1 in /editors/code
dependabot[bot] Mar 14, 2026
c34e7ff
Migrate 'convert_named_struct_to_tuple_struct' assist
A4-Tacks Mar 14, 2026
31f31ab
Fix overlap edit on record to tuple assist uses self
A4-Tacks Mar 11, 2026
4aa2d6f
Fix field ref in macro for 'convert_tuple_struct_to_named_struct'
A4-Tacks Mar 14, 2026
77a2014
Fix overlap edit on tuple to record assist expr uses self
A4-Tacks Mar 14, 2026
ed15a20
fix: fill match arms on last comma and empty expr
A4-Tacks Mar 15, 2026
1bc2c44
fix: remove empty angle brackets in inline type alias code assist.
80avin Mar 8, 2026
8dba85c
update wrap_expr in utils ref_field_expr and update corresponding han…
Shourya742 Mar 16, 2026
7f3bc0b
update wrap_block to accept SyntaxFactory and correspondingly update …
Shourya742 Mar 16, 2026
d6b3207
convert_param_list_to_arg_list accept syntaxFactory and update the co…
Shourya742 Mar 16, 2026
f2bc624
update convert_param_list_to_arg_list to get ArgList via make
Shourya742 Mar 16, 2026
cc02838
add syntaxFactory to tt_from_syntax and update corresponding handlers
Shourya742 Mar 16, 2026
4e50d13
remove invert_boolean_expression_legacy
Shourya742 Mar 16, 2026
f5836b5
make insert_attribute accept syntaxFactory
Shourya742 Mar 16, 2026
fc73d18
Merge pull request #21815 from rust-lang/dependabot/npm_and_yarn/edit…
lnicola Mar 16, 2026
f01a047
Merge pull request #21784 from 80avin/fix-inline-type-assist
A4-Tacks Mar 16, 2026
637cc71
Don't trigger GC on slow tests
ChayimFriedman2 Mar 16, 2026
1b48210
Merge pull request #21827 from ChayimFriedman2/multiprocess-slow-tests
Veykril Mar 16, 2026
b7bc962
fix: SCIP generation should prime caches in parallel
Wilfred Mar 13, 2026
5fe6600
add mappings for constructors
Shourya742 Mar 16, 2026
f926929
Merge pull request #21828 from Wilfred/parallel_prime_caches_scip
ChayimFriedman2 Mar 16, 2026
60207de
small clean-up
ada4a Mar 12, 2026
607d64a
Merge pull request #21829 from ada4a/push-zwprmlkyptmx
lnicola Mar 16, 2026
1cd4c2a
Merge pull request #21826 from Shourya742/2026-02-03-migrate-utils-to…
A4-Tacks Mar 16, 2026
0d35d9c
add mapping to struct_ syntax_factory constructor method
Shourya742 Mar 17, 2026
7c21a38
add mapping to enum_ syntax_factory constructor method
Shourya742 Mar 17, 2026
ea2bebd
add mapping to unnamed_param syntax_factory constructor method
Shourya742 Mar 17, 2026
9c6a66d
add mapping to ty_fn_ptr syntax_factory constructor method
Shourya742 Mar 17, 2026
597f11b
add mapping to where_pred syntax_factory constructor method
Shourya742 Mar 17, 2026
16949c5
add mapping to where_clause syntax_factory constructor method
Shourya742 Mar 17, 2026
3e9dc4e
add mapping to impl_trait_type syntax_factory constructor method
Shourya742 Mar 17, 2026
f3f1448
add mapping to generic_ty_path_segment syntax_factory constructor method
Shourya742 Mar 17, 2026
4ed8442
add mapping to tail_only_block_expr syntax_factory constructor method
Shourya742 Mar 17, 2026
7a5d26d
add mapping to expr_bin_op syntax_factory constructor method
Shourya742 Mar 17, 2026
01716dd
add mapping to use_ syntax_factory constructor method
Shourya742 Mar 17, 2026
ec8ab85
add mapping to use_tree syntax_factory constructor method
Shourya742 Mar 17, 2026
257bcc4
remove redundant enum_ constructor
Shourya742 Mar 17, 2026
7c93774
internal: Add codecov badge
Wilfred Mar 10, 2026
be963fb
Merge pull request #21796 from Wilfred/codecov_badge
lnicola Mar 17, 2026
9d9f68f
fix: .let no complete semicolon before semicolon
A4-Tacks Mar 18, 2026
b0d4f7a
Migrate convert_from_to_tryfrom assist to SyntaxEditor API
sengmonkham Mar 18, 2026
e15897f
Parenthesize or-patterns in prefix pattern positions in pretty printer
aytey Mar 19, 2026
1a1a0d2
Update Clippy test expectations for or-pattern parenthesization
aytey Mar 19, 2026
f9752e2
bootstrap: Pass `--features=rustc` to rustc_transmute
jyn514 Mar 19, 2026
191969d
remove outdated TODO
ada4a Mar 19, 2026
3e35ce4
Merge pull request #21845 from ada4a/push-yoxkrkvpupkl
ChayimFriedman2 Mar 19, 2026
e5c44d0
Merge pull request #21843 from sengmonkham/gsoc/migrate-convert-from-…
ChayimFriedman2 Mar 20, 2026
54819a1
migrate qualify_path to use SyntaxEditor and SyntaxFactory
Shourya742 Mar 20, 2026
4307825
remove direct make usage in add_label_to_loop via syntaxFactory
Shourya742 Mar 20, 2026
61be42c
migrate desugar_try_expr to use syntax editor and syntax Factory
Shourya742 Mar 20, 2026
345a80f
remove use make directly from extract_variable assist
Shourya742 Mar 20, 2026
6c82469
migrate qualify_method_call to use syntaxEditor and SyntaxFactory
Shourya742 Mar 20, 2026
eabc019
remove mapping for expr underscore in syntax factory constructor
Shourya742 Mar 20, 2026
09197c9
Merge pull request #21839 from A4-Tacks/dedup-comp-postfix-let-semi
ChayimFriedman2 Mar 20, 2026
fb84963
Merge pull request #21848 from Shourya742/2026-03-20-remove-mapping-e…
ChayimFriedman2 Mar 20, 2026
03ea352
Merge pull request #21779 from Albab-Hasan/fix/next-solver-ir-print
ChayimFriedman2 Mar 20, 2026
4a18159
Merge pull request #21775 from A4-Tacks/inline-let-expr
ChayimFriedman2 Mar 20, 2026
b161e51
Merge pull request #20614 from A4-Tacks/diag-not-apply-empty-struct-n…
ChayimFriedman2 Mar 20, 2026
b015909
Merge pull request #21756 from A4-Tacks/fallback-let-closure
ChayimFriedman2 Mar 20, 2026
378fcb3
Merge pull request #21787 from A4-Tacks/replace-is-some-and-fallback
ChayimFriedman2 Mar 20, 2026
fbb8d2d
Merge pull request #20566 from A4-Tacks/part-selection-merge-uses
ChayimFriedman2 Mar 20, 2026
7e6a279
Merge pull request #20594 from A4-Tacks/conv-clos-to-fn-indent
ChayimFriedman2 Mar 20, 2026
4c93d12
Merge pull request #20600 from A4-Tacks/unwrap-tuple-on-let-expr
ChayimFriedman2 Mar 20, 2026
ca1fc35
Remove doc comments for generate_trait_from_impl
A4-Tacks Aug 8, 2025
69a0120
Merge pull request #20407 from A4-Tacks/remove-doc-for-gen-trait
A4-Tacks Mar 20, 2026
f17bfda
Merge pull request #21768 from A4-Tacks/complete-fully-param-qualifier
ChayimFriedman2 Mar 20, 2026
3d3302c
Merge pull request #20625 from A4-Tacks/multi-attr-to-cfg_attr
ChayimFriedman2 Mar 20, 2026
04b7a5a
Merge pull request #21822 from A4-Tacks/tail-offer-fill-match-arm
ChayimFriedman2 Mar 20, 2026
c01af5a
Add `ops::AddAssign` implement for IndentLevel
A4-Tacks Sep 3, 2025
6294bbc
Merge pull request #20601 from A4-Tacks/indent-level-add-assign
A4-Tacks Mar 20, 2026
eee8bdd
Add auto trait name for generate_trait_from_impl
A4-Tacks Jul 24, 2025
a307600
Do not suggest trait name on multi fn
A4-Tacks Mar 20, 2026
ff57969
Merge pull request #20299 from A4-Tacks/auto-trait-name-for-gen-trait…
A4-Tacks Mar 20, 2026
03ecc85
Merge pull request #21333 from A4-Tacks/expected-tuple-struct-pat
Veykril Mar 20, 2026
ee041a3
add without_mappings variant in let_expr_needs_paren
Shourya742 Mar 20, 2026
7486788
Merge pull request #21847 from Shourya742/2026-03-20-migrate-assist
A4-Tacks Mar 20, 2026
3ad92c9
On E0277 tweak help when single type impls traits
estebank Mar 21, 2026
ed0a99f
Merge pull request #21832 from Shourya742/2026-03-04-add-mapping-to-c…
A4-Tacks Mar 21, 2026
c1a24b4
ide-assists: add tests for const, static in add_braces
Amit5601 Mar 21, 2026
9bff35b
add tests for let-expr in add_braces
A4-Tacks Mar 21, 2026
dc8d64d
feat: offer 'add_braces' on bin-expr assignment
A4-Tacks Mar 21, 2026
734914e
Merge pull request #21850 from A4-Tacks/add-braces-bin-expr
A4-Tacks Mar 21, 2026
1a05c11
Bump flatted from 3.3.3 to 3.4.2 in /editors/code
dependabot[bot] Mar 21, 2026
77aac00
Merge pull request #21817 from A4-Tacks/conv-struct-to-tuple-uses-self
A4-Tacks Mar 21, 2026
5841fa8
Inline and remove `QueryVTable::is_loadable_from_disk_fn`.
nnethercote Mar 22, 2026
5491c35
check earlier for misused crate-level attributes
scrabsha Feb 27, 2026
1c6a8fe
check earlier for attributes that are placed in `where` predicate
scrabsha Mar 4, 2026
29e9273
drop derive helpers during ast lowering
scrabsha Feb 27, 2026
d52943a
Remove assertion in `load_from_disk_or_invoke_provider_green`.
nnethercote Mar 22, 2026
f1c710b
internal: Remove clone_for_update from apply_demorgan.rs
Amit5601 Mar 22, 2026
bde4008
Merge pull request #21854 from Amit5601/remove-mut-tree-demorgan
A4-Tacks Mar 22, 2026
be8dee1
interpret/validity: remove unreachable error kind
RalfJung Mar 22, 2026
6eb75b7
Merge pull request #20628 from A4-Tacks/add-lifetime-for-infer
ChayimFriedman2 Mar 22, 2026
bbec9ac
Merge pull request #20762 from A4-Tacks/non-exhaustive-let-fixes
ChayimFriedman2 Mar 22, 2026
9d74e3c
Merge pull request #20984 from A4-Tacks/add-label-while-for
ChayimFriedman2 Mar 22, 2026
8befc9d
refactor RangeFromIter overflow-checks impl
pitaj Mar 21, 2026
fa3e85a
diagnostics: avoid ICE in confusable_method_name for associated funct…
Unique-Usman Mar 22, 2026
a7f691e
Merge pull request #21324 from A4-Tacks/dedent-dot-comp-snippet
ChayimFriedman2 Mar 22, 2026
9e22fa4
Merge pull request #21395 from dfireBird/push-sqrmpnzrzwpt
ChayimFriedman2 Mar 22, 2026
470b725
Merge pull request #21423 from cormacrelf/project-json-compatibility
ChayimFriedman2 Mar 22, 2026
c070408
Merge pull request #21424 from cormacrelf/support-more-runnable-kinds
ChayimFriedman2 Mar 22, 2026
0087e3e
Merge pull request #21473 from A4-Tacks/unwrap-let-else-block
ChayimFriedman2 Mar 22, 2026
cde59f0
Remove another assertion in `load_from_disk_or_invoke_provider_green`.
nnethercote Mar 22, 2026
6f08437
improve inline assembly error messages
folkertdev Mar 22, 2026
327216d
Refactor `load_from_disk_or_invoke_provider_green`.
nnethercote Mar 22, 2026
7606287
Merge pull request #21809 from A4-Tacks/extract-const-like-path-expr
ChayimFriedman2 Mar 22, 2026
a022c19
Merge pull request #21851 from rust-lang/dependabot/npm_and_yarn/edit…
ChayimFriedman2 Mar 22, 2026
c9a65cf
Merge pull request #21795 from Wilfred/fix_unit_test_rust_project
ChayimFriedman2 Mar 22, 2026
8dcb257
Document consteval behavior of ub_checks & overflow_checks.
theemathas Mar 23, 2026
338deef
Remove outdated consteval docs for is_val_statically_known.
theemathas Mar 23, 2026
08ff97a
Rollup merge of #154241 - lnicola:sync-from-ra, r=lnicola
JonathanBrouwer Mar 23, 2026
9177dbe
Rollup merge of #153686 - Twey:patch-1, r=Mark-Simulacrum
JonathanBrouwer Mar 23, 2026
7386010
Rollup merge of #154105 - ferrocene:jyn/test-transmute, r=Mark-Simula…
JonathanBrouwer Mar 23, 2026
8b69918
Rollup merge of #153069 - blueshift-gg:BPF_unaligned, r=chenyukang
JonathanBrouwer Mar 23, 2026
9e25329
Rollup merge of #154085 - aytey:fix-at-or-pattern-parens, r=chenyukang
JonathanBrouwer Mar 23, 2026
61b4c77
Rollup merge of #154191 - pitaj:fix-154124, r=tgross35
JonathanBrouwer Mar 23, 2026
83a0bd9
Rollup merge of #154207 - nnethercote:refactor-query-loading, r=Zalathar
JonathanBrouwer Mar 23, 2026
37d76a5
Rollup merge of #153540 - scrabsha:sasha/drop-derive-helpers, r=jdons…
JonathanBrouwer Mar 23, 2026
452af7e
Rollup merge of #154140 - theemathas:checks_always_on_in_const, r=Ral…
JonathanBrouwer Mar 23, 2026
773db3e
Rollup merge of #154161 - estebank:e0277-ty-impls, r=Kivooeo
JonathanBrouwer Mar 23, 2026
b828ed9
Rollup merge of #154218 - RalfJung:validity-init-scalar, r=nnethercote
JonathanBrouwer Mar 23, 2026
50018ab
Rollup merge of #154225 - Unique-Usman:ua/rustc_confusable, r=Kivooeo
JonathanBrouwer Mar 23, 2026
1448ab9
Rollup merge of #154228 - folkertdev:mention-invalid-template-modifie…
JonathanBrouwer Mar 23, 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
29 changes: 9 additions & 20 deletions compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::hash_map::Entry;
use std::fmt::Write;

use rustc_ast::*;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
Expand Down Expand Up @@ -124,13 +123,9 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
self.dcx().emit_err(ClobberAbiNotSupported { abi_span: *abi_span });
}
Err(supported_abis) => {
let mut abis = format!("`{}`", supported_abis[0]);
for m in &supported_abis[1..] {
let _ = write!(abis, ", `{m}`");
}
self.dcx().emit_err(InvalidAbiClobberAbi {
abi_span: *abi_span,
supported_abis: abis,
supported_abis: supported_abis.to_vec().into(),
});
}
}
Expand Down Expand Up @@ -164,15 +159,12 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
asm::InlineAsmRegOrRegClass::RegClass(if let Some(asm_arch) = asm_arch {
asm::InlineAsmRegClass::parse(asm_arch, reg_class).unwrap_or_else(
|supported_register_classes| {
let mut register_classes =
format!("`{}`", supported_register_classes[0]);
for m in &supported_register_classes[1..] {
let _ = write!(register_classes, ", `{m}`");
}
self.dcx().emit_err(InvalidRegisterClass {
op_span: *op_sp,
reg_class,
supported_register_classes: register_classes,
supported_register_classes: supported_register_classes
.to_vec()
.into(),
});
asm::InlineAsmRegClass::Err
},
Expand Down Expand Up @@ -272,23 +264,20 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
}
let valid_modifiers = class.valid_modifiers(asm_arch.unwrap());
if !valid_modifiers.contains(&modifier) {
let sub = if !valid_modifiers.is_empty() {
let mut mods = format!("`{}`", valid_modifiers[0]);
for m in &valid_modifiers[1..] {
let _ = write!(mods, ", `{m}`");
}
InvalidAsmTemplateModifierRegClassSub::SupportModifier {
let sub = if valid_modifiers.is_empty() {
InvalidAsmTemplateModifierRegClassSub::DoesNotSupportModifier {
class_name: class.name(),
modifiers: mods,
}
} else {
InvalidAsmTemplateModifierRegClassSub::DoesNotSupportModifier {
InvalidAsmTemplateModifierRegClassSub::SupportModifier {
class_name: class.name(),
modifiers: valid_modifiers.to_vec().into(),
}
};
self.dcx().emit_err(InvalidAsmTemplateModifierRegClass {
placeholder_span,
op_span: op_sp,
modifier: modifier.to_string(),
sub,
});
}
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_errors::DiagArgFromDisplay;
use rustc_errors::codes::*;
use rustc_errors::{DiagArgFromDisplay, DiagSymbolList};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Ident, Span, Symbol};

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

#[derive(Diagnostic)]
Expand All @@ -215,17 +215,18 @@ pub(crate) struct InvalidRegisterClass {
#[primary_span]
pub op_span: Span,
pub reg_class: Symbol,
pub supported_register_classes: String,
pub supported_register_classes: DiagSymbolList<Symbol>,
}

#[derive(Diagnostic)]
#[diag("invalid asm template modifier for this register class")]
#[diag("invalid asm template modifier `{$modifier}` for this register class")]
pub(crate) struct InvalidAsmTemplateModifierRegClass {
#[primary_span]
#[label("template modifier")]
pub placeholder_span: Span,
#[label("argument")]
pub op_span: Span,
pub modifier: String,
#[subdiagnostic]
pub sub: InvalidAsmTemplateModifierRegClassSub,
}
Expand All @@ -235,7 +236,7 @@ pub(crate) enum InvalidAsmTemplateModifierRegClassSub {
#[note(
"the `{$class_name}` register class supports the following template modifiers: {$modifiers}"
)]
SupportModifier { class_name: Symbol, modifiers: String },
SupportModifier { class_name: Symbol, modifiers: DiagSymbolList<char> },
#[note("the `{$class_name}` register class does not support template modifiers")]
DoesNotSupportModifier { class_name: Symbol },
}
Expand Down
23 changes: 20 additions & 3 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,23 @@ impl<'a> State<'a> {
}
}

/// Print a pattern, parenthesizing it if it is an or-pattern (`A | B`).
///
/// Or-patterns have the lowest precedence among patterns, so they need
/// parentheses when nested inside `@` bindings, `&` references, or `box`
/// patterns — otherwise `x @ A | B` parses as `(x @ A) | B`, `&A | B`
/// parses as `(&A) | B`, etc.
fn print_pat_paren_if_or(&mut self, pat: &ast::Pat) {
let needs_paren = matches!(pat.kind, PatKind::Or(..));
if needs_paren {
self.popen();
}
self.print_pat(pat);
if needs_paren {
self.pclose();
}
}

fn print_pat(&mut self, pat: &ast::Pat) {
self.maybe_print_comment(pat.span.lo());
self.ann.pre(self, AnnNode::Pat(pat));
Expand Down Expand Up @@ -1813,7 +1830,7 @@ impl<'a> State<'a> {
if let Some(p) = sub {
self.space();
self.word_space("@");
self.print_pat(p);
self.print_pat_paren_if_or(p);
}
}
PatKind::TupleStruct(qself, path, elts) => {
Expand Down Expand Up @@ -1885,7 +1902,7 @@ impl<'a> State<'a> {
}
PatKind::Box(inner) => {
self.word("box ");
self.print_pat(inner);
self.print_pat_paren_if_or(inner);
}
PatKind::Deref(inner) => {
self.word("deref!");
Expand All @@ -1909,7 +1926,7 @@ impl<'a> State<'a> {
self.print_pat(inner);
self.pclose();
} else {
self.print_pat(inner);
self.print_pat_paren_if_or(inner);
}
}
PatKind::Expr(e) => self.print_expr(e, FixupContext::default()),
Expand Down
35 changes: 35 additions & 0 deletions compiler/rustc_attr_parsing/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use rustc_errors::MultiSpan;
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol};

#[derive(Diagnostic)]
#[diag("`{$name}` attribute cannot be used at crate level")]
pub(crate) struct InvalidAttrAtCrateLevel {
#[primary_span]
pub span: Span,
#[suggestion(
"perhaps you meant to use an outer attribute",
code = "#[",
applicability = "machine-applicable",
style = "verbose"
)]
pub pound_to_opening_bracket: Span,
pub name: Symbol,
#[subdiagnostic]
pub item: Option<ItemFollowingInnerAttr>,
}

#[derive(Clone, Copy, Subdiagnostic)]
#[label("the inner attribute doesn't annotate this item")]
pub(crate) struct ItemFollowingInnerAttr {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag("most attributes are not supported in `where` clauses")]
#[help("only `#[cfg]` and `#[cfg_attr]` are supported")]
pub(crate) struct UnsupportedAttributesInWhere {
#[primary_span]
pub span: MultiSpan,
}
51 changes: 33 additions & 18 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
mut emit_lint: impl FnMut(LintId, Span, AttributeLintKind),
) -> Vec<Attribute> {
let mut attributes = Vec::new();
// We store the attributes we intend to discard at the end of this function in order to
// check they are applied to the right target and error out if necessary. In practice, we
// end up dropping only derive attributes and derive helpers, both being fully processed
// at macro expansion.
let mut dropped_attributes = Vec::new();
let mut attr_paths: Vec<RefPathParser<'_>> = Vec::new();
let mut early_parsed_state = EarlyParsedState::default();

Expand Down Expand Up @@ -304,7 +309,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
kind: DocFragmentKind::Sugared(*comment_kind),
span: attr_span,
comment: *symbol,
}))
}));
}
ast::AttrKind::Normal(n) => {
attr_paths.push(PathParser(&n.item.path));
Expand Down Expand Up @@ -393,29 +398,33 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
Self::check_target(&accept.allowed_targets, target, &mut cx);
}
} else {
// If we're here, we must be compiling a tool attribute... Or someone
// forgot to parse their fancy new attribute. Let's warn them in any case.
// If you are that person, and you really think your attribute should
// remain unparsed, carefully read the documentation in this module and if
// you still think so you can add an exception to this assertion.

// FIXME(jdonszelmann): convert other attributes, and check with this that
// we caught em all
// const FIXME_TEMPORARY_ATTR_ALLOWLIST: &[Symbol] = &[sym::cfg];
// assert!(
// self.tools.contains(&parts[0]) || true,
// // || FIXME_TEMPORARY_ATTR_ALLOWLIST.contains(&parts[0]),
// "attribute {path} wasn't parsed and isn't a know tool attribute",
// );

attributes.push(Attribute::Unparsed(Box::new(AttrItem {
let attr = AttrItem {
path: attr_path.clone(),
args: self
.lower_attr_args(n.item.args.unparsed_ref().unwrap(), lower_span),
id: HashIgnoredAttrId { attr_id: attr.id },
style: attr.style,
span: attr_span,
})));
};

if !matches!(self.stage.should_emit(), ShouldEmit::Nothing)
&& target == Target::Crate
{
self.check_invalid_crate_level_attr_item(&attr, n.item.span());
}

let attr = Attribute::Unparsed(Box::new(attr));

if self.tools.contains(&parts[0])
// FIXME: this can be removed once #152369 has been merged.
// https://github.com/rust-lang/rust/pull/152369
|| [sym::allow, sym::deny, sym::expect, sym::forbid, sym::warn]
.contains(&parts[0])
{
attributes.push(attr);
} else {
dropped_attributes.push(attr);
}
}
}
}
Expand All @@ -431,6 +440,12 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
}
}

if !matches!(self.stage.should_emit(), ShouldEmit::Nothing)
&& target == Target::WherePredicate
{
self.check_invalid_where_predicate_attrs(attributes.iter().chain(&dropped_attributes));
}

attributes
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_attr_parsing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
// tidy-alphabetical-start
#![feature(decl_macro)]
#![feature(iter_intersperse)]
#![feature(try_blocks)]
#![recursion_limit = "256"]
// tidy-alphabetical-end

Expand All @@ -99,6 +100,7 @@ mod interface;
pub mod parser;

mod early_parsed;
mod errors;
mod safety;
mod session_diagnostics;
mod target_checking;
Expand Down
Loading
Loading