Skip to content

Commit 226f1c7

Browse files
committed
test [std_instead_of_core]: add some additional test cases
1 parent 6689963 commit 226f1c7

5 files changed

Lines changed: 260 additions & 2 deletions

tests/ui/std_instead_of_core.fixed

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,20 @@ fn issue17260() {
115115
use core::concat;
116116
//~^ std_instead_of_core
117117
}
118+
119+
#[warn(clippy::std_instead_of_alloc)]
120+
fn non_use_paths() {
121+
type Foo = alloc::sync::Arc<std::sync::Mutex<bool>>;
122+
//~^ std_instead_of_alloc
123+
124+
let _x = core::iter::repeat(u8::default());
125+
//~^ std_instead_of_core
126+
127+
fn impl_trait(_: impl core::fmt::Display) {}
128+
//~^ std_instead_of_core
129+
130+
struct Bar {
131+
layout: core::alloc::Layout,
132+
//~^ std_instead_of_core
133+
}
134+
}

tests/ui/std_instead_of_core.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,20 @@ fn issue17260() {
115115
use std::concat;
116116
//~^ std_instead_of_core
117117
}
118+
119+
#[warn(clippy::std_instead_of_alloc)]
120+
fn non_use_paths() {
121+
type Foo = std::sync::Arc<std::sync::Mutex<bool>>;
122+
//~^ std_instead_of_alloc
123+
124+
let _x = std::iter::repeat(u8::default());
125+
//~^ std_instead_of_core
126+
127+
fn impl_trait(_: impl std::fmt::Display) {}
128+
//~^ std_instead_of_core
129+
130+
struct Bar {
131+
layout: std::alloc::Layout,
132+
//~^ std_instead_of_core
133+
}
134+
}

tests/ui/std_instead_of_core.stderr

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,29 @@ error: used import from `std` instead of `core`
115115
LL | use std::concat;
116116
| ^^^ help: consider importing the item from `core`: `core`
117117

118-
error: aborting due to 18 previous errors
118+
error: used import from `std` instead of `alloc`
119+
--> tests/ui/std_instead_of_core.rs:121:16
120+
|
121+
LL | type Foo = std::sync::Arc<std::sync::Mutex<bool>>;
122+
| ^^^ help: consider importing the item from `alloc`: `alloc`
123+
124+
error: used import from `std` instead of `core`
125+
--> tests/ui/std_instead_of_core.rs:124:14
126+
|
127+
LL | let _x = std::iter::repeat(u8::default());
128+
| ^^^ help: consider importing the item from `core`: `core`
129+
130+
error: used import from `std` instead of `core`
131+
--> tests/ui/std_instead_of_core.rs:127:27
132+
|
133+
LL | fn impl_trait(_: impl std::fmt::Display) {}
134+
| ^^^ help: consider importing the item from `core`: `core`
135+
136+
error: used import from `std` instead of `core`
137+
--> tests/ui/std_instead_of_core.rs:131:17
138+
|
139+
LL | layout: std::alloc::Layout,
140+
| ^^^ help: consider importing the item from `core`: `core`
141+
142+
error: aborting due to 22 previous errors
119143

tests/ui/std_instead_of_core_unfixable.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,92 @@ fn issue15579() {
3333
let layout = alloc::Layout::new::<u8>();
3434
//~^ std_instead_of_core
3535
}
36+
37+
#[rustfmt::skip]
38+
fn issue12468() {
39+
use std::{
40+
fmt::Result,
41+
//~^ std_instead_of_core
42+
io::Write,
43+
};
44+
45+
use std::sync::{
46+
Arc,
47+
//~^ std_instead_of_alloc
48+
Mutex,
49+
};
50+
}
51+
52+
#[allow(clippy::legacy_numeric_constants)]
53+
#[warn(clippy::alloc_instead_of_core)]
54+
#[rustfmt::skip]
55+
fn pr17252_large() {
56+
extern crate alloc;
57+
58+
use {
59+
std::sync::Mutex,
60+
::{
61+
std::{
62+
fmt::{*, Formatter},
63+
//~^ std_instead_of_alloc
64+
//~| std_instead_of_core
65+
fs,
66+
//~v std_instead_of_core
67+
sync::atomic,
68+
//~v std_instead_of_core
69+
sync::atomic::{
70+
AtomicUsize,
71+
AtomicU8,
72+
Ordering,
73+
},
74+
},
75+
core::u32,
76+
std::collections::HashMap,
77+
},
78+
alloc::{
79+
fmt::Result as FmtResult,
80+
//~^ alloc_instead_of_core
81+
format,
82+
}
83+
};
84+
}
85+
86+
#[warn(clippy::alloc_instead_of_core)]
87+
#[rustfmt::skip]
88+
fn issue11159() {
89+
use std::fmt;
90+
//~^ std_instead_of_alloc
91+
92+
struct S;
93+
94+
impl fmt::Display for S {
95+
//~^ alloc_instead_of_core
96+
fn fmt(
97+
&self,
98+
_: &mut fmt::Formatter<'_>,
99+
//~^ alloc_instead_of_core
100+
) -> fmt::Result {
101+
//~^ alloc_instead_of_core
102+
todo!()
103+
}
104+
}
105+
}
106+
107+
#[warn(clippy::alloc_instead_of_core)]
108+
#[rustfmt::skip]
109+
fn mixed_name_spaces() {
110+
extern crate alloc;
111+
112+
use std::{
113+
io,
114+
iter::repeat_with,
115+
//~^ std_instead_of_core
116+
};
117+
118+
use alloc::alloc::{
119+
alloc,
120+
dealloc,
121+
Layout,
122+
//~^ alloc_instead_of_core
123+
};
124+
}

