-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 #6013 - ebroto:diagnostic_item_restriction, r=flip1995
Internal lint: suggest `is_type_diagnostic_item` over `match_type` where applicable changelog: none
- Loading branch information
Showing
10 changed files
with
217 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#![deny(clippy::internal)] | ||
#![feature(rustc_private)] | ||
|
||
extern crate rustc_hir; | ||
extern crate rustc_lint; | ||
extern crate rustc_middle; | ||
#[macro_use] | ||
extern crate rustc_session; | ||
use rustc_hir::Expr; | ||
use rustc_lint::{LateContext, LateLintPass}; | ||
use rustc_middle::ty::Ty; | ||
|
||
mod paths { | ||
pub const VEC: [&str; 3] = ["alloc", "vec", "Vec"]; | ||
} | ||
|
||
mod utils { | ||
use super::*; | ||
|
||
pub fn match_type(_cx: &LateContext<'_>, _ty: Ty<'_>, _path: &[&str]) -> bool { | ||
false | ||
} | ||
} | ||
|
||
use utils::match_type; | ||
|
||
declare_lint! { | ||
pub TEST_LINT, | ||
Warn, | ||
"" | ||
} | ||
|
||
declare_lint_pass!(Pass => [TEST_LINT]); | ||
|
||
static OPTION: [&str; 3] = ["core", "option", "Option"]; | ||
|
||
impl<'tcx> LateLintPass<'tcx> for Pass { | ||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr) { | ||
let ty = cx.typeck_results().expr_ty(expr); | ||
|
||
let _ = match_type(cx, ty, &paths::VEC); | ||
let _ = match_type(cx, ty, &OPTION); | ||
let _ = match_type(cx, ty, &["core", "result", "Result"]); | ||
|
||
let rc_path = &["alloc", "rc", "Rc"]; | ||
let _ = utils::match_type(cx, ty, rc_path); | ||
} | ||
} | ||
|
||
fn main() {} |
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,33 @@ | ||
error: usage of `utils::match_type()` on a type diagnostic item | ||
--> $DIR/match_type_on_diag_item.rs:41:17 | ||
| | ||
LL | let _ = match_type(cx, ty, &paths::VEC); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `utils::is_type_diagnostic_item(cx, ty, sym!(vec_type))` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/match_type_on_diag_item.rs:1:9 | ||
| | ||
LL | #![deny(clippy::internal)] | ||
| ^^^^^^^^^^^^^^^^ | ||
= note: `#[deny(clippy::match_type_on_diagnostic_item)]` implied by `#[deny(clippy::internal)]` | ||
|
||
error: usage of `utils::match_type()` on a type diagnostic item | ||
--> $DIR/match_type_on_diag_item.rs:42:17 | ||
| | ||
LL | let _ = match_type(cx, ty, &OPTION); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `utils::is_type_diagnostic_item(cx, ty, sym!(option_type))` | ||
|
||
error: usage of `utils::match_type()` on a type diagnostic item | ||
--> $DIR/match_type_on_diag_item.rs:43:17 | ||
| | ||
LL | let _ = match_type(cx, ty, &["core", "result", "Result"]); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `utils::is_type_diagnostic_item(cx, ty, sym!(result_type))` | ||
|
||
error: usage of `utils::match_type()` on a type diagnostic item | ||
--> $DIR/match_type_on_diag_item.rs:46:17 | ||
| | ||
LL | let _ = utils::match_type(cx, ty, rc_path); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `utils::is_type_diagnostic_item(cx, ty, sym!(Rc))` | ||
|
||
error: aborting due to 4 previous errors | ||
|