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

Allow crate:: in local paths #50131

Merged
merged 1 commit into from
Apr 26, 2018
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
9 changes: 5 additions & 4 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3245,6 +3245,7 @@ impl<'a> Resolver<'a> {

if ns == TypeNS {
if (i == 0 && name == keywords::CrateRoot.name()) ||
(i == 0 && name == keywords::Crate.name()) ||
(i == 1 && name == keywords::Crate.name() &&
path[0].name == keywords::CrateRoot.name()) {
// `::a::b` or `::crate::a::b`
Expand Down Expand Up @@ -3279,17 +3280,17 @@ impl<'a> Resolver<'a> {
name == keywords::SelfType.name() && i != 0 ||
name == keywords::Super.name() && i != 0 ||
name == keywords::Extern.name() && i != 0 ||
name == keywords::Crate.name() && i != 1 &&
path[0].name != keywords::CrateRoot.name() {
// we allow crate::foo and ::crate::foo but nothing else
name == keywords::Crate.name() && i > 1 &&
path[0].name != keywords::CrateRoot.name() ||
name == keywords::Crate.name() && path.len() == 1 {
let name_str = if name == keywords::CrateRoot.name() {
format!("crate root")
} else {
format!("`{}`", name)
};
let msg = if i == 1 && path[0].name == keywords::CrateRoot.name() {
format!("global paths cannot start with {}", name_str)
} else if i == 0 && name == keywords::Crate.name() {
format!("{} can only be used in absolute paths", name_str)
} else {
format!("{} in paths can only be used in start position", name_str)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

struct S;

mod m {
pub mod m {
fn f() {
let s = crate::S; //~ ERROR `crate` can only be used in absolute paths
let s = ::m::crate::S; //~ ERROR failed to resolve
let s2 = crate::S; // no error
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
#![feature(crate_in_paths)]

fn main() {
let crate = 0; //~ ERROR `crate` can only be used in absolute paths
let crate = 0; //~ ERROR failed to resolve. `crate` in paths can only be used in start position
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod m {
pub struct Z;
pub struct S1(crate (::m::Z)); // OK
pub struct S2(::crate ::m::Z); // OK
pub struct S3(crate ::m::Z); //~ ERROR `crate` can only be used in absolute paths
pub struct S3(crate ::m::Z); // OK
}

fn main() {
Expand Down