about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-08 15:59:00 +0000
committerbors <bors@rust-lang.org>2023-09-08 15:59:00 +0000
commit27165acadfa15f0e17a2c3404d9cf1f7bcd046ef (patch)
tree13a1e4b5d7387ce88326dd474d8822f39395475b /tests
parent253f1c410b8ae111cd2f8bc0323a54dabbea3067 (diff)
parente0014afa2df2df55bf9246ba22dcc706fe98dc83 (diff)
downloadrust-27165acadfa15f0e17a2c3404d9cf1f7bcd046ef.tar.gz
rust-27165acadfa15f0e17a2c3404d9cf1f7bcd046ef.zip
Auto merge of #11456 - tom-anders:std_instead_of_core_suggestion, r=Manishearth
Add suggestions for std_instead_of_core

```
changelog: [`std_instead_of_core`]: add suggestions
```

Fixes #11446
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/std_instead_of_core.fixed62
-rw-r--r--tests/ui/std_instead_of_core.rs1
-rw-r--r--tests/ui/std_instead_of_core.stderr71
3 files changed, 84 insertions, 50 deletions
diff --git a/tests/ui/std_instead_of_core.fixed b/tests/ui/std_instead_of_core.fixed
new file mode 100644
index 00000000000..8027c053fb5
--- /dev/null
+++ b/tests/ui/std_instead_of_core.fixed
@@ -0,0 +1,62 @@
+#![warn(clippy::std_instead_of_core)]
+#![allow(unused_imports)]
+
+extern crate alloc;
+
+#[warn(clippy::std_instead_of_core)]
+fn std_instead_of_core() {
+    // Regular import
+    use core::hash::Hasher;
+    //~^ ERROR: used import from `std` instead of `core`
+    // Absolute path
+    use ::core::hash::Hash;
+    //~^ ERROR: used import from `std` instead of `core`
+    // Don't lint on `env` macro
+    use std::env;
+
+    // Multiple imports
+    use core::fmt::{Debug, Result};
+    //~^ ERROR: used import from `std` instead of `core`
+
+    // Function calls
+    let ptr = core::ptr::null::<u32>();
+    //~^ ERROR: used import from `std` instead of `core`
+    let ptr_mut = ::core::ptr::null_mut::<usize>();
+    //~^ ERROR: used import from `std` instead of `core`
+
+    // Types
+    let cell = core::cell::Cell::new(8u32);
+    //~^ ERROR: used import from `std` instead of `core`
+    let cell_absolute = ::core::cell::Cell::new(8u32);
+    //~^ ERROR: used import from `std` instead of `core`
+
+    let _ = std::env!("PATH");
+
+    // do not lint until `error_in_core` is stable
+    use std::error::Error;
+
+    // lint items re-exported from private modules, `core::iter::traits::iterator::Iterator`
+    use core::iter::Iterator;
+    //~^ ERROR: used import from `std` instead of `core`
+}
+
+#[warn(clippy::std_instead_of_alloc)]
+fn std_instead_of_alloc() {
+    // Only lint once.
+    use alloc::vec;
+    //~^ ERROR: used import from `std` instead of `alloc`
+    use alloc::vec::Vec;
+    //~^ ERROR: used import from `std` instead of `alloc`
+}
+
+#[warn(clippy::alloc_instead_of_core)]
+fn alloc_instead_of_core() {
+    use core::slice::from_ref;
+    //~^ ERROR: used import from `alloc` instead of `core`
+}
+
+fn main() {
+    std_instead_of_core();
+    std_instead_of_alloc();
+    alloc_instead_of_core();
+}
diff --git a/tests/ui/std_instead_of_core.rs b/tests/ui/std_instead_of_core.rs
index 2e44487d77e..63a096384d7 100644
--- a/tests/ui/std_instead_of_core.rs
+++ b/tests/ui/std_instead_of_core.rs
@@ -17,7 +17,6 @@ fn std_instead_of_core() {
     // Multiple imports
     use std::fmt::{Debug, Result};
     //~^ ERROR: used import from `std` instead of `core`
-    //~| ERROR: used import from `std` instead of `core`
 
     // Function calls
     let ptr = std::ptr::null::<u32>();
diff --git a/tests/ui/std_instead_of_core.stderr b/tests/ui/std_instead_of_core.stderr
index 7435d716157..ca26f77bd37 100644
--- a/tests/ui/std_instead_of_core.stderr
+++ b/tests/ui/std_instead_of_core.stderr
@@ -2,103 +2,76 @@ error: used import from `std` instead of `core`
   --> $DIR/std_instead_of_core.rs:9:9
    |
 LL |     use std::hash::Hasher;
-   |         ^^^^^^^^^^^^^^^^^
+   |         ^^^ help: consider importing the item from `core`: `core`
    |
-   = help: consider importing the item from `core`
    = note: `-D clippy::std-instead-of-core` implied by `-D warnings`
    = 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:9
+  --> $DIR/std_instead_of_core.rs:12:11
    |
 LL |     use ::std::hash::Hash;
-   |         ^^^^^^^^^^^^^^^^^
-   |
-   = help: consider importing the item from `core`
+   |           ^^^ help: consider importing the item from `core`: `core`
 
 error: used import from `std` instead of `core`
-  --> $DIR/std_instead_of_core.rs:18:20
+  --> $DIR/std_instead_of_core.rs:18:9
    |
 LL |     use std::fmt::{Debug, Result};
-   |                    ^^^^^
-   |
-   = help: consider importing the item from `core`
-
-error: used import from `std` instead of `core`
-  --> $DIR/std_instead_of_core.rs:18:27
-   |
-LL |     use std::fmt::{Debug, Result};
-   |                           ^^^^^^
-   |
-   = help: consider importing the item from `core`
+   |         ^^^ help: consider importing the item from `core`: `core`
 
 error: used import from `std` instead of `core`
-  --> $DIR/std_instead_of_core.rs:23:15
+  --> $DIR/std_instead_of_core.rs:22:15
    |
 LL |     let ptr = std::ptr::null::<u32>();
-   |               ^^^^^^^^^^^^^^^^^^^^^
-   |
-   = help: consider importing the item from `core`
+   |               ^^^ help: consider importing the item from `core`: `core`
 
 error: used import from `std` instead of `core`
-  --> $DIR/std_instead_of_core.rs:25:19
+  --> $DIR/std_instead_of_core.rs:24:21
    |
 LL |     let ptr_mut = ::std::ptr::null_mut::<usize>();
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = help: consider importing the item from `core`
+   |                     ^^^ help: consider importing the item from `core`: `core`
 
 error: used import from `std` instead of `core`
-  --> $DIR/std_instead_of_core.rs:29:16
+  --> $DIR/std_instead_of_core.rs:28:16
    |
 LL |     let cell = std::cell::Cell::new(8u32);
-   |                ^^^^^^^^^^^^^^^
-   |
-   = help: consider importing the item from `core`
+   |                ^^^ help: consider importing the item from `core`: `core`
 
 error: used import from `std` instead of `core`
-  --> $DIR/std_instead_of_core.rs:31:25
+  --> $DIR/std_instead_of_core.rs:30:27
    |
 LL |     let cell_absolute = ::std::cell::Cell::new(8u32);
-   |                         ^^^^^^^^^^^^^^^^^
-   |
-   = help: consider importing the item from `core`
+   |                           ^^^ help: consider importing the item from `core`: `core`
 
 error: used import from `std` instead of `core`
-  --> $DIR/std_instead_of_core.rs:40:9
+  --> $DIR/std_instead_of_core.rs:39:9
    |
 LL |     use std::iter::Iterator;
-   |         ^^^^^^^^^^^^^^^^^^^
-   |
-   = help: consider importing the item from `core`
+   |         ^^^ help: consider importing the item from `core`: `core`
 
 error: used import from `std` instead of `alloc`
-  --> $DIR/std_instead_of_core.rs:47:9
+  --> $DIR/std_instead_of_core.rs:46:9
    |
 LL |     use std::vec;
-   |         ^^^^^^^^
+   |         ^^^ help: consider importing the item from `alloc`: `alloc`
    |
-   = help: consider importing the item from `alloc`
    = note: `-D clippy::std-instead-of-alloc` implied by `-D warnings`
    = 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:49:9
+  --> $DIR/std_instead_of_core.rs:48:9
    |
 LL |     use std::vec::Vec;
-   |         ^^^^^^^^^^^^^
-   |
-   = help: consider importing the item from `alloc`
+   |         ^^^ help: consider importing the item from `alloc`: `alloc`
 
 error: used import from `alloc` instead of `core`
-  --> $DIR/std_instead_of_core.rs:55:9
+  --> $DIR/std_instead_of_core.rs:54:9
    |
 LL |     use alloc::slice::from_ref;
-   |         ^^^^^^^^^^^^^^^^^^^^^^
+   |         ^^^^^ help: consider importing the item from `core`: `core`
    |
-   = help: consider importing the item from `core`
    = note: `-D clippy::alloc-instead-of-core` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::alloc_instead_of_core)]`
 
-error: aborting due to 12 previous errors
+error: aborting due to 11 previous errors