about summary refs log tree commit diff
path: root/compiler/rustc_ast/src
AgeCommit message (Collapse)AuthorLines
2024-09-11clippy::useless_conversionMichael Goulet-4/+2
2024-09-11Also fix if in elseMichael Goulet-11/+9
2024-09-10disallow `naked_asm!` outside of `#[naked]` functionsFolkert de Vries-0/+13
2024-09-09Remove needless returns detected by clippy in the compilerEduardo Sánchez Muñoz-2/+2
2024-09-06Add initial support for raw lifetimesMichael Goulet-12/+14
2024-08-31Create opaque definitions in resolver.Camille GILLOT-6/+10
2024-08-31Rollup merge of #120221 - compiler-errors:statements-are-not-patterns, ↵Matthias Krüger-21/+36
r=nnethercote Don't make statement nonterminals match pattern nonterminals Right now, the heuristic we use to check if a token may begin a pattern nonterminal falls back to `may_be_ident`: https://github.com/rust-lang/rust/blob/ef71f1047e04438181d7cb925a833e2ada6ab390/compiler/rustc_parse/src/parser/nonterminal.rs#L21-L37 This has the unfortunate side effect that a `stmt` nonterminal eagerly matches against a `pat` nonterminal, leading to a parse error: ```rust macro_rules! m { ($pat:pat) => {}; ($stmt:stmt) => {}; } macro_rules! m2 { ($stmt:stmt) => { m! { $stmt } }; } m2! { let x = 1 } ``` This PR fixes it by more accurately reflecting the set of nonterminals that may begin a pattern nonterminal. As a side-effect, I modified `Token::can_begin_pattern` to work correctly and used that in `Parser::nonterminal_may_begin_with`.
2024-08-27Rollup merge of #126013 - nnethercote:unreachable_pub, r=UrgauMatthias Krüger-0/+1
Add `#[warn(unreachable_pub)]` to a bunch of compiler crates By default `unreachable_pub` identifies things that need not be `pub` and tells you to make them `pub(crate)`. But sometimes those things don't need any kind of visibility. So they way I did these was to remove the visibility entirely for each thing the lint identifies, and then add `pub(crate)` back in everywhere the compiler said it was necessary. (Or occasionally `pub(super)` when context suggested that was appropriate.) Tedious, but results in more `pub` removal. There are plenty more crates to do but this seems like enough for a first PR. r? `@compiler-errors`
2024-08-26Don't make pattern nonterminals match statement nonterminalsMichael Goulet-21/+36
2024-08-24Rollup merge of #128524 - ↵Trevor Gross-0/+11
chenyukang:yukang-fix-127930-invalid-outer-style-sugg, r=cjgillot Don't suggest turning crate-level attributes into outer style Fixes #127930
2024-08-16Add `warn(unreachable_pub)` to several crates.Nicholas Nethercote-0/+1
It requires no additonal changes to these crates, but will prevent unnecessary `pub`s in the future.
2024-08-07Use more slice patterns inside the compilerLeón Orell Valerian Liehr-4/+8
2024-08-04don't suggest turning crate-level attributes into outer styleyukang-0/+11
2024-07-29Reformat `use` declarations.Nicholas Nethercote-79/+91
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-27Rollup merge of #128207 - folkertdev:asm-parser-generalize, r=AmanieuTrevor Gross-0/+5
improve error message when `global_asm!` uses `asm!` options specifically, what was error: expected one of `)`, `att_syntax`, or `raw`, found `preserves_flags` --> $DIR/bad-options.rs:45:25 | LL | global_asm!("", options(preserves_flags)); | ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, or `raw` is now error: the `preserves_flags` option cannot be used with `global_asm!` --> $DIR/bad-options.rs:45:25 | LL | global_asm!("", options(preserves_flags)); | ^^^^^^^^^^^^^^^ the `preserves_flags` option is not meaningful for global-scoped inline assembly mirroring the phrasing of the [reference](https://doc.rust-lang.org/reference/inline-assembly.html#options). This is also a bit of a refactor for a future `naked_asm!` macro (for use in `#[naked]` functions). Currently this sort of error can come up when switching from inline to global asm, or when a user just isn't that experienced with assembly. With `naked_asm!` added to the mix hitting this error is more likely.
2024-07-25improve error message when `global_asm!` uses `asm!` optionsFolkert-0/+5
2024-07-25Auto merge of #128195 - matthiaskrgr:rollup-195dfdf, r=matthiaskrgrbors-1/+2
Rollup of 6 pull requests Successful merges: - #126908 (Use Cow<'static, str> for InlineAsmTemplatePiece::String) - #127999 (Inject arm32 shims into Windows metadata generation) - #128137 (CStr: derive PartialEq, Eq; add test for Ord) - #128185 (Fix a span error when parsing a wrong param of function.) - #128187 (Fix 1.80.0 version in RELEASES.md) - #128189 (Turn an unreachable code path into an ICE) r? `@ghost` `@rustbot` modify labels: rollup
2024-07-25Rollup merge of #128138 - folkertdev:asm-option-allowlist, r=lcnrMatthias Krüger-0/+36
`#[naked]`: use an allowlist for allowed options on `asm!` in naked functions tracking issue: https://github.com/rust-lang/rust/issues/90957 this is mostly just a refactor, but using an allowlist (rather than a denylist) for which asm options are allowed in naked functions is a little safer. These options are disallowed because naked functions are effectively global asm, but defined using inline asm.
2024-07-24Use Cow<'static, str> for InlineAsmTemplatePiece::StringGnomedDev-1/+2
2024-07-24centralize turning asm flags into human readable namesFolkert-0/+36
2024-07-22Avoid passing state that will not be visitedOli Scherer-53/+16
2024-07-22Update trait name from Noop -> WalkOli Scherer-6/+6
2024-07-22Always pass the visitor as the first argument to walk* functionsOli Scherer-207/+207
2024-07-22Sync `mut_visit` function names with immut `visit` ones (s/noop_visit/walk/)Oli Scherer-134/+125
2024-07-22Add `Ident` to `FnKind::Fn`, just like with the immutable visitorOli Scherer-7/+16
2024-07-22Split up `visit_path` so `MutVisitor` has a `path_segment` method just like ↵Oli Scherer-4/+13
the immutable visitor
2024-07-22Pass id and span to `visit_fn`, just like for the immutable visitorOli Scherer-13/+43
2024-07-22Make function items in mut visitors all go through the same visit_fn ↵Oli Scherer-30/+52
function, just like with immutable visitors
2024-07-22Track visit_param_bound in mut visit just like in the immutable visitorOli Scherer-15/+15
2024-07-22Merge impl and trait item mut visitor methods to mirror immut visitorOli Scherer-7/+8
2024-07-17Rollup merge of #127806 - nnethercote:parser-improvements, r=spastorinoTrevor Gross-2/+1
Some parser improvements I was looking closely at attribute handling in the parser while debugging some issues relating to #124141, and found a few small improvements. ``@spastorino``
2024-07-16Fix a bunch of sites that were walking instead of visiting, making it ↵Oli Scherer-3/+3
impossible for visitor impls to look at these values
2024-07-16Remove references to `maybe_whole_expr`.Nicholas Nethercote-2/+1
It was removed in #126571.
2024-07-13Rollup merge of #127558 - nnethercote:more-Attribute-cleanups, r=petrochenkovJubilee-77/+82
More attribute cleanups A follow-up to #127308. r? ```@petrochenkov```
2024-07-10Make `visit_clobber`'s impl safeOli Scherer-14/+3
2024-07-10Add some comments.Nicholas Nethercote-1/+4
Explaining things that took me some time to work out.
2024-07-10Factor out `AttrsTarget` flattening code.Nicholas Nethercote-64/+68
This commit does the following. - Pulls the code out of `AttrTokenStream::to_token_trees` into a new function `attrs_and_tokens_to_token_trees`. - Simplifies `TokenStream::from_ast` by calling the new function. This is nicer than the old way, which created a temporary `AttrTokenStream` containing a single `AttrsTarget` (which required some cloning) just to call `to_token_trees` on it. (It is good to remove this use of `AttrsTarget` which isn't related to `cfg_attr` expansion.)
2024-07-10Rework `Attribute::get_tokens`.Nicholas Nethercote-17/+15
Returning `Vec<TokenTree>` works better for the call sites than returning `TokenStream`.
2024-07-07Rollup merge of #127308 - nnethercote:Attribute-cleanups, r=petrochenkovMatthias Krüger-52/+21
Attribute cleanups More refactoring done while trying to fix the final remaining test failure for #124141. r? `@petrochenkov`
2024-07-07Add an size assertion.Nicholas Nethercote-0/+1
`Option<LazyAttrTokenStream>` is the type that's actually used in all the aST nodes.
2024-07-07Rename some attribute types for consistency.Nicholas Nethercote-12/+12
- `AttributesData` -> `AttrsTarget` - `AttrTokenTree::Attributes` -> `AttrTokenTree::AttrsTarget` - `FlatToken::AttrTarget` -> `FlatToken::AttrsTarget`
2024-07-07Remove `HasSpan` trait.Nicholas Nethercote-37/+4
The only place it is meaningfully used is in a panic message in `TokenStream::from_ast`. But `node.span()` doesn't need to be printed because `node` is also printed and it must contain the span.
2024-07-07Rename `Attribute::tokens` (the inherent method).Nicholas Nethercote-3/+4
To distinguish it from the `HasTokens` method.
2024-07-05Rollup merge of #127368 - YohDeadfall:dots-in-docs, r=fmeaseMichael Goulet-32/+32
Added dots at the sentence ends of rustc AST doc Just a tiny improvement for the AST documentation by bringing consistency to sentence ends. I intentionally didn't terminate every sentence, there are still some members not having them, but at least there's no mixing style on the type level.
2024-07-05Added dots at the sentence ends of rustc AST docYoh Deadfall-32/+32
2024-07-05Auto merge of #127008 - Jules-Bertholet:tc-ergonomics, r=Nadrierilbors-0/+1
Match ergonomics 2024: Implement TC's match ergonomics proposal Under gate `ref_pat_eat_one_layer_2024_structural`. Enabling `ref_pat_eat_one_layer_2024` at the same time allows the union of what the individual gates allow. `@traviscross` r? `@Nadrieril` cc https://github.com/rust-lang/rust/issues/123076 `@rustbot` label A-edition-2024 A-patterns
2024-07-03Rollup merge of #127092 - compiler-errors:rtn-dots-redux, r=estebankMatthias Krüger-2/+7
Change return-type-notation to use `(..)` Aligns the syntax with the current wording of [RFC 3654](https://github.com/rust-lang/rfcs/pull/3654). Also implements rustfmt support (along with making a match exhaustive). Tracking: * https://github.com/rust-lang/rust/issues/109417
2024-07-03Rollup merge of #127233 - nnethercote:parser-cleanups, r=petrochenkovMatthias Krüger-37/+26
Some parser cleanups Cleanups I made while looking closely at this code. r? ``@petrochenkov``
2024-07-02Rollup merge of #126883 - dtolnay:breakvalue, r=fmeaseMatthias Krüger-1/+78
Parenthesize break values containing leading label The AST pretty printer previously produced invalid syntax in the case of `break` expressions with a value that begins with a loop or block label. ```rust macro_rules! expr { ($e:expr) => { $e }; } fn main() { loop { break expr!('a: loop { break 'a 1; } + 1); }; } ``` `rustc -Zunpretty=expanded main.rs `: ```console #![feature(prelude_import)] #![no_std] #[prelude_import] use ::std::prelude::rust_2015::*; #[macro_use] extern crate std; macro_rules! expr { ($e:expr) => { $e }; } fn main() { loop { break 'a: loop { break 'a 1; } + 1; }; } ``` The expanded code is not valid Rust syntax. Printing invalid syntax is bad because it blocks `cargo expand` from being able to format the output as Rust syntax using rustfmt. ```console error: parentheses are required around this expression to avoid confusion with a labeled break expression --> <anon>:9:26 | 9 | fn main() { loop { break 'a: loop { break 'a 1; } + 1; }; } | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: wrap the expression in parentheses | 9 | fn main() { loop { break ('a: loop { break 'a 1; }) + 1; }; } | + + ``` This PR updates the AST pretty-printer to insert parentheses around the value of a `break` expression as required to avoid this edge case.
2024-07-02Just `push` in `AttrTokenStream::to_token_trees`.Nicholas Nethercote-16/+12
Currently it uses a mixture of functional style (`flat_map`) and imperative style (`push`), which is a bit hard to read. This commit converts it to fully imperative, which is more concise and avoids the need for `smallvec`.