Skip to content

Commit

Permalink
Rollup merge of #64439 - 12101111:fix-owned-box, r=Centril
Browse files Browse the repository at this point in the history
fix #64430, confusing `owned_box` error message in no_std build

Fixes #64430
  • Loading branch information
Centril authored Sep 14, 2019
2 parents bf1253b + e484f21 commit 1c7959b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2396,9 +2396,9 @@ impl<'tcx> TyCtxt<'tcx> {
}

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

#[inline]
Expand Down
41 changes: 18 additions & 23 deletions src/librustc_typeck/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,18 +813,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
error: MethodError<'tcx>
) {
let rcvr = &args[0];
let try_alt_rcvr = |err: &mut DiagnosticBuilder<'_>, new_rcvr_t| {
if let Ok(pick) = self.lookup_probe(
span,
segment.ident,
new_rcvr_t,
rcvr,
probe::ProbeScope::AllTraits,
) {
err.span_label(
pick.item.ident.span,
&format!("the method is available for `{}` here", new_rcvr_t),
);
let try_alt_rcvr = |err: &mut DiagnosticBuilder<'_>, rcvr_t, lang_item| {
if let Some(new_rcvr_t) = self.tcx.mk_lang_item(rcvr_t, lang_item) {
if let Ok(pick) = self.lookup_probe(
span,
segment.ident,
new_rcvr_t,
rcvr,
probe::ProbeScope::AllTraits,
) {
err.span_label(
pick.item.ident.span,
&format!("the method is available for `{}` here", new_rcvr_t),
);
}
}
};

Expand All @@ -840,17 +842,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Try alternative arbitrary self types that could fulfill this call.
// FIXME: probe for all types that *could* be arbitrary self-types, not
// just this whitelist.
let box_rcvr_t = self.tcx.mk_box(rcvr_t);
try_alt_rcvr(&mut err, box_rcvr_t);
let pin_rcvr_t = self.tcx.mk_lang_item(
rcvr_t,
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);
try_alt_rcvr(&mut err, rcvr_t, lang_items::OwnedBoxLangItem);
try_alt_rcvr(&mut err, rcvr_t, lang_items::PinTypeLangItem);
try_alt_rcvr(&mut err, rcvr_t, lang_items::Arc);
try_alt_rcvr(&mut err, rcvr_t, lang_items::Rc);
}
err.emit();
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/issues/issue-64430.rs
Original file line number Diff line number Diff line change
@@ -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{}
}
12 changes: 12 additions & 0 deletions src/test/ui/issues/issue-64430.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 1c7959b

Please sign in to comment.