Skip to content

Commit

Permalink
clippy: support QPath::LangItem
Browse files Browse the repository at this point in the history
This commit updates clippy with the introduction of `QPath::LangItem` so
that it still compiles.

Signed-off-by: David Wood <david@davidtw.co>
  • Loading branch information
davidtwco committed Aug 16, 2020
1 parent dde93c9 commit bde529f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/default_trait_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultTraitAccess {
);
}
},
QPath::TypeRelative(..) => {},
QPath::TypeRelative(..) | QPath::LangItem(..) => {},
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ impl Types {
}
}
},
QPath::LangItem(..) => {},
}
},
TyKind::Rptr(ref lt, ref mut_ty) => self.check_ty_rptr(cx, hir_ty, is_local, lt, mut_ty),
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/clippy_lints/src/utils/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,5 +760,6 @@ fn print_path(path: &QPath<'_>, first: &mut bool) {
},
ref other => print!("/* unimplemented: {:?}*/", other),
},
QPath::LangItem(lang_item, ..) => print!("#[lang = \"{}\"]", lang_item.name()),
}
}
6 changes: 6 additions & 0 deletions src/tools/clippy/clippy_lints/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
QPath::TypeRelative(_, ref path) => {
self.hash_name(path.ident.name);
},
QPath::LangItem(lang_item, ..) => {
lang_item.hash_stable(&mut self.cx.tcx.get_stable_hashing_context(), &mut self.s);
}
}
// self.maybe_typeck_results.unwrap().qpath_res(p, id).hash(&mut self.s);
}
Expand Down Expand Up @@ -710,6 +713,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
self.hash_ty(ty);
segment.ident.name.hash(&mut self.s);
},
QPath::LangItem(lang_item, ..) => {
lang_item.hash(&mut self.s);
}
},
TyKind::OpaqueDef(_, arg_list) => {
self.hash_generic_args(arg_list);
Expand Down
6 changes: 6 additions & 0 deletions src/tools/clippy/clippy_lints/src/utils/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
println!("{}Relative Path, {:?}", ind, ty);
println!("{}seg: {:?}", ind, seg);
},
hir::ExprKind::Path(hir::QPath::LangItem(lang_item, ..)) => {
println!("{}Lang Item Path, {:?}", ind, lang_item.name());
},
hir::ExprKind::AddrOf(kind, ref muta, ref e) => {
println!("{}AddrOf", ind);
println!("kind: {:?}", kind);
Expand Down Expand Up @@ -488,6 +491,9 @@ fn print_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, indent: usize) {
println!("{}Relative Path, {:?}", ind, ty);
println!("{}seg: {:?}", ind, seg);
},
hir::PatKind::Path(hir::QPath::LangItem(lang_item, ..)) => {
println!("{}Lang Item Path, {:?}", ind, lang_item.name());
},
hir::PatKind::Tuple(pats, opt_dots_position) => {
println!("{}Tuple", ind);
if let Some(dot_position) = opt_dots_position {
Expand Down
5 changes: 4 additions & 1 deletion src/tools/clippy/clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ pub fn last_path_segment<'tcx>(path: &QPath<'tcx>) -> &'tcx PathSegment<'tcx> {
match *path {
QPath::Resolved(_, ref path) => path.segments.last().expect("A path must have at least one segment"),
QPath::TypeRelative(_, ref seg) => seg,
QPath::LangItem(..) => panic!("last_path_segment: lang item has no path segments"),
}
}

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

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

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

0 comments on commit bde529f

Please sign in to comment.