Skip to content

use core::prelude::* conflicts with use collections::slice::SliceExt #20513

@SimonSapin

Description

@SimonSapin

In Nightly c894171 2015-01-02, it is apparently not possible to use methods from collections::slice::SliceExt such as to_vec in a scope where use core::prelude::*; (very useful in #![no_std] crates) is also used.

Imports can not shadow each other, a name conflict is fatal:

#![no_std]
#![feature(globs)]

extern crate core;
extern crate collections;

use core::prelude::*;
use collections::slice::SliceExt;

fn foo() {
    ['a', 'b'].slice_to(1).to_vec()
}
a.rs:8:5: 8:33 error: a type named `SliceExt` has already been imported in this module
a.rs:8 use collections::slice::SliceExt;
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

Renaming the trait at import doesn’t help, core methods are now duplicated in the scope:

#![no_std]
#![feature(globs)]

extern crate core;
extern crate collections;

use core::prelude::*;
use collections::slice::SliceExt as CollectionsSliceExt;

fn foo() {
    ['a', 'b'].slice_to(1).to_vec()
}
a.rs:11:16: 11:27 error: multiple applicable methods in scope [E0034]
a.rs:11     ['a', 'b'].slice_to(1).to_vec()
                       ^~~~~~~~~~~
a.rs:11:16: 11:27 note: candidate #1 is defined in an impl of the trait `core::slice::SliceExt` for the type `[_]`
a.rs:11     ['a', 'b'].slice_to(1).to_vec()
                       ^~~~~~~~~~~
a.rs:11:16: 11:27 note: candidate #2 is defined in an impl of the trait `collections::slice::SliceExt` for the type `[_]`
a.rs:11     ['a', 'b'].slice_to(1).to_vec()
                       ^~~~~~~~~~~
error: aborting due to previous error

As a work around when upgrading rust-wtf8, I moved use collections::slice::SliceExt; into the block that uses to_vec but does not use other slice methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions