about summary refs log tree commit diff
path: root/compiler/rustc_expand/src/expand.rs
AgeCommit message (Collapse)AuthorLines
2025-04-10Address review comments.Nicholas Nethercote-1/+1
2025-04-10Rename some `name` variables as `ident`.Nicholas Nethercote-5/+5
It bugs me when variables of type `Ident` are called `name`. It leads to silly things like `name.name`. `Ident` variables should be called `ident`, and `name` should be used for variables of type `Symbol`. This commit improves things by by doing `s/name/ident/` on a bunch of `Ident` variables. Not all of them, but a decent chunk.
2025-04-01Address review comments.Nicholas Nethercote-3/+1
2025-04-01Move `ast::Item::ident` into `ast::ItemKind`.Nicholas Nethercote-5/+8
`ast::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, `Trait`, `TraitAlias`, `MacroDef`, `Delegation`. - It's always empty for these item kinds: `Use`, `ForeignMod`, `GlobalAsm`, `Impl`, `MacCall`, `DelegationMac`. There is a similar story for `AssocItemKind` and `ForeignItemKind`. Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. The commit is large but it's mostly obvious plumbing work. Some notable things. - `ast::Item` got 8 bytes bigger. This could be avoided by boxing the fields within some of the `ast::ItemKind` variants (specifically: `Struct`, `Union`, `Enum`). I might do that in a follow-up; this commit is big enough already. - For the visitors: `FnKind` no longer needs an `ident` field because the `Fn` within how has one. - In the parser, the `ItemInfo` typedef is no longer needed. It was used in various places to return an `Ident` alongside an `ItemKind`, but now the `Ident` (if present) is within the `ItemKind`. - In a few places I renamed identifier variables called `name` (or `foo_name`) as `ident` (or `foo_ident`), to better match the type, and because `name` is normally used for `Symbol`s. It's confusing to see something like `foo_name.name`.
2025-03-26expand: Leave traces when expanding `cfg` attributesVadim Petrochenkov-7/+6
2025-03-25Track whether an assoc item is in a trait impl or an inherent implOli Scherer-15/+86
2025-03-21expand: Do not report `cfg_attr` traces on macros as unused attributesVadim Petrochenkov-1/+1
2025-03-11Keep items around even if builtin macros on them fail to parseOli Scherer-2/+2
2025-03-01Implment `#[cfg]` and `#[cfg_attr]` in `where` clausesFrank King-3/+35
2025-02-03tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`Askar Safin-3/+3
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-16rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structuresJonathan Dönszelmann-1/+1
2024-12-10Keep track of parse errors in `mod`s and don't emit resolve errors for paths ↵Esteban Küber-13/+19
involving them When we expand a `mod foo;` and parse `foo.rs`, we now track whether that file had an unrecovered parse error that reached the end of the file. If so, we keep that information around. When resolving a path like `foo::bar`, we do not emit any errors for "`bar` not found in `foo`", as we know that the parse error might have caused `bar` to not be parsed and accounted for. When this happens in an existing project, every path referencing `foo` would be an irrelevant compile error. Instead, we now skip emitting anything until `foo.rs` is fixed. Tellingly enough, we didn't have any test for errors caused by `mod` expansion. Fix #97734.
2024-12-08Rollup merge of #133424 - Nadrieril:guard-patterns-parsing, r=fee1-deadMatthias Krüger-1/+1
Parse guard patterns This implements the parsing of [RFC3637 Guard Patterns](https://rust-lang.github.io/rfcs/3637-guard-patterns.html) (see also [tracking issue](https://github.com/rust-lang/rust/issues/129967)). This PR is extracted from https://github.com/rust-lang/rust/pull/129996 with minor modifications. cc `@max-niederman`
2024-12-02Change `AttrArgs::Eq` into a struct variantOli Scherer-1/+1
2024-11-24parse guard patternsNadrieril-1/+1
Co-authored-by: Max Niederman <max@maxniederman.com>
2024-11-24refactor pat parser method names/doc-comments to agree with RFC 3637Max Niederman-1/+1
2024-11-20Itemsmaxcabrajac-1/+1
2024-11-15Add WalkItemKind::Ctxt so AssocCtxt is not sent to non-Assoc ItemKindsmaxcabrajac-2/+2
2024-10-28Tweak `expand_incomplete_parse` warning.Nicholas Nethercote-2/+3
By using `token_descr`, as is done for many other errors, we can get slightly better descriptions in error messages, e.g. "macro expansion ignores token `let` and any following" becomes "macro expansion ignores keyword `let` and any tokens following". This will be more important once invisible delimiters start being mentioned in error messages -- without this commit, that leads to error messages such as "error at ``" because invisible delimiters are pretty printed as an empty string.
2024-10-23nightly feature tracking: get rid of the per-feature bool fieldsRalf Jung-2/+2
2024-10-07Rename nested_meta to meta_item_innercodemountains-1/+1
2024-10-06Rename NestedMetaItem to MetaItemInnercodemountains-2/+2
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-5/+5
2024-09-11rustc_expand: remember module #[path]s during expansiondianne-2/+10
this fixes cycle detection for modules that need a second invocation collection pass after parsing
2024-08-21Use bool in favor of Option<()> for diagnosticsMichael Goulet-1/+1
2024-08-17Auto merge of #128771 - carbotaniuman:stabilize_unsafe_attr, r=nnethercotebors-1/+1
Stabilize `unsafe_attributes` # Stabilization report ## Summary This is a tracking issue for the RFC 3325: unsafe attributes We are stabilizing `#![feature(unsafe_attributes)]`, which makes certain attributes considered 'unsafe', meaning that they must be surrounded by an `unsafe(...)`, as in `#[unsafe(no_mangle)]`. RFC: rust-lang/rfcs#3325 Tracking issue: #123757 ## What is stabilized ### Summary of stabilization Certain attributes will now be designated as unsafe attributes, namely, `no_mangle`, `export_name`, and `link_section` (stable only), and these attributes will need to be called by surrounding them in `unsafe(...)` syntax. On editions prior to 2024, this is simply an edition lint, but it will become a hard error in 2024. This also works in `cfg_attr`, but `unsafe` is not allowed for any other attributes, including proc-macros ones. ```rust #[unsafe(no_mangle)] fn a() {} #[cfg_attr(any(), unsafe(export_name = "c"))] fn b() {} ``` For a table showing the attributes that were considered to be included in the list to require unsafe, and subsequent reasoning about why each such attribute was or was not included, see [this comment here](https://github.com/rust-lang/rust/pull/124214#issuecomment-2124753464) ## Tests The relevant tests are in `tests/ui/rust-2024/unsafe-attributes` and `tests/ui/attributes/unsafe`.
2024-08-10rustc_expand: make a message translatablePavel Grigorenko-2/+2
2024-08-10rustc_expand: remove some redundant `#[allow(rustc::untranslatable_diagnostic)]`Pavel Grigorenko-1/+0
2024-08-07Stabilize `unsafe_attributes`carbotaniuman-1/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-19/+20
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-22Avoid passing state that will not be visitedOli Scherer-4/+4
2024-07-22Always pass the visitor as the first argument to walk* functionsOli Scherer-21/+21
2024-07-22Sync `mut_visit` function names with immut `visit` ones (s/noop_visit/walk/)Oli Scherer-54/+54
2024-07-22Make function items in mut visitors all go through the same visit_fn ↵Oli Scherer-4/+4
function, just like with immutable visitors
2024-07-22Merge impl and trait item mut visitor methods to mirror immut visitorOli Scherer-16/+18
2024-06-24Rollup merge of #126177 - carbotaniuman:unsafe_attr_errors, r=jieyouxuMatthias Krüger-1/+1
Add hard error and migration lint for unsafe attrs More implementation work for https://github.com/rust-lang/rust/issues/123757 This adds the migration lint for unsafe attributes, as well as making it a hard error in Rust 2024.
2024-06-23Add hard error and migration lint for unsafe attrscarbotaniuman-1/+1
2024-06-22delegation: Do not crash on qpaths without a traitVadim Petrochenkov-2/+10
2024-06-14delegation: Implement glob delegationVadim Petrochenkov-38/+114
2024-06-06Fix buildcarbotaniuman-1/+1
2024-06-06Disallow unsafe in derivecarbotaniuman-1/+2
2024-06-06Parse unsafe attributescarbotaniuman-1/+7
2024-05-21Rename buffer_lint_with_diagnostic to buffer_lintXiretza-2/+2
2024-05-21Generate lint diagnostic message from BuiltinLintDiagXiretza-2/+0
Translation of the lint message happens when the actual diagnostic is created, not when the lint is buffered. Generating the message from BuiltinLintDiag ensures that all required data to construct the message is preserved in the LintBuffer, eventually allowing the messages to be moved to fluent. Remove the `msg` field from BufferedEarlyLint, it is either generated from the data in the BuiltinLintDiag or stored inside BuiltinLintDiag::Normal.
2024-05-15delegation: Implement list delegationVadim Petrochenkov-2/+115
```rust reuse prefix::{a, b, c} ```
2024-05-08Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=NilstriebMatthias Krüger-2/+2
Remove braces when fixing a nested use tree into a single item [Back in 2019](https://github.com/rust-lang/rust/pull/56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`. This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then. A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`. This PR is best reviewed commit-by-commit.
2024-05-03Introduce `Invocation::span_mut`.Nicholas Nethercote-5/+9
Alongside the existing `Invocation::span`.
2024-05-03Replace a hard-to-read line.Nicholas Nethercote-1/+2
Too clever by half, IMO.
2024-05-03Tweak `fully_expand_fragment` loop.Nicholas Nethercote-11/+9
Control flow never gets past the end of the `ExpandResult::Retry` match arm, due to the `span_bug` and the `continue`. Therefore, the code after the match can only be reached from the `ExpandResult::Ready` arm. This commit moves that code after the match into the `ExpandResult::Ready` arm, avoiding the need for the `continue` in the `ExpandResult::Retry` arm.