Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 👍 -- this bug fix turned out to make the code cleaner 🎉

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`.