about summary refs log tree commit diff
path: root/src/test/ui/proc-macro
AgeCommit message (Collapse)AuthorLines
2021-10-10Stabilize proc_macro::is_availablebjorn3-3/+0
2021-10-04Make `proc_macro_derive_resolution_fallback` a future-breakage lintAaron Hill-0/+72
When `cargo report future-incompatibilities` is stabilized (see #71249), this will cause dependencies that trigger this lint to be included in the report.
2021-10-02resolve: Cache module loading for all foreign modulesVadim Petrochenkov-5/+11
It was previously cached for modules loaded from `fn get_module`, but not for modules loaded from `fn build_reduced_graph_for_external_crate_res`. This also makes all foreign modules use their real parent, span and expansion instead of possibly a parent/span/expansion of their reexport. An ICE happening on attempt to decode expansions for foreign enums and traits is avoided. Also local enums and traits are now added to the module map.
2021-09-24Stabilize `feature(macro_attributes_in_derive_output)`Vadim Petrochenkov-107/+38
2021-09-24builtin_macros: Make #[derive(A, B, ...)] cfg-eval its input only for `A, B, ↵Vadim Petrochenkov-2/+46
...`
2021-09-13Auto merge of #87915 - estebank:fancy-spans, r=oli-obkbors-1/+1
Use smaller spans for some structured suggestions Use more accurate suggestion spans for * argument parse error * fully qualified path * missing code block type * numeric casts
2021-09-05Rollup merge of #88257 - estebank:invalid-attr-error, r=oli-obkMara Bos-3/+22
Provide more context on incorrect inner attribute Suggest changing an inner attribute into an outer attribute if followed by an item.
2021-09-02Provide more context on incorrect inner attributeEsteban Kuber-3/+22
Suggest changing an inner attribute into an outer attribute if followed by an item.
2021-09-01Stop sorting bodies by span.Camille GILLOT-8/+8
The definition order is already close to the span order, and only differs in corner cases.
2021-08-28fix evaluation of target_feature = "crt-static"12101111-1/+8
2021-08-23Clarify what attribute and derive macros look like.Mara Bos-2/+2
2021-08-23Update tests.Mara Bos-0/+10
2021-08-22Suggest importing the right kind of macro.Mara Bos-0/+4
2021-08-12Use smaller spans for some structured suggestionsEsteban Kuber-1/+1
Use more accurate suggestion spans for * argument parse error * fully qualified path * missing code block type * numeric casts * E0212
2021-08-11Modify structured suggestion outputEsteban Küber-3/+3
* On suggestions that include deletions, use a diff inspired output format * When suggesting addition, use `+` as underline * Color highlight modified span
2021-08-04Remove trailing whitespace from error messagesFabian Wolff-25/+25
2021-08-04Auto merge of #87712 - est31:line-column-1-based, r=petrochenkovbors-0/+75
Proc macro spans: make columns 1 based This makes proc macro spans consistent with the `column!()` macro as well as `std::panic::Location`, as both are 1-based. https://github.com/rust-lang/rust/issues/54725#issuecomment-497246753
2021-08-03Remove space after negative sign in Literal to_stringDavid Tolnay-3/+3
2021-08-03Auto merge of #87262 - dtolnay:negative, r=Aaron1011bors-0/+11
Support negative numbers in Literal::from_str proc_macro::Literal has allowed negative numbers in a single literal token ever since Rust 1.29, using https://doc.rust-lang.org/stable/proc_macro/struct.Literal.html#method.isize_unsuffixed and similar constructors. ```rust let lit = proc_macro::Literal::isize_unsuffixed(-10); ``` However, the suite of constructors on Literal is not sufficient for all use cases, for example arbitrary precision floats, or custom suffixes in FFI macros. ```rust let lit = proc_macro::Literal::f64_unsuffixed(0.101001000100001000001000000100000001); // :( let lit = proc_macro::Literal::i???_suffixed(10ulong); // :( ``` For those, macros construct the literal using from_str instead, which preserves arbitrary precision, custom suffixes, base, and digit grouping. ```rust let lit = "0.101001000100001000001000000100000001".parse::<Literal>().unwrap(); let lit = "10ulong".parse::<Literal>().unwrap(); let lit = "0b1000_0100_0010_0001".parse::<Literal>().unwrap(); ``` However, until this PR it was not possible to construct a literal token that is **both** negative **and** preserving of arbitrary precision etc. This PR fixes `Literal::from_str` to recognize negative integer and float literals.
2021-08-03Make the UTF-8 statement more explicit and explicitly test for itest31-7/+15
2021-08-03Add testsest31-0/+67
2021-07-27Make `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` warn by defaultAaron Hill-1/+1
2021-07-19Auto merge of #87225 - estebank:cleanup, r=oli-obkbors-8/+12
Various diagnostics clean ups/tweaks * Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-07-19Various diagnostics clean ups/tweaksEsteban Küber-8/+12
* Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-07-19Auto merge of #87146 - Aaron1011:better-macro-lint, r=petrochenkovbors-0/+69
Compute a better `lint_node_id` during expansion 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-18Support negative numbers in Literal::from_strDavid Tolnay-0/+11
2021-07-18Rollup merge of #86814 - Aaron1011:inner-doc-recover, r=estebankYuki Okushi-0/+22
Recover from a misplaced inner doc comment Fixes #86781
2021-07-17Add test for `#[allow]` for warnings on attribute macroAaron Hill-0/+69
2021-07-17Use LocalExpnId where possible.Camille GILLOT-33/+33
2021-07-14Add -Zfuture-incompat-test to assist with testing future-incompat reports.Eric Huss-6/+6
2021-07-10rustc_span: Revert addition of `proc_macro` field to `ExpnKind::Macro`Vadim Petrochenkov-10/+10
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-03rustc_ast_pretty: Don't print space after `$`Noah Lev-3/+3
For example, this code: $arg:expr used to be pretty-printed as: $ arg : expr but is now pretty-printed as: $arg : expr
2021-07-02Recover from a misplaced inner doc commentAaron Hill-0/+22
Fixes #86781
2021-06-06parser: Ensure that all nonterminals have tokens after parsingVadim Petrochenkov-0/+577
2021-05-19Add proc macro Literal parse testDavid Tolnay-0/+27
2021-05-19Make a more meaningful test for Punct eqDavid Tolnay-5/+5
2021-05-19Move proc_macro tests to ui testDavid Tolnay-0/+25
2021-05-19Make a ui test to take the role of libproc_macro #[test] testsDavid Tolnay-0/+28
2021-05-15Remove some unncessary spaces from pretty-printed tokenstream outputAaron Hill-41/+161
In addition to making the output look nicer for all crates, this also aligns the pretty-printing output with what the `rental` crate expects. This will allow us to eventually disable a backwards-compat hack in a follow-up PR.
2021-05-12Show macro name in 'this error originates in macro' messageAaron Hill-68/+68
When there are multiple macros in use, it can be difficult to tell which one was responsible for producing an error.
2021-05-12Implement span quoting for proc-macrosAaron Hill-6/+235
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-05-03parser: Remove support for inner attributes on non-block expressionsVadim Petrochenkov-542/+185
2021-04-29Implement RFC 1260 with feature_name `imported_main`.Charles Lew-12/+2
2021-04-12Turn old edition lints (anonymous-parameters, keyword-idents) into ↵Manish Goregaokar-0/+2
warn-by-default on 2015
2021-04-11Implement token-based handling of attributes during expansionAaron Hill-713/+725
This PR modifies the macro expansion infrastructure to handle attributes in a fully token-based manner. As a result: * Derives macros no longer lose spans when their input is modified by eager cfg-expansion. This is accomplished by performing eager cfg-expansion on the token stream that we pass to the derive proc-macro * Inner attributes now preserve spans in all cases, including when we have multiple inner attributes in a row. This is accomplished through the following changes: * New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced. These are very similar to a normal `TokenTree`, but they also track the position of attributes and attribute targets within the stream. They are built when we collect tokens during parsing. An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when we invoke a macro. * Token capturing and `LazyTokenStream` are modified to work with `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which is created during the parsing of a nested AST node to make the 'outer' AST node aware of the attributes and attribute target stored deeper in the token stream. * When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`), we tokenize and reparse our target, capturing additional information about the locations of `#[cfg]` and `#[cfg_attr]` attributes at any depth within the target. This is a performance optimization, allowing us to perform less work in the typical case where captured tokens never have eager cfg-expansion run.
2021-04-10Auto merge of #84023 - Aaron1011:derive-invoc-order, r=petrochenkovbors-24/+65
Expand derive invocations in left-to-right order While derives were being collected in left-to-order order, the corresponding `Invocation`s were being pushed in the wrong order.
2021-04-10Expand derive invocations in left-to-right orderAaron Hill-24/+65
While derives were being collected in left-to-order order, the corresponding `Invocation`s were being pushed in the wrong order.
2021-04-10Add some proc-macro attribute token handling testsAaron Hill-66/+1199
2021-04-07Rollup merge of #83634 - JohnTitor:proc-macro-ice, r=varkorDylan DPC-0/+68
Do not emit the advanced diagnostics on macros Fixes #83510
2021-04-03Remove redundant `ignore-tidy-linelength` annotationsSimon Jakobi-3/+1
This is step 2 towards fixing #77548. In the codegen and codegen-units test suites, the `//` comment markers were kept in order not to affect any source locations. This is because these tests cannot be automatically `--bless`ed.