Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0441150

Browse files
committed
Auto merge of #113422 - Urgau:cast_ref_to_mut-pre-beta, r=Nilstrieb
Rename and allow `cast_ref_to_mut` lint This PR is a small subset of #112431, that is the renaming of the lint (`cast_ref_to_mut` -> `invalid_reference_casting`). BUT also temporarily change the default level of the lint from deny-by-default to allow-by-default until #112431 is merged. r? `@Nilstrieb`
2 parents 2dc6610 + f25ad54 commit 0441150

File tree

14 files changed

+42
-45
lines changed

14 files changed

+42
-45
lines changed

‎compiler/rustc_lint/messages.ftl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ lint_builtin_unused_doc_comment = unused doc comment
155155
lint_builtin_while_true = denote infinite loops with `loop {"{"} ... {"}"}`
156156
.suggestion = use `loop`
157157
158-
lint_cast_ref_to_mut = casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
159-
160158
lint_check_name_deprecated = lint name `{$lint_name}` is deprecated and does not have an effect anymore. Use: {$new_name}
161159
162160
lint_check_name_unknown = unknown lint: `{$lint_name}`
@@ -320,6 +318,8 @@ lint_invalid_nan_comparisons_eq_ne = incorrect NaN comparison, NaN cannot be dir
320318
321319
lint_invalid_nan_comparisons_lt_le_gt_ge = incorrect NaN comparison, NaN is not orderable
322320
321+
lint_invalid_reference_casting = casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
322+
323323
lint_lintpass_by_hand = implementing `LintPass` by hand
324324
.help = try using `declare_lint_pass!` or `impl_lint_pass!` instead
325325

‎compiler/rustc_lint/src/lib.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ extern crate tracing;
5050

5151
mod array_into_iter;
5252
pub mod builtin;
53-
mod cast_ref_to_mut;
5453
mod context;
5554
mod deref_into_dyn_supertrait;
5655
mod drop_forget_useless;
@@ -78,6 +77,7 @@ mod opaque_hidden_inferred_bound;
7877
mod pass_by_value;
7978
mod passes;
8079
mod redundant_semicolon;
80+
mod reference_casting;
8181
mod traits;
8282
mod types;
8383
mod unused;
@@ -99,7 +99,6 @@ use rustc_span::Span;
9999

100100
use array_into_iter::ArrayIntoIter;
101101
use builtin::*;
102-
use cast_ref_to_mut::*;
103102
use deref_into_dyn_supertrait::*;
104103
use drop_forget_useless::*;
105104
use enum_intrinsics_non_enums::EnumIntrinsicsNonEnums;
@@ -119,6 +118,7 @@ use noop_method_call::*;
119118
use opaque_hidden_inferred_bound::*;
120119
use pass_by_value::*;
121120
use redundant_semicolon::*;
121+
use reference_casting::*;
122122
use traits::*;
123123
use types::*;
124124
use unused::*;
@@ -218,7 +218,7 @@ late_lint_methods!(
218218
BoxPointers: BoxPointers,
219219
PathStatements: PathStatements,
220220
LetUnderscore: LetUnderscore,
221-
CastRefToMut:CastRefToMut,
221+
InvalidReferenceCasting:InvalidReferenceCasting,
222222
// Depends on referenced function signatures in expressions
223223
UnusedResults: UnusedResults,
224224
NonUpperCaseGlobals: NonUpperCaseGlobals,

‎compiler/rustc_lint/src/lints.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,10 @@ pub enum InvalidFromUtf8Diag {
743743
},
744744
}
745745

746-
// cast_ref_to_mut.rs
746+
// reference_casting.rs
747747
#[derive(LintDiagnostic)]
748-
#[diag(lint_cast_ref_to_mut)]
749-
pub struct CastRefToMutDiag;
748+
#[diag(lint_invalid_reference_casting)]
749+
pub struct InvalidReferenceCastingDiag;
750750

751751
// hidden_unicode_codepoints.rs
752752
#[derive(LintDiagnostic)]

‎compiler/rustc_lint/src/cast_ref_to_mut.rs‎ renamed to ‎compiler/rustc_lint/src/reference_casting.rs‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ use rustc_hir::{Expr, ExprKind, MutTy, TyKind, UnOp};
33
use rustc_middle::ty;
44
use rustc_span::sym;
55

6-
use crate::{lints::CastRefToMutDiag, LateContext, LateLintPass, LintContext};
6+
use crate::{lints::InvalidReferenceCastingDiag, LateContext, LateLintPass, LintContext};
77

