forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
89 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use rustc_hir as hir; | ||
use rustc_lint::{LateContext, LateLintPass}; | ||
use rustc_session::declare_lint_pass; | ||
|
||
use rustc_middle::mir as mir; | ||
|
||
declare_clippy_lint! { | ||
/// ### What it does | ||
/// | ||
/// ### Why is this bad? | ||
/// | ||
/// ### Example | ||
/// ```no_run | ||
/// // example code where clippy issues a warning | ||
/// ``` | ||
/// Use instead: | ||
/// ```no_run | ||
/// // example code which does not raise clippy warning | ||
/// ``` | ||
#[clippy::version = "1.78.0"] | ||
pub BORROW_PATS, | ||
nursery, | ||
"default lint description" | ||
} | ||
|
||
declare_lint_pass!(BorrowPats => [BORROW_PATS]); | ||
|
||
impl<'tcx> LateLintPass<'tcx> for BorrowPats { | ||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx hir::Body<'tcx>) { | ||
// if in_external_macro(cx.tcx.sess, body.value.span) && is_from_proc_macro(cx, &(&kind, body, body.value.hir_id, body.value.span)) { | ||
// return; | ||
// } | ||
|
||
let def = cx.tcx.hir().body_owner_def_id(body.id()); | ||
|
||
|
||
// let mir = cx.tcx.mir_built(def).borrow(); | ||
// let mir = cx.tcx.mir_promoted(def); | ||
let mir = cx.tcx.optimized_mir(def); | ||
print_body(mir); | ||
} | ||
} | ||
|
||
fn print_body(body: &mir::Body<'_>) { | ||
for (idx, data) in body.basic_blocks.iter_enumerated() { | ||
println!("bb{}:", idx.index()); | ||
for stmt in &data.statements { | ||
println!(" {stmt:#?}"); | ||
} | ||
println!(" {:#?}", data.terminator().kind); | ||
|
||
println!(); | ||
} | ||
|
||
println!("{body:#?}"); | ||
} |
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,5 @@ | ||
#![warn(clippy::borrow_pats)] | ||
|
||
fn main() { | ||
// test code goes here | ||
} |
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,20 @@ | ||
#![allow(unused)] | ||
|
||
|
||
fn main() { | ||
|
||
// let owned_1 = String::new(); | ||
// | ||
// { | ||
// let owned_2 = String::new(); | ||
// let owned_3 = String::new(); | ||
// | ||
// drop(owned_2); | ||
// } | ||
|
||
let owned_4b = { | ||
let owned_4a = String::new(); | ||
|
||
owned_4a | ||
}; | ||
} |