forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#128925 - dingxiangfei2009:smart-ptr-helper-attr, r=compiler-errors derive(SmartPointer): register helper attributes Fix rust-lang#128888 This PR enables built-in macros to register helper attributes, if any, to support correct name resolution in the correct lexical scope under the macros. Also, `#[pointee]` is moved into the scope under `derive(SmartPointer)`. cc `@Darksonn` `@davidtwco`
- Loading branch information
Showing
9 changed files
with
165 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//@ force-host | ||
//@ no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
#![feature(proc_macro_quote)] | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::{quote, TokenStream}; | ||
|
||
#[proc_macro_derive(AnotherMacro, attributes(pointee))] | ||
pub fn derive(_input: TokenStream) -> TokenStream { | ||
quote! { | ||
const _: () = { | ||
const ANOTHER_MACRO_DERIVED: () = (); | ||
}; | ||
} | ||
.into() | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn pointee( | ||
_attr: proc_macro::TokenStream, | ||
_item: proc_macro::TokenStream, | ||
) -> proc_macro::TokenStream { | ||
quote! { | ||
const _: () = { | ||
const POINTEE_MACRO_ATTR_DERIVED: () = (); | ||
}; | ||
} | ||
.into() | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn default( | ||
_attr: proc_macro::TokenStream, | ||
_item: proc_macro::TokenStream, | ||
) -> proc_macro::TokenStream { | ||
quote! { | ||
const _: () = { | ||
const DEFAULT_MACRO_ATTR_DERIVED: () = (); | ||
}; | ||
} | ||
.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//@ check-pass | ||
//@ aux-build: another-proc-macro.rs | ||
//@ compile-flags: -Zunpretty=expanded | ||
|
||
#![feature(derive_smart_pointer)] | ||
|
||
#[macro_use] | ||
extern crate another_proc_macro; | ||
|
||
use another_proc_macro::{pointee, AnotherMacro}; | ||
|
||
#[derive(core::marker::SmartPointer)] | ||
#[repr(transparent)] | ||
pub struct Ptr<'a, #[pointee] T: ?Sized> { | ||
data: &'a mut T, | ||
} | ||
|
||
#[pointee] | ||
fn f() {} | ||
|
||
#[derive(AnotherMacro)] | ||
#[pointee] | ||
struct MyStruct; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#![feature(prelude_import)] | ||
#![no_std] | ||
//@ check-pass | ||
//@ aux-build: another-proc-macro.rs | ||
//@ compile-flags: -Zunpretty=expanded | ||
|
||
#![feature(derive_smart_pointer)] | ||
#[prelude_import] | ||
use ::std::prelude::rust_2015::*; | ||
#[macro_use] | ||
extern crate std; | ||
|
||
#[macro_use] | ||
extern crate another_proc_macro; | ||
|
||
use another_proc_macro::{pointee, AnotherMacro}; | ||
|
||
#[repr(transparent)] | ||
pub struct Ptr<'a, #[pointee] T: ?Sized> { | ||
data: &'a mut T, | ||
} | ||
#[automatically_derived] | ||
impl<'a, T: ?Sized + ::core::marker::Unsize<__S>, __S: ?Sized> | ||
::core::ops::DispatchFromDyn<Ptr<'a, __S>> for Ptr<'a, T> { | ||
} | ||
#[automatically_derived] | ||
impl<'a, T: ?Sized + ::core::marker::Unsize<__S>, __S: ?Sized> | ||
::core::ops::CoerceUnsized<Ptr<'a, __S>> for Ptr<'a, T> { | ||
} | ||
|
||
|
||
|
||
const _: () = | ||
{ | ||
const POINTEE_MACRO_ATTR_DERIVED: () = (); | ||
}; | ||
#[pointee] | ||
struct MyStruct; | ||
const _: () = | ||
{ | ||
const ANOTHER_MACRO_DERIVED: () = (); | ||
}; | ||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// This test certify that we can mix attribute macros from Rust and external proc-macros. | ||
// For instance, `#[derive(Default)]` uses `#[default]` and `#[derive(SmartPointer)]` uses | ||
// `#[pointee]`. | ||
// The scoping rule should allow the use of the said two attributes when external proc-macros | ||
// are in scope. | ||
|
||
//@ check-pass | ||
//@ aux-build: another-proc-macro.rs | ||
//@ compile-flags: -Zunpretty=expanded | ||
|
||
#![feature(derive_smart_pointer)] | ||
|
||
#[macro_use] | ||
extern crate another_proc_macro; | ||
|
||
#[pointee] | ||
fn f() {} | ||
|
||
#[default] | ||
fn g() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#![feature(prelude_import)] | ||
#![no_std] | ||
// This test certify that we can mix attribute macros from Rust and external proc-macros. | ||
// For instance, `#[derive(Default)]` uses `#[default]` and `#[derive(SmartPointer)]` uses | ||
// `#[pointee]`. | ||
// The scoping rule should allow the use of the said two attributes when external proc-macros | ||
// are in scope. | ||
|
||
//@ check-pass | ||
//@ aux-build: another-proc-macro.rs | ||
//@ compile-flags: -Zunpretty=expanded | ||
|
||
#![feature(derive_smart_pointer)] | ||
#[prelude_import] | ||
use ::std::prelude::rust_2015::*; | ||
#[macro_use] | ||
extern crate std; | ||
|
||
#[macro_use] | ||
extern crate another_proc_macro; | ||
|
||
|
||
const _: () = | ||
{ | ||
const POINTEE_MACRO_ATTR_DERIVED: () = (); | ||
}; | ||
const _: () = | ||
{ | ||
const DEFAULT_MACRO_ATTR_DERIVED: () = (); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters