Skip to content

Commit 8295b31

Browse files
committed
eddyb's nits
1 parent bb4440c commit 8295b31

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

clippy_lints/src/consts.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
247247
if_chain! {
248248
if args.is_empty();
249249
if let ExprKind::Path(qpath) = &callee.node;
250-
let def = self.tables.qpath_res(qpath, callee.hir_id);
251-
if let Some(def_id) = def.opt_def_id();
250+
let res = self.tables.qpath_res(qpath, callee.hir_id);
251+
if let Some(def_id) = res.opt_def_id();
252252
let def_path = self.lcx.get_def_path(def_id)
253253
.iter()
254254
.map(LocalInternedString::get)
@@ -322,8 +322,8 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
322322
fn fetch_path(&mut self, qpath: &QPath, id: HirId) -> Option<Constant> {
323323
use rustc::mir::interpret::GlobalId;
324324

325-
let def = self.tables.qpath_res(qpath, id);
326-
match def {
325+
let res = self.tables.qpath_res(qpath, id);
326+
match res {
327327
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssociatedConst, def_id) => {
328328
let substs = self.tables.node_substs(id);
329329
let substs = if self.substs.is_empty() {

clippy_lints/src/loops.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1637,8 +1637,8 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<HirId>
16371637
if let ExprKind::Path(ref qpath) = bound.node;
16381638
if let QPath::Resolved(None, _) = *qpath;
16391639
then {
1640-
let def = cx.tables.qpath_res(qpath, bound.hir_id);
1641-
if let Res::Local(node_id) = def {
1640+
let res = cx.tables.qpath_res(qpath, bound.hir_id);
1641+
if let Res::Local(node_id) = res {
16421642
let node_str = cx.tcx.hir().get_by_hir_id(node_id);
16431643
if_chain! {
16441644
if let Node::Binding(pat) = node_str;
@@ -2380,9 +2380,9 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
23802380
if_chain! {
23812381
if let ExprKind::Path(ref qpath) = ex.node;
23822382
if let QPath::Resolved(None, _) = *qpath;
2383-
let def = self.cx.tables.qpath_res(qpath, ex.hir_id);
2383+
let res = self.cx.tables.qpath_res(qpath, ex.hir_id);
23842384
then {
2385-
match def {
2385+
match res {
23862386
Res::Local(node_id) | Res::Def(Res::Upvar(..), node_id, ..) => {
23872387
self.ids.insert(node_id);
23882388
},

clippy_lints/src/misc.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
411411
binding != "_result" && // FIXME: #944
412412
is_used(cx, expr) &&
413413
// don't lint if the declaration is in a macro
414-
non_macro_local(cx, &cx.tables.qpath_res(qpath, expr.hir_id))
414+
non_macro_local(cx, cx.tables.qpath_res(qpath, expr.hir_id))
415415
{
416416
Some(binding)
417417
} else {
@@ -600,9 +600,9 @@ fn in_attributes_expansion(expr: &Expr) -> bool {
600600
.map_or(false, |info| matches!(info.format, ExpnFormat::MacroAttribute(_)))
601601
}
602602

603-
/// Tests whether `def` is a variable defined outside a macro.
604-
fn non_macro_local(cx: &LateContext<'_, '_>, def: &def::DefKind) -> bool {
605-
match *def {
603+
/// Tests whether `res` is a variable defined outside a macro.
604+
fn non_macro_local(cx: &LateContext<'_, '_>, res: def::Res) -> bool {
605+
match res {
606606
def::Res::Local(id) | def::Res(Res::Upvar(..), id, _, _) => !in_macro(cx.tcx.hir().span_by_hir_id(id)),
607607
_ => false,
608608
}

clippy_lints/src/no_effect.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
7070
},
7171
ExprKind::Call(ref callee, ref args) => {
7272
if let ExprKind::Path(ref qpath) = callee.node {
73-
let def = cx.tables.qpath_res(qpath, callee.hir_id);
74-
match def {
73+
let res = cx.tables.qpath_res(qpath, callee.hir_id);
74+
match res {
7575
Res::Def(DefKind::Struct, ..) | Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _) => {
7676
!has_drop(cx, cx.tables.expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg))
7777
},
@@ -153,8 +153,8 @@ fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<Vec
153153
},
154154
ExprKind::Call(ref callee, ref args) => {
155155
if let ExprKind::Path(ref qpath) = callee.node {
156-
let def = cx.tables.qpath_res(qpath, callee.hir_id);
157-
match def {
156+
let res = cx.tables.qpath_res(qpath, callee.hir_id);
157+
match res {
158158
Res::Def(DefKind::Struct, ..) | Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _) if !has_drop(cx, cx.tables.expr_ty(expr)) => {
159159
Some(args.iter().collect())
160160
},

clippy_lints/src/types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) {
238238
match hir_ty.node {
239239
TyKind::Path(ref qpath) if !is_local => {
240240
let hir_id = hir_ty.hir_id;
241-
let def = cx.tables.qpath_res(qpath, hir_id);
242-
if let Some(def_id) = def.opt_def_id() {
241+
let res = cx.tables.qpath_res(qpath, hir_id);
242+
if let Some(def_id) = res.opt_def_id() {
243243
if Some(def_id) == cx.tcx.lang_items().owned_box() {
244244
if match_type_parameter(cx, qpath, &paths::VEC) {
245245
span_help_and_lint(
@@ -261,8 +261,8 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) {
261261
});
262262
// ty is now _ at this point
263263
if let TyKind::Path(ref ty_qpath) = ty.node;
264-
let def = cx.tables.qpath_res(ty_qpath, ty.hir_id);
265-
if let Some(def_id) = def.opt_def_id();
264+
let res = cx.tables.qpath_res(ty_qpath, ty.hir_id);
265+
if let Some(def_id) = res.opt_def_id();
266266
if Some(def_id) == cx.tcx.lang_items().owned_box();
267267
// At this point, we know ty is Box<T>, now get T
268268
if let Some(ref last) = last_path_segment(ty_qpath).args;

clippy_lints/src/utils/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub fn match_path_ast(path: &ast::Path, segments: &[&str]) -> bool {
213213
}
214214

215215
/// Gets the definition associated to a path.
216-
pub fn path_to_def(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<(def::Res)> {
216+
pub fn path_to_res(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<(def::Res)> {
217217
let crates = cx.tcx.crates();
218218
let krate = crates.iter().find(|&&krate| cx.tcx.crate_name(krate) == path[0]);
219219
if let Some(krate) = krate {
@@ -248,12 +248,12 @@ pub fn path_to_def(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<(def::Res)
248248

249249
/// Convenience function to get the `DefId` of a trait by path.
250250
pub fn get_trait_def_id(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<DefId> {
251-
let def = match path_to_def(cx, path) {
252-
Some(def) => def,
251+
let res = match path_to_res(cx, path) {
252+
Some(res) => res,
253253
None => return None,
254254
};
255255

256-
match def {
256+
match res {
257257
def::Res::Def(DefKind::Trait, trait_id) => Some(trait_id),
258258
_ => None,
259259
}

0 commit comments

Comments
 (0)