about summary refs log tree commit diff
path: root/compiler/rustc_expand/src
AgeCommit message (Collapse)AuthorLines
2023-08-17Remove some unnecessary (and badly named) local variables.Nicholas Nethercote-4/+3
2023-08-11rustc: Move `features` from `Session` to `GlobalCtxt`Vadim Petrochenkov-15/+18
Removes two pieces of mutable state. Follow up to #114622.
2023-08-04Auto merge of #114104 - oli-obk:syn2, r=compiler-errorsbors-14/+19
Lots of tiny incremental simplifications of `EmitterWriter` internals ignore the first commit, it's https://github.com/rust-lang/rust/pull/114088 squashed and rebased, but it's needed to use to use `derive_setters`, as they need a newer `syn` version. Then this PR starts out with removing many arguments that are almost always defaulted to `None` or `false` and replace them with builder methods that can set these fields in the few cases that want to set them. After that it's one commit after the other that removes or merges things until everything becomes some very simple trait objects
2023-08-03Add `internal_features` lintNilstrieb-0/+1
It lints against features that are inteded to be internal to the compiler and standard library. Implements MCP #596. We allow `internal_features` in the standard library and compiler as those use many features and this _is_ the standard library from the "internal to the compiler and standard library" after all. Marking some features as internal wasn't exactly the most scientific approach, I just marked some mostly obvious features. While there is a categorization in the macro, it's not very well upheld (should probably be fixed in another PR). We always pass `-Ainternal_features` in the testsuite About 400 UI tests and several other tests use internal features. Instead of throwing the attribute on each one, just always allow them. There's nothing wrong with testing internal features^^
2023-08-03Remove `MacDelimiter`.Nicholas Nethercote-1/+2
It's the same as `Delimiter`, minus the `Invisible` variant. I'm generally in favour of using types to make impossible states unrepresentable, but this one feels very low-value, and the conversions between the two types are annoying and confusing. Look at the change in `src/tools/rustfmt/src/expr.rs` for an example: the old code converted from `MacDelimiter` to `Delimiter` and back again, for no good reason. This suggests the author was confused about the types.
2023-08-01Auto merge of #114273 - nnethercote:move-doc-comment-desugaring, r=petrochenkovbors-12/+16
Move doc comment desugaring out of `TokenCursor`. It's awkward that `TokenCursor` sometimes desugars doc comments on the fly, but usually doesn't. r? `@petrochenkov`
2023-07-31Remove a `bool` for color in favor of the `WriteColor` trait wrapping ↵Oli Scherer-4/+18
colored and uncolored printing
2023-07-31Use builder pattern instead of lots of arguments for `EmitterWriter::new`Oli Scherer-14/+5
2023-07-31Remove `desugar_doc_comments` arg from `Parser::new()`.Nicholas Nethercote-4/+9
It's only true at one call site; do the desugaring there instead.
2023-07-31No need to desugar doc comments when parsing decl macro definitions.Nicholas Nethercote-1/+1
2023-07-31Reflow an overlong comment.Nicholas Nethercote-2/+2
2023-07-31Remove more unnecessary `return` keywords.Nicholas Nethercote-6/+5
2023-07-30inline format!() args up to and including rustc_middleMatthias Krüger-24/+23
2023-07-28Parse generic const itemsLeón Orell Valerian Liehr-1/+10
2023-07-28Auto merge of #114115 - nnethercote:less-token-tree-cloning, r=petrochenkovbors-34/+31
Less `TokenTree` cloning `TokenTreeCursor` has this comment on it: ``` // FIXME: Many uses of this can be replaced with by-reference iterator to avoid clones. ``` This PR completes that FIXME. It doesn't have much perf effect, but at least we now know that. r? `@petrochenkov`
2023-07-27Remove `Iterator` impl for `TokenTreeCursor`.Nicholas Nethercote-5/+5
This is surprising, but the new comment explains why. It's a logical conclusion in the drive to avoid `TokenTree` clones. `TokenTreeCursor` is now only used within `Parser`. It's still needed due to `replace_prev_and_rewind`.
2023-07-27Avoid some token tree cloning in decl macro parsing.Nicholas Nethercote-23/+23
By changing `into_trees` into `trees`. Some of the subsequent paths require explicit clones, but not all.
2023-07-27Replace `into_trees` with `trees` in a test.Nicholas Nethercote-3/+2
There's no need for token tree cloning here.
2023-07-27Simplify the `ttdelim_span` test.Nicholas Nethercote-3/+1
The existing code is a very complex and inefficient way to the get the span of the last token.
2023-07-26Squelch a noisy rustc_expand unittestEric Huss-24/+57
2023-07-25Use a builder instead of boolean/option argumentsOli Scherer-1/+1
2023-07-20Don't translate compiler-internal bug messagesOli Scherer-1/+1
2023-07-20Auto merge of #108714 - estebank:ice_dump, r=oli-obkbors-1/+1
On nightly, dump ICE backtraces to disk Implement rust-lang/compiler-team#578. When an ICE is encountered on nightly releases, the new rustc panic handler will also write the contents of the backtrace to disk. If any `delay_span_bug`s are encountered, their backtrace is also added to the file. The platform and rustc version will also be collected. <img width="1032" alt="Screenshot 2023-03-03 at 2 13 25 PM" src="https://user-images.githubusercontent.com/1606434/222842420-8e039740-4042-4563-b31d-599677171acf.png"> The current behavior will *always* write to disk on nightly builds, regardless of whether the backtrace is printed to the terminal, unless the environment variable `RUSTC_ICE_DISK_DUMP` is set to `0`. This is a compromise and can be changed.
2023-07-19Make it clearer that edition functions are >=, not ==Michael Goulet-1/+1
2023-07-19On nightly, dump ICE backtraces to diskEsteban Küber-1/+1
Implement rust-lang/compiler-team#578. When an ICE is encountered on nightly releases, the new rustc panic handler will also write the contents of the backtrace to disk. If any `delay_span_bug`s are encountered, their backtrace is also added to the file. The platform and rustc version will also be collected.
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-23/+26
2023-07-03perform TokenStream replacement in-place when possible in expand_macroThe 8472-2/+1
2023-06-28Rollup merge of #111571 - jhpratt:proc-macro-span, r=m-ou-seDylan DPC-12/+11
Implement proposed API for `proc_macro_span` As proposed in [#54725 (comment)](https://github.com/rust-lang/rust/issues/54725#issuecomment-1546918161). I have omitted the byte-level API as it's already available as [`Span::byte_range`](https://doc.rust-lang.org/nightly/proc_macro/struct.Span.html#method.byte_range). `@rustbot` label +A-proc-macros r? `@m-ou-se`
2023-06-27Rollup merge of #113084 - WaffleLapkin:less_map_or, r=NilstriebMatthias Krüger-1/+1
Simplify some conditions r? `@Nilstrieb` Some things taken out of my `is_none_or` pr.
2023-06-27Simplify some conditionsMaybe Waffle-1/+1
2023-06-21Fix msg passed to span_bugRaminder Singh-1/+1
2023-06-20Add `Span::{line, column}`Jacob Pratt-0/+10
2023-06-20`Span::{before, after}` → `Span::{start, end}`Jacob Pratt-2/+2
2023-06-20Remove `LineColumn`, `Span::start`, `Span::end`Jacob Pratt-12/+1
2023-06-16Add `SyntaxContext::is_root`Maybe Waffle-2/+2
2023-06-10expand: Change how `#![cfg(FALSE)]` behaves on crate rootVadim Petrochenkov-7/+21
Previously it removed all other attributes from the crate root. Now it removes only attributes below itself. So it becomes possible to configure some global crate properties even for fully unconfigured crates.
2023-06-08Rollup merge of #112396 - WaffleLapkin:track_more_diagnostics, r=compiler-errorsGuillaume Gomez-0/+5
Track more diagnostics in `rustc_expand` I wish we could lint this somehow...
2023-06-07Track more diagnostics in `rustc_expand`Maybe Waffle-0/+5
2023-06-07Auto merge of #109005 - Nilstrieb:dont-forgor-too-much-from-cfg, r=petrochenkovbors-12/+61
Remember names of `cfg`-ed out items to mention them in diagnostics # Examples ## `serde::Deserialize` without the `derive` feature (a classic beginner mistake) I had to slightly modify serde so that it uses explicit re-exports instead of a glob re-export. (Update: a serde PR was merged that adds the manual re-exports) ``` error[E0433]: failed to resolve: could not find `Serialize` in `serde` --> src/main.rs:1:17 | 1 | #[derive(serde::Serialize)] | ^^^^^^^^^ could not find `Serialize` in `serde` | note: crate `serde` has an item named `Serialize` but it is inactive because its cfg predicate evaluated to false --> /home/gh-Nilstrieb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.160/src/lib.rs:343:1 | 343 | #[cfg(feature = "serde_derive")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 344 | pub use serde_derive::{Deserialize, Serialize}; | ^^^^^^^^^ = note: the item is gated behind the `serde_derive` feature = note: see https://doc.rust-lang.org/cargo/reference/features.html for how to activate a crate's feature ``` (the suggestion is not ideal but that's serde's fault) I already tested the metadata size impact locally by compiling the `windows` crate without any features. `800k` -> `809k` r? `@ghost`
2023-06-07feat(expand): emit note for doc comment in macro matcherbohan-11/+35
2023-06-06fix(expand): prevent infinity loop in macro containing only "///"bohan-0/+2
2023-06-01Remember names of `cfg`-ed out items to mention them in diagnosticsNilstrieb-12/+61
`#[cfg]`s are frequently used to gate crate content behind cargo features. This can lead to very confusing errors when features are missing. For example, `serde` doesn't have the `derive` feature by default. Therefore, `serde::Serialize` fails to resolve with a generic error, even though the macro is present in the docs. This commit adds a list of all stripped item names to metadata. This is filled during macro expansion and then, through a fed query, persisted in metadata. The downstream resolver can then access the metadata to look at possible candidates for mentioning in the errors. This slightly increases metadata (800k->809k for the feature-heavy windows crate), but not enough to really matter.
2023-05-29Use `Cow` in `{D,Subd}iagnosticMessage`.Nicholas Nethercote-8/+8
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile.
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-5/+5
2023-05-19fix: emit error when fragment is `MethodReceiverExpr` and items is emptybohan-1/+5
2023-05-16Avoid `&format("...")` calls in error message code.Nicholas Nethercote-13/+19
Error message all end up passing into a function as an `impl Into<{D,Subd}iagnosticMessage>`. If an error message is creatd as `&format("...")` that means we allocate a string (in the `format!` call), then take a reference, and then clone (allocating again) the reference to produce the `{D,Subd}iagnosticMessage`, which is silly. This commit removes the leading `&` from a lot of these cases. This means the original `String` is moved into the `{D,Subd}iagnosticMessage`, avoiding the double allocations. This requires changing some function argument types from `&str` to `String` (when all arguments are `String`) or `impl Into<{D,Subd}iagnosticMessage>` (when some arguments are `String` and some are `&str`).
2023-05-06introduce `DynSend` and `DynSync` auto traitSparrowLii-6/+6
2023-05-05Rollup merge of #108801 - fee1-dead-contrib:c-str, r=compiler-errorsDylan DPC-0/+6
Implement RFC 3348, `c"foo"` literals RFC: https://github.com/rust-lang/rfcs/pull/3348 Tracking issue: #105723
2023-05-04Auto merge of #111014 - klensy:no-rc, r=WaffleLapkinbors-11/+12
try to downgrade Arc -> Lrc -> Rc -> no-Rc in few places Expecting this be not slower on non-parallel compiler and probably faster on parallel (checked that this PR builds on it).
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-17/+17
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.