rust/tests/ui/std_instead_of_core.rs
Jason Newcomb 6bc024df18 Improve [std|alloc]_instead_of_[alloc|core] lints
* Don't call `TyCtxt::crate_name` unless necessary
* Don't lint on `use std::env`
* Only lint once on `use std::vec`
2022-07-24 23:15:39 -04:00

46 lines
951 B
Rust

#![warn(clippy::std_instead_of_core)]
#![allow(unused_imports)]
extern crate alloc;
#[warn(clippy::std_instead_of_core)]
fn std_instead_of_core() {
// Regular import
use std::hash::Hasher;
// Absolute path
use ::std::hash::Hash;
// Don't lint on `env` macro
use std::env;
// Multiple imports
use std::fmt::{Debug, Result};
// Function calls
let ptr = std::ptr::null::<u32>();
let ptr_mut = ::std::ptr::null_mut::<usize>();
// Types
let cell = std::cell::Cell::new(8u32);
let cell_absolute = ::std::cell::Cell::new(8u32);
let _ = std::env!("PATH");
}
#[warn(clippy::std_instead_of_alloc)]
fn std_instead_of_alloc() {
// Only lint once.
use std::vec;
use std::vec::Vec;
}
#[warn(clippy::alloc_instead_of_core)]
fn alloc_instead_of_core() {
use alloc::slice::from_ref;
}
fn main() {
std_instead_of_core();
std_instead_of_alloc();
alloc_instead_of_core();
}