Skip to content

Commit 1c7959b

Browse files
authored
Rollup merge of #64439 - 12101111:fix-owned-box, r=Centril
fix #64430, confusing `owned_box` error message in no_std build Fixes #64430
2 parents bf1253b + e484f21 commit 1c7959b

File tree

4 files changed

+47
-26
lines changed

4 files changed

+47
-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
}

src/test/ui/issues/issue-64430.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// compile-flags:-C panic=abort
2+
3+
#![no_std]
4+
pub struct Foo;
5+
6+
fn main() {
7+
Foo.bar()
8+
//~^ ERROR E0599
9+
}
10+
11+
#[panic_handler]
12+
fn panic(_info: &core::panic::PanicInfo) -> ! {
13+
loop{}
14+
}

src/test/ui/issues/issue-64430.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0599]: no method named `bar` found for type `Foo` in the current scope
2+
--> $DIR/issue-64430.rs:7:9
3+
|
4+
LL | pub struct Foo;
5+
| --------------- method `bar` not found for this
6+
...
7+
LL | Foo.bar()
8+
| ^^^ method not found in `Foo`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)