Skip to content

Commit 627e910

Browse files
committed
Auto merge of #6868 - Jarcho:lang_item, r=flip1995
Don't assume lang items will exist. ~~Should fix lintcheck warnings caused by #6823~~ See below changelog: None
2 parents 3ed0bcc + f2d917e commit 627e910

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

clippy_lints/src/derive.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,12 @@ fn check_ord_partial_ord<'tcx>(
293293

294294
/// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint.
295295
fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &TraitRef<'_>, ty: Ty<'tcx>) {
296-
if cx.tcx.lang_items().clone_trait() == trait_ref.trait_def_id() {
296+
if cx
297+
.tcx
298+
.lang_items()
299+
.clone_trait()
300+
.map_or(false, |id| Some(id) == trait_ref.trait_def_id())
301+
{
297302
if !is_copy(cx, ty) {
298303
return;
299304
}

clippy_lints/src/lifetimes.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,13 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
358358

359359
fn visit_poly_trait_ref(&mut self, poly_tref: &'tcx PolyTraitRef<'tcx>, tbm: TraitBoundModifier) {
360360
let trait_ref = &poly_tref.trait_ref;
361-
if CLOSURE_TRAIT_BOUNDS
362-
.iter()
363-
.any(|&item| trait_ref.trait_def_id() == self.cx.tcx.lang_items().require(item).ok())
364-
{
361+
if CLOSURE_TRAIT_BOUNDS.iter().any(|&item| {
362+
self.cx
363+
.tcx
364+
.lang_items()
365+
.require(item)
366+
.map_or(false, |id| Some(id) == trait_ref.trait_def_id())
367+
}) {
365368
let mut sub_visitor = RefVisitor::new(self.cx);
366369
sub_visitor.visit_trait_ref(trait_ref);
367370
self.nested_elision_site_lts.append(&mut sub_visitor.all_lts());

clippy_lints/src/map_clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
8181
if ident_eq(name, obj) && method.ident.name == sym::clone;
8282
if let Some(fn_id) = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id);
8383
if let Some(trait_id) = cx.tcx.trait_of_item(fn_id);
84-
if Some(trait_id) == cx.tcx.lang_items().clone_trait();
84+
if cx.tcx.lang_items().clone_trait().map_or(false, |id| id == trait_id);
8585
// no autoderefs
8686
if !cx.typeck_results().expr_adjustments(obj).iter()
8787
.any(|a| matches!(a.kind, Adjust::Deref(Some(..))));

clippy_utils/src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ pub fn is_ty_param_lang_item(cx: &LateContext<'_>, qpath: &QPath<'tcx>, item: La
239239
if let TyKind::Path(qpath) = &ty.kind {
240240
cx.qpath_res(qpath, ty.hir_id)
241241
.opt_def_id()
242-
.and_then(|id| (cx.tcx.lang_items().require(item) == Ok(id)).then(|| ty))
242+
.map_or(false, |id| {
243+
cx.tcx.lang_items().require(item).map_or(false, |lang_id| id == lang_id)
244+
})
245+
.then(|| ty)
243246
} else {
244247
None
245248
}
@@ -256,7 +259,8 @@ pub fn is_ty_param_diagnostic_item(
256259
if let TyKind::Path(qpath) = &ty.kind {
257260
cx.qpath_res(qpath, ty.hir_id)
258261
.opt_def_id()
259-
.and_then(|id| cx.tcx.is_diagnostic_item(item, id).then(|| ty))
262+
.map_or(false, |id| cx.tcx.is_diagnostic_item(item, id))
263+
.then(|| ty)
260264
} else {
261265
None
262266
}

0 commit comments

Comments
 (0)