mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 13:43:17 +00:00
ayy it compiles! ship it, right? 😎 /s
why was `rustc_lint_defs` not already externed in `lib.rs`?
and how was r-a able to find it but cargo wasn't? 🤔
This commit is contained in:
parent
c69387a0d5
commit
92d3b775bd
2 changed files with 33 additions and 45 deletions
|
@ -30,6 +30,7 @@ extern crate rustc_index;
|
|||
extern crate rustc_infer;
|
||||
extern crate rustc_lexer;
|
||||
extern crate rustc_lint;
|
||||
extern crate rustc_lint_defs;
|
||||
extern crate rustc_middle;
|
||||
extern crate rustc_mir_dataflow;
|
||||
extern crate rustc_parse;
|
||||
|
@ -487,6 +488,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
store.register_late_pass(|| Box::new(utils::internal_lints::OuterExpnDataPass));
|
||||
}
|
||||
|
||||
store.register_early_pass(|| Box::new(trailing_zero_sized_array_without_repr_c::TrailingZeroSizedArrayWithoutReprC));
|
||||
store.register_late_pass(|| Box::new(utils::author::Author));
|
||||
store.register_late_pass(|| Box::new(await_holding_invalid::AwaitHolding));
|
||||
store.register_late_pass(|| Box::new(serde_api::SerdeApi));
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use rustc_hir::*;
|
||||
use rustc_lint::{EarlyContext, EarlyLintPass};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_lint_defs::Applicability;
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -33,55 +32,42 @@ declare_clippy_lint! {
|
|||
}
|
||||
declare_lint_pass!(TrailingZeroSizedArrayWithoutReprC => [TRAILING_ZERO_SIZED_ARRAY_WITHOUT_REPR_C]);
|
||||
|
||||
impl LateLintPass<'_> for TrailingZeroSizedArrayWithoutReprC {
|
||||
fn check_struct_def(&mut self, cx: &LateContext<'tcx>, data: &'tcx rustc_hir::VariantData<'tcx>) {
|
||||
dbg!("in check_struct_def");
|
||||
if_chain! {
|
||||
if let Some(def) = data.fields().last();
|
||||
if let rustc_hir::TyKind::Array(ty, acost) = def.ty.kind;
|
||||
then {
|
||||
// is the AnonConst `0`
|
||||
}
|
||||
}
|
||||
|
||||
// span_lint_and_sugg(
|
||||
// cx,
|
||||
// todo!(),
|
||||
// todo!(),
|
||||
// todo!(),
|
||||
// todo!(),
|
||||
// todo!(),
|
||||
// rustc_errors::Applicability::MaybeIncorrect,
|
||||
// )
|
||||
}
|
||||
// https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/sty/enum.TyKind.html#variant.Array in latepass
|
||||
// or https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/enum.TyKind.html#variant.Array in early pass
|
||||
|
||||
// fn check_struct_def_post(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_hir::VariantData<'tcx>)
|
||||
// {}
|
||||
|
||||
// fn check_field_def(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_hir::FieldDef<'tcx>) {}
|
||||
|
||||
// fn check_attribute(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_ast::Attribute) {}
|
||||
|
||||
// fn enter_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [rustc_ast::Attribute]) {}
|
||||
|
||||
// fn exit_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [rustc_ast::Attribute]) {}
|
||||
}
|
||||
//
|
||||
// TODO: Register the lint pass in `clippy_lints/src/lib.rs`,
|
||||
// e.g. store.register_late_pass(||
|
||||
// e.g. store.register_early_pass(||
|
||||
// Box::new(trailing_zero_sized_array_without_repr_c::TrailingZeroSizedArrayWithoutReprC));
|
||||
|
||||
// fn temp_alert() {}
|
||||
|
||||
impl EarlyLintPass for TrailingZeroSizedArrayWithoutReprC {
|
||||
fn check_struct_def(&mut self, cx: &EarlyContext<'_>, data: &rustc_ast::VariantData) {
|
||||
if is_struct_with_trailing_zero_sized_array(cx, data) && !has_repr_c(cx, data) {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
todo!(),
|
||||
todo!(),
|
||||
todo!(),
|
||||
"try",
|
||||
"`#[repr(C)]`".to_string(),
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_struct_with_trailing_zero_sized_array(cx: &EarlyContext<'_>, data: &rustc_ast::VariantData) -> bool {
|
||||
if_chain! {
|
||||
if let rustc_ast::ast::VariantData::Struct(field_defs, some_bool_huh) = data;
|
||||
if let Some(last_field) = field_defs.last();
|
||||
if let rustc_ast::ast::TyKind::Array(_, aconst) = &last_field.ty.kind;
|
||||
then {dbg!(aconst); return ();}
|
||||
// TODO: if array is zero-sized;
|
||||
then {
|
||||
dbg!(aconst);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn has_repr_c(cx: &EarlyContext<'_>, data: &rustc_ast::VariantData) -> bool {
|
||||
todo!()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue