about summary refs log tree commit diff
path: root/compiler/rustc_ast
AgeCommit message (Collapse)AuthorLines
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-32/+32
2024-09-21Handle macro calls in anon const def creation take 2Boxy-5/+6
2024-09-17Rollup merge of #130314 - compiler-errors:mac-prec, r=davidtwcoMatthias Krüger-11/+6
Use the same precedence for all macro-like exprs No need to make these have a different precedence since they're all written like `whatever!(expr)`, and it makes it simpler when adding new macro-based built-in operators in the future.
2024-09-13Use the same precedence for all macro-like exprsMichael Goulet-11/+6
2024-09-12Fix anon const def-creation when macros are involvedNoah Lev-8/+12
Ever since #125915, some `ast::AnonConst`s turn into `hir::ConstArgKind::Path`s, which don't have associated `DefId`s. To deal with the fact that we don't have resolution information in `DefCollector`, we decided to implement a process where if the anon const *appeared* to be trivial (i.e., `N` or `{ N }`), we would avoid creating a def for it in `DefCollector`. If later, in AST lowering, we realized it turned out to be a unit struct literal, or we were lowering it to something that didn't use `hir::ConstArg`, we'd create its def there. However, let's say we have a macro `m!()` that expands to a reference to a free constant `FOO`. If we use `m!()` in the body of an anon const (e.g., `Foo<{ m!() }>`), then in def collection, it appears to be a nontrivial anon const and we create a def. But the macro expands to something that looks like a trivial const arg, but is not, so in AST lowering we "fix" the mistake we assumed def collection made and create a def for it. This causes a duplicate definition ICE. The ideal long-term fix for this is a bit unclear. One option is to delay def creation for all expression-like nodes until AST lowering (see #128844 for an incomplete attempt at this). This would avoid issues like this one that are caused by hacky workarounds. However, this approach has some downsides as well, and the best approach is yet to be determined. In the meantime, this PR fixes the bug by delaying def creation for anon consts whose bodies are macro invocations until after we expand the macro and know what is inside it. This is accomplished by adding information to create the anon const's def to the data in `Resolver.invocation_parents`.
2024-09-12Rollup merge of #130252 - compiler-errors:const-gen, r=chenyukangStuart Cook-6/+6
Properly report error on `const gen fn` Fixes #130232 Also removes some (what I thought were unused) functions, and fixes a bug in clippy where we considered `gen fn` to be the same as `fn` because it was only built to consider asyncness.
2024-09-12Rollup merge of #130250 - compiler-errors:useless-conversion, r=jieyouxuStuart Cook-4/+2
Fix `clippy::useless_conversion` Self-explanatory. Probably the last clippy change I'll actually put up since this is the only other one I've actually seen in the wild.
2024-09-12Rollup merge of #130235 - compiler-errors:nested-if, r=michaelwoeristerStuart Cook-11/+9
Simplify some nested `if` statements Applies some but not all instances of `clippy::collapsible_if`. Some ended up looking worse afterwards, though, so I left those out. Also applies instances of `clippy::collapsible_else_if` Review with whitespace disabled please.
2024-09-11Remove unused functions from ast CoroutineKindMichael Goulet-8/+0
2024-09-11Rollup merge of #130114 - eduardosm:needless-returns, r=compiler-errorsJubilee-2/+2
Remove needless returns detected by clippy in the compiler
2024-09-11Properly deny const gen/async gen fnsMichael Goulet-0/+8
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`