add more info link

This commit is contained in:
asquared31415 2023-06-06 14:58:54 -04:00
parent 6681914b54
commit 7cd0ec58aa
2 changed files with 17 additions and 3 deletions

View File

@ -1,6 +1,5 @@
use clippy_utils::diagnostics::span_lint;
use rustc_hir::Expr; use rustc_hir::Expr;
use rustc_lint::LateContext; use rustc_lint::{LateContext, LintContext};
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use super::{utils, CAST_POSSIBLE_WRAP}; use super::{utils, CAST_POSSIBLE_WRAP};
@ -9,6 +8,7 @@
const ALLOWED_POINTER_SIZES: [u64; 3] = [16, 32, 64]; const ALLOWED_POINTER_SIZES: [u64; 3] = [16, 32, 64];
// whether the lint should be emitted, and the required pointer size, if it matters // whether the lint should be emitted, and the required pointer size, if it matters
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum EmitState { enum EmitState {
NoLint, NoLint,
LintAlways, LintAlways,
@ -77,5 +77,13 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, ca
), ),
}; };
span_lint(cx, CAST_POSSIBLE_WRAP, expr.span, message.as_str()); cx.struct_span_lint(CAST_POSSIBLE_WRAP, expr.span, message, |diag| {
if let EmitState::LintOnPtrSize(16) = should_lint {
diag
.note("`usize` and `isize` may be as small as 16 bits on some platforms")
.note("for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types")
} else {
diag
}
});
} }

View File

@ -244,6 +244,9 @@ error: casting `usize` to `i16` may wrap around the value on targets with 16-bit
| |
LL | 1usize as i16; // wraps on 16 bit ptr size LL | 1usize as i16; // wraps on 16 bit ptr size
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
|
= note: `usize` and `isize` may be as small as 16 bits on some platforms
= note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types
error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers
--> $DIR/cast.rs:46:5 --> $DIR/cast.rs:46:5
@ -274,6 +277,9 @@ error: casting `u16` to `isize` may wrap around the value on targets with 16-bit
| |
LL | 1u16 as isize; // wraps on 16 bit ptr size LL | 1u16 as isize; // wraps on 16 bit ptr size
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
|
= note: `usize` and `isize` may be as small as 16 bits on some platforms
= note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types
error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers
--> $DIR/cast.rs:50:5 --> $DIR/cast.rs:50:5