]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/std_instead_of_core.fixed
New upstream version 1.75.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / std_instead_of_core.fixed
1 //@aux-build:proc_macro_derive.rs
2 #![warn(clippy::std_instead_of_core)]
3 #![allow(unused_imports)]
4
5 extern crate alloc;
6
7 #[macro_use]
8 extern crate proc_macro_derive;
9
10 #[warn(clippy::std_instead_of_core)]
11 fn std_instead_of_core() {
12 // Regular import
13 use core::hash::Hasher;
14 //~^ ERROR: used import from `std` instead of `core`
15 // Absolute path
16 use ::core::hash::Hash;
17 //~^ ERROR: used import from `std` instead of `core`
18 // Don't lint on `env` macro
19 use std::env;
20
21 // Multiple imports
22 use core::fmt::{Debug, Result};
23 //~^ ERROR: used import from `std` instead of `core`
24
25 // Function calls
26 let ptr = core::ptr::null::<u32>();
27 //~^ ERROR: used import from `std` instead of `core`
28 let ptr_mut = ::core::ptr::null_mut::<usize>();
29 //~^ ERROR: used import from `std` instead of `core`
30
31 // Types
32 let cell = core::cell::Cell::new(8u32);
33 //~^ ERROR: used import from `std` instead of `core`
34 let cell_absolute = ::core::cell::Cell::new(8u32);
35 //~^ ERROR: used import from `std` instead of `core`
36
37 let _ = std::env!("PATH");
38
39 // do not lint until `error_in_core` is stable
40 use std::error::Error;
41
42 // lint items re-exported from private modules, `core::iter::traits::iterator::Iterator`
43 use core::iter::Iterator;
44 //~^ ERROR: used import from `std` instead of `core`
45 }
46
47 #[warn(clippy::std_instead_of_alloc)]
48 fn std_instead_of_alloc() {
49 // Only lint once.
50 use alloc::vec;
51 //~^ ERROR: used import from `std` instead of `alloc`
52 use alloc::vec::Vec;
53 //~^ ERROR: used import from `std` instead of `alloc`
54 }
55
56 #[warn(clippy::alloc_instead_of_core)]
57 fn alloc_instead_of_core() {
58 use core::slice::from_ref;
59 //~^ ERROR: used import from `alloc` instead of `core`
60 }
61
62 mod std_in_proc_macro_derive {
63 #[warn(clippy::alloc_instead_of_core)]
64 #[allow(unused)]
65 #[derive(ImplStructWithStdDisplay)]
66 struct B {}
67 }
68
69 fn main() {
70 std_instead_of_core();
71 std_instead_of_alloc();
72 alloc_instead_of_core();
73 }