Rollup merge of #63867 - petrochenkov:dhelpers, r=matthewjasper
resolve: Block expansion of a derive container until all its derives are resolved So, it turns out there's one more reason to block expansion of a `#[derive]` container until all the derives inside it are resolved, beside `Copy` (https://github.com/rust-lang/rust/pull/63248). The set of derive helper attributes registered by derives in the container also has to be known before the derives themselves are expanded, otherwise it may be too late (see https://github.com/rust-lang/rust/pull/63468#issuecomment-524550872 and the `#[stable_hasher]`-related test failures in https://github.com/rust-lang/rust/pull/63468). So, we stop our attempts to unblock the container earlier, as soon as the `Copy` status is known, and just block until all its derives are resolved. After all the derives are resolved we immediately go and process their helper attributes in the item, without delaying it until expansion of the individual derives. Unblocks https://github.com/rust-lang/rust/pull/63468 r? @matthewjasper (as a reviewer of https://github.com/rust-lang/rust/pull/63248) cc @c410-f3r
This commit is contained in:
commit
e4e6b01ca1
15 changed files with 206 additions and 164 deletions
|
|
@ -1,15 +1,3 @@
|
|||
error: cannot find derive macro `Send` in this scope
|
||||
--> $DIR/deriving-bounds.rs:1:10
|
||||
|
|
||||
LL | #[derive(Send)]
|
||||
| ^^^^
|
||||
|
|
||||
note: unsafe traits like `Send` should be implemented explicitly
|
||||
--> $DIR/deriving-bounds.rs:1:10
|
||||
|
|
||||
LL | #[derive(Send)]
|
||||
| ^^^^
|
||||
|
||||
error: cannot find derive macro `Sync` in this scope
|
||||
--> $DIR/deriving-bounds.rs:5:10
|
||||
|
|
||||
|
|
@ -22,5 +10,17 @@ note: unsafe traits like `Sync` should be implemented explicitly
|
|||
LL | #[derive(Sync)]
|
||||
| ^^^^
|
||||
|
||||
error: cannot find derive macro `Send` in this scope
|
||||
--> $DIR/deriving-bounds.rs:1:10
|
||||
|
|
||||
LL | #[derive(Send)]
|
||||
| ^^^^
|
||||
|
|
||||
note: unsafe traits like `Send` should be implemented explicitly
|
||||
--> $DIR/deriving-bounds.rs:1:10
|
||||
|
|
||||
LL | #[derive(Send)]
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: cannot find derive macro `x3300` in this scope
|
||||
--> $DIR/issue-43106-gating-of-derive-2.rs:4:14
|
||||
--> $DIR/issue-43106-gating-of-derive-2.rs:12:14
|
||||
|
|
||||
LL | #[derive(x3300)]
|
||||
| ^^^^^
|
||||
|
|
@ -11,7 +11,7 @@ LL | #[derive(x3300)]
|
|||
| ^^^^^
|
||||
|
||||
error: cannot find derive macro `x3300` in this scope
|
||||
--> $DIR/issue-43106-gating-of-derive-2.rs:12:14
|
||||
--> $DIR/issue-43106-gating-of-derive-2.rs:4:14
|
||||
|
|
||||
LL | #[derive(x3300)]
|
||||
| ^^^^^
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
// `#![derive]` raises errors when it occurs at contexts other than ADT
|
||||
// definitions.
|
||||
|
||||
#![derive(Debug)]
|
||||
//~^ ERROR `derive` may only be applied to structs, enums and unions
|
||||
|
||||
#[derive(Debug)]
|
||||
//~^ ERROR `derive` may only be applied to structs, enums and unions
|
||||
mod derive {
|
||||
|
|
|
|||
|
|
@ -1,38 +1,32 @@
|
|||
error: `derive` may only be applied to structs, enums and unions
|
||||
--> $DIR/issue-43106-gating-of-derive.rs:4:1
|
||||
|
|
||||
LL | #![derive(Debug)]
|
||||
| ^^^^^^^^^^^^^^^^^ help: try an outer attribute: `#[derive(Debug)]`
|
||||
|
||||
error: `derive` may only be applied to structs, enums and unions
|
||||
--> $DIR/issue-43106-gating-of-derive.rs:7:1
|
||||
|
|
||||
LL | #[derive(Debug)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `derive` may only be applied to structs, enums and unions
|
||||
--> $DIR/issue-43106-gating-of-derive.rs:10:17
|
||||
--> $DIR/issue-43106-gating-of-derive.rs:7:17
|
||||
|
|
||||
LL | mod inner { #![derive(Debug)] }
|
||||
| ^^^^^^^^^^^^^^^^^ help: try an outer attribute: `#[derive(Debug)]`
|
||||
|
||||
error: `derive` may only be applied to structs, enums and unions
|
||||
--> $DIR/issue-43106-gating-of-derive.rs:13:5
|
||||
--> $DIR/issue-43106-gating-of-derive.rs:10:5
|
||||
|
|
||||
LL | #[derive(Debug)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `derive` may only be applied to structs, enums and unions
|
||||
--> $DIR/issue-43106-gating-of-derive.rs:26:5
|
||||
--> $DIR/issue-43106-gating-of-derive.rs:23:5
|
||||
|
|
||||
LL | #[derive(Debug)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `derive` may only be applied to structs, enums and unions
|
||||
--> $DIR/issue-43106-gating-of-derive.rs:30:5
|
||||
--> $DIR/issue-43106-gating-of-derive.rs:27:5
|
||||
|
|
||||
LL | #[derive(Debug)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![derive(Copy)] //~ ERROR `derive` may only be applied to structs, enums and unions
|
||||
//~| ERROR cannot determine resolution for the derive macro `Copy`
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -4,5 +4,13 @@ error: `derive` may only be applied to structs, enums and unions
|
|||
LL | #![derive(Copy)]
|
||||
| ^^^^^^^^^^^^^^^^ help: try an outer attribute: `#[derive(Copy)]`
|
||||
|
||||
error: aborting due to previous error
|
||||
error: cannot determine resolution for the derive macro `Copy`
|
||||
--> $DIR/issue-36617.rs:1:11
|
||||
|
|
||||
LL | #![derive(Copy)]
|
||||
| ^^^^
|
||||
|
|
||||
= note: import resolution is stuck, try simplifying macro imports
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
18
src/test/ui/proc-macro/derive-helper-configured.rs
Normal file
18
src/test/ui/proc-macro/derive-helper-configured.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Derive helpers are resolved successfully inside `cfg_attr`.
|
||||
|
||||
// check-pass
|
||||
// compile-flats:--cfg TRUE
|
||||
// aux-build:test-macros.rs
|
||||
|
||||
#[macro_use]
|
||||
extern crate test_macros;
|
||||
|
||||
#[cfg_attr(TRUE, empty_helper)]
|
||||
#[derive(Empty)]
|
||||
#[cfg_attr(TRUE, empty_helper)]
|
||||
struct S {
|
||||
#[cfg_attr(TRUE, empty_helper)]
|
||||
field: u8,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -19,7 +19,8 @@ struct S {
|
|||
struct U;
|
||||
|
||||
mod inner {
|
||||
#[empty_helper] //~ ERROR cannot find attribute macro `empty_helper` in this scope
|
||||
// FIXME No ambiguity, attributes in non-macro positions are not resolved properly
|
||||
#[empty_helper]
|
||||
struct V;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,3 @@
|
|||
error: cannot find attribute macro `empty_helper` in this scope
|
||||
--> $DIR/derive-helper-shadowing.rs:22:15
|
||||
|
|
||||
LL | #[empty_helper]
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error[E0659]: `empty_helper` is ambiguous (derive helper attribute vs any other name)
|
||||
--> $DIR/derive-helper-shadowing.rs:8:3
|
||||
|
|
||||
|
|
@ -22,6 +16,6 @@ LL | use test_macros::empty_attr as empty_helper;
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= help: use `crate::empty_helper` to refer to this attribute macro unambiguously
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0659`.
|
||||
|
|
|
|||
|
|
@ -1,50 +1,8 @@
|
|||
error: cannot find derive macro `FooWithLongNan` in this scope
|
||||
--> $DIR/resolve-error.rs:22:10
|
||||
error: cannot find macro `bang_proc_macrp!` in this scope
|
||||
--> $DIR/resolve-error.rs:56:5
|
||||
|
|
||||
LL | #[derive(FooWithLongNan)]
|
||||
| ^^^^^^^^^^^^^^ help: a derive macro with a similar name exists: `FooWithLongName`
|
||||
|
||||
error: cannot find attribute macro `attr_proc_macra` in this scope
|
||||
--> $DIR/resolve-error.rs:27:3
|
||||
|
|
||||
LL | #[attr_proc_macra]
|
||||
| ^^^^^^^^^^^^^^^ help: an attribute macro with a similar name exists: `attr_proc_macro`
|
||||
|
||||
error: cannot find attribute macro `FooWithLongNan` in this scope
|
||||
--> $DIR/resolve-error.rs:31:3
|
||||
|
|
||||
LL | #[FooWithLongNan]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: cannot find derive macro `Dlone` in this scope
|
||||
--> $DIR/resolve-error.rs:34:10
|
||||
|
|
||||
LL | #[derive(Dlone)]
|
||||
| ^^^^^ help: a derive macro with a similar name exists: `Clone`
|
||||
|
||||
error: cannot find derive macro `Dlona` in this scope
|
||||
--> $DIR/resolve-error.rs:38:10
|
||||
|
|
||||
LL | #[derive(Dlona)]
|
||||
| ^^^^^ help: a derive macro with a similar name exists: `Clona`
|
||||
|
||||
error: cannot find derive macro `attr_proc_macra` in this scope
|
||||
--> $DIR/resolve-error.rs:42:10
|
||||
|
|
||||
LL | #[derive(attr_proc_macra)]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: cannot find macro `FooWithLongNama!` in this scope
|
||||
--> $DIR/resolve-error.rs:47:5
|
||||
|
|
||||
LL | FooWithLongNama!();
|
||||
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `FooWithLongNam`
|
||||
|
||||
error: cannot find macro `attr_proc_macra!` in this scope
|
||||
--> $DIR/resolve-error.rs:50:5
|
||||
|
|
||||
LL | attr_proc_macra!();
|
||||
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `attr_proc_mac`
|
||||
LL | bang_proc_macrp!();
|
||||
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `bang_proc_macro`
|
||||
|
||||
error: cannot find macro `Dlona!` in this scope
|
||||
--> $DIR/resolve-error.rs:53:5
|
||||
|
|
@ -52,11 +10,53 @@ error: cannot find macro `Dlona!` in this scope
|
|||
LL | Dlona!();
|
||||
| ^^^^^
|
||||
|
||||
error: cannot find macro `bang_proc_macrp!` in this scope
|
||||
--> $DIR/resolve-error.rs:56:5
|
||||
error: cannot find macro `attr_proc_macra!` in this scope
|
||||
--> $DIR/resolve-error.rs:50:5
|
||||
|
|
||||
LL | bang_proc_macrp!();
|
||||
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `bang_proc_macro`
|
||||
LL | attr_proc_macra!();
|
||||
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `attr_proc_mac`
|
||||
|
||||
error: cannot find macro `FooWithLongNama!` in this scope
|
||||
--> $DIR/resolve-error.rs:47:5
|
||||
|
|
||||
LL | FooWithLongNama!();
|
||||
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `FooWithLongNam`
|
||||
|
||||
error: cannot find derive macro `attr_proc_macra` in this scope
|
||||
--> $DIR/resolve-error.rs:42:10
|
||||
|
|
||||
LL | #[derive(attr_proc_macra)]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: cannot find derive macro `Dlona` in this scope
|
||||
--> $DIR/resolve-error.rs:38:10
|
||||
|
|
||||
LL | #[derive(Dlona)]
|
||||
| ^^^^^ help: a derive macro with a similar name exists: `Clona`
|
||||
|
||||
error: cannot find derive macro `Dlone` in this scope
|
||||
--> $DIR/resolve-error.rs:34:10
|
||||
|
|
||||
LL | #[derive(Dlone)]
|
||||
| ^^^^^ help: a derive macro with a similar name exists: `Clone`
|
||||
|
||||
error: cannot find attribute macro `FooWithLongNan` in this scope
|
||||
--> $DIR/resolve-error.rs:31:3
|
||||
|
|
||||
LL | #[FooWithLongNan]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: cannot find attribute macro `attr_proc_macra` in this scope
|
||||
--> $DIR/resolve-error.rs:27:3
|
||||
|
|
||||
LL | #[attr_proc_macra]
|
||||
| ^^^^^^^^^^^^^^^ help: an attribute macro with a similar name exists: `attr_proc_macro`
|
||||
|
||||
error: cannot find derive macro `FooWithLongNan` in this scope
|
||||
--> $DIR/resolve-error.rs:22:10
|
||||
|
|
||||
LL | #[derive(FooWithLongNan)]
|
||||
| ^^^^^^^^^^^^^^ help: a derive macro with a similar name exists: `FooWithLongName`
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue