Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
90f5cfdf
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
90f5cfdf
编写于
11月 19, 2017
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Report special messages for path segment keywords in wrong positions
上级
2e9b89dd
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
47 addition
and
18 deletion
+47
-18
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+30
-6
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+8
-2
src/test/compile-fail/dollar-crate-is-keyword-2.rs
src/test/compile-fail/dollar-crate-is-keyword-2.rs
+2
-2
src/test/compile-fail/rfc-2126-crate-paths/crate-path-non-absolute.rs
...pile-fail/rfc-2126-crate-paths/crate-path-non-absolute.rs
+1
-1
src/test/compile-fail/rfc-2126-crate-paths/crate-visibility-ambiguity.rs
...e-fail/rfc-2126-crate-paths/crate-visibility-ambiguity.rs
+1
-1
src/test/compile-fail/rfc-2126-crate-paths/keyword-crate-as-identifier.rs
...-fail/rfc-2126-crate-paths/keyword-crate-as-identifier.rs
+1
-1
src/test/compile-fail/super-at-top-level.rs
src/test/compile-fail/super-at-top-level.rs
+1
-2
src/test/compile-fail/use-super-global-path.rs
src/test/compile-fail/use-super-global-path.rs
+3
-3
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
90f5cfdf
...
...
@@ -2865,12 +2865,13 @@ fn resolve_path(&mut self,
debug!
(
"resolve_path ident {} {:?}"
,
i
,
ident
);
let
is_last
=
i
==
path
.len
()
-
1
;
let
ns
=
if
is_last
{
opt_ns
.unwrap_or
(
TypeNS
)
}
else
{
TypeNS
};
let
name
=
ident
.node.name
;
if
i
==
0
&&
ns
==
TypeNS
&&
ident
.node.
name
==
keywords
::
SelfValue
.name
()
{
if
i
==
0
&&
ns
==
TypeNS
&&
name
==
keywords
::
SelfValue
.name
()
{
let
mut
ctxt
=
ident
.node.ctxt
.modern
();
module
=
Some
(
self
.resolve_self
(
&
mut
ctxt
,
self
.current_module
));
continue
}
else
if
allow_super
&&
ns
==
TypeNS
&&
ident
.node.
name
==
keywords
::
Super
.name
()
{
}
else
if
allow_super
&&
ns
==
TypeNS
&&
name
==
keywords
::
Super
.name
()
{
let
mut
ctxt
=
ident
.node.ctxt
.modern
();
let
self_module
=
match
i
{
0
=>
self
.resolve_self
(
&
mut
ctxt
,
self
.current_module
),
...
...
@@ -2887,19 +2888,42 @@ fn resolve_path(&mut self,
allow_super
=
false
;
if
ns
==
TypeNS
{
if
(
i
==
0
&&
ident
.node.
name
==
keywords
::
CrateRoot
.name
())
||
(
i
==
1
&&
ident
.node.
name
==
keywords
::
Crate
.name
()
&&
if
(
i
==
0
&&
name
==
keywords
::
CrateRoot
.name
())
||
(
i
==
1
&&
name
==
keywords
::
Crate
.name
()
&&
path
[
0
]
.node.name
==
keywords
::
CrateRoot
.name
())
{
// `::a::b` or `::crate::a::b`
module
=
Some
(
self
.resolve_crate_root
(
ident
.node.ctxt
.modern
()));
continue
}
else
if
i
==
0
&&
ident
.node.
name
==
keywords
::
DollarCrate
.name
()
{
}
else
if
i
==
0
&&
name
==
keywords
::
DollarCrate
.name
()
{
// `$crate::a::b`
module
=
Some
(
self
.resolve_crate_root
(
ident
.node.ctxt
));
continue
}
}
// Report special messages for path segment keywords in wrong positions.
if
name
==
keywords
::
CrateRoot
.name
()
&&
i
!=
0
||
name
==
keywords
::
DollarCrate
.name
()
&&
i
!=
0
||
name
==
keywords
::
SelfValue
.name
()
&&
i
!=
0
||
name
==
keywords
::
SelfType
.name
()
&&
i
!=
0
||
name
==
keywords
::
Super
.name
()
&&
i
!=
0
||
name
==
keywords
::
Crate
.name
()
&&
i
!=
1
&&
path
[
0
]
.node.name
!=
keywords
::
CrateRoot
.name
()
{
let
name_str
=
if
name
==
keywords
::
CrateRoot
.name
()
{
format!
(
"crate root"
)
}
else
{
format!
(
"`{}`"
,
name
)
};
let
msg
=
if
i
==
1
&&
path
[
0
]
.node.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
)
};
return
PathResult
::
Failed
(
ident
.span
,
msg
,
false
);
}
let
binding
=
if
let
Some
(
module
)
=
module
{
self
.resolve_ident_in_module
(
module
,
ident
.node
,
ns
,
false
,
record_used
,
path_span
)
}
else
if
opt_ns
==
Some
(
MacroNS
)
{
...
...
@@ -2948,7 +2972,7 @@ fn resolve_path(&mut self,
let
msg
=
if
module
.and_then
(
ModuleData
::
def
)
==
self
.graph_root
.def
()
{
let
is_mod
=
|
def
|
match
def
{
Def
::
Mod
(
..
)
=>
true
,
_
=>
false
};
let
mut
candidates
=
self
.lookup_import_candidates
(
ident
.node.
name
,
TypeNS
,
is_mod
);
self
.lookup_import_candidates
(
name
,
TypeNS
,
is_mod
);
candidates
.sort_by_key
(|
c
|
(
c
.path.segments
.len
(),
c
.path
.to_string
()));
if
let
Some
(
candidate
)
=
candidates
.get
(
0
)
{
format!
(
"Did you mean `{}`?"
,
candidate
.path
)
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
90f5cfdf
...
...
@@ -606,10 +606,16 @@ fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> Option<(Spa
let
module_result
=
self
.resolve_path
(
&
module_path
,
None
,
true
,
span
);
let
module
=
match
module_result
{
PathResult
::
Module
(
module
)
=>
module
,
PathResult
::
Failed
(
span
,
msg
,
_
)
=>
{
PathResult
::
Failed
(
span
,
msg
,
false
)
=>
{
resolve_error
(
self
,
span
,
ResolutionError
::
FailedToResolve
(
&
msg
));
return
None
;
}
PathResult
::
Failed
(
span
,
msg
,
true
)
=>
{
let
(
mut
self_path
,
mut
self_result
)
=
(
module_path
.clone
(),
None
);
if
!
self_path
.is_empty
()
&&
!
token
::
Ident
(
self_path
[
0
]
.node
)
.is_path_segment_keyword
()
!
token
::
Ident
(
self_path
[
0
]
.node
)
.is_path_segment_keyword
()
&&
!
(
self_path
.len
()
>
1
&&
token
::
Ident
(
self_path
[
1
]
.node
)
.is_path_segment_keyword
())
{
self_path
[
0
]
.node.name
=
keywords
::
SelfValue
.name
();
self_result
=
Some
(
self
.resolve_path
(
&
self_path
,
None
,
false
,
span
));
...
...
src/test/compile-fail/dollar-crate-is-keyword-2.rs
浏览文件 @
90f5cfdf
...
...
@@ -13,8 +13,8 @@ mod a {}
macro_rules!
m
{
()
=>
{
use
a
::
$crate
;
//~ ERROR unresolved import `a::$crate`
use
a
::
$crate
::
b
;
//~ ERROR
unresolved import `a::$crate`
type
A
=
a
::
$crate
;
//~ ERROR
cannot find type `$crate` in module `a`
use
a
::
$crate
::
b
;
//~ ERROR
`$crate` in paths can only be used in start position
type
A
=
a
::
$crate
;
//~ ERROR
`$crate` in paths can only be used in start position
}
}
...
...
src/test/compile-fail/rfc-2126-crate-paths/crate-path-non-absolute.rs
浏览文件 @
90f5cfdf
...
...
@@ -14,7 +14,7 @@
mod
m
{
fn
f
()
{
let
s
=
crate
::
S
;
//~ ERROR
undeclared type or module `crate`
let
s
=
crate
::
S
;
//~ ERROR
`crate` can only be used in absolute paths
}
}
...
...
src/test/compile-fail/rfc-2126-crate-paths/crate-visibility-ambiguity.rs
浏览文件 @
90f5cfdf
...
...
@@ -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
undeclared type or module `crate`
pub
struct
S3
(
crate
::
m
::
Z
);
//~ ERROR
`crate` can only be used in absolute paths
}
fn
main
()
{
...
...
src/test/compile-fail/rfc-2126-crate-paths/keyword-crate-as-identifier.rs
浏览文件 @
90f5cfdf
...
...
@@ -11,5 +11,5 @@
#![feature(crate_in_paths)]
fn
main
()
{
let
crate
=
0
;
//~ ERROR
cannot find unit struct/variant or constant `crate` in this scope
let
crate
=
0
;
//~ ERROR
`crate` can only be used in absolute paths
}
src/test/compile-fail/super-at-top-level.rs
浏览文件 @
90f5cfdf
...
...
@@ -8,8 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
super
::
f
;
//~ ERROR unresolved import `super` [E0432]
//~^ There are too many initial `super`s.
use
super
::
f
;
//~ ERROR There are too many initial `super`s
fn
main
()
{
}
src/test/compile-fail/use-super-global-path.rs
浏览文件 @
90f5cfdf
...
...
@@ -14,11 +14,11 @@
struct
Z
;
mod
foo
{
use
::
super
::{
S
,
Z
};
//~ ERROR
unresolved import
`super`
use
::
super
::{
S
,
Z
};
//~ ERROR
global paths cannot start with
`super`
pub
fn
g
()
{
use
::
super
::
main
;
//~ ERROR
unresolved import
`super`
main
();
use
::
super
::
main
;
//~ ERROR
global paths cannot start with
`super`
main
();
//~ ERROR cannot find function `main` in this scope
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录