tests/ui/std_instead_of_core_unfixable.stderr

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,116 @@ LL | let layout = alloc::Layout::new::<u8>();
5050
|
5151
= help: consider importing the item from `core`
5252

53-
error: aborting due to 6 previous errors
53+
error: used import from `std` instead of `core`
54+
--> tests/ui/std_instead_of_core_unfixable.rs:40:14
55+
|
56+
LL | fmt::Result,
57+
| ^^^^^^
58+
|
59+
= help: consider importing the item from `core`
60+
61+
error: used import from `std` instead of `alloc`
62+
--> tests/ui/std_instead_of_core_unfixable.rs:46:9
63+
|
64+
LL | Arc,
65+
| ^^^
66+
|
67+
= help: consider importing the item from `alloc`
68+
69+
error: used import from `std` instead of `core`
70+
--> tests/ui/std_instead_of_core_unfixable.rs:62:26
71+
|
72+
LL | fmt::{*, Formatter},
73+
| ^^^^^^^^^
74+
|
75+
= help: consider importing the item from `core`
76+
77+
error: used import from `std` instead of `core`
78+
--> tests/ui/std_instead_of_core_unfixable.rs:67:23
79+
|
80+
LL | sync::atomic,
81+
| ^^^^^^
82+
|
83+
= help: consider importing the item from `core`
84+
85+
error: used import from `std` instead of `core`
86+
--> tests/ui/std_instead_of_core_unfixable.rs:69:17
87+
|
88+
LL | / sync::atomic::{
89+
LL | | AtomicUsize,
90+
LL | | AtomicU8,
91+
LL | | Ordering,
92+
LL | | },
93+
| |_________________^
94+
|
95+
= help: consider importing the item from `core`
96+
97+
error: used import from `std` instead of `alloc`
98+
--> tests/ui/std_instead_of_core_unfixable.rs:62:17
99+
|
100+
LL | fmt::{*, Formatter},
101+
| ^^^
102+
|
103+
= help: consider importing the item from `alloc`
104+
105+
error: used import from `alloc` instead of `core`
106+
--> tests/ui/std_instead_of_core_unfixable.rs:79:18
107+
|
108+
LL | fmt::Result as FmtResult,
109+
| ^^^^^^
110+
|
111+
= help: consider importing the item from `core`
112+
= note: `-D clippy::alloc-instead-of-core` implied by `-D warnings`
113+
= help: to override `-D warnings` add `#[allow(clippy::alloc_instead_of_core)]`
114+
115+
error: used import from `std` instead of `alloc`
116+
--> tests/ui/std_instead_of_core_unfixable.rs:89:9
117+
|
118+
LL | use std::fmt;
119+
| ^^^
120+
|
121+
= help: consider importing the item from `alloc`
122+
= help: consider adding an `extern crate` statement at the crate root
123+
124+
error: used import from `alloc` instead of `core`
125+
--> tests/ui/std_instead_of_core_unfixable.rs:94:10
126+
|
127+
LL | impl fmt::Display for S {
128+
| ^^^^^^^^^^^^
129+
|
130+
= help: consider importing the item from `core`
131+
132+
error: used import from `alloc` instead of `core`
133+
--> tests/ui/std_instead_of_core_unfixable.rs:98:21
134+
|
135+
LL | _: &mut fmt::Formatter<'_>,
136+
| ^^^^^^^^^^^^^^
137+
|
138+
= help: consider importing the item from `core`
139+
140+
error: used import from `alloc` instead of `core`
141+
--> tests/ui/std_instead_of_core_unfixable.rs:100:14
142+
|
143+
LL | ) -> fmt::Result {
144+
| ^^^^^^^^^^^
145+
|
146+
= help: consider importing the item from `core`
147+
148+
error: used import from `std` instead of `core`
149+
--> tests/ui/std_instead_of_core_unfixable.rs:114:15
150+
|
151+
LL | iter::repeat_with,
152+
| ^^^^^^^^^^^
153+
|
154+
= help: consider importing the item from `core`
155+
156+
error: used import from `alloc` instead of `core`
157+
--> tests/ui/std_instead_of_core_unfixable.rs:121:9
158+
|
159+
LL | Layout,
160+
| ^^^^^^
161+
|
162+
= help: consider importing the item from `core`
163+
164+
error: aborting due to 19 previous errors
54165

0 commit comments

Comments
 (0)