1
Fork 0

Rollup merge of #64439 - 12101111:fix-owned-box, r=Centril

fix #64430, confusing `owned_box` error message in no_std build

Fixes #64430
This commit is contained in:
Mazdak Farrokhzad 2019-09-14 16:42:42 +02:00 committed by GitHub
commit 1c7959bb5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 26 deletions

View file

@ -2396,9 +2396,9 @@ impl<'tcx> TyCtxt<'tcx> {
} }
#[inline] #[inline]
pub fn mk_lang_item(self, ty: Ty<'tcx>, item: lang_items::LangItem) -> Ty<'tcx> { pub fn mk_lang_item(self, ty: Ty<'tcx>, item: lang_items::LangItem) -> Option<Ty<'tcx>> {
let def_id = self.require_lang_item(item, None); let def_id = self.lang_items().require(item).ok()?;
self.mk_generic_adt(def_id, ty) Some(self.mk_generic_adt(def_id, ty))
} }
#[inline] #[inline]

View file

@ -813,18 +813,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
error: MethodError<'tcx> error: MethodError<'tcx>
) { ) {
let rcvr = &args[0]; let rcvr = &args[0];
let try_alt_rcvr = |err: &mut DiagnosticBuilder<'_>, new_rcvr_t| { let try_alt_rcvr = |err: &mut DiagnosticBuilder<'_>, rcvr_t, lang_item| {
if let Ok(pick) = self.lookup_probe( if let Some(new_rcvr_t) = self.tcx.mk_lang_item(rcvr_t, lang_item) {
span, if let Ok(pick) = self.lookup_probe(
segment.ident, span,
new_rcvr_t, segment.ident,
rcvr, new_rcvr_t,
probe::ProbeScope::AllTraits, rcvr,
) { probe::ProbeScope::AllTraits,
err.span_label( ) {
pick.item.ident.span, err.span_label(
&format!("the method is available for `{}` here", new_rcvr_t), pick.item.ident.span,
); &format!("the method is available for `{}` here", new_rcvr_t),
);
}
} }
}; };
@ -840,17 +842,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Try alternative arbitrary self types that could fulfill this call. // Try alternative arbitrary self types that could fulfill this call.
// FIXME: probe for all types that *could* be arbitrary self-types, not // FIXME: probe for all types that *could* be arbitrary self-types, not
// just this whitelist. // just this whitelist.
let box_rcvr_t = self.tcx.mk_box(rcvr_t); try_alt_rcvr(&mut err, rcvr_t, lang_items::OwnedBoxLangItem);
try_alt_rcvr(&mut err, box_rcvr_t); try_alt_rcvr(&mut err, rcvr_t, lang_items::PinTypeLangItem);
let pin_rcvr_t = self.tcx.mk_lang_item( try_alt_rcvr(&mut err, rcvr_t, lang_items::Arc);
rcvr_t, try_alt_rcvr(&mut err, rcvr_t, lang_items::Rc);
lang_items::PinTypeLangItem,
);
try_alt_rcvr(&mut err, pin_rcvr_t);
let arc_rcvr_t = self.tcx.mk_lang_item(rcvr_t, lang_items::Arc);
try_alt_rcvr(&mut err, arc_rcvr_t);
let rc_rcvr_t = self.tcx.mk_lang_item(rcvr_t, lang_items::Rc);
try_alt_rcvr(&mut err, rc_rcvr_t);
} }
err.emit(); err.emit();
} }

View file

@ -0,0 +1,14 @@
// compile-flags:-C panic=abort
#![no_std]
pub struct Foo;
fn main() {
Foo.bar()
//~^ ERROR E0599
}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop{}
}

View file

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