Skip to content

Commit bde529f

Browse files
committed
clippy: support QPath::LangItem
This commit updates clippy with the introduction of `QPath::LangItem` so that it still compiles. Signed-off-by: David Wood <[email protected]>
1 parent dde93c9 commit bde529f

File tree

6 files changed

+19
-2
lines changed

6 files changed

+19
-2
lines changed

src/tools/clippy/clippy_lints/src/default_trait_access.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultTraitAccess {
6868
);
6969
}
7070
},
71-
QPath::TypeRelative(..) => {},
71+
QPath::TypeRelative(..) | QPath::LangItem(..) => {},
7272
}
7373
}
7474
}

src/tools/clippy/clippy_lints/src/types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ impl Types {
475475
}
476476
}
477477
},
478+
QPath::LangItem(..) => {},
478479
}
479480
},
480481
TyKind::Rptr(ref lt, ref mut_ty) => self.check_ty_rptr(cx, hir_ty, is_local, lt, mut_ty),

src/tools/clippy/clippy_lints/src/utils/author.rs

+1
Original file line numberDiff line numberDiff line change
@@ -760,5 +760,6 @@ fn print_path(path: &QPath<'_>, first: &mut bool) {
760760
},
761761
ref other => print!("/* unimplemented: {:?}*/", other),
762762
},
763+
QPath::LangItem(lang_item, ..) => print!("#[lang = \"{}\"]", lang_item.name()),
763764
}
764765
}

src/tools/clippy/clippy_lints/src/utils/hir_utils.rs

+6
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
601601
QPath::TypeRelative(_, ref path) => {
602602
self.hash_name(path.ident.name);
603603
},
604+
QPath::LangItem(lang_item, ..) => {
605+
lang_item.hash_stable(&mut self.cx.tcx.get_stable_hashing_context(), &mut self.s);
606+
}
604607
}
605608
// self.maybe_typeck_results.unwrap().qpath_res(p, id).hash(&mut self.s);
606609
}
@@ -710,6 +713,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
710713
self.hash_ty(ty);
711714
segment.ident.name.hash(&mut self.s);
712715
},
716+
QPath::LangItem(lang_item, ..) => {
717+
lang_item.hash(&mut self.s);
718+
}
713719
},
714720
TyKind::OpaqueDef(_, arg_list) => {
715721
self.hash_generic_args(arg_list);

src/tools/clippy/clippy_lints/src/utils/inspector.rs

+6
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
266266
println!("{}Relative Path, {:?}", ind, ty);
267267
println!("{}seg: {:?}", ind, seg);
268268
},
269+
hir::ExprKind::Path(hir::QPath::LangItem(lang_item, ..)) => {
270+
println!("{}Lang Item Path, {:?}", ind, lang_item.name());
271+
},
269272
hir::ExprKind::AddrOf(kind, ref muta, ref e) => {
270273
println!("{}AddrOf", ind);
271274
println!("kind: {:?}", kind);
@@ -488,6 +491,9 @@ fn print_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, indent: usize) {
488491
println!("{}Relative Path, {:?}", ind, ty);
489492
println!("{}seg: {:?}", ind, seg);
490493
},
494+
hir::PatKind::Path(hir::QPath::LangItem(lang_item, ..)) => {
495+
println!("{}Lang Item Path, {:?}", ind, lang_item.name());
496+
},
491497
hir::PatKind::Tuple(pats, opt_dots_position) => {
492498
println!("{}Tuple", ind);
493499
if let Some(dot_position) = opt_dots_position {

src/tools/clippy/clippy_lints/src/utils/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,15 @@ pub fn last_path_segment<'tcx>(path: &QPath<'tcx>) -> &'tcx PathSegment<'tcx> {
163163
match *path {
164164
QPath::Resolved(_, ref path) => path.segments.last().expect("A path must have at least one segment"),
165165
QPath::TypeRelative(_, ref seg) => seg,
166+
QPath::LangItem(..) => panic!("last_path_segment: lang item has no path segments"),
166167
}
167168
}
168169

169170
pub fn single_segment_path<'tcx>(path: &QPath<'tcx>) -> Option<&'tcx PathSegment<'tcx>> {
170171
match *path {
171172
QPath::Resolved(_, ref path) => path.segments.get(0),
172173
QPath::TypeRelative(_, ref seg) => Some(seg),
174+
QPath::LangItem(..) => panic!("single_segment_path: lang item has no path segments"),
173175
}
174176
}
175177

@@ -196,6 +198,7 @@ pub fn match_qpath(path: &QPath<'_>, segments: &[&str]) -> bool {
196198
},
197199
_ => false,
198200
},
201+
QPath::LangItem(..) => panic!("match_qpath: lang item has no path segments"),
199202
}
200203
}
201204

@@ -277,7 +280,7 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Option<def::Res> {
277280
pub fn qpath_res(cx: &LateContext<'_>, qpath: &hir::QPath<'_>, id: hir::HirId) -> Res {
278281
match qpath {
279282
hir::QPath::Resolved(_, path) => path.res,
280-
hir::QPath::TypeRelative(..) => {
283+
hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => {
281284
if cx.tcx.has_typeck_results(id.owner.to_def_id()) {
282285
cx.tcx.typeck(id.owner.to_def_id().expect_local()).qpath_res(qpath, id)
283286
} else {

0 commit comments

Comments
 (0)