Auto merge of #50131 - Manishearth:crate-in-local, r=petrochenkov
Allow crate:: in local paths Currently if you want to use `crate` locally you have to do `::crate::`. This shouldn't be necessary (will fix up tests later) r? @petrochenkov
This commit is contained in:
commit
84ce67ef95
4 changed files with 10 additions and 8 deletions
|
@ -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`
|
||||
|
@ -3279,8 +3280,10 @@ 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 {
|
||||
|
@ -3288,8 +3291,6 @@ impl<'a> Resolver<'a> {
|
|||
};
|
||||
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)
|
||||
};
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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() {
|
Loading…
Add table
Add a link
Reference in a new issue