about summary refs log tree commit diff
path: root/compiler/rustc_expand/src
AgeCommit message (Collapse)AuthorLines
2022-06-16Rollup merge of #97757 - xFrednet:rfc-2383-expect-with-force-warn, ↵Matthias Krüger-1/+1
r=wesleywiser,flip1995 Support lint expectations for `--force-warn` lints (RFC 2383) Rustc has a `--force-warn` flag, which overrides lint level attributes and forces the diagnostics to always be warn. This means, that for lint expectations, the diagnostic can't be suppressed as usual. This also means that the expectation would not be fulfilled, even if a lint had been triggered in the expected scope. This PR now also tracks the expectation ID in the `ForceWarn` level. I've also made some minor adjustments, to possibly catch more bugs and make the whole implementation more robust. This will probably conflict with https://github.com/rust-lang/rust/pull/97718. That PR should ideally be reviewed and merged first. The conflict itself will be trivial to fix. --- r? `@wesleywiser` cc: `@flip1995` since you've helped with the initial review and also discussed this topic with me. :upside_down_face: Follow-up of: https://github.com/rust-lang/rust/pull/87835 Issue: https://github.com/rust-lang/rust/issues/85549 Yeah, and that's it.
2022-06-16Support lint expectations for `--force-warn` lints (RFC 2383)xFrednet-1/+1
2022-06-13remove unnecessary `to_string` and `String::new`Takayuki Maeda-6/+6
2022-06-12Auto merge of #98020 - ↵bors-1/+1
TaKO8Ki:use-create-snapshot-for-diagnostic-in-rustc-expand, r=Dylan-DPC Use `create_snapshot_for_diagnostic` instead of `clone` for `Parser` Use [`create_snapshot_for_diagnostic`](https://github.com/rust-lang/rust/blob/cd119057160cedea245aa2679add56723f3dc784/compiler/rustc_parse/src/parser/diagnostics.rs#L214-L223) I implemented in https://github.com/rust-lang/rust/pull/94731 instead of `clone` to avoid duplicate unclosed delims errors being emitted when the `Parser` is dropped. I missed this one in #95068.
2022-06-12use `create_snapshot_for_diagnostic` instead of `clone`Takayuki Maeda-1/+1
2022-06-11Auto merge of #97903 - est31:unused_macro_rules_compile_error, r=petrochenkovbors-6/+41
Never regard macro rules with compile_error! invocations as unused The very point of compile_error! is to never be reached, and one of the use cases of the macro, currently also listed as examples in the documentation of compile_error, is to create nicer errors for wrong macro invocations. Thus, we should never warn about unused macro arms that contain invocations of compile_error. See also https://github.com/rust-lang/rust/pull/96150#issuecomment-1126599107 and the discussion after that. Furthermore, the PR also contains two commits to silence `unused_macro_rules` when a macro has an invalid rule, and to add a test that `unused_macros` does not behave badly in the same situation. r? `@petrochenkov` as I've talked to them about this
2022-06-09Suppress the unused_macro_rules lint if malformed rules are encounteredest31-4/+6
Prior to this commit, if a macro had any malformed rules, all rules would be reported as unused, regardless of whether they were used or not. So we just turn off unused rule checking completely for macros with malformed rules.
2022-06-09Never regard macro rules with compile_error! invocations as unusedest31-2/+35
The very point of compile_error! is to never be reached, and one of the use cases of the macro, currently also listed as examples in the documentation of compile_error, is to create nicer errors for wrong macro invocations. Thus, we shuuld never warn about unused macro arms that contain invocations of compile_error.
2022-06-09Rollup merge of #95860 - c410-f3r:stabilize-meta, r=joshtriplettYuki Okushi-2/+0
Stabilize `$$` in Rust 1.63.0 # Stabilization proposal This PR proposes the stabilization of a subset of `#![feature(macro_metavar_expr)]` or more specifically, the stabilization of dollar-dollar (`$$`). Tracking issue: #83527 Version: 1.63 (2022-06-28 => beta, 2022-08-11 => stable). ## What is stabilized ```rust macro_rules! foo { () => { macro_rules! bar { ( $$( $$any:tt )* ) => { $$( $$any )* }; } }; } fn main() { foo!(); } ``` ## Motivation For more examples, see the [RFC](https://github.com/markbt/rfcs/blob/macro_metavar_expr/text/0000-macro-metavar-expr.md). Users must currently resort to a tricky and not so well-known hack to declare nested macros with repetitions. ```rust macro_rules! foo { ($dollar:tt) => { macro_rules! bar { ( $dollar ( $any:tt )* ) => { $dollar ( $any )* }; } }; } fn main() { foo!($); } ``` As seen above, such hack is fragile and makes work with declarative macros much more unpleasant. Dollar-dollar (`$$`), on the other hand, makes nested macros more intuitive. ## What isn't stabilized `count`, `ignore`, `index` and `length` are not being stabilized due to the lack of consensus. ## History * 2021-02-22, [RFC: Declarative macro metavariable expressions](https://github.com/rust-lang/rfcs/pull/3086) * 2021-03-26, [Tracking Issue for RFC 3086: macro metavariable expressions](https://github.com/rust-lang/rust/issues/83527) * 2022-02-01, [Implement macro meta-variable expressions](https://github.com/rust-lang/rust/pull/93545) * 2022-02-25, [[1/2] Implement macro meta-variable expressions](https://github.com/rust-lang/rust/pull/94368) * 2022-03-11, [[2/2] Implement macro meta-variable expressions](https://github.com/rust-lang/rust/pull/94833) * 2022-03-12, [Fix remaining meta-variable expression TODOs](https://github.com/rust-lang/rust/pull/94884) * 2019-03-21, [[macro-metavar-expr] Fix generated tokens hygiene](https://github.com/rust-lang/rust/pull/95188) * 2022-04-07, [Kickstart the inner usage of macro_metavar_expr](https://github.com/rust-lang/rust/pull/95761) * 2022-04-07, [[macro_metavar_expr] Add tests to ensure the feature requirement](https://github.com/rust-lang/rust/pull/95764) ## Non-stabilized expressions https://github.com/rust-lang/rust/issues/83527 lists several concerns about some characteristics of `count`, `index` and `length` that effectively make their stabilization unfeasible. `$$` and `ignore`, however, are not part of any discussion and thus are suitable for stabilization. It is not in the scope of this PR to detail each concern or suggest any possible converging solution. Such thing should be restrained in this tracking issue. ## Tests This list is a subset of https://github.com/rust-lang/rust/tree/master/src/test/ui/macros/rfc-3086-metavar-expr * [Ensures that nested macros have correct behavior](https://github.com/rust-lang/rust/blob/master/src/test/ui/macros/rfc-3086-metavar-expr/dollar-dollar-has-correct-behavior.rs) * [Compares produced tokens to assert expected outputs](https://github.com/rust-lang/rust/blob/master/src/test/ui/macros/rfc-3086-metavar-expr/feature-gate-macro_metavar_expr.rs) * [Checks the declarations of the feature](https://github.com/rust-lang/rust/blob/master/src/test/ui/macros/rfc-3086-metavar-expr/required-feature.rs) * [Verifies all possible errors that can occur due to incorrect user input](https://github.com/rust-lang/rust/blob/master/src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.rs) ## Possible future work Once consensus is achieved, other nightly expressions can be stabilized. Thanks ``@markbt`` for creating the RFC and thanks to ``@petrochenkov`` and ``@mark-i-m`` for reviewing the implementations.
2022-06-08Fix typo: fo->forChayim Refael Friedman-1/+1
2022-06-07Stabilize $$ in Rust 1.63.0Caio-2/+0
2022-06-02Basic compiler infraCaio-1/+5
2022-05-29Rollup merge of #97536 - est31:remove_unused_lifetimes, r=compiler-errorsMichael Goulet-3/+3
Remove unused lifetimes from expand_macro The function doesn't need the lifetimes of the two arguments be bound together.
2022-05-29Remove unused lifetimes from expand_macroest31-3/+3
The function doesn't need the lifetimes of the two arguments be bound together.
2022-05-29Rollup merge of #97478 - JohnTitor:fixme-fn-decl, r=compiler-errorsGuillaume Gomez-1/+1
Remove FIXME on `ExtCtxt::fn_decl()` `ExtCtxt::fn_decl()` is used like `self.fn_decl(..)` or `self.cx.fn_decl(..)`, coverting it to an assoc fn, for example, makes it inconvenience (e.g. `self.cx.fn_decl(..)` would be longer to represent). Given that, it doesn't seem a "FIXME" thing and unused `self` is okay, I think.
2022-05-28Remove FIXME on `ExtCtxt::fn_decl()`Yuki Okushi-1/+1
2022-05-27proc_macro: don't pass a client-side function pointer through the server.Eduard-Mihai Burtescu-3/+3
2022-05-27Rename `ProcMacroDerive` as `DeriveProcMacro`.Nicholas Nethercote-2/+2
So it matches the existing `AttrProcMacro` and `BangProcMacro` types.
2022-05-27Rename `ProcMacro` trait as `BangProcMacro`.Nicholas Nethercote-4/+4
Similar to the existing `AttrProcMacro` trait.
2022-05-22rustc_parse: Move AST -> TokenStream conversion logic to `rustc_ast`Vadim Petrochenkov-19/+18
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-33/+32
2022-05-18use `CursorRef` more, to not to clone `Tree`sklensy-18/+20
2022-05-13Use pluralize in one instanceest31-2/+2
2022-05-13Improve name and documentation of generic_extensionest31-3/+4
This function doesn't *create* a (rules based) macro, it *expands* it. Thus, the documentation was wrong.
2022-05-12Auto merge of #96150 - est31:unused_macro_rules, r=petrochenkovbors-12/+30
Implement a lint to warn about unused macro rules This implements a new lint to warn about unused macro rules (arms/matchers), similar to the `unused_macros` lint added by #41907 that warns about entire macros. ```rust macro_rules! unused_empty { (hello) => { println!("Hello, world!") }; () => { println!("empty") }; //~ ERROR: 1st rule of macro `unused_empty` is never used } fn main() { unused_empty!(hello); } ``` Builds upon #96149 and #96156. Fixes #73576
2022-05-11ast: Introduce some traits to get AST node properties genericallyVadim Petrochenkov-119/+70
And use them to avoid constructing some artificial `Nonterminal` tokens during expansion
2022-05-07Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errorsbors-5/+6
Begin fixing all the broken doctests in `compiler/` Begins to fix #95994. All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are. There are also a few that I marked `ignore` that could maybe be made to work but seem less important. Each `ignore` has a rough "reason" for ignoring after it parentheses, with - `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax" - `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy. - `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR. - `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup. Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful. I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
2022-05-05Implement the unused_macro_rules lintest31-12/+30
2022-05-05Auto merge of #91779 - ridwanabdillahi:natvis, r=michaelwoeristerbors-2/+39
Add a new Rust attribute to support embedding debugger visualizers Implemented [this RFC](https://github.com/rust-lang/rfcs/pull/3191) to add support for embedding debugger visualizers into a PDB. Added a new attribute `#[debugger_visualizer]` and updated the `CrateMetadata` to store debugger visualizers for crate dependencies. RFC: https://github.com/rust-lang/rfcs/pull/3191
2022-05-04Auto merge of #96683 - nnethercote:speed-up-Token-ident-lifetime, r=petrochenkovbors-4/+4
Speed up `Token::{ident,lifetime}` Some speed and cleanliness improvements. r? `@petrochenkov`
2022-05-04Fix spelling of an identifier.Nicholas Nethercote-4/+4
2022-05-03Add support for a new attribute `#[debugger_visualizer]` to support ↵ridwanabdillahi-2/+39
embedding debugger visualizers into a generated PDB. Cleanup `DebuggerVisualizerFile` type and other minor cleanup of queries. Merge the queries for debugger visualizers into a single query. Revert move of `resolve_path` to `rustc_builtin_macros`. Update dependencies in Cargo.toml for `rustc_passes`. Respond to PR comments. Load visualizer files into opaque bytes `Vec<u8>`. Debugger visualizers for dynamically linked crates should not be embedded in the current crate. Update the unstable book with the new feature. Add the tracking issue for the debugger_visualizer feature. Respond to PR comments and minor cleanups.
2022-05-02fix most compiler/ doctestsElliot Roberts-5/+6
2022-04-30Save colon span to suggest bounds.Camille GILLOT-0/+2
2022-04-29errors: `span_suggestion` takes `impl ToString`David Wood-1/+1
Change `span_suggestion` (and variants) to take `impl ToString` rather than `String` for the suggested code, as this simplifies the requirements on the diagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-28rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`Vadim Petrochenkov-61/+54
2022-04-28Rollup merge of #96471 - BoxyUwU:let_else_considered_harmful, r=lcnrDylan DPC-3/+1
replace let else with `?` r? `@oli-obk`
2022-04-27tut tut tutEllen-3/+1
2022-04-27Avoid producing `NoDelim` values in `Frame`.Nicholas Nethercote-11/+11
The code currently ignores the actual delimiter on the RHS and fakes up a `NoDelim`/`DelimSpan::dummy()` one. This commit changes it to use the actual delimiter. The commit also reorders the fields for the `Delimited` variant to match the `Sequence` variant.
2022-04-22start tracking proc-macros expansion spans in the self-profilerRémy Rakic-3/+12
2022-04-16Rollup merge of #96023 - matthiaskrgr:clippyper1304, r=lcnrDylan DPC-1/+1
couple of clippy::perf fixes
2022-04-15Rollup merge of #96027 - matthiaskrgr:clippy_rec, r=fee1-deadDylan DPC-27/+13
remove function parameters only used in recursion
2022-04-15Rollup merge of #96026 - matthiaskrgr:clippy_compl_1304, r=Dylan-DPCDylan DPC-1/+1
couple of clippy::complexity fixes
2022-04-15Rollup merge of #94461 - jhpratt:2024-edition, r=pnkfelixDylan DPC-1/+1
Create (unstable) 2024 edition [On Zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Deprecating.20macro.20scoping.20shenanigans/near/272860652), there was a small aside regarding creating the 2024 edition now as opposed to later. There was a reasonable amount of support and no stated opposition. This change creates the 2024 edition in the compiler and creates a prelude for the 2024 edition. There is no current difference between the 2021 and 2024 editions. Cargo and other tools will need to be updated separately, as it's not in the same repository. This change permits the vast majority of work towards the next edition to proceed _now_ instead of waiting until 2024. For sanity purposes, I've merged the "hello" UI tests into a single file with multiple revisions. Otherwise we'd end up with a file per edition, despite them being essentially identical. ````@rustbot```` label +T-lang +S-waiting-on-review Not sure on the relevant team, to be honest.
2022-04-14remove reudndant function param in check_matcher_core()Matthias Krüger-19/+7
2022-04-14remove function param that is only used in recursive of fn inner()Matthias Krüger-8/+6
2022-04-14Auto merge of #95928 - nnethercote:rm-TokenTree-Clone, r=petrochenkovbors-106/+164
Remove `<mbe::TokenTree as Clone>` `mbe::TokenTree` doesn't really need to implement `Clone`, and getting rid of that impl leads to some speed-ups. r? `@petrochenkov`
2022-04-14`mbe::TokenTree`: remove `Lrc` around `Delimited` and `SequenceRepetition`.Nicholas Nethercote-19/+10
2022-04-14Introduce `TtHandle` and use it in `TokenSet`.Nicholas Nethercote-53/+111
This removes the last use of `<mbe::TokenTree as Clone>`. It also removes two trivial methods on `Delimited`.
2022-04-13couple of clippy::complexity fixesMatthias Krüger-1/+1