about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkoka <koka.code@gmail.com>2023-10-01 00:47:57 +0900
committerkoka <koka.code@gmail.com>2023-10-01 00:47:57 +0900
commitd5cc97e32c9b1919a175aa798e99bd7dde814073 (patch)
tree341f2df1c4e42e57621670cfcb797844abec9627
parent44b6aca96b48299adf0ab44307c40d7f3392d060 (diff)
downloadrust-d5cc97e32c9b1919a175aa798e99bd7dde814073.tar.gz
rust-d5cc97e32c9b1919a175aa798e99bd7dde814073.zip
Add macro for test which use std internally
-rw-r--r--tests/ui/auxiliary/proc_macro_derive.rs12
-rw-r--r--tests/ui/std_instead_of_core.fixed11
-rw-r--r--tests/ui/std_instead_of_core.rs11
-rw-r--r--tests/ui/std_instead_of_core.stderr22
4 files changed, 45 insertions, 11 deletions
diff --git a/tests/ui/auxiliary/proc_macro_derive.rs b/tests/ui/auxiliary/proc_macro_derive.rs
index 37f0ec2b37d..556b886f386 100644
--- a/tests/ui/auxiliary/proc_macro_derive.rs
+++ b/tests/ui/auxiliary/proc_macro_derive.rs
@@ -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! {
diff --git a/tests/ui/std_instead_of_core.fixed b/tests/ui/std_instead_of_core.fixed
index 8027c053fb5..a7555704fbe 100644
--- a/tests/ui/std_instead_of_core.fixed
+++ b/tests/ui/std_instead_of_core.fixed
@@ -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();
diff --git a/tests/ui/std_instead_of_core.rs b/tests/ui/std_instead_of_core.rs
index 63a096384d7..af7f3399f49 100644
--- a/tests/ui/std_instead_of_core.rs
+++ b/tests/ui/std_instead_of_core.rs
@@ -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();
diff --git a/tests/ui/std_instead_of_core.stderr b/tests/ui/std_instead_of_core.stderr
index ca26f77bd37..4f7bdc4045e 100644
--- a/tests/ui/std_instead_of_core.stderr
+++ b/tests/ui/std_instead_of_core.stderr
@@ -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`