summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/macros.rs
AgeCommit message (Collapse)AuthorLines
2022-07-21avoid embedding StabilityLevel::Unstable reason string into metadata ↵klensy-1/+1
multiple times
2022-07-20middle: add `implies_by` to `#[unstable]`David Wood-2/+9
If part of a feature is stabilized and a new feature is added for the remaining parts, then the `implied_by` attribute can be used to indicate which now-stable feature previously contained a item. If the now-stable feature is still active (if the user has only just updated rustc, for example) then there will not be an stability error for uses of the item from the implied feature. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-18avoid `Symbol` to `&str` conversionsTakayuki Maeda-2/+2
2022-06-17Auto merge of #98106 - cjgillot:split-definitions, r=michaelwoeristerbors-1/+0
Split up `Definitions` and `ResolverAstLowering`. Split off https://github.com/rust-lang/rust/pull/95573 r? `@michaelwoerister`
2022-06-14Make ResolverAstLowering a struct.Camille GILLOT-1/+0
2022-06-15implement `MacroData`Takayuki Maeda-2/+2
2022-06-09Never regard macro rules with compile_error! invocations as unusedest31-1/+1
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-03Conservatively report "not sure" in cfg_accessibleUrgau-1/+3
2022-05-30Handle more cases in cfg_accessibleUrgau-8/+13
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-8/+11
2022-05-05Implement the unused_macro_rules lintest31-6/+35
2022-05-01resolve: Merge `last_import_segment` into `Finalize`Vadim Petrochenkov-3/+0
2022-05-01resolve: Pass full `Finalize` in nearly all casesVadim Petrochenkov-2/+2
2022-05-01resolve: Turn `enum Finalize` into an optional structVadim Petrochenkov-1/+1
2022-04-12Pass last_import_segment and unusable_binding as parameters.Camille GILLOT-2/+9
2022-04-12Move ident resolution to a dedicated module.Camille GILLOT-362/+10
2022-03-30Spellchecking compiler commentsYuri Astrakhan-1/+1
This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-25resolve: Rename `CrateLint` to `Finalize`Vadim Petrochenkov-10/+10
And `crate_lint`/`record_used` to `finalize`
2022-03-25resolve: Stop passing unused spans and node ids to path resolution functionsVadim Petrochenkov-30/+18
2022-03-25resolve: Do not build expensive suggestions if they are not actually usedVadim Petrochenkov-4/+2
Also remove a redundant parameter from `fn resolve_path(_with_ribs)`, `crate_lint: CrateLint` is a more detailed version of `record_used: bool` with `CrateLint::No` meaning `false` and anything else meaning `true`.
2022-02-24resolve: Fix incorrect results of `opt_def_kind` query for some built-in macrosVadim Petrochenkov-1/+7
Previously it always returned `MacroKind::Bang` while some of those macros are actually attributes and derives
2022-02-15Rename `PtrKey` as `Interned` and improve it.Nicholas Nethercote-2/+2
In particular, there's now more protection against incorrect usage, because you can only create one via `Interned::new_unchecked`, which makes it more obvious that you must be careful. There are also some tests.
2022-01-23rustc_lint: Reuse the set of registered tools from resolverVadim Petrochenkov-1/+5
2021-12-15Remove unnecessary sigils around `Ident::as_str()` calls.Nicholas Nethercote-1/+1
2021-11-24Suggestion to wrap inner types using `allocator_api` in tupleKen Matsui-0/+1
2021-11-11Shorten Span of unused macro lintsMarcel Hellwig-2/+7
The span has been recuded to the actual ident, instead of linting the *whole* macro.
2021-09-30Remove visible path calculation from allowed deprecation lintAlik Aslanyan-1/+1
2021-09-25Auto merge of #87220 - petrochenkov:derivecfglimit2, r=Aaron1011bors-32/+0
Make `#[derive(A, B, ...)]` cfg-eval its input only for `A, B, ...` and stabilize `feature(macro_attributes_in_derive_output)` Stabilization report: https://github.com/rust-lang/rust/pull/87220#issuecomment-881923657 Closes #81119 r? `@Aaron1011`
2021-09-24Stabilize `feature(macro_attributes_in_derive_output)`Vadim Petrochenkov-32/+0
2021-09-24resolve: Refactor obtaining `Module` from its `DefId`Vadim Petrochenkov-1/+1
The `Option<Module>` version is supported for the case where we don't know whether the `DefId` refers to a module or not. Non-local traits and enums are also correctly found now.
2021-09-24resolve: Use a single common map for local and foreign modulesVadim Petrochenkov-4/+5
2021-09-24resolve: Rename some expansion def scope methodsVadim Petrochenkov-4/+3
2021-09-24resolve: Do not cache nearest parent mod in `ModuleData`Vadim Petrochenkov-1/+1
2021-09-10Record call_site parent for macros.Camille GILLOT-0/+4
2021-09-01Compute proc_macros in resolutions.Camille GILLOT-0/+4
2021-08-22Stop tracking namespce in used_imports.Mara Bos-1/+1
The information was tracked, but unused.
2021-07-17Compute a better `lint_node_id` during expansionAaron Hill-10/+6
When we need to emit a lint at a macro invocation, we currently use the `NodeId` of its parent definition (e.g. the enclosing function). This means that any `#[allow]` / `#[deny]` attributes placed 'closer' to the macro (e.g. on an enclosing block or statement) will have no effect. This commit computes a better `lint_node_id` in `InvocationCollector`. When we visit/flat_map an AST node, we assign it a `NodeId` (earlier than we normally would), and store than `NodeId` in current `ExpansionData`. When we collect a macro invocation, the current `lint_node_id` gets cloned along with our `ExpansionData`, allowing it to be used if we need to emit a lint later on. This improves the handling of `#[allow]` / `#[deny]` for `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` and some `asm!`-related lints. The 'legacy derive helpers' lint retains its current behavior (I've inlined the now-removed `lint_node_id` function), since there isn't an `ExpansionData` readily available.
2021-07-17Use LocalExpnId where possible.Camille GILLOT-13/+22
2021-07-13Cache expansion hash.Camille GILLOT-17/+23
2021-07-10rustc_span: Revert addition of `proc_macro` field to `ExpnKind::Macro`Vadim Petrochenkov-5/+1
The flag has a vague meaning and is used for a single diagnostic change that is low benefit and appears only under `-Z macro_backtrace`.
2021-07-06Store macro parent module in ExpnData.Camille GILLOT-15/+9
2021-06-20expand: Move some more derive logic to `rustc_builtin_macros`Vadim Petrochenkov-1/+1
2021-05-12Implement span quoting for proc-macrosAaron Hill-2/+10
This PR implements span quoting, allowing proc-macros to produce spans pointing *into their own crate*. This is used by the unstable `proc_macro::quote!` macro, allowing us to get error messages like this: ``` error[E0412]: cannot find type `MissingType` in this scope --> $DIR/auxiliary/span-from-proc-macro.rs:37:20 | LL | pub fn error_from_attribute(_args: TokenStream, _input: TokenStream) -> TokenStream { | ----------------------------------------------------------------------------------- in this expansion of procedural macro `#[error_from_attribute]` ... LL | field: MissingType | ^^^^^^^^^^^ not found in this scope | ::: $DIR/span-from-proc-macro.rs:8:1 | LL | #[error_from_attribute] | ----------------------- in this macro invocation ``` Here, `MissingType` occurs inside the implementation of the proc-macro `#[error_from_attribute]`. Previosuly, this would always result in a span pointing at `#[error_from_attribute]` This will make many proc-macro-related error message much more useful - when a proc-macro generates code containing an error, users will get an error message pointing directly at that code (within the macro definition), instead of always getting a span pointing at the macro invocation site. This is implemented as follows: * When a proc-macro crate is being *compiled*, it causes the `quote!` macro to get run. This saves all of the sapns in the input to `quote!` into the metadata of *the proc-macro-crate* (which we are currently compiling). The `quote!` macro then expands to a call to `proc_macro::Span::recover_proc_macro_span(id)`, where `id` is an opaque identifier for the span in the crate metadata. * When the same proc-macro crate is *run* (e.g. it is loaded from disk and invoked by some consumer crate), the call to `proc_macro::Span::recover_proc_macro_span` causes us to load the span from the proc-macro crate's metadata. The proc-macro then produces a `TokenStream` containing a `Span` pointing into the proc-macro crate itself. The recursive nature of 'quote!' can be difficult to understand at first. The file `src/test/ui/proc-macro/quote-debug.stdout` shows the output of the `quote!` macro, which should make this eaier to understand. This PR also supports custom quoting spans in custom quote macros (e.g. the `quote` crate). All span quoting goes through the `proc_macro::quote_span` method, which can be called by a custom quote macro to perform span quoting. An example of this usage is provided in `src/test/ui/proc-macro/auxiliary/custom-quote.rs` Custom quoting currently has a few limitations: In order to quote a span, we need to generate a call to `proc_macro::Span::recover_proc_macro_span`. However, proc-macros support renaming the `proc_macro` crate, so we can't simply hardcode this path. Previously, the `quote_span` method used the path `crate::Span` - however, this only works when it is called by the builtin `quote!` macro in the same crate. To support being called from arbitrary crates, we need access to the name of the `proc_macro` crate to generate a path. This PR adds an additional argument to `quote_span` to specify the name of the `proc_macro` crate. Howver, this feels kind of hacky, and we may want to change this before stabilizing anything quote-related. Additionally, using `quote_span` currently requires enabling the `proc_macro_internals` feature. The builtin `quote!` macro has an `#[allow_internal_unstable]` attribute, but this won't work for custom quote implementations. This will likely require some additional tricks to apply `allow_internal_unstable` to the span of `proc_macro::Span::recover_proc_macro_span`.
2021-04-04resolve: Stable order for derive helper attributesVadim Petrochenkov-5/+8
2021-04-04resolve/expand: Cache intermediate results of `#[derive]` expansionVadim Petrochenkov-38/+49
2021-03-27resolve: Partially unify early and late scope-relative ident resolutionVadim Petrochenkov-5/+22
2021-03-25Ban custom inner attributes in expressions and statementsAaron Hill-6/+15
2021-03-14expand: Resolve and expand inner attributes on out-of-line modulesVadim Petrochenkov-2/+25
2021-03-12Make def_key and HIR parenting consistent.Camille GILLOT-1/+1
2021-02-07Feature gate macro attributes in `#[derive]` outputVadim Petrochenkov-0/+30