forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#116139 - flip1995:clippyup, r=Manishearth
Clippy subtree update r? `@Manishearth`
- Loading branch information
Showing
198 changed files
with
3,995 additions
and
2,324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use clippy_utils::diagnostics::span_lint_and_sugg; | ||
use clippy_utils::source::snippet_opt; | ||
use clippy_utils::{in_constant, is_integer_literal, std_or_core}; | ||
use rustc_errors::Applicability; | ||
use rustc_hir::{Expr, Mutability, Ty, TyKind}; | ||
use rustc_lint::LateContext; | ||
|
||
use super::ZERO_PTR; | ||
|
||
pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, from: &Expr<'_>, to: &Ty<'_>) { | ||
if let TyKind::Ptr(ref mut_ty) = to.kind | ||
&& is_integer_literal(from, 0) | ||
&& !in_constant(cx, from.hir_id) | ||
&& let Some(std_or_core) = std_or_core(cx) | ||
{ | ||
let (msg, sugg_fn) = match mut_ty.mutbl { | ||
Mutability::Mut => ("`0 as *mut _` detected", "ptr::null_mut"), | ||
Mutability::Not => ("`0 as *const _` detected", "ptr::null"), | ||
}; | ||
|
||
let sugg = if let TyKind::Infer = mut_ty.ty.kind { | ||
format!("{std_or_core}::{sugg_fn}()") | ||
} else if let Some(mut_ty_snip) = snippet_opt(cx, mut_ty.ty.span) { | ||
format!("{std_or_core}::{sugg_fn}::<{mut_ty_snip}>()") | ||
} else { | ||
return; | ||
}; | ||
|
||
span_lint_and_sugg( | ||
cx, | ||
ZERO_PTR, | ||
expr.span, | ||
msg, | ||
"try", | ||
sugg, | ||
Applicability::MachineApplicable, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.