88
declare_lint! {
9-
/// The `cast_ref_to_mut` lint checks for casts of `&T` to `&mut T`
9+
/// The `invalid_reference_casting` lint checks for casts of `&T` to `&mut T`
1010
/// without using interior mutability.
1111
///
1212
/// ### Example
1313
///
1414
/// ```rust,compile_fail
15+
/// # #![deny(invalid_reference_casting)]
1516
/// fn x(r: &i32) {
1617
/// unsafe {
1718
/// *(r as *const i32 as *mut i32) += 1;
@@ -28,14 +29,14 @@ declare_lint! {
2829
///
2930
/// `UnsafeCell` is the only way to obtain aliasable data that is considered
3031
/// mutable.
31-
CAST_REF_TO_MUT,
32-
Deny,
32+
INVALID_REFERENCE_CASTING,
33+
Allow,
3334
"casts of `&T` to `&mut T` without interior mutability"
3435
}
3536

36-
declare_lint_pass!(CastRefToMut => [CAST_REF_TO_MUT]);
37+
declare_lint_pass!(InvalidReferenceCasting => [INVALID_REFERENCE_CASTING]);
3738

38-
impl<'tcx> LateLintPass<'tcx> for CastRefToMut {
39+
impl<'tcx> LateLintPass<'tcx> for InvalidReferenceCasting {
3940
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
4041
let ExprKind::Unary(UnOp::Deref, e) = &expr.kind else {
4142
return;
@@ -68,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for CastRefToMut {
6869

6970
let e = e.peel_blocks();
7071
if let ty::Ref(..) = cx.typeck_results().node_type(e.hir_id).kind() {
71-
cx.emit_spanned_lint(CAST_REF_TO_MUT, expr.span, CastRefToMutDiag);
72+
cx.emit_spanned_lint(INVALID_REFERENCE_CASTING, expr.span, InvalidReferenceCastingDiag);
7273
}
7374
}
7475
}

‎src/tools/clippy/clippy_lints/src/renamed_lints.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
3131
("clippy::stutter", "clippy::module_name_repetitions"),
3232
("clippy::to_string_in_display", "clippy::recursive_format_impl"),
3333
("clippy::zero_width_space", "clippy::invisible_characters"),
34-
("clippy::cast_ref_to_mut", "cast_ref_to_mut"),
34+
("clippy::cast_ref_to_mut", "invalid_reference_casting"),
3535
("clippy::clone_double_ref", "suspicious_double_ref_op"),
3636
("clippy::cmp_nan", "invalid_nan_comparisons"),
3737
("clippy::drop_bounds", "drop_bounds"),

‎src/tools/clippy/tests/ui/rename.fixed‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
#![allow(clippy::module_name_repetitions)]
2929
#![allow(clippy::recursive_format_impl)]
3030
#![allow(clippy::invisible_characters)]
31-
#![allow(cast_ref_to_mut)]
3231
#![allow(suspicious_double_ref_op)]
3332
#![allow(invalid_nan_comparisons)]
33+
#![allow(invalid_reference_casting)]
3434
#![allow(drop_bounds)]
3535
#![allow(dropping_copy_types)]
3636
#![allow(dropping_references)]
@@ -79,7 +79,7 @@
7979
#![warn(clippy::module_name_repetitions)]
8080
#![warn(clippy::recursive_format_impl)]
8181
#![warn(clippy::invisible_characters)]
82-
#![warn(cast_ref_to_mut)]
82+
#![warn(invalid_reference_casting)]
8383
#![warn(suspicious_double_ref_op)]
8484
#![warn(invalid_nan_comparisons)]
8585
#![warn(drop_bounds)]

‎src/tools/clippy/tests/ui/rename.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
#![allow(clippy::module_name_repetitions)]
2929
#![allow(clippy::recursive_format_impl)]
3030
#![allow(clippy::invisible_characters)]
31-
#![allow(cast_ref_to_mut)]
3231
#![allow(suspicious_double_ref_op)]
3332
#![allow(invalid_nan_comparisons)]
33+
#![allow(invalid_reference_casting)]
3434
#![allow(drop_bounds)]
3535
#![allow(dropping_copy_types)]
3636
#![allow(dropping_references)]

‎src/tools/clippy/tests/ui/rename.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_ch
174174
LL | #![warn(clippy::zero_width_space)]
175175
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters`
176176

177-
error: lint `clippy::cast_ref_to_mut` has been renamed to `cast_ref_to_mut`
177+
error: lint `clippy::cast_ref_to_mut` has been renamed to `invalid_reference_casting`
178178
--> $DIR/rename.rs:82:9
179179
|
180180
LL | #![warn(clippy::cast_ref_to_mut)]
181-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `cast_ref_to_mut`
181+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_reference_casting`
182182

183183
error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op`
184184
--> $DIR/rename.rs:83:9

‎src/tools/miri/tests/fail/both_borrows/shr_frozen_violation1.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@revisions: stack tree
22
//@[tree]compile-flags: -Zmiri-tree-borrows
33

4-
#![allow(cast_ref_to_mut)]
4+
#![allow(invalid_reference_casting)]
55

66
fn foo(x: &mut i32) -> i32 {
77
*x = 5;

‎src/tools/miri/tests/fail/modifying_constants.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This should fail even without validation/SB
22
//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
33

4-
#![allow(cast_ref_to_mut)]
4+
#![allow(invalid_reference_casting)]
55

66
fn main() {
77
let x = &1; // the `&1` is promoted to a constant, but it used to be that only the pointer is marked static, not the pointee

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /