Skip to content

Commit bad1275

Browse files
committed
test [std_instead_of_core]: add some additional test cases
1 parent 71bb04b commit bad1275

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
@@ -114,3 +114,20 @@ fn issue17260() {
114114
use core::concat;
115115
//~^ std_instead_of_core
116116
}
117+
118+
#[warn(clippy::std_instead_of_alloc)]
119+
fn non_use_paths() {
120+
type Foo = alloc::sync::Arc<std::sync::Mutex<bool>>;
121+
//~^ std_instead_of_alloc
122+
123+
let _x = core::iter::repeat(u8::default());
124+
//~^ std_instead_of_core
125+
126+
fn impl_trait(_: impl core::fmt::Display) {}
127+
//~^ std_instead_of_core
128+
129+
struct Bar {
130+
layout: core::alloc::Layout,
131+
//~^ std_instead_of_core
132+
}
133+
}

tests/ui/std_instead_of_core.rs

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

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

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:38: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:44: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:60: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:65: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:67: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:60: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:77: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:87: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:92: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:96: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:98: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:112: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:119: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)