Skip to content

Commit 7ee75f8

Browse files
committed
Auto merge of #12447 - MarcusGrass:mg/fix-12438-regression, r=y21
Fix #12438 std_instead_of_core regression Fixes #12438. Boy-scouting removed two paths that checks for duplication since I thought they were unused. However, that's just because I didn't spot it in the diff. I installed [difftastic](https://github.com/Wilfred/difftastic) and ran it on the old one: ![image](https://github.com/rust-lang/rust-clippy/assets/34198073/5c51276c-055a-49a3-9425-6f7da0590fb0) And the new one (fixed): ![image](https://github.com/rust-lang/rust-clippy/assets/34198073/6e10f29c-6d6b-4f64-893f-de526424f1cd) New one (stderr): ![image](https://github.com/rust-lang/rust-clippy/assets/34198073/c4c07776-ee0f-47ba-996f-6b632de47c81) Good teachings for the future when inspecting diffs with a lot of line changes, should've thought of that before, sorry for the trouble! changelog: [`std_instead_of_core`] Fix false positive for crates that are in `std` but not `core`
2 parents d8a9068 + b44ab66 commit 7ee75f8

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

clippy_lints/src/std_instead_of_core.rs

+2
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,15 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports {
109109
sym::core => (STD_INSTEAD_OF_CORE, "std", "core"),
110110
sym::alloc => (STD_INSTEAD_OF_ALLOC, "std", "alloc"),
111111
_ => {
112+
self.prev_span = first_segment.ident.span;
112113
return;
113114
},
114115
},
115116
sym::alloc => {
116117
if cx.tcx.crate_name(def_id.krate) == sym::core {
117118
(ALLOC_INSTEAD_OF_CORE, "alloc", "core")
118119
} else {
120+
self.prev_span = first_segment.ident.span;
119121
return;
120122
}
121123
},

tests/ui/std_instead_of_core.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn std_instead_of_core() {
1717
use ::core::hash::Hash;
1818
//~^ ERROR: used import from `std` instead of `core`
1919
// Don't lint on `env` macro
20-
use core::env;
20+
use std::env;
2121

2222
// Multiple imports
2323
use core::fmt::{Debug, Result};

tests/ui/std_instead_of_core.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ error: used import from `std` instead of `core`
1313
LL | use ::std::hash::Hash;
1414
| ^^^ help: consider importing the item from `core`: `core`
1515

16-
error: used import from `std` instead of `core`
17-
--> tests/ui/std_instead_of_core.rs:20:9
18-
|
19-
LL | use std::env;
20-
| ^^^ help: consider importing the item from `core`: `core`
21-
2216
error: used import from `std` instead of `core`
2317
--> tests/ui/std_instead_of_core.rs:23:9
2418
|
@@ -85,5 +79,5 @@ LL | use alloc::slice::from_ref;
8579
= note: `-D clippy::alloc-instead-of-core` implied by `-D warnings`
8680
= help: to override `-D warnings` add `#[allow(clippy::alloc_instead_of_core)]`
8781

88-
error: aborting due to 13 previous errors
82+
error: aborting due to 12 previous errors
8983

0 commit comments

Comments
 (0)