about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarcusGrass <marcus.grass@protonmail.com>2024-03-09 18:37:18 +0100
committerMarcusGrass <marcus.grass@protonmail.com>2024-03-09 18:37:18 +0100
commitb44ab661568d3fc6070fe9c6e3ff87dc7884ceb2 (patch)
tree0e57315a2e0a7d34ddeb50b54f4c249929975d6a
parentc173ea64b7c3ff289098569de04217e34454c59f (diff)
downloadrust-b44ab661568d3fc6070fe9c6e3ff87dc7884ceb2.tar.gz
rust-b44ab661568d3fc6070fe9c6e3ff87dc7884ceb2.zip
Fix #12438 false positive regression
-rw-r--r--clippy_lints/src/std_instead_of_core.rs2
-rw-r--r--tests/ui/std_instead_of_core.fixed2
-rw-r--r--tests/ui/std_instead_of_core.stderr8
3 files changed, 4 insertions, 8 deletions
diff --git a/clippy_lints/src/std_instead_of_core.rs b/clippy_lints/src/std_instead_of_core.rs
index c0e4f3c368a..cf839941123 100644
--- a/clippy_lints/src/std_instead_of_core.rs
+++ b/clippy_lints/src/std_instead_of_core.rs
@@ -109,6 +109,7 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports {
                     sym::core => (STD_INSTEAD_OF_CORE, "std", "core"),
                     sym::alloc => (STD_INSTEAD_OF_ALLOC, "std", "alloc"),
                     _ => {
+                        self.prev_span = first_segment.ident.span;
                         return;
                     },
                 },
@@ -116,6 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports {
                     if cx.tcx.crate_name(def_id.krate) == sym::core {
                         (ALLOC_INSTEAD_OF_CORE, "alloc", "core")
                     } else {
+                        self.prev_span = first_segment.ident.span;
                         return;
                     }
                 },
diff --git a/tests/ui/std_instead_of_core.fixed b/tests/ui/std_instead_of_core.fixed
index 0a734a65d29..ec4ae2ea13c 100644
--- a/tests/ui/std_instead_of_core.fixed
+++ b/tests/ui/std_instead_of_core.fixed
@@ -17,7 +17,7 @@ fn std_instead_of_core() {
     use ::core::hash::Hash;
     //~^ ERROR: used import from `std` instead of `core`
     // Don't lint on `env` macro
-    use core::env;
+    use std::env;
 
     // Multiple imports
     use core::fmt::{Debug, Result};
diff --git a/tests/ui/std_instead_of_core.stderr b/tests/ui/std_instead_of_core.stderr
index ee42b474a32..8f920511cc5 100644
--- a/tests/ui/std_instead_of_core.stderr
+++ b/tests/ui/std_instead_of_core.stderr
@@ -14,12 +14,6 @@ LL |     use ::std::hash::Hash;
    |           ^^^ help: consider importing the item from `core`: `core`
 
 error: used import from `std` instead of `core`
-  --> tests/ui/std_instead_of_core.rs:20:9
-   |
-LL |     use std::env;
-   |         ^^^ help: consider importing the item from `core`: `core`
-
-error: used import from `std` instead of `core`
   --> tests/ui/std_instead_of_core.rs:23:9
    |
 LL |     use std::fmt::{Debug, Result};
@@ -85,5 +79,5 @@ LL |     use alloc::slice::from_ref;
    = 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 13 previous errors
+error: aborting due to 12 previous errors