mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-16 09:48:08 +00:00
Some renamings: s/ast_ty/hir_ty and s/StructField/hir::StructField
I think in both cases the new names make the code more understandable. For `StructField` specifically because there's one in [`syntax::ast`][ast] and one in [`rustc::hir`][hir]. [ast]: https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ast/struct.StructField.html [hir]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/hir/struct.StructField.html
This commit is contained in:
parent
410d5ba6c3
commit
ee7bad455b
1 changed files with 13 additions and 13 deletions
|
@ -186,7 +186,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypePass {
|
||||||
check_fn_decl(cx, decl);
|
check_fn_decl(cx, decl);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, field: &StructField) {
|
fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, field: &hir::StructField) {
|
||||||
check_ty(cx, &field.ty, false);
|
check_ty(cx, &field.ty, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,13 +240,13 @@ fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath, path: &[&str])
|
||||||
///
|
///
|
||||||
/// The parameter `is_local` distinguishes the context of the type; types from
|
/// The parameter `is_local` distinguishes the context of the type; types from
|
||||||
/// local bindings should only be checked for the `BORROWED_BOX` lint.
|
/// local bindings should only be checked for the `BORROWED_BOX` lint.
|
||||||
fn check_ty(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool) {
|
fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) {
|
||||||
if in_macro(ast_ty.span) {
|
if in_macro(hir_ty.span) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match ast_ty.node {
|
match hir_ty.node {
|
||||||
TyKind::Path(ref qpath) if !is_local => {
|
TyKind::Path(ref qpath) if !is_local => {
|
||||||
let hir_id = cx.tcx.hir().node_to_hir_id(ast_ty.id);
|
let hir_id = cx.tcx.hir().node_to_hir_id(hir_ty.id);
|
||||||
let def = cx.tables.qpath_def(qpath, hir_id);
|
let def = cx.tables.qpath_def(qpath, hir_id);
|
||||||
if let Some(def_id) = opt_def_id(def) {
|
if let Some(def_id) = opt_def_id(def) {
|
||||||
if Some(def_id) == cx.tcx.lang_items().owned_box() {
|
if Some(def_id) == cx.tcx.lang_items().owned_box() {
|
||||||
|
@ -254,7 +254,7 @@ fn check_ty(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool) {
|
||||||
span_help_and_lint(
|
span_help_and_lint(
|
||||||
cx,
|
cx,
|
||||||
BOX_VEC,
|
BOX_VEC,
|
||||||
ast_ty.span,
|
hir_ty.span,
|
||||||
"you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`",
|
"you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`",
|
||||||
"`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation.",
|
"`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation.",
|
||||||
);
|
);
|
||||||
|
@ -288,7 +288,7 @@ fn check_ty(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool) {
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
VEC_BOX,
|
VEC_BOX,
|
||||||
ast_ty.span,
|
hir_ty.span,
|
||||||
"`Vec<T>` is already on the heap, the boxing is unnecessary.",
|
"`Vec<T>` is already on the heap, the boxing is unnecessary.",
|
||||||
"try",
|
"try",
|
||||||
format!("Vec<{}>", boxed_type),
|
format!("Vec<{}>", boxed_type),
|
||||||
|
@ -302,7 +302,7 @@ fn check_ty(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool) {
|
||||||
span_lint(
|
span_lint(
|
||||||
cx,
|
cx,
|
||||||
OPTION_OPTION,
|
OPTION_OPTION,
|
||||||
ast_ty.span,
|
hir_ty.span,
|
||||||
"consider using `Option<T>` instead of `Option<Option<T>>` or a custom \
|
"consider using `Option<T>` instead of `Option<Option<T>>` or a custom \
|
||||||
enum if you need to distinguish all 3 cases",
|
enum if you need to distinguish all 3 cases",
|
||||||
);
|
);
|
||||||
|
@ -312,7 +312,7 @@ fn check_ty(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool) {
|
||||||
span_help_and_lint(
|
span_help_and_lint(
|
||||||
cx,
|
cx,
|
||||||
LINKEDLIST,
|
LINKEDLIST,
|
||||||
ast_ty.span,
|
hir_ty.span,
|
||||||
"I see you're using a LinkedList! Perhaps you meant some other data structure?",
|
"I see you're using a LinkedList! Perhaps you meant some other data structure?",
|
||||||
"a VecDeque might work",
|
"a VecDeque might work",
|
||||||
);
|
);
|
||||||
|
@ -360,7 +360,7 @@ fn check_ty(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
TyKind::Rptr(ref lt, ref mut_ty) => check_ty_rptr(cx, ast_ty, is_local, lt, mut_ty),
|
TyKind::Rptr(ref lt, ref mut_ty) => check_ty_rptr(cx, hir_ty, is_local, lt, mut_ty),
|
||||||
// recurse
|
// recurse
|
||||||
TyKind::Slice(ref ty) | TyKind::Array(ref ty, _) | TyKind::Ptr(MutTy { ref ty, .. }) => {
|
TyKind::Slice(ref ty) | TyKind::Array(ref ty, _) | TyKind::Ptr(MutTy { ref ty, .. }) => {
|
||||||
check_ty(cx, ty, is_local)
|
check_ty(cx, ty, is_local)
|
||||||
|
@ -374,7 +374,7 @@ fn check_ty(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_ty_rptr(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool, lt: &Lifetime, mut_ty: &MutTy) {
|
fn check_ty_rptr(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool, lt: &Lifetime, mut_ty: &MutTy) {
|
||||||
match mut_ty.ty.node {
|
match mut_ty.ty.node {
|
||||||
TyKind::Path(ref qpath) => {
|
TyKind::Path(ref qpath) => {
|
||||||
let hir_id = cx.tcx.hir().node_to_hir_id(mut_ty.ty.id);
|
let hir_id = cx.tcx.hir().node_to_hir_id(mut_ty.ty.id);
|
||||||
|
@ -410,7 +410,7 @@ fn check_ty_rptr(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool, lt:
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
BORROWED_BOX,
|
BORROWED_BOX,
|
||||||
ast_ty.span,
|
hir_ty.span,
|
||||||
"you seem to be trying to use `&Box<T>`. Consider using just `&T`",
|
"you seem to be trying to use `&Box<T>`. Consider using just `&T`",
|
||||||
"try",
|
"try",
|
||||||
format!(
|
format!(
|
||||||
|
@ -1317,7 +1317,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexityPass {
|
||||||
self.check_fndecl(cx, decl);
|
self.check_fndecl(cx, decl);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_struct_field(&mut self, cx: &LateContext<'a, 'tcx>, field: &'tcx StructField) {
|
fn check_struct_field(&mut self, cx: &LateContext<'a, 'tcx>, field: &'tcx hir::StructField) {
|
||||||
// enum variants are also struct fields now
|
// enum variants are also struct fields now
|
||||||
self.check_type(cx, &field.ty);
|
self.check_type(cx, &field.ty);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue