Skip to content
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

Confusing `owned_box` error message since nightly-2019-09-04 #64430

Closed
phil-opp opened this issue Sep 13, 2019 · 4 comments · Fixed by #64439 or #64456

Comments

@phil-opp
Copy link
Contributor

commented Sep 13, 2019

Test Program:

// lib.rs

#![no_std]

pub fn foo() {
    pub struct Writer;
    write!(Writer, "");
}

Error message on nightly [9af1775 2019-09-02] and before:

error[E0599]: no method named `write_fmt` found for type `foo::Writer` in the current scope
 --> src/lib.rs:5:5
  |
4 |     pub struct Writer;
  |     ------------------ method `write_fmt` not found for this
5 |     write!(Writer, "");
  |     ^^^^^^^^^^^^^^^^^^^
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `write_fmt`, perhaps you need to implement it:
          candidate #1: `core::fmt::Write`
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Error message since nightly [b9de4ef 2019-09-03]:

error: requires `owned_box` lang_item

error: aborting due to previous error

Diff Between the Nightlies: 9af1775...b9de4ef


Reported by @wgfm and @ambye85 in phil-opp/blog_os#405 (comment).

@12101111

This comment has been minimized.

Copy link
Contributor

commented Sep 13, 2019

I'm testing this with cargo-bisect-rustc
regression in b9de4ef
Maybe #64056 cause it

@Centril

This comment has been minimized.

Copy link
Member

commented Sep 13, 2019

cc @estebank -- I think we need to be more graceful by checking if liballoc exists or not or not requiring the language items.

@12101111

This comment has been minimized.

Copy link
Contributor

commented Sep 13, 2019

PR #64056 fix #62373, show more suggestions on method take Box<Self> ,Pin<Self>, Arc<Self> or Rc<Self> when method not found

        if let Some(mut err) = self.report_method_error(
            span,
            rcvr_t,
            segment.ident,
            SelfSource::MethodCall(rcvr),
            error,
            Some(args),
        ) {
            if let ty::Adt(..) = rcvr_t.sty {
                // 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);
            }
            err.emit();
        }

However,Box , Arc and Rc don't exist in core, but in alloc.

#![no_std]
extern crate alloc;

fn main() {
    pub struct Writer;
    write!(Writer, "");
}

Error message of this code:

error: no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait.

error: `#[panic_handler]` function required, but not found

error: language item required, but not found: `eh_personality`

error: `#[alloc_error_handler]` function required, but not found

error[E0599]: no method named `write_fmt` found for type `main::Writer` in the current scope
 --> src/main.rs:6:5
  |
5 |     pub struct Writer;
  |     ------------------ method `write_fmt` not found for this
6 |     write!(Writer, "");
  |     ^^^^^^^^^^^^^^^^^^^ method not found in `main::Writer`
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `write_fmt`, perhaps you need to implement it:
          candidate #1: `core::fmt::Write`
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to 5 previous errors
@Centril

This comment has been minimized.

Copy link
Member

commented Sep 13, 2019

Mentoring instructions:

  • Change mk_lang_item to return Option<Ty<'tcx>> and use self.lang_items().require(lang_item) instead of require_lang_item.

  • Make try_alt_rcvr take in recv_t and call mk_lang_item instead and return early if let None = new_rcvr_t. Also be sure to not use mk_box.

  • Include tests like above and make sure to check for Box, Rc, and Arc.

  • Use ./x.py -i test src/test/ui --stage 1 --bless --pass check to update the tests.

12101111 added a commit to 12101111/rust that referenced this issue Sep 13, 2019
Centril added a commit to Centril/rust that referenced this issue Sep 14, 2019
fix rust-lang#64430, confusing `owned_box` error message in no_std build

Fixes rust-lang#64430
bors added a commit that referenced this issue Sep 14, 2019
Rollup of 17 pull requests

Successful merges:

 - #64116 (Fix minor typo in docs.)
 - #64290 (Provide a span if main function is not present in crate)
 - #64302 (Shrink `ObligationCauseCode`)
 - #64372 (use randSecure and randABytes)
 - #64374 (Box `DiagnosticBuilder`.)
 - #64375 (Fast path for vec.clear/truncate )
 - #64378 (Fix inconsistent link formatting.)
 - #64384 (Trim rustc-workspace-hack)
 - #64393 ( declare EnvKey before use to fix build error)
 - #64420 (Inline `mark_neighbours_as_waiting_from`.)
 - #64422 (Remove raw string literal quotes from error index descriptions)
 - #64423 (Add self to .mailmap)
 - #64424 (Fix false "never constructed" warnings for `Self::` variant paths)
 - #64425 (typo fix)
 - #64431 (fn ptr is structural match)
 - #64435 (codegen: use "_N" (like for other locals) instead of "argN", for argument names.)
 - #64439 (fix #64430, confusing `owned_box` error message in no_std build)

Failed merges:

r? @ghost
Centril added a commit to Centril/rust that referenced this issue Sep 14, 2019
fix rust-lang#64430, confusing `owned_box` error message in no_std build

Fixes rust-lang#64430
bors added a commit that referenced this issue Sep 14, 2019
Rollup of 17 pull requests

Successful merges:

 - #63846 (Added table containing the system calls used by Instant and SystemTime.)
 - #64116 (Fix minor typo in docs.)
 - #64290 (Provide a span if main function is not present in crate)
 - #64302 (Shrink `ObligationCauseCode`)
 - #64372 (use randSecure and randABytes)
 - #64374 (Box `DiagnosticBuilder`.)
 - #64375 (Fast path for vec.clear/truncate )
 - #64378 (Fix inconsistent link formatting.)
 - #64384 (Trim rustc-workspace-hack)
 - #64393 ( declare EnvKey before use to fix build error)
 - #64420 (Inline `mark_neighbours_as_waiting_from`.)
 - #64422 (Remove raw string literal quotes from error index descriptions)
 - #64423 (Add self to .mailmap)
 - #64425 (typo fix)
 - #64431 (fn ptr is structural match)
 - #64435 (codegen: use "_N" (like for other locals) instead of "argN", for argument names.)
 - #64439 (fix #64430, confusing `owned_box` error message in no_std build)

Failed merges:

r? @ghost
Centril added a commit to Centril/rust that referenced this issue Sep 14, 2019
fix rust-lang#64430, confusing `owned_box` error message in no_std build

Fixes rust-lang#64430
bors added a commit that referenced this issue Sep 14, 2019
Rollup of 17 pull requests

Successful merges:

 - #63846 (Added table containing the system calls used by Instant and SystemTime.)
 - #64116 (Fix minor typo in docs.)
 - #64203 (A few cosmetic improvements to code & comments in liballoc and libcore)
 - #64302 (Shrink `ObligationCauseCode`)
 - #64372 (use randSecure and randABytes)
 - #64374 (Box `DiagnosticBuilder`.)
 - #64375 (Fast path for vec.clear/truncate )
 - #64378 (Fix inconsistent link formatting.)
 - #64384 (Trim rustc-workspace-hack)
 - #64393 ( declare EnvKey before use to fix build error)
 - #64420 (Inline `mark_neighbours_as_waiting_from`.)
 - #64422 (Remove raw string literal quotes from error index descriptions)
 - #64423 (Add self to .mailmap)
 - #64425 (typo fix)
 - #64431 (fn ptr is structural match)
 - #64435 (codegen: use "_N" (like for other locals) instead of "argN", for argument names.)
 - #64439 (fix #64430, confusing `owned_box` error message in no_std build)

Failed merges:

r? @ghost
@bors bors closed this in 57e8287 Sep 14, 2019
@bors bors closed this in #64456 Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.