-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
derive(SmartPointer): register helper attributes
- Loading branch information
1 parent
899eb03
commit f254ee6
Showing
7 changed files
with
102 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,32 @@ | ||
//@ 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 ANOTHER_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 ANOTHER_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
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