summary refs log tree commit diff
path: root/compiler/rustc_ast/src
AgeCommit message (Collapse)AuthorLines
2024-10-11Auto merge of #131045 - compiler-errors:remove-unnamed_fields, r=wesleywiserbors-21/+0
Retire the `unnamed_fields` feature for now `#![feature(unnamed_fields)]` was implemented in part in #115131 and #115367, however work on that feature has (afaict) stalled and in the mean time there have been some concerns raised (e.g.[^1][^2]) about whether `unnamed_fields` is worthwhile to have in the language, especially in its current desugaring. Because it represents a compiler implementation burden including a new kind of anonymous ADT and additional complication to field selection, and is quite prone to bugs today, I'm choosing to remove the feature. However, since I'm not one to really write a bunch of words, I'm specifically *not* going to de-RFC this feature. This PR essentially *rolls back* the state of this feature to "RFC accepted but not yet implemented"; however if anyone wants to formally unapprove the RFC from the t-lang side, then please be my guest. I'm just not totally willing to summarize the various language-facing reasons for why this feature is or is not worthwhile, since I'm coming from the compiler side mostly. Fixes #117942 Fixes #121161 Fixes #121263 Fixes #121299 Fixes #121722 Fixes #121799 Fixes #126969 Fixes #131041 Tracking: * https://github.com/rust-lang/rust/issues/49804 [^1]: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Unnamed.20struct.2Funion.20fields [^2]: https://github.com/rust-lang/rust/issues/49804#issuecomment-1972619108
2024-10-07Auto merge of #131235 - ↵bors-30/+30
codemountains:rename-nestedmetaitem-to-metaitemlnner, r=nnethercote Rename `NestedMetaItem` to `MetaItemInner` Fixes #131087 r? `@nnethercote`
2024-10-06various fixes for `naked_asm!` implementationFolkert de Vries-2/+10
- fix for divergence - fix error message - fix another cranelift test - fix some cranelift things - don't set the NORETURN option for naked asm - fix use of naked_asm! in doc comment - fix use of naked_asm! in run-make test - use `span_bug` in unreachable branch
2024-10-06disallow `asm!` in `#[naked]` functionsFolkert de Vries-1/+19
also disallow the `noreturn` option, and infer `naked_asm!` as `!`
2024-10-06Rename NestedMetaItem to MetaItemInnercodemountains-30/+30
2024-10-01Remove anon struct and union typesMichael Goulet-21/+0
2024-10-01Implement boolean lit support in cfg predicatesUrgau-0/+10
2024-09-23Rollup merge of #130551 - nnethercote:fix-break-last-token, r=petrochenkovJubilee-29/+35
Fix `break_last_token`. It currently doesn't handle the three-char tokens `>>=` and `<<=` correctly. These can be broken twice, resulting in three individual tokens. This is a latent bug that currently doesn't cause any problems, but does cause problems for #124141, because that PR increases the usage of lazy token streams. r? `@petrochenkov`
2024-09-23Fix `break_last_token`.Nicholas Nethercote-29/+35
It currently doesn't handle the three-char tokens `>>=` and `<<=` correctly. These can be broken twice, resulting in three individual tokens. This is a latent bug that currently doesn't cause any problems, but does cause problems for #124141, because that PR increases the usage of lazy token streams.
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