2022-10-01 18:59:17 +02:00
|
|
|
|
mod as_ptr_cast_mut;
|
2022-06-05 09:13:13 -04:00
|
|
|
|
mod as_underscore;
|
2022-06-05 09:33:15 -04:00
|
|
|
|
mod borrow_as_ptr;
|
2022-04-04 18:38:38 +02:00
|
|
|
|
mod cast_abs_to_unsigned;
|
2022-03-17 16:04:45 -04:00
|
|
|
|
mod cast_enum_constructor;
|
2021-03-09 11:44:52 +09:00
|
|
|
|
mod cast_lossless;
|
2022-10-08 23:33:23 +02:00
|
|
|
|
mod cast_nan_to_int;
|
2021-03-09 12:10:59 +09:00
|
|
|
|
mod cast_possible_truncation;
|
2021-03-09 16:11:46 +09:00
|
|
|
|
mod cast_possible_wrap;
|
2021-03-09 11:22:17 +09:00
|
|
|
|
mod cast_precision_loss;
|
2021-03-09 17:15:18 +09:00
|
|
|
|
mod cast_ptr_alignment;
|
2021-03-09 17:22:21 +09:00
|
|
|
|
mod cast_ref_to_mut;
|
2021-03-09 12:37:46 +09:00
|
|
|
|
mod cast_sign_loss;
|
2022-02-18 05:17:07 -05:00
|
|
|
|
mod cast_slice_different_sizes;
|
2022-07-26 19:17:21 +01:00
|
|
|
|
mod cast_slice_from_raw_parts;
|
2021-03-09 17:28:56 +09:00
|
|
|
|
mod char_lit_as_u8;
|
2021-03-09 17:03:07 +09:00
|
|
|
|
mod fn_to_numeric_cast;
|
2021-10-07 11:50:14 +11:00
|
|
|
|
mod fn_to_numeric_cast_any;
|
2021-03-09 17:06:25 +09:00
|
|
|
|
mod fn_to_numeric_cast_with_truncation;
|
2021-03-09 20:04:19 +09:00
|
|
|
|
mod ptr_as_ptr;
|
2023-05-14 19:25:23 -05:00
|
|
|
|
mod ptr_cast_constness;
|
2021-03-09 16:43:10 +09:00
|
|
|
|
mod unnecessary_cast;
|
2021-03-09 11:22:17 +09:00
|
|
|
|
mod utils;
|
|
|
|
|
|
2022-11-21 14:37:51 +00:00
|
|
|
|
use clippy_utils::is_hir_ty_cfg_dependant;
|
|
|
|
|
use clippy_utils::msrvs::{self, Msrv};
|
2021-03-09 20:04:19 +09:00
|
|
|
|
use rustc_hir::{Expr, ExprKind};
|
2021-03-09 10:57:25 +09:00
|
|
|
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
|
|
|
|
use rustc_middle::lint::in_external_macro;
|
2021-03-09 20:04:19 +09:00
|
|
|
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
2021-03-09 10:57:25 +09:00
|
|
|
|
|
|
|
|
|
declare_clippy_lint! {
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for casts from any numerical to a float type where
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// the receiving type cannot store all values from the original type without
|
|
|
|
|
/// rounding errors. This possible rounding is to be expected, so this lint is
|
|
|
|
|
/// `Allow` by default.
|
|
|
|
|
///
|
|
|
|
|
/// Basically, this warns on casting any integer with 32 or more bits to `f32`
|
|
|
|
|
/// or any 64-bit integer to `f64`.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// It's not bad at all. But in some applications it can be
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// helpful to know where precision loss can take place. This lint can help find
|
|
|
|
|
/// those places in the code.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Example
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// ```rust
|
|
|
|
|
/// let x = u64::MAX;
|
|
|
|
|
/// x as f64;
|
|
|
|
|
/// ```
|
Added `clippy::version` attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
2021-10-21 21:06:26 +02:00
|
|
|
|
#[clippy::version = "pre 1.29.0"]
|
2021-03-09 10:57:25 +09:00
|
|
|
|
pub CAST_PRECISION_LOSS,
|
|
|
|
|
pedantic,
|
|
|
|
|
"casts that cause loss of precision, e.g., `x as f32` where `x: u64`"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
declare_clippy_lint! {
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for casts from a signed to an unsigned numerical
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// type. In this case, negative values wrap around to large positive values,
|
|
|
|
|
/// which can be quite surprising in practice. However, as the cast works as
|
|
|
|
|
/// defined, this lint is `Allow` by default.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// Possibly surprising results. You can activate this lint
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// as a one-time check to see where numerical wrapping can arise.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Example
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// ```rust
|
|
|
|
|
/// let y: i8 = -1;
|
|
|
|
|
/// y as u128; // will return 18446744073709551615
|
|
|
|
|
/// ```
|
Added `clippy::version` attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
2021-10-21 21:06:26 +02:00
|
|
|
|
#[clippy::version = "pre 1.29.0"]
|
2021-03-09 10:57:25 +09:00
|
|
|
|
pub CAST_SIGN_LOSS,
|
|
|
|
|
pedantic,
|
|
|
|
|
"casts from signed types to unsigned types, e.g., `x as u32` where `x: i32`"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
declare_clippy_lint! {
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for casts between numerical types that may
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// truncate large values. This is expected behavior, so the cast is `Allow` by
|
2022-12-06 19:05:49 +01:00
|
|
|
|
/// default. It suggests user either explicitly ignore the lint,
|
|
|
|
|
/// or use `try_from()` and handle the truncation, default, or panic explicitly.
|
2021-03-09 10:57:25 +09:00
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// In some problem domains, it is good practice to avoid
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// truncation. This lint can be activated to help assess where additional
|
2022-12-06 19:05:49 +01:00
|
|
|
|
/// checks could be beneficial.
|
2021-03-09 10:57:25 +09:00
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Example
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// ```rust
|
|
|
|
|
/// fn as_u8(x: u64) -> u8 {
|
|
|
|
|
/// x as u8
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2022-12-06 19:07:18 +01:00
|
|
|
|
/// Use instead:
|
|
|
|
|
/// ```
|
|
|
|
|
/// fn as_u8(x: u64) -> u8 {
|
|
|
|
|
/// if let Ok(x) = u8::try_from(x) {
|
|
|
|
|
/// x
|
|
|
|
|
/// } else {
|
|
|
|
|
/// todo!();
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
|
|
|
|
/// // Or
|
|
|
|
|
/// #[allow(clippy::cast_possible_truncation)]
|
|
|
|
|
/// fn as_u16(x: u64) -> u16 {
|
|
|
|
|
/// x as u16
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
Added `clippy::version` attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
2021-10-21 21:06:26 +02:00
|
|
|
|
#[clippy::version = "pre 1.29.0"]
|
2021-03-09 10:57:25 +09:00
|
|
|
|
pub CAST_POSSIBLE_TRUNCATION,
|
|
|
|
|
pedantic,
|
|
|
|
|
"casts that may cause truncation of the value, e.g., `x as u8` where `x: u32`, or `x as i32` where `x: f32`"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
declare_clippy_lint! {
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for casts from an unsigned type to a signed type of
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// the same size. Performing such a cast is a 'no-op' for the compiler,
|
|
|
|
|
/// i.e., nothing is changed at the bit level, and the binary representation of
|
|
|
|
|
/// the value is reinterpreted. This can cause wrapping if the value is too big
|
|
|
|
|
/// for the target signed type. However, the cast works as defined, so this lint
|
|
|
|
|
/// is `Allow` by default.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// While such a cast is not bad in itself, the results can
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// be surprising when this is not the intended behavior, as demonstrated by the
|
|
|
|
|
/// example below.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Example
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// ```rust
|
|
|
|
|
/// u32::MAX as i32; // will yield a value of `-1`
|
|
|
|
|
/// ```
|
Added `clippy::version` attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
2021-10-21 21:06:26 +02:00
|
|
|
|
#[clippy::version = "pre 1.29.0"]
|
2021-03-09 10:57:25 +09:00
|
|
|
|
pub CAST_POSSIBLE_WRAP,
|
|
|
|
|
pedantic,
|
|
|
|
|
"casts that may cause wrapping around the value, e.g., `x as i32` where `x: u32` and `x > i32::MAX`"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
declare_clippy_lint! {
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for casts between numerical types that may
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// be replaced by safe conversion functions.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// Rust's `as` keyword will perform many kinds of
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// conversions, including silently lossy conversions. Conversion functions such
|
|
|
|
|
/// as `i32::from` will only perform lossless conversions. Using the conversion
|
|
|
|
|
/// functions prevents conversions from turning into silent lossy conversions if
|
|
|
|
|
/// the types of the input expressions ever change, and make it easier for
|
|
|
|
|
/// people reading the code to know that the conversion is lossless.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Example
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// ```rust
|
|
|
|
|
/// fn as_u64(x: u8) -> u64 {
|
|
|
|
|
/// x as u64
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// Using `::from` would look like this:
|
|
|
|
|
///
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// fn as_u64(x: u8) -> u64 {
|
|
|
|
|
/// u64::from(x)
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
Added `clippy::version` attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
2021-10-21 21:06:26 +02:00
|
|
|
|
#[clippy::version = "pre 1.29.0"]
|
2021-03-09 10:57:25 +09:00
|
|
|
|
pub CAST_LOSSLESS,
|
|
|
|
|
pedantic,
|
|
|
|
|
"casts using `as` that are known to be lossless, e.g., `x as u64` where `x: u8`"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
declare_clippy_lint! {
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for casts to the same type, casts of int literals to integer types
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// and casts of float literals to float types.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// It's just unnecessary.
|
2021-03-09 10:57:25 +09:00
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Example
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// ```rust
|
|
|
|
|
/// let _ = 2i32 as i32;
|
|
|
|
|
/// let _ = 0.5 as f32;
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// Better:
|
|
|
|
|
///
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// let _ = 2_i32;
|
|
|
|
|
/// let _ = 0.5_f32;
|
|
|
|
|
/// ```
|
Added `clippy::version` attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
2021-10-21 21:06:26 +02:00
|
|
|
|
#[clippy::version = "pre 1.29.0"]
|
2021-03-09 10:57:25 +09:00
|
|
|
|
pub UNNECESSARY_CAST,
|
|
|
|
|
complexity,
|
|
|
|
|
"cast to the same type, e.g., `x as i32` where `x: i32`"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
declare_clippy_lint! {
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for casts, using `as` or `pointer::cast`,
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// from a less-strictly-aligned pointer to a more-strictly-aligned pointer
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// Dereferencing the resulting pointer may be undefined
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// behavior.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Known problems
|
|
|
|
|
/// Using `std::ptr::read_unaligned` and `std::ptr::write_unaligned` or similar
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// on the resulting pointer is fine. Is over-zealous: Casts with manual alignment checks or casts like
|
|
|
|
|
/// u64-> u8 -> u16 can be fine. Miri is able to do a more in-depth analysis.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Example
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// ```rust
|
|
|
|
|
/// let _ = (&1u8 as *const u8) as *const u16;
|
|
|
|
|
/// let _ = (&mut 1u8 as *mut u8) as *mut u16;
|
|
|
|
|
///
|
|
|
|
|
/// (&1u8 as *const u8).cast::<u16>();
|
|
|
|
|
/// (&mut 1u8 as *mut u8).cast::<u16>();
|
|
|
|
|
/// ```
|
Added `clippy::version` attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
2021-10-21 21:06:26 +02:00
|
|
|
|
#[clippy::version = "pre 1.29.0"]
|
2021-03-09 10:57:25 +09:00
|
|
|
|
pub CAST_PTR_ALIGNMENT,
|
|
|
|
|
pedantic,
|
|
|
|
|
"cast from a pointer to a more-strictly-aligned pointer"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
declare_clippy_lint! {
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for casts of function pointers to something other than usize
|
2021-03-09 10:57:25 +09:00
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Why is this bad?
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// Casting a function pointer to anything other than usize/isize is not portable across
|
|
|
|
|
/// architectures, because you end up losing bits if the target type is too small or end up with a
|
|
|
|
|
/// bunch of extra bits that waste space and add more instructions to the final binary than
|
|
|
|
|
/// strictly necessary for the problem
|
|
|
|
|
///
|
|
|
|
|
/// Casting to isize also doesn't make sense since there are no signed addresses.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Example
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// ```rust
|
|
|
|
|
/// fn fun() -> i32 { 1 }
|
2022-06-06 20:28:16 -04:00
|
|
|
|
/// let _ = fun as i64;
|
2022-06-05 15:24:41 -04:00
|
|
|
|
/// ```
|
2021-03-09 10:57:25 +09:00
|
|
|
|
///
|
2022-06-05 15:24:41 -04:00
|
|
|
|
/// Use instead:
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// # fn fun() -> i32 { 1 }
|
2022-06-06 20:28:16 -04:00
|
|
|
|
/// let _ = fun as usize;
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// ```
|
Added `clippy::version` attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
2021-10-21 21:06:26 +02:00
|
|
|
|
#[clippy::version = "pre 1.29.0"]
|
2021-03-09 10:57:25 +09:00
|
|
|
|
pub FN_TO_NUMERIC_CAST,
|
|
|
|
|
style,
|
|
|
|
|
"casting a function pointer to a numeric type other than usize"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
declare_clippy_lint! {
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for casts of a function pointer to a numeric type not wide enough to
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// store address.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Why is this bad?
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// Such a cast discards some bits of the function's address. If this is intended, it would be more
|
|
|
|
|
/// clearly expressed by casting to usize first, then casting the usize to the intended type (with
|
|
|
|
|
/// a comment) to perform the truncation.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Example
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// ```rust
|
|
|
|
|
/// fn fn1() -> i16 {
|
|
|
|
|
/// 1
|
|
|
|
|
/// };
|
2022-06-06 20:28:16 -04:00
|
|
|
|
/// let _ = fn1 as i32;
|
2022-06-05 15:24:41 -04:00
|
|
|
|
/// ```
|
2021-03-09 10:57:25 +09:00
|
|
|
|
///
|
2022-06-05 15:24:41 -04:00
|
|
|
|
/// Use instead:
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// // Cast to usize first, then comment with the reason for the truncation
|
|
|
|
|
/// fn fn1() -> i16 {
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// 1
|
|
|
|
|
/// };
|
2022-06-05 15:24:41 -04:00
|
|
|
|
/// let fn_ptr = fn1 as usize;
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// let fn_ptr_truncated = fn_ptr as i32;
|
|
|
|
|
/// ```
|
Added `clippy::version` attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
2021-10-21 21:06:26 +02:00
|
|
|
|
#[clippy::version = "pre 1.29.0"]
|
2021-03-09 10:57:25 +09:00
|
|
|
|
pub FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
|
|
|
|
|
style,
|
|
|
|
|
"casting a function pointer to a numeric type not wide enough to store the address"
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 11:50:14 +11:00
|
|
|
|
declare_clippy_lint! {
|
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for casts of a function pointer to any integer type.
|
|
|
|
|
///
|
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// Casting a function pointer to an integer can have surprising results and can occur
|
2022-04-15 14:25:55 -04:00
|
|
|
|
/// accidentally if parentheses are omitted from a function call. If you aren't doing anything
|
2021-10-07 11:50:14 +11:00
|
|
|
|
/// low-level with function pointers then you can opt-out of casting functions to integers in
|
|
|
|
|
/// order to avoid mistakes. Alternatively, you can use this lint to audit all uses of function
|
|
|
|
|
/// pointer casts in your code.
|
|
|
|
|
///
|
|
|
|
|
/// ### Example
|
|
|
|
|
/// ```rust
|
2022-06-05 15:24:41 -04:00
|
|
|
|
/// // fn1 is cast as `usize`
|
2021-10-07 11:50:14 +11:00
|
|
|
|
/// fn fn1() -> u16 {
|
|
|
|
|
/// 1
|
|
|
|
|
/// };
|
2022-06-06 20:28:16 -04:00
|
|
|
|
/// let _ = fn1 as usize;
|
2022-06-05 15:24:41 -04:00
|
|
|
|
/// ```
|
2021-10-07 11:50:14 +11:00
|
|
|
|
///
|
2022-06-05 15:24:41 -04:00
|
|
|
|
/// Use instead:
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// // maybe you intended to call the function?
|
2021-10-07 11:50:14 +11:00
|
|
|
|
/// fn fn2() -> u16 {
|
|
|
|
|
/// 1
|
|
|
|
|
/// };
|
2022-06-06 20:28:16 -04:00
|
|
|
|
/// let _ = fn2() as usize;
|
2022-06-05 15:24:41 -04:00
|
|
|
|
///
|
|
|
|
|
/// // or
|
2021-10-07 11:50:14 +11:00
|
|
|
|
///
|
2022-06-05 15:24:41 -04:00
|
|
|
|
/// // maybe you intended to cast it to a function type?
|
2021-10-07 11:50:14 +11:00
|
|
|
|
/// fn fn3() -> u16 {
|
|
|
|
|
/// 1
|
|
|
|
|
/// }
|
2022-06-06 20:28:16 -04:00
|
|
|
|
/// let _ = fn3 as fn() -> u16;
|
2021-10-07 11:50:14 +11:00
|
|
|
|
/// ```
|
Added `clippy::version` attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
2021-10-21 21:06:26 +02:00
|
|
|
|
#[clippy::version = "1.58.0"]
|
2021-10-07 11:50:14 +11:00
|
|
|
|
pub FN_TO_NUMERIC_CAST_ANY,
|
|
|
|
|
restriction,
|
|
|
|
|
"casting a function pointer to any integer type"
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-09 17:22:21 +09:00
|
|
|
|
declare_clippy_lint! {
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for casts of `&T` to `&mut T` anywhere in the code.
|
2021-03-09 17:22:21 +09:00
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Why is this bad?
|
2022-05-13 14:20:25 +09:00
|
|
|
|
/// It’s basically guaranteed to be undefined behavior.
|
2021-03-09 17:22:21 +09:00
|
|
|
|
/// `UnsafeCell` is the only way to obtain aliasable data that is considered
|
|
|
|
|
/// mutable.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Example
|
2021-03-09 17:22:21 +09:00
|
|
|
|
/// ```rust,ignore
|
|
|
|
|
/// fn x(r: &i32) {
|
|
|
|
|
/// unsafe {
|
|
|
|
|
/// *(r as *const _ as *mut _) += 1;
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// Instead consider using interior mutability types.
|
|
|
|
|
///
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// use std::cell::UnsafeCell;
|
|
|
|
|
///
|
|
|
|
|
/// fn x(r: &UnsafeCell<i32>) {
|
|
|
|
|
/// unsafe {
|
|
|
|
|
/// *r.get() += 1;
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
Added `clippy::version` attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
2021-10-21 21:06:26 +02:00
|
|
|
|
#[clippy::version = "1.33.0"]
|
2021-03-09 17:22:21 +09:00
|
|
|
|
pub CAST_REF_TO_MUT,
|
|
|
|
|
correctness,
|
|
|
|
|
"a cast of reference to a mutable pointer"
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-09 17:28:56 +09:00
|
|
|
|
declare_clippy_lint! {
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for expressions where a character literal is cast
|
2021-03-09 17:28:56 +09:00
|
|
|
|
/// to `u8` and suggests using a byte literal instead.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// In general, casting values to smaller types is
|
2021-03-09 17:28:56 +09:00
|
|
|
|
/// error-prone and should be avoided where possible. In the particular case of
|
|
|
|
|
/// converting a character literal to u8, it is easy to avoid by just using a
|
|
|
|
|
/// byte literal instead. As an added bonus, `b'a'` is even slightly shorter
|
|
|
|
|
/// than `'a' as u8`.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Example
|
2021-03-09 17:28:56 +09:00
|
|
|
|
/// ```rust,ignore
|
|
|
|
|
/// 'x' as u8
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// A better version, using the byte literal:
|
|
|
|
|
///
|
|
|
|
|
/// ```rust,ignore
|
|
|
|
|
/// b'x'
|
|
|
|
|
/// ```
|
Added `clippy::version` attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
2021-10-21 21:06:26 +02:00
|
|
|
|
#[clippy::version = "pre 1.29.0"]
|
2021-03-09 17:28:56 +09:00
|
|
|
|
pub CHAR_LIT_AS_U8,
|
|
|
|
|
complexity,
|
|
|
|
|
"casting a character literal to `u8` truncates"
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-09 10:57:25 +09:00
|
|
|
|
declare_clippy_lint! {
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### What it does
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// Checks for `as` casts between raw pointers without changing its mutability,
|
|
|
|
|
/// namely `*const T` to `*const U` and `*mut T` to `*mut U`.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Why is this bad?
|
2023-05-14 19:25:23 -05:00
|
|
|
|
/// Though `as` casts between raw pointers are not terrible, `pointer::cast` is safer because
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// it cannot accidentally change the pointer's mutability nor cast the pointer to other types like `usize`.
|
|
|
|
|
///
|
2021-07-02 20:37:11 +02:00
|
|
|
|
/// ### Example
|
2021-03-09 10:57:25 +09:00
|
|
|
|
/// ```rust
|
|
|
|
|
/// let ptr: *const u32 = &42_u32;
|
|
|
|
|
/// let mut_ptr: *mut u32 = &mut 42_u32;
|
|
|
|
|
/// let _ = ptr as *const i32;
|
|
|
|
|
/// let _ = mut_ptr as *mut i32;
|
|
|
|
|
/// ```
|
|
|
|
|
/// Use instead:
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// let ptr: *const u32 = &42_u32;
|
|
|
|
|
/// let mut_ptr: *mut u32 = &mut 42_u32;
|
|
|
|
|
/// let _ = ptr.cast::<i32>();
|
|
|
|
|
/// let _ = mut_ptr.cast::<i32>();
|
|
|
|
|
/// ```
|
Added `clippy::version` attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...
And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...
Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.
```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;
let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
ls | where name =~ "rust-" | select name | format {name}/lints.json |
each { open $it | select id | insert version $it | str substring "5,11" version} |
group-by id | rotate counter-clockwise id version |
update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
let version = ($versions | where id == ($row.id) | format {version})
let idu = ($row.id | str upcase)
$"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```
And this still has some problems, but at this point I just want to be done -.-
2021-10-21 21:06:26 +02:00
|
|
|
|
#[clippy::version = "1.51.0"]
|
2021-03-09 10:57:25 +09:00
|
|
|
|
pub PTR_AS_PTR,
|
|
|
|
|
pedantic,
|
|
|
|
|
"casting using `as` from and to raw pointers that doesn't change its mutability, where `pointer::cast` could take the place of `as`"
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-14 19:25:23 -05:00
|
|
|
|
declare_clippy_lint! {
|
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for `as` casts between raw pointers which change its constness, namely `*const T` to
|
|
|
|
|
/// `*mut T` and `*mut T` to `*const T`.
|
|
|
|
|
///
|
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// Though `as` casts between raw pointers are not terrible, `pointer::cast_mut` and
|
|
|
|
|
/// `pointer::cast_const` are safer because they cannot accidentally cast the pointer to another
|
|
|
|
|
/// type.
|
|
|
|
|
///
|
|
|
|
|
/// ### Example
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// let ptr: *const u32 = &42_u32;
|
|
|
|
|
/// let mut_ptr = ptr as *mut u32;
|
|
|
|
|
/// let ptr = mut_ptr as *const u32;
|
|
|
|
|
/// ```
|
|
|
|
|
/// Use instead:
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// let ptr: *const u32 = &42_u32;
|
|
|
|
|
/// let mut_ptr = ptr.cast_mut();
|
|
|
|
|
/// let ptr = mut_ptr.cast_const();
|
|
|
|
|
/// ```
|
|
|
|
|
#[clippy::version = "1.65.0"]
|
|
|
|
|
pub PTR_CAST_CONSTNESS,
|
|
|
|
|
pedantic,
|
|
|
|
|
"TODO"
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-31 21:22:47 -05:00
|
|
|
|
declare_clippy_lint! {
|
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for casts from an enum type to an integral type which will definitely truncate the
|
|
|
|
|
/// value.
|
|
|
|
|
///
|
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// The resulting integral value will not match the value of the variant it came from.
|
|
|
|
|
///
|
|
|
|
|
/// ### Example
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// enum E { X = 256 };
|
|
|
|
|
/// let _ = E::X as u8;
|
|
|
|
|
/// ```
|
2022-06-09 13:43:26 +00:00
|
|
|
|
#[clippy::version = "1.61.0"]
|
2022-01-31 21:22:47 -05:00
|
|
|
|
pub CAST_ENUM_TRUNCATION,
|
|
|
|
|
suspicious,
|
|
|
|
|
"casts from an enum type to an integral type which will truncate the value"
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-18 05:17:07 -05:00
|
|
|
|
declare_clippy_lint! {
|
2022-05-05 18:50:34 +02:00
|
|
|
|
/// ### What it does
|
2022-02-18 05:17:07 -05:00
|
|
|
|
/// Checks for `as` casts between raw pointers to slices with differently sized elements.
|
|
|
|
|
///
|
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// The produced raw pointer to a slice does not update its length metadata. The produced
|
|
|
|
|
/// pointer will point to a different number of bytes than the original pointer because the
|
|
|
|
|
/// length metadata of a raw slice pointer is in elements rather than bytes.
|
|
|
|
|
/// Producing a slice reference from the raw pointer will either create a slice with
|
|
|
|
|
/// less data (which can be surprising) or create a slice with more data and cause Undefined Behavior.
|
|
|
|
|
///
|
|
|
|
|
/// ### Example
|
|
|
|
|
/// // Missing data
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// let a = [1_i32, 2, 3, 4];
|
|
|
|
|
/// let p = &a as *const [i32] as *const [u8];
|
|
|
|
|
/// unsafe {
|
|
|
|
|
/// println!("{:?}", &*p);
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
/// // Undefined Behavior (note: also potential alignment issues)
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// let a = [1_u8, 2, 3, 4];
|
|
|
|
|
/// let p = &a as *const [u8] as *const [u32];
|
|
|
|
|
/// unsafe {
|
|
|
|
|
/// println!("{:?}", &*p);
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
/// Instead use `ptr::slice_from_raw_parts` to construct a slice from a data pointer and the correct length
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// let a = [1_i32, 2, 3, 4];
|
|
|
|
|
/// let old_ptr = &a as *const [i32];
|
|
|
|
|
/// // The data pointer is cast to a pointer to the target `u8` not `[u8]`
|
|
|
|
|
/// // The length comes from the known length of 4 i32s times the 4 bytes per i32
|
|
|
|
|
/// let new_ptr = core::ptr::slice_from_raw_parts(old_ptr as *const u8, 16);
|
|
|
|
|
/// unsafe {
|
|
|
|
|
/// println!("{:?}", &*new_ptr);
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2022-06-09 13:43:26 +00:00
|
|
|
|
#[clippy::version = "1.61.0"]
|
2022-02-18 05:17:07 -05:00
|
|
|
|
pub CAST_SLICE_DIFFERENT_SIZES,
|
|
|
|
|
correctness,
|
|
|
|
|
"casting using `as` between raw pointers to slices of types with different sizes"
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 16:04:45 -04:00
|
|
|
|
declare_clippy_lint! {
|
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for casts from an enum tuple constructor to an integer.
|
|
|
|
|
///
|
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// The cast is easily confused with casting a c-like enum value to an integer.
|
|
|
|
|
///
|
|
|
|
|
/// ### Example
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// enum E { X(i32) };
|
|
|
|
|
/// let _ = E::X as usize;
|
|
|
|
|
/// ```
|
|
|
|
|
#[clippy::version = "1.61.0"]
|
|
|
|
|
pub CAST_ENUM_CONSTRUCTOR,
|
|
|
|
|
suspicious,
|
|
|
|
|
"casts from an enum tuple constructor to an integer"
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 18:38:38 +02:00
|
|
|
|
declare_clippy_lint! {
|
|
|
|
|
/// ### What it does
|
2023-04-12 13:48:03 +02:00
|
|
|
|
/// Checks for usage of the `abs()` method that cast the result to unsigned.
|
2022-04-04 18:38:38 +02:00
|
|
|
|
///
|
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// The `unsigned_abs()` method avoids panic when called on the MIN value.
|
|
|
|
|
///
|
|
|
|
|
/// ### Example
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// let x: i32 = -42;
|
|
|
|
|
/// let y: u32 = x.abs() as u32;
|
|
|
|
|
/// ```
|
|
|
|
|
/// Use instead:
|
2022-04-15 16:34:44 -04:00
|
|
|
|
/// ```rust
|
2022-04-04 18:38:38 +02:00
|
|
|
|
/// let x: i32 = -42;
|
|
|
|
|
/// let y: u32 = x.unsigned_abs();
|
|
|
|
|
/// ```
|
2022-07-03 17:02:48 +02:00
|
|
|
|
#[clippy::version = "1.62.0"]
|
2022-04-04 18:38:38 +02:00
|
|
|
|
pub CAST_ABS_TO_UNSIGNED,
|
|
|
|
|
suspicious,
|
|
|
|
|
"casting the result of `abs()` to an unsigned integer can panic"
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-05 09:13:13 -04:00
|
|
|
|
declare_clippy_lint! {
|
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Check for the usage of `as _` conversion using inferred type.
|
|
|
|
|
///
|
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// The conversion might include lossy conversion and dangerous cast that might go
|
|
|
|
|
/// undetected due to the type being inferred.
|
|
|
|
|
///
|
|
|
|
|
/// The lint is allowed by default as using `_` is less wordy than always specifying the type.
|
|
|
|
|
///
|
|
|
|
|
/// ### Example
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// fn foo(n: usize) {}
|
|
|
|
|
/// let n: u16 = 256;
|
|
|
|
|
/// foo(n as _);
|
|
|
|
|
/// ```
|
|
|
|
|
/// Use instead:
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// fn foo(n: usize) {}
|
|
|
|
|
/// let n: u16 = 256;
|
|
|
|
|
/// foo(n as usize);
|
|
|
|
|
/// ```
|
|
|
|
|
#[clippy::version = "1.63.0"]
|
|
|
|
|
pub AS_UNDERSCORE,
|
|
|
|
|
restriction,
|
|
|
|
|
"detects `as _` conversion"
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-05 09:33:15 -04:00
|
|
|
|
declare_clippy_lint! {
|
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for the usage of `&expr as *const T` or
|
|
|
|
|
/// `&mut expr as *mut T`, and suggest using `ptr::addr_of` or
|
|
|
|
|
/// `ptr::addr_of_mut` instead.
|
|
|
|
|
///
|
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// This would improve readability and avoid creating a reference
|
|
|
|
|
/// that points to an uninitialized value or unaligned place.
|
|
|
|
|
/// Read the `ptr::addr_of` docs for more information.
|
|
|
|
|
///
|
|
|
|
|
/// ### Example
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// let val = 1;
|
|
|
|
|
/// let p = &val as *const i32;
|
|
|
|
|
///
|
|
|
|
|
/// let mut val_mut = 1;
|
|
|
|
|
/// let p_mut = &mut val_mut as *mut i32;
|
|
|
|
|
/// ```
|
|
|
|
|
/// Use instead:
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// let val = 1;
|
|
|
|
|
/// let p = std::ptr::addr_of!(val);
|
|
|
|
|
///
|
|
|
|
|
/// let mut val_mut = 1;
|
|
|
|
|
/// let p_mut = std::ptr::addr_of_mut!(val_mut);
|
|
|
|
|
/// ```
|
|
|
|
|
#[clippy::version = "1.60.0"]
|
|
|
|
|
pub BORROW_AS_PTR,
|
|
|
|
|
pedantic,
|
|
|
|
|
"borrowing just to cast to a raw pointer"
|
|
|
|
|
}
|
2022-10-08 23:33:23 +02:00
|
|
|
|
|
2022-07-26 19:17:21 +01:00
|
|
|
|
declare_clippy_lint! {
|
2022-08-29 15:17:23 +01:00
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for a raw slice being cast to a slice pointer
|
2022-07-26 19:17:21 +01:00
|
|
|
|
///
|
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// This can result in multiple `&mut` references to the same location when only a pointer is
|
|
|
|
|
/// required.
|
|
|
|
|
/// `ptr::slice_from_raw_parts` is a safe alternative that doesn't require
|
|
|
|
|
/// the same [safety requirements] to be upheld.
|
|
|
|
|
///
|
|
|
|
|
/// ### Example
|
|
|
|
|
/// ```rust,ignore
|
|
|
|
|
/// let _: *const [u8] = std::slice::from_raw_parts(ptr, len) as *const _;
|
|
|
|
|
/// let _: *mut [u8] = std::slice::from_raw_parts_mut(ptr, len) as *mut _;
|
|
|
|
|
/// ```
|
|
|
|
|
/// Use instead:
|
|
|
|
|
/// ```rust,ignore
|
|
|
|
|
/// let _: *const [u8] = std::ptr::slice_from_raw_parts(ptr, len);
|
|
|
|
|
/// let _: *mut [u8] = std::ptr::slice_from_raw_parts_mut(ptr, len);
|
|
|
|
|
/// ```
|
|
|
|
|
/// [safety requirements]: https://doc.rust-lang.org/std/slice/fn.from_raw_parts.html#safety
|
2022-10-31 21:28:02 +01:00
|
|
|
|
#[clippy::version = "1.65.0"]
|
2022-07-26 19:17:21 +01:00
|
|
|
|
pub CAST_SLICE_FROM_RAW_PARTS,
|
|
|
|
|
suspicious,
|
|
|
|
|
"casting a slice created from a pointer and length to a slice pointer"
|
|
|
|
|
}
|
2022-06-05 09:33:15 -04:00
|
|
|
|
|
2022-10-01 18:59:17 +02:00
|
|
|
|
declare_clippy_lint! {
|
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for the result of a `&self`-taking `as_ptr` being cast to a mutable pointer
|
|
|
|
|
///
|
|
|
|
|
/// ### Why is this bad?
|
2022-10-01 20:10:43 +02:00
|
|
|
|
/// Since `as_ptr` takes a `&self`, the pointer won't have write permissions unless interior
|
|
|
|
|
/// mutability is used, making it unlikely that having it as a mutable pointer is correct.
|
2022-10-01 18:59:17 +02:00
|
|
|
|
///
|
|
|
|
|
/// ### Example
|
|
|
|
|
/// ```rust
|
2023-04-11 11:17:18 +00:00
|
|
|
|
/// let mut vec = Vec::<u8>::with_capacity(1);
|
|
|
|
|
/// let ptr = vec.as_ptr() as *mut u8;
|
2022-10-01 18:59:17 +02:00
|
|
|
|
/// unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR
|
|
|
|
|
/// ```
|
|
|
|
|
/// Use instead:
|
|
|
|
|
/// ```rust
|
2023-04-11 11:17:18 +00:00
|
|
|
|
/// let mut vec = Vec::<u8>::with_capacity(1);
|
|
|
|
|
/// let ptr = vec.as_mut_ptr();
|
2022-10-01 18:59:17 +02:00
|
|
|
|
/// unsafe { ptr.write(4) };
|
|
|
|
|
/// ```
|
|
|
|
|
#[clippy::version = "1.66.0"]
|
|
|
|
|
pub AS_PTR_CAST_MUT,
|
|
|
|
|
nursery,
|
2023-04-13 17:59:01 -04:00
|
|
|
|
"casting the result of the `&self`-taking `as_ptr` to a mutable pointer"
|
2022-10-01 18:59:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 23:33:23 +02:00
|
|
|
|
declare_clippy_lint! {
|
|
|
|
|
/// ### What it does
|
|
|
|
|
/// Checks for a known NaN float being cast to an integer
|
|
|
|
|
///
|
|
|
|
|
/// ### Why is this bad?
|
|
|
|
|
/// NaNs are cast into zero, so one could simply use this and make the
|
|
|
|
|
/// code more readable. The lint could also hint at a programmer error.
|
|
|
|
|
///
|
|
|
|
|
/// ### Example
|
|
|
|
|
/// ```rust,ignore
|
|
|
|
|
/// let _: (0.0_f32 / 0.0) as u64;
|
|
|
|
|
/// ```
|
|
|
|
|
/// Use instead:
|
|
|
|
|
/// ```rust,ignore
|
|
|
|
|
/// let _: = 0_u64;
|
|
|
|
|
/// ```
|
2022-12-13 18:29:22 +01:00
|
|
|
|
#[clippy::version = "1.66.0"]
|
2022-10-08 23:33:23 +02:00
|
|
|
|
pub CAST_NAN_TO_INT,
|
|
|
|
|
suspicious,
|
|
|
|
|
"casting a known floating-point NaN into an integer"
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-09 20:04:19 +09:00
|
|
|
|
pub struct Casts {
|
2022-11-21 14:37:51 +00:00
|
|
|
|
msrv: Msrv,
|
2021-03-09 10:57:25 +09:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-09 20:04:19 +09:00
|
|
|
|
impl Casts {
|
2021-03-09 10:57:25 +09:00
|
|
|
|
#[must_use]
|
2022-11-21 14:37:51 +00:00
|
|
|
|
pub fn new(msrv: Msrv) -> Self {
|
2021-03-09 10:57:25 +09:00
|
|
|
|
Self { msrv }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-09 20:04:19 +09:00
|
|
|
|
impl_lint_pass!(Casts => [
|
|
|
|
|
CAST_PRECISION_LOSS,
|
|
|
|
|
CAST_SIGN_LOSS,
|
|
|
|
|
CAST_POSSIBLE_TRUNCATION,
|
|
|
|
|
CAST_POSSIBLE_WRAP,
|
|
|
|
|
CAST_LOSSLESS,
|
|
|
|
|
CAST_REF_TO_MUT,
|
|
|
|
|
CAST_PTR_ALIGNMENT,
|
2022-02-18 05:17:07 -05:00
|
|
|
|
CAST_SLICE_DIFFERENT_SIZES,
|
2021-03-09 20:04:19 +09:00
|
|
|
|
UNNECESSARY_CAST,
|
2021-10-07 11:50:14 +11:00
|
|
|
|
FN_TO_NUMERIC_CAST_ANY,
|
2021-03-09 20:04:19 +09:00
|
|
|
|
FN_TO_NUMERIC_CAST,
|
|
|
|
|
FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
|
|
|
|
|
CHAR_LIT_AS_U8,
|
|
|
|
|
PTR_AS_PTR,
|
2023-05-14 19:25:23 -05:00
|
|
|
|
PTR_CAST_CONSTNESS,
|
2022-01-31 21:22:47 -05:00
|
|
|
|
CAST_ENUM_TRUNCATION,
|
2022-04-04 18:38:38 +02:00
|
|
|
|
CAST_ENUM_CONSTRUCTOR,
|
2022-06-05 09:13:13 -04:00
|
|
|
|
CAST_ABS_TO_UNSIGNED,
|
|
|
|
|
AS_UNDERSCORE,
|
2022-06-05 09:33:15 -04:00
|
|
|
|
BORROW_AS_PTR,
|
2022-10-01 18:59:17 +02:00
|
|
|
|
CAST_SLICE_FROM_RAW_PARTS,
|
|
|
|
|
AS_PTR_CAST_MUT,
|
2022-10-08 23:33:23 +02:00
|
|
|
|
CAST_NAN_TO_INT,
|
2021-03-09 20:04:19 +09:00
|
|
|
|
]);
|
2021-03-09 10:57:25 +09:00
|
|
|
|
|
2021-03-09 20:04:19 +09:00
|
|
|
|
impl<'tcx> LateLintPass<'tcx> for Casts {
|
2021-03-09 10:57:25 +09:00
|
|
|
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
2022-02-17 01:08:53 +01:00
|
|
|
|
if !in_external_macro(cx.sess(), expr.span) {
|
2022-11-21 14:37:51 +00:00
|
|
|
|
ptr_as_ptr::check(cx, expr, &self.msrv);
|
2022-02-17 01:08:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-09 10:57:25 +09:00
|
|
|
|
if expr.span.from_expansion() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-05 09:13:13 -04:00
|
|
|
|
if let ExprKind::Cast(cast_expr, cast_to_hir) = expr.kind {
|
|
|
|
|
if is_hir_ty_cfg_dependant(cx, cast_to_hir) {
|
2021-03-09 20:04:19 +09:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let (cast_from, cast_to) = (
|
|
|
|
|
cx.typeck_results().expr_ty(cast_expr),
|
|
|
|
|
cx.typeck_results().expr_ty(expr),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if unnecessary_cast::check(cx, expr, cast_expr, cast_from, cast_to) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-21 14:37:51 +00:00
|
|
|
|
cast_slice_from_raw_parts::check(cx, expr, cast_expr, cast_to, &self.msrv);
|
2023-05-14 19:31:12 -05:00
|
|
|
|
ptr_cast_constness::check(cx, expr, cast_expr, cast_from, cast_to, &self.msrv);
|
2022-10-01 18:59:17 +02:00
|
|
|
|
as_ptr_cast_mut::check(cx, expr, cast_expr, cast_to);
|
2021-10-07 11:50:14 +11:00
|
|
|
|
fn_to_numeric_cast_any::check(cx, expr, cast_expr, cast_from, cast_to);
|
2021-03-09 20:04:19 +09:00
|
|
|
|
fn_to_numeric_cast::check(cx, expr, cast_expr, cast_from, cast_to);
|
|
|
|
|
fn_to_numeric_cast_with_truncation::check(cx, expr, cast_expr, cast_from, cast_to);
|
2021-11-08 20:44:50 +00:00
|
|
|
|
|
|
|
|
|
if cast_to.is_numeric() && !in_external_macro(cx.sess(), expr.span) {
|
2023-01-12 12:35:29 +01:00
|
|
|
|
cast_possible_truncation::check(cx, expr, cast_expr, cast_from, cast_to, cast_to_hir.span);
|
2021-11-08 20:44:50 +00:00
|
|
|
|
if cast_from.is_numeric() {
|
|
|
|
|
cast_possible_wrap::check(cx, expr, cast_from, cast_to);
|
|
|
|
|
cast_precision_loss::check(cx, expr, cast_from, cast_to);
|
|
|
|
|
cast_sign_loss::check(cx, expr, cast_expr, cast_from, cast_to);
|
2022-11-21 14:37:51 +00:00
|
|
|
|
cast_abs_to_unsigned::check(cx, expr, cast_expr, cast_from, cast_to, &self.msrv);
|
2022-10-08 23:33:23 +02:00
|
|
|
|
cast_nan_to_int::check(cx, expr, cast_expr, cast_from, cast_to);
|
2021-11-08 20:44:50 +00:00
|
|
|
|
}
|
2022-11-21 14:37:51 +00:00
|
|
|
|
cast_lossless::check(cx, expr, cast_expr, cast_from, cast_to, &self.msrv);
|
2022-03-17 16:04:45 -04:00
|
|
|
|
cast_enum_constructor::check(cx, expr, cast_expr, cast_from);
|
2021-03-09 10:57:25 +09:00
|
|
|
|
}
|
2022-06-05 09:13:13 -04:00
|
|
|
|
|
|
|
|
|
as_underscore::check(cx, expr, cast_to_hir);
|
2022-06-05 09:33:15 -04:00
|
|
|
|
|
2022-11-21 14:37:51 +00:00
|
|
|
|
if self.msrv.meets(msrvs::BORROW_AS_PTR) {
|
2022-06-05 09:33:15 -04:00
|
|
|
|
borrow_as_ptr::check(cx, expr, cast_expr, cast_to_hir);
|
|
|
|
|
}
|
2021-03-09 10:57:25 +09:00
|
|
|
|
}
|
2021-03-09 20:04:19 +09:00
|
|
|
|
|
|
|
|
|
cast_ref_to_mut::check(cx, expr);
|
|
|
|
|
cast_ptr_alignment::check(cx, expr);
|
|
|
|
|
char_lit_as_u8::check(cx, expr);
|
2022-11-21 14:37:51 +00:00
|
|
|
|
ptr_as_ptr::check(cx, expr, &self.msrv);
|
|
|
|
|
cast_slice_different_sizes::check(cx, expr, &self.msrv);
|
2021-03-09 10:57:25 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extract_msrv_attr!(LateContext);
|
|
|
|
|
}
|