2020-10-09 05:45:29 -05:00
|
|
|
// compile-flags: --emit=link
|
2019-04-09 16:19:11 -05:00
|
|
|
// no-prefer-dynamic
|
|
|
|
|
|
|
|
#![crate_type = "proc-macro"]
|
2020-01-31 16:02:31 -06:00
|
|
|
#![feature(repr128, proc_macro_quote)]
|
2020-10-22 07:23:14 -05:00
|
|
|
#![allow(incomplete_features)]
|
2021-01-15 03:56:44 -06:00
|
|
|
#![allow(clippy::field_reassign_with_default)]
|
2020-10-23 15:16:59 -05:00
|
|
|
#![allow(clippy::eq_op)]
|
2019-04-09 16:19:11 -05:00
|
|
|
|
|
|
|
extern crate proc_macro;
|
|
|
|
|
|
|
|
use proc_macro::{quote, TokenStream};
|
|
|
|
|
|
|
|
#[proc_macro_derive(DeriveSomething)]
|
|
|
|
pub fn derive(_: TokenStream) -> TokenStream {
|
2022-05-05 09:12:52 -05:00
|
|
|
// Should not trigger `used_underscore_binding`
|
2019-04-20 02:33:13 -05:00
|
|
|
let _inside_derive = 1;
|
|
|
|
assert_eq!(_inside_derive, _inside_derive);
|
|
|
|
|
2019-04-09 16:19:11 -05:00
|
|
|
let output = quote! {
|
2019-04-20 02:33:13 -05:00
|
|
|
// Should not trigger `useless_attribute`
|
2019-04-09 16:19:11 -05:00
|
|
|
#[allow(dead_code)]
|
2020-03-30 04:02:14 -05:00
|
|
|
extern crate rustc_middle;
|
2019-04-09 16:19:11 -05:00
|
|
|
};
|
|
|
|
output
|
|
|
|
}
|
2021-01-15 03:56:44 -06:00
|
|
|
|
|
|
|
#[proc_macro_derive(FieldReassignWithDefault)]
|
|
|
|
pub fn derive_foo(_input: TokenStream) -> TokenStream {
|
|
|
|
quote! {
|
|
|
|
#[derive(Default)]
|
|
|
|
struct A {
|
|
|
|
pub i: i32,
|
|
|
|
pub j: i64,
|
|
|
|
}
|
|
|
|
#[automatically_derived]
|
|
|
|
fn lint() {
|
|
|
|
let mut a: A = Default::default();
|
|
|
|
a.i = 42;
|
|
|
|
a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-25 04:25:22 -06:00
|
|
|
|
|
|
|
#[proc_macro_derive(StructAUseSelf)]
|
|
|
|
pub fn derive_use_self(_input: TokenStream) -> proc_macro::TokenStream {
|
|
|
|
quote! {
|
|
|
|
struct A;
|
|
|
|
impl A {
|
|
|
|
fn new() -> A {
|
|
|
|
A
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-03 01:41:37 -05:00
|
|
|
|
|
|
|
#[proc_macro_derive(ClippyMiniMacroTest)]
|
|
|
|
pub fn mini_macro(_: TokenStream) -> TokenStream {
|
|
|
|
quote!(
|
|
|
|
#[allow(unused)]
|
|
|
|
fn needless_take_by_value(s: String) {
|
|
|
|
println!("{}", s.len());
|
|
|
|
}
|
|
|
|
#[allow(unused)]
|
|
|
|
fn needless_loop(items: &[u8]) {
|
|
|
|
for i in 0..items.len() {
|
|
|
|
println!("{}", items[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn line_wrapper() {
|
|
|
|
println!("{}", line!());
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2022-06-30 03:50:09 -05:00
|
|
|
|
|
|
|
#[proc_macro_derive(ExtraLifetimeDerive)]
|
|
|
|
#[allow(unused)]
|
|
|
|
pub fn extra_lifetime(_input: TokenStream) -> TokenStream {
|
|
|
|
quote!(
|
|
|
|
pub struct ExtraLifetime;
|
|
|
|
|
|
|
|
impl<'b> ExtraLifetime {
|
|
|
|
pub fn something<'c>() -> Self {
|
|
|
|
Self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|