Skip to content

Commit d236b30

Browse files
committed
Auto merge of rust-lang#5457 - phansch:sym, r=matthiaskrgr
Cleanup: Use our `sym!` macro more It's much shorter than Symbol::intern and the effect should still be clear --- changelog: none
2 parents 85e8b64 + 31c5664 commit d236b30

File tree

7 files changed

+19
-21
lines changed

7 files changed

+19
-21
lines changed

clippy_lints/src/get_last_with_len.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_hir::{BinOpKind, Expr, ExprKind};
88
use rustc_lint::{LateContext, LateLintPass};
99
use rustc_session::{declare_lint_pass, declare_tool_lint};
1010
use rustc_span::source_map::Spanned;
11-
use rustc_span::symbol::Symbol;
1211

1312
declare_clippy_lint! {
1413
/// **What it does:** Checks for using `x.get(x.len() - 1)` instead of
@@ -51,12 +50,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen {
5150
if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind;
5251

5352
// Method name is "get"
54-
if path.ident.name == Symbol::intern("get");
53+
if path.ident.name == sym!(get);
5554

5655
// Argument 0 (the struct we're calling the method on) is a vector
5756
if let Some(struct_calling_on) = args.get(0);
5857
let struct_ty = cx.tables.expr_ty(struct_calling_on);
59-
if is_type_diagnostic_item(cx, struct_ty, Symbol::intern("vec_type"));
58+
if is_type_diagnostic_item(cx, struct_ty, sym!(vec_type));
6059

6160
// Argument to "get" is a subtraction
6261
if let Some(get_index_arg) = args.get(1);
@@ -71,7 +70,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen {
7170

7271
// LHS of subtraction is "x.len()"
7372
if let ExprKind::MethodCall(arg_lhs_path, _, lhs_args) = &lhs.kind;
74-
if arg_lhs_path.ident.name == Symbol::intern("len");
73+
if arg_lhs_path.ident.name == sym!(len);
7574
if let Some(arg_lhs_struct) = lhs_args.get(0);
7675

7776
// The two vectors referenced (x in x.get(...) and in x.len())

clippy_lints/src/loops.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_middle::middle::region;
2828
use rustc_middle::ty::{self, Ty};
2929
use rustc_session::{declare_lint_pass, declare_tool_lint};
3030
use rustc_span::source_map::Span;
31-
use rustc_span::{BytePos, Symbol};
31+
use rustc_span::BytePos;
3232
use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase};
3333
use std::iter::{once, Iterator};
3434
use std::mem;
@@ -804,7 +804,7 @@ fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool {
804804
_ => false,
805805
};
806806

807-
is_slice || is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type")) || match_type(cx, ty, &paths::VEC_DEQUE)
807+
is_slice || is_type_diagnostic_item(cx, ty, sym!(vec_type)) || match_type(cx, ty, &paths::VEC_DEQUE)
808808
}
809809

810810
fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>, var: HirId) -> Option<FixedOffsetVar> {
@@ -1955,7 +1955,7 @@ fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool {
19551955
// will allow further borrows afterwards
19561956
let ty = cx.tables.expr_ty(e);
19571957
is_iterable_array(ty, cx) ||
1958-
is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type")) ||
1958+
is_type_diagnostic_item(cx, ty, sym!(vec_type)) ||
19591959
match_type(cx, ty, &paths::LINKED_LIST) ||
19601960
match_type(cx, ty, &paths::HASHMAP) ||
19611961
match_type(cx, ty, &paths::HASHSET) ||
@@ -2465,7 +2465,7 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'a, '
24652465
if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0);
24662466
then {
24672467
let ty = cx.tables.node_type(ty.hir_id);
2468-
if is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type")) ||
2468+
if is_type_diagnostic_item(cx, ty, sym!(vec_type)) ||
24692469
match_type(cx, ty, &paths::VEC_DEQUE) ||
24702470
match_type(cx, ty, &paths::BTREEMAP) ||
24712471
match_type(cx, ty, &paths::HASHMAP) {

clippy_lints/src/methods/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_middle::ty::subst::GenericArgKind;
1919
use rustc_middle::ty::{self, Predicate, Ty};
2020
use rustc_session::{declare_lint_pass, declare_tool_lint};
2121
use rustc_span::source_map::Span;
22-
use rustc_span::symbol::{sym, Symbol, SymbolStr};
22+
use rustc_span::symbol::{sym, SymbolStr};
2323

2424
use crate::consts::{constant, Constant};
2525
use crate::utils::usage::mutated_variables;
@@ -2111,7 +2111,7 @@ fn lint_iter_cloned_collect<'a, 'tcx>(
21112111
iter_args: &'tcx [hir::Expr<'_>],
21122112
) {
21132113
if_chain! {
2114-
if is_type_diagnostic_item(cx, cx.tables.expr_ty(expr), Symbol::intern("vec_type"));
2114+
if is_type_diagnostic_item(cx, cx.tables.expr_ty(expr), sym!(vec_type));
21152115
if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.tables.expr_ty(&iter_args[0]));
21162116
if let Some(to_replace) = expr.span.trim_start(slice.span.source_callsite());
21172117

@@ -2240,7 +2240,7 @@ fn lint_iter_nth<'a, 'tcx>(
22402240
let mut_str = if is_mut { "_mut" } else { "" };
22412241
let caller_type = if derefs_to_slice(cx, &iter_args[0], cx.tables.expr_ty(&iter_args[0])).is_some() {
22422242
"slice"
2243-
} else if is_type_diagnostic_item(cx, cx.tables.expr_ty(&iter_args[0]), Symbol::intern("vec_type")) {
2243+
} else if is_type_diagnostic_item(cx, cx.tables.expr_ty(&iter_args[0]), sym!(vec_type)) {
22442244
"Vec"
22452245
} else if match_type(cx, cx.tables.expr_ty(&iter_args[0]), &paths::VEC_DEQUE) {
22462246
"VecDeque"
@@ -2297,7 +2297,7 @@ fn lint_get_unwrap<'a, 'tcx>(
22972297
let caller_type = if derefs_to_slice(cx, &get_args[0], expr_ty).is_some() {
22982298
needs_ref = get_args_str.parse::<usize>().is_ok();
22992299
"slice"
2300-
} else if is_type_diagnostic_item(cx, expr_ty, Symbol::intern("vec_type")) {
2300+
} else if is_type_diagnostic_item(cx, expr_ty, sym!(vec_type)) {
23012301
needs_ref = get_args_str.parse::<usize>().is_ok();
23022302
"Vec"
23032303
} else if match_type(cx, expr_ty, &paths::VEC_DEQUE) {
@@ -2378,7 +2378,7 @@ fn derefs_to_slice<'a, 'tcx>(
23782378
match ty.kind {
23792379
ty::Slice(_) => true,
23802380
ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()),
2381-
ty::Adt(..) => is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type")),
2381+
ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym!(vec_type)),
23822382
ty::Array(_, size) => {
23832383
if let Some(size) = size.try_eval_usize(cx.tcx, cx.param_env) {
23842384
size < 32

clippy_lints/src/needless_pass_by_value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_infer::infer::TyCtxtInferExt;
1313
use rustc_lint::{LateContext, LateLintPass};
1414
use rustc_middle::ty::{self, TypeFoldable};
1515
use rustc_session::{declare_lint_pass, declare_tool_lint};
16-
use rustc_span::{Span, Symbol};
16+
use rustc_span::Span;
1717
use rustc_target::spec::abi::Abi;
1818
use rustc_trait_selection::traits;
1919
use rustc_trait_selection::traits::misc::can_type_implement_copy;
@@ -214,7 +214,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
214214

215215
let deref_span = spans_need_deref.get(&canonical_id);
216216
if_chain! {
217-
if is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type"));
217+
if is_type_diagnostic_item(cx, ty, sym!(vec_type));
218218
if let Some(clone_spans) =
219219
get_spans(cx, Some(body.id()), idx, &[("clone", ".to_owned()")]);
220220
if let TyKind::Path(QPath::Resolved(_, ref path)) = input.kind;

clippy_lints/src/ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_lint::{LateContext, LateLintPass};
1515
use rustc_middle::ty;
1616
use rustc_session::{declare_lint_pass, declare_tool_lint};
1717
use rustc_span::source_map::Span;
18-
use rustc_span::{MultiSpan, Symbol};
18+
use rustc_span::MultiSpan;
1919
use std::borrow::Cow;
2020

2121
declare_clippy_lint! {
@@ -153,7 +153,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_
153153

154154
for (idx, (arg, ty)) in decl.inputs.iter().zip(fn_ty.inputs()).enumerate() {
155155
if let ty::Ref(_, ty, Mutability::Not) = ty.kind {
156-
if is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type")) {
156+
if is_type_diagnostic_item(cx, ty, sym!(vec_type)) {
157157
let mut ty_snippet = None;
158158
if_chain! {
159159
if let TyKind::Path(QPath::Resolved(_, ref path)) = walk_ptrs_hir_ty(arg).kind;

clippy_lints/src/swap.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_hir::{Block, Expr, ExprKind, PatKind, QPath, StmtKind};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_middle::ty;
1111
use rustc_session::{declare_lint_pass, declare_tool_lint};
12-
use rustc_span::Symbol;
1312

1413
declare_clippy_lint! {
1514
/// **What it does:** Checks for manual swapping.
@@ -199,7 +198,7 @@ fn check_for_slice<'a>(cx: &LateContext<'_, '_>, lhs1: &'a Expr<'_>, lhs2: &'a E
199198

200199
if matches!(ty.kind, ty::Slice(_))
201200
|| matches!(ty.kind, ty::Array(_, _))
202-
|| is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type"))
201+
|| is_type_diagnostic_item(cx, ty, sym!(vec_type))
203202
|| match_type(cx, ty, &paths::VEC_DEQUE)
204203
{
205204
return Slice::Swappable(lhs1, idx1, idx2);

clippy_lints/src/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::ty::{self, InferTy, Ty, TyCtxt, TypeckTables};
2121
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
2222
use rustc_span::hygiene::{ExpnKind, MacroKind};
2323
use rustc_span::source_map::Span;
24-
use rustc_span::symbol::{sym, Symbol};
24+
use rustc_span::symbol::sym;
2525
use rustc_target::abi::LayoutOf;
2626
use rustc_target::spec::abi::Abi;
2727
use rustc_typeck::hir_ty_to_ty;
@@ -384,7 +384,7 @@ impl Types {
384384
);
385385
return; // don't recurse into the type
386386
}
387-
} else if cx.tcx.is_diagnostic_item(Symbol::intern("vec_type"), def_id) {
387+
} else if cx.tcx.is_diagnostic_item(sym!(vec_type), def_id) {
388388
if_chain! {
389389
// Get the _ part of Vec<_>
390390
if let Some(ref last) = last_path_segment(qpath).args;

0 commit comments

Comments
 (0)