Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ pub mod hardwired {
UNREACHABLE_PATTERNS,
UNSAFE_ATTR_OUTSIDE_UNSAFE,
UNSAFE_OP_IN_UNSAFE_FN,
UNSTABLE_IMPORTS,
UNSTABLE_NAME_COLLISIONS,
UNSTABLE_SYNTAX_PRE_EXPANSION,
UNSUPPORTED_CALLING_CONVENTIONS,
Expand Down Expand Up @@ -5858,3 +5859,28 @@ declare_lint! {
"`repr(C, align)` types nested inside `repr(C, packed)` types \
do not always have a C-compatible layout",
}

declare_lint! {
/// The `unstable_imports` lints detects imports that go through unstable modules.
///
/// ### Example
///
/// ```rust
/// use core::intrinsics::transmute;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Previous versions of Rust accidentally allowed certain imports through unstable modules
/// because stability information of modules was not correctly accounted for if the imported
/// item was stable itself.
pub UNSTABLE_IMPORTS,
Deny,
"lints on accidentally allowed unstable imports",
@future_incompatible = FutureIncompatibleInfo {
reason: fcw!(FutureReleaseError # 163160),
report_in_deps: true,
};
}
6 changes: 3 additions & 3 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use rustc_hir::{
UsePath, Variant,
};
use rustc_lint_defs::builtin::{
DEPRECATED, DUPLICATE_FEATURES, INEFFECTIVE_UNSTABLE_REEXPORTS,
INEFFECTIVE_UNSTABLE_TRAIT_IMPL, STABLE_FEATURES,
DUPLICATE_FEATURES, INEFFECTIVE_UNSTABLE_REEXPORTS, INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
STABLE_FEATURES, UNSTABLE_IMPORTS,
};
use rustc_middle::hir::nested_filter;
use rustc_middle::middle::lib_features::{FeatureStability, LibFeatures};
Expand Down Expand Up @@ -1079,7 +1079,7 @@ impl<'tcx> Checker<'tcx> {
suggestion,
};
self.tcx.emit_node_span_lint(
DEPRECATED,
UNSTABLE_IMPORTS,
id,
method_span.unwrap_or(span),
diag,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/std_instead_of_core.fixed
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@aux-build:proc_macro_derive.rs

#![warn(clippy::std_instead_of_core)]
#![expect(deprecated)]

extern crate alloc;

Expand Down Expand Up @@ -77,6 +76,7 @@ mod std_in_proc_macro_derive {
// replacing std -> core
fn intrinsic(a: *mut u8, b: *mut u8) {
unsafe {
#[allow(unstable_imports)]
core::intrinsics::copy(a, b, 1);
//~^ std_instead_of_core
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/std_instead_of_core.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@aux-build:proc_macro_derive.rs

#![warn(clippy::std_instead_of_core)]
#![expect(deprecated)]

extern crate alloc;

Expand Down Expand Up @@ -77,6 +76,7 @@ mod std_in_proc_macro_derive {
// replacing std -> core
fn intrinsic(a: *mut u8, b: *mut u8) {
unsafe {
#[allow(unstable_imports)]
std::intrinsics::copy(a, b, 1);
//~^ std_instead_of_core
}
Expand Down
26 changes: 13 additions & 13 deletions src/tools/clippy/tests/ui/std_instead_of_core.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: used import from `std` instead of `core`
--> tests/ui/std_instead_of_core.rs:13:9
--> tests/ui/std_instead_of_core.rs:12:9
|
LL | use std::hash::Hasher;
| ^^^ help: consider importing the item from `core`: `core`
Expand All @@ -8,61 +8,61 @@ LL | use std::hash::Hasher;
= help: to override `-D warnings` add `#[allow(clippy::std_instead_of_core)]`

error: used import from `std` instead of `core`
--> tests/ui/std_instead_of_core.rs:16:11
--> tests/ui/std_instead_of_core.rs:15:11
|
LL | use ::std::hash::Hash;
| ^^^ help: consider importing the item from `core`: `core`

error: used import from `std` instead of `core`
--> tests/ui/std_instead_of_core.rs:22:9
--> tests/ui/std_instead_of_core.rs:21:9
|
LL | use std::fmt::{Debug, Result};
| ^^^ help: consider importing the item from `core`: `core`

error: used import from `std` instead of `core`
--> tests/ui/std_instead_of_core.rs:27:9
--> tests/ui/std_instead_of_core.rs:26:9
|
LL | use std::{
| ^^^ help: consider importing the item from `core`: `core`

error: used import from `std` instead of `core`
--> tests/ui/std_instead_of_core.rs:34:15
--> tests/ui/std_instead_of_core.rs:33:15
|
LL | let ptr = std::ptr::null::<u32>();
| ^^^ help: consider importing the item from `core`: `core`

error: used import from `std` instead of `core`
--> tests/ui/std_instead_of_core.rs:36:21
--> tests/ui/std_instead_of_core.rs:35:21
|
LL | let ptr_mut = ::std::ptr::null_mut::<usize>();
| ^^^ help: consider importing the item from `core`: `core`

error: used import from `std` instead of `core`
--> tests/ui/std_instead_of_core.rs:40:16
--> tests/ui/std_instead_of_core.rs:39:16
|
LL | let cell = std::cell::Cell::new(8u32);
| ^^^ help: consider importing the item from `core`: `core`

error: used import from `std` instead of `core`
--> tests/ui/std_instead_of_core.rs:42:27
--> tests/ui/std_instead_of_core.rs:41:27
|
LL | let cell_absolute = ::std::cell::Cell::new(8u32);
| ^^^ help: consider importing the item from `core`: `core`

error: used import from `std` instead of `core`
--> tests/ui/std_instead_of_core.rs:47:9
--> tests/ui/std_instead_of_core.rs:46:9
|
LL | use std::error::Error;
| ^^^ help: consider importing the item from `core`: `core`

error: used import from `std` instead of `core`
--> tests/ui/std_instead_of_core.rs:51:9
--> tests/ui/std_instead_of_core.rs:50:9
|
LL | use std::iter::Iterator;
| ^^^ help: consider importing the item from `core`: `core`

error: used import from `std` instead of `alloc`
--> tests/ui/std_instead_of_core.rs:58:9
--> tests/ui/std_instead_of_core.rs:57:9
|
LL | use std::vec;
| ^^^ help: consider importing the item from `alloc`: `alloc`
Expand All @@ -71,13 +71,13 @@ LL | use std::vec;
= help: to override `-D warnings` add `#[allow(clippy::std_instead_of_alloc)]`

error: used import from `std` instead of `alloc`
--> tests/ui/std_instead_of_core.rs:60:9
--> tests/ui/std_instead_of_core.rs:59:9
|
LL | use std::vec::Vec;
| ^^^ help: consider importing the item from `alloc`: `alloc`

error: used import from `alloc` instead of `core`
--> tests/ui/std_instead_of_core.rs:66:9
--> tests/ui/std_instead_of_core.rs:65:9
|
LL | use alloc::slice::from_ref;
| ^^^^^ help: consider importing the item from `core`: `core`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ use core::unicode::UNICODE_VERSION; //~ ERROR use of unstable library feature `u
// Known accidental stabilizations with known users
// fully stable @ core::mem::transmute
use core::intrinsics::transmute; // depended upon by rand_core
//~^WARN deprecated
//~^ERROR use of deprecated import through accidentally stabilized module
//~| WARN previously accepted
24 changes: 21 additions & 3 deletions tests/ui/stability-attribute/accidental-stable-in-unstable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,37 @@ LL | use core::unicode::UNICODE_VERSION;
= help: add `#![feature(unicode_internals)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

warning: use of deprecated import through accidentally stabilized module `intrinsics`
error: use of deprecated import through accidentally stabilized module `intrinsics`
--> $DIR/accidental-stable-in-unstable.rs:10:5
|
LL | use core::intrinsics::transmute; // depended upon by rand_core
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(deprecated)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #163160 <https://github.com/rust-lang/rust/issues/163160>
= note: `#[deny(unstable_imports)]` (part of `#[deny(future_incompatible)]`) on by default
help: import this function via the `mem` module instead
|
LL - use core::intrinsics::transmute; // depended upon by rand_core
LL + use core::mem::transmute; // depended upon by rand_core
|

error: aborting due to 1 previous error; 1 warning emitted
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
Future incompatibility report: Future breakage diagnostic:
error: use of deprecated import through accidentally stabilized module `intrinsics`
--> $DIR/accidental-stable-in-unstable.rs:10:5
|
LL | use core::intrinsics::transmute; // depended upon by rand_core
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #163160 <https://github.com/rust-lang/rust/issues/163160>
= note: `#[deny(unstable_imports)]` (part of `#[deny(future_incompatible)]`) on by default
help: import this function via the `mem` module instead
|
LL - use core::intrinsics::transmute; // depended upon by rand_core
LL + use core::mem::transmute; // depended upon by rand_core
|

Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
//@ run-rustfix
#![crate_type = "lib"]
#![allow(unnecessary_transmutes, unused_imports)]
#![deny(deprecated)]

extern crate core;

use std::mem::transmute as _;
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
use core::ptr::copy as _;
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
use std::ptr::copy_nonoverlapping as _;
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
use core::ptr::write_bytes as _;
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted

use core::ptr::{
copy as _,
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
copy_nonoverlapping as _,
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
write_bytes as _,
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
};

pub fn what() {
Expand All @@ -29,11 +35,15 @@ pub fn what() {
let mut dst = 0;
let _ = std::mem::transmute::<u8, i8>(value);
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
core::ptr::copy(&value, &mut dst, 1);
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
core::ptr::copy_nonoverlapping(&value, &mut dst, 1);
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
std::ptr::write_bytes(&mut dst, value, 1)
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
}
}
12 changes: 11 additions & 1 deletion tests/ui/stability-attribute/accidentally-stable-intrinsics.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
//@ run-rustfix
#![crate_type = "lib"]
#![allow(unnecessary_transmutes, unused_imports)]
#![deny(deprecated)]

extern crate core;

use std::intrinsics::transmute as _;
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
use core::intrinsics::copy as _;
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
use std::intrinsics::copy_nonoverlapping as _;
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
use core::intrinsics::write_bytes as _;
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted

use core::intrinsics::{
copy as _,
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
copy_nonoverlapping as _,
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
write_bytes as _,
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
};

pub fn what() {
Expand All @@ -29,11 +35,15 @@ pub fn what() {
let mut dst = 0;
let _ = std::intrinsics::transmute::<u8, i8>(value);
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
core::intrinsics::copy(&value, &mut dst, 1);
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
core::intrinsics::copy_nonoverlapping(&value, &mut dst, 1);
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
std::intrinsics::write_bytes(&mut dst, value, 1)
//~^ ERROR use of deprecated import through accidentally stabilized module `intrinsics`
//~| WARN previously accepted
}
}
Loading
Loading