Skip to content

Box::new requires use std::boxed::Box despite prelude injection #20730

Closed
@pnkfelix

Description

@pnkfelix

In my branch that has #20723 landed, this oddity comes up:

#[cfg(workaround)]
use std::boxed::Box;

fn main() {
    let x: Box<char>;
    x = Box::new('c');
    println!(" x: {}", x);
}

Ready? Watch this:

% ./x86_64-apple-darwin/stage2/bin/rustc /tmp/boxnew2.rs
/tmp/boxnew2.rs:6:9: 6:17 error: unresolved name `Box::new`
/tmp/boxnew2.rs:6     x = Box::new('c');
                          ^~~~~~~~
error: aborting due to previous error
% ./x86_64-apple-darwin/stage2/bin/rustc /tmp/boxnew2.rs --cfg workaround
% 

That is, the Box::new call fails, unless one includes a use std::boxed::Box in one's code. Truly weird.

I spent much time today trying to dig into this (when I should have been dealing with the other fallout from feature gating box), but in the end I decided that this is "just a bug" and its an easy enough work around for the purposes of the alpha.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions