Skip to content

Commit d5cc97e

Browse files
committed
Add macro for test which use std internally
1 parent 44b6aca commit d5cc97e

File tree

4 files changed

+45
-11
lines changed

4 files changed

+45
-11
lines changed

tests/ui/auxiliary/proc_macro_derive.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ pub fn derive(_: TokenStream) -> TokenStream {
2121
output
2222
}
2323

24+
#[proc_macro_derive(ImplStructWithStdDisplay)]
25+
pub fn derive_std(_: TokenStream) -> TokenStream {
26+
quote! {
27+
struct A {}
28+
impl ::std::fmt::Display for A {
29+
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
30+
write!(f, "A")
31+
}
32+
}
33+
}
34+
}
35+
2436
#[proc_macro_derive(FieldReassignWithDefault)]
2537
pub fn derive_foo(_input: TokenStream) -> TokenStream {
2638
quote! {

tests/ui/std_instead_of_core.fixed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
//@aux-build:proc_macro_derive.rs
12
#![warn(clippy::std_instead_of_core)]
23
#![allow(unused_imports)]
34

45
extern crate alloc;
56

7+
#[macro_use]
8+
extern crate proc_macro_derive;
9+
610
#[warn(clippy::std_instead_of_core)]
711
fn std_instead_of_core() {
812
// Regular import
@@ -55,6 +59,13 @@ fn alloc_instead_of_core() {
5559
//~^ ERROR: used import from `alloc` instead of `core`
5660
}
5761

62+
mod std_in_proc_macro_derive {
63+
#[warn(clippy::alloc_instead_of_core)]
64+
#[allow(unused)]
65+
#[derive(ImplStructWithStdDisplay)]
66+
struct B {}
67+
}
68+
5869
fn main() {
5970
std_instead_of_core();
6071
std_instead_of_alloc();

tests/ui/std_instead_of_core.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
//@aux-build:proc_macro_derive.rs
12
#![warn(clippy::std_instead_of_core)]
23
#![allow(unused_imports)]
34

45
extern crate alloc;
56

7+
#[macro_use]
8+
extern crate proc_macro_derive;
9+
610
#[warn(clippy::std_instead_of_core)]
711
fn std_instead_of_core() {
812
// Regular import
@@ -55,6 +59,13 @@ fn alloc_instead_of_core() {
5559
//~^ ERROR: used import from `alloc` instead of `core`
5660
}
5761

62+
mod std_in_proc_macro_derive {
63+
#[warn(clippy::alloc_instead_of_core)]
64+
#[allow(unused)]
65+
#[derive(ImplStructWithStdDisplay)]
66+
struct B {}
67+
}
68+
5869
fn main() {
5970
std_instead_of_core();
6071
std_instead_of_alloc();

tests/ui/std_instead_of_core.stderr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: used import from `std` instead of `core`
2-
--> $DIR/std_instead_of_core.rs:9:9
2+
--> $DIR/std_instead_of_core.rs:13:9
33
|
44
LL | use std::hash::Hasher;
55
| ^^^ help: consider importing the item from `core`: `core`
@@ -8,49 +8,49 @@ LL | use std::hash::Hasher;
88
= help: to override `-D warnings` add `#[allow(clippy::std_instead_of_core)]`
99

1010
error: used import from `std` instead of `core`
11-
--> $DIR/std_instead_of_core.rs:12:11
11+
--> $DIR/std_instead_of_core.rs:16:11
1212
|
1313
LL | use ::std::hash::Hash;
1414
| ^^^ help: consider importing the item from `core`: `core`
1515

1616
error: used import from `std` instead of `core`
17-
--> $DIR/std_instead_of_core.rs:18:9
17+
--> $DIR/std_instead_of_core.rs:22:9
1818
|
1919
LL | use std::fmt::{Debug, Result};
2020
| ^^^ help: consider importing the item from `core`: `core`
2121

2222
error: used import from `std` instead of `core`
23-
--> $DIR/std_instead_of_core.rs:22:15
23+
--> $DIR/std_instead_of_core.rs:26:15
2424
|
2525
LL | let ptr = std::ptr::null::<u32>();
2626
| ^^^ help: consider importing the item from `core`: `core`
2727

2828
error: used import from `std` instead of `core`
29-
--> $DIR/std_instead_of_core.rs:24:21
29+
--> $DIR/std_instead_of_core.rs:28:21
3030
|
3131
LL | let ptr_mut = ::std::ptr::null_mut::<usize>();
3232
| ^^^ help: consider importing the item from `core`: `core`
3333

3434
error: used import from `std` instead of `core`
35-
--> $DIR/std_instead_of_core.rs:28:16
35+
--> $DIR/std_instead_of_core.rs:32:16
3636
|
3737
LL | let cell = std::cell::Cell::new(8u32);
3838
| ^^^ help: consider importing the item from `core`: `core`
3939

4040
error: used import from `std` instead of `core`
41-
--> $DIR/std_instead_of_core.rs:30:27
41+
--> $DIR/std_instead_of_core.rs:34:27
4242
|
4343
LL | let cell_absolute = ::std::cell::Cell::new(8u32);
4444
| ^^^ help: consider importing the item from `core`: `core`
4545

4646
error: used import from `std` instead of `core`
47-
--> $DIR/std_instead_of_core.rs:39:9
47+
--> $DIR/std_instead_of_core.rs:43:9
4848
|
4949
LL | use std::iter::Iterator;
5050
| ^^^ help: consider importing the item from `core`: `core`
5151

5252
error: used import from `std` instead of `alloc`
53-
--> $DIR/std_instead_of_core.rs:46:9
53+
--> $DIR/std_instead_of_core.rs:50:9
5454
|
5555
LL | use std::vec;
5656
| ^^^ help: consider importing the item from `alloc`: `alloc`
@@ -59,13 +59,13 @@ LL | use std::vec;
5959
= help: to override `-D warnings` add `#[allow(clippy::std_instead_of_alloc)]`
6060

6161
error: used import from `std` instead of `alloc`
62-
--> $DIR/std_instead_of_core.rs:48:9
62+
--> $DIR/std_instead_of_core.rs:52:9
6363
|
6464
LL | use std::vec::Vec;
6565
| ^^^ help: consider importing the item from `alloc`: `alloc`
6666

6767
error: used import from `alloc` instead of `core`
68-
--> $DIR/std_instead_of_core.rs:54:9
68+
--> $DIR/std_instead_of_core.rs:58:9
6969
|
7070
LL | use alloc::slice::from_ref;
7171
| ^^^^^ help: consider importing the item from `core`: `core`

0 commit comments

Comments
 (0)