Skip to content

Commit 57e8287

Browse files
committed
fix #64430
1 parent 28e85d7 commit 57e8287

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

src/librustc/ty/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2396,9 +2396,9 @@ impl<'tcx> TyCtxt<'tcx> {
23962396
}
23972397

23982398
#[inline]
2399-
pub fn mk_lang_item(self, ty: Ty<'tcx>, item: lang_items::LangItem) -> Ty<'tcx> {
2400-
let def_id = self.require_lang_item(item, None);
2401-
self.mk_generic_adt(def_id, ty)
2399+
pub fn mk_lang_item(self, ty: Ty<'tcx>, item: lang_items::LangItem) -> Option<Ty<'tcx>> {
2400+
let def_id = self.lang_items().require(item).ok()?;
2401+
Some(self.mk_generic_adt(def_id, ty))
24022402
}
24032403

24042404
#[inline]

src/librustc_typeck/check/expr.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -813,18 +813,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
813813
error: MethodError<'tcx>
814814
) {
815815
let rcvr = &args[0];
816-
let try_alt_rcvr = |err: &mut DiagnosticBuilder<'_>, new_rcvr_t| {
817-
if let Ok(pick) = self.lookup_probe(
818-
span,
819-
segment.ident,
820-
new_rcvr_t,
821-
rcvr,
822-
probe::ProbeScope::AllTraits,
823-
) {
824-
err.span_label(
825-
pick.item.ident.span,
826-
&format!("the method is available for `{}` here", new_rcvr_t),
827-
);
816+
let try_alt_rcvr = |err: &mut DiagnosticBuilder<'_>, rcvr_t, lang_item| {
817+
if let Some(new_rcvr_t) = self.tcx.mk_lang_item(rcvr_t, lang_item) {
818+
if let Ok(pick) = self.lookup_probe(
819+
span,
820+
segment.ident,
821+
new_rcvr_t,
822+
rcvr,
823+
probe::ProbeScope::AllTraits,
824+
) {
825+
err.span_label(
826+
pick.item.ident.span,
827+
&format!("the method is available for `{}` here", new_rcvr_t),
828+
);
829+
}
828830
}
829831
};
830832

@@ -840,17 +842,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
840842
// Try alternative arbitrary self types that could fulfill this call.
841843
// FIXME: probe for all types that *could* be arbitrary self-types, not
842844
// just this whitelist.
843-
let box_rcvr_t = self.tcx.mk_box(rcvr_t);
844-
try_alt_rcvr(&mut err, box_rcvr_t);
845-
let pin_rcvr_t = self.tcx.mk_lang_item(
846-
rcvr_t,
847-
lang_items::PinTypeLangItem,
848-
);
849-
try_alt_rcvr(&mut err, pin_rcvr_t);
850-
let arc_rcvr_t = self.tcx.mk_lang_item(rcvr_t, lang_items::Arc);
851-
try_alt_rcvr(&mut err, arc_rcvr_t);
852-
let rc_rcvr_t = self.tcx.mk_lang_item(rcvr_t, lang_items::Rc);
853-
try_alt_rcvr(&mut err, rc_rcvr_t);
845+
try_alt_rcvr(&mut err, rcvr_t, lang_items::OwnedBoxLangItem);
846+
try_alt_rcvr(&mut err, rcvr_t, lang_items::PinTypeLangItem);
847+
try_alt_rcvr(&mut err, rcvr_t, lang_items::Arc);
848+
try_alt_rcvr(&mut err, rcvr_t, lang_items::Rc);
854849
}
855850
err.emit();
856851
}

0 commit comments

Comments
 (0)