Add macro for test which use std internally

This commit is contained in:
koka 2023-10-01 00:47:57 +09:00
parent 44b6aca96b
commit d5cc97e32c
No known key found for this signature in database
GPG Key ID: A5917A40697774CD
4 changed files with 45 additions and 11 deletions

View File

@ -21,6 +21,18 @@ pub fn derive(_: TokenStream) -> TokenStream {
output
}
#[proc_macro_derive(ImplStructWithStdDisplay)]
pub fn derive_std(_: TokenStream) -> TokenStream {
quote! {
struct A {}
impl ::std::fmt::Display for A {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write!(f, "A")
}
}
}
}
#[proc_macro_derive(FieldReassignWithDefault)]
pub fn derive_foo(_input: TokenStream) -> TokenStream {
quote! {

View File

@ -1,8 +1,12 @@
//@aux-build:proc_macro_derive.rs
#![warn(clippy::std_instead_of_core)]
#![allow(unused_imports)]
extern crate alloc;
#[macro_use]
extern crate proc_macro_derive;
#[warn(clippy::std_instead_of_core)]
fn std_instead_of_core() {
// Regular import
@ -55,6 +59,13 @@ fn alloc_instead_of_core() {
//~^ ERROR: used import from `alloc` instead of `core`
}
mod std_in_proc_macro_derive {
#[warn(clippy::alloc_instead_of_core)]
#[allow(unused)]
#[derive(ImplStructWithStdDisplay)]
struct B {}
}
fn main() {
std_instead_of_core();
std_instead_of_alloc();

View File

@ -1,8 +1,12 @@
//@aux-build:proc_macro_derive.rs
#![warn(clippy::std_instead_of_core)]
#![allow(unused_imports)]
extern crate alloc;
#[macro_use]
extern crate proc_macro_derive;
#[warn(clippy::std_instead_of_core)]
fn std_instead_of_core() {
// Regular import
@ -55,6 +59,13 @@ fn alloc_instead_of_core() {
//~^ ERROR: used import from `alloc` instead of `core`
}
mod std_in_proc_macro_derive {
#[warn(clippy::alloc_instead_of_core)]
#[allow(unused)]
#[derive(ImplStructWithStdDisplay)]
struct B {}
}
fn main() {
std_instead_of_core();
std_instead_of_alloc();

View File

@ -1,5 +1,5 @@
error: used import from `std` instead of `core`
--> $DIR/std_instead_of_core.rs:9:9
--> $DIR/std_instead_of_core.rs:13:9
|
LL | use std::hash::Hasher;
| ^^^ help: consider importing the item from `core`: `core`
@ -8,49 +8,49 @@ LL | use std::hash::Hasher;
= help: to override `-D warnings` add `#[allow(clippy::std_instead_of_core)]`
error: used import from `std` instead of `core`
--> $DIR/std_instead_of_core.rs:12:11
--> $DIR/std_instead_of_core.rs:16:11
|
LL | use ::std::hash::Hash;
| ^^^ help: consider importing the item from `core`: `core`
error: used import from `std` instead of `core`
--> $DIR/std_instead_of_core.rs:18:9
--> $DIR/std_instead_of_core.rs:22:9
|
LL | use std::fmt::{Debug, Result};
| ^^^ help: consider importing the item from `core`: `core`
error: used import from `std` instead of `core`
--> $DIR/std_instead_of_core.rs:22:15
--> $DIR/std_instead_of_core.rs:26:15
|
LL | let ptr = std::ptr::null::<u32>();
| ^^^ help: consider importing the item from `core`: `core`
error: used import from `std` instead of `core`
--> $DIR/std_instead_of_core.rs:24:21
--> $DIR/std_instead_of_core.rs:28:21
|
LL | let ptr_mut = ::std::ptr::null_mut::<usize>();
| ^^^ help: consider importing the item from `core`: `core`
error: used import from `std` instead of `core`
--> $DIR/std_instead_of_core.rs:28:16
--> $DIR/std_instead_of_core.rs:32:16
|
LL | let cell = std::cell::Cell::new(8u32);
| ^^^ help: consider importing the item from `core`: `core`
error: used import from `std` instead of `core`
--> $DIR/std_instead_of_core.rs:30:27
--> $DIR/std_instead_of_core.rs:34:27
|
LL | let cell_absolute = ::std::cell::Cell::new(8u32);
| ^^^ help: consider importing the item from `core`: `core`
error: used import from `std` instead of `core`
--> $DIR/std_instead_of_core.rs:39:9
--> $DIR/std_instead_of_core.rs:43:9
|
LL | use std::iter::Iterator;
| ^^^ help: consider importing the item from `core`: `core`
error: used import from `std` instead of `alloc`
--> $DIR/std_instead_of_core.rs:46:9
--> $DIR/std_instead_of_core.rs:50:9
|
LL | use std::vec;
| ^^^ help: consider importing the item from `alloc`: `alloc`
@ -59,13 +59,13 @@ LL | use std::vec;
= help: to override `-D warnings` add `#[allow(clippy::std_instead_of_alloc)]`
error: used import from `std` instead of `alloc`
--> $DIR/std_instead_of_core.rs:48:9
--> $DIR/std_instead_of_core.rs:52:9
|
LL | use std::vec::Vec;
| ^^^ help: consider importing the item from `alloc`: `alloc`
error: used import from `alloc` instead of `core`
--> $DIR/std_instead_of_core.rs:54:9
--> $DIR/std_instead_of_core.rs:58:9
|
LL | use alloc::slice::from_ref;
| ^^^^^ help: consider importing the item from `core`: `core`