Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b418cd23
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,发现更多精彩内容 >>
提交
b418cd23
编写于
3月 10, 2016
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleanup
+ Fix a comment and add a test based on it
上级
77f033ba
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
30 deletion
+32
-30
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+18
-30
src/test/run-pass/issue-20427.rs
src/test/run-pass/issue-20427.rs
+14
-0
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
b418cd23
...
...
@@ -2616,6 +2616,19 @@ pub fn resolve_path(&mut self,
// Try to find a path to an item in a module.
let
last_ident
=
segments
.last
()
.unwrap
()
.identifier
;
// Resolve a single identifier with fallback to primitive types
let
resolve_identifier_with_fallback
=
|
this
:
&
mut
Self
,
record_used
|
{
let
def
=
this
.resolve_identifier
(
last_ident
,
namespace
,
record_used
);
match
def
{
None
|
Some
(
LocalDef
{
def
:
Def
::
Mod
(
..
),
..
})
if
namespace
==
TypeNS
=>
this
.primitive_type_table
.primitive_types
.get
(
&
last_ident
.unhygienic_name
)
.map_or
(
def
,
|
prim_ty
|
Some
(
LocalDef
::
from_def
(
Def
::
PrimTy
(
*
prim_ty
)))),
_
=>
def
}
};
if
segments
.len
()
==
1
{
// In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we
// don't report an error right away, but try to fallback to a primitive type.
...
...
@@ -2623,20 +2636,17 @@ pub fn resolve_path(&mut self,
//
// use std::u8; // bring module u8 in scope
// fn f() -> u8 { // OK, resolves to primitive u8, not to std::u8
// u8::
MAX // OK, resolves to associated constant <u8>::MAX
,
//
// not to non-existent std::u8::MAX
// u8::
max_value() // OK, resolves to associated function <u8>::max_value
,
//
// not to non-existent std::u8::max_value
// }
//
// Such behavior is required for backward compatibility.
// The same fallback is used when `a` resolves to nothing.
let
unqualified_def
=
self
.resolve_identifier_with_fallback
(
last_ident
,
namespace
,
true
);
return
unqualified_def
.and_then
(|
def
|
self
.adjust_local_def
(
def
,
span
))
.map
(|
def
|
{
PathResolution
::
new
(
def
,
path_depth
)
});
let
unqualified_def
=
resolve_identifier_with_fallback
(
self
,
true
);
return
unqualified_def
.and_then
(|
def
|
self
.adjust_local_def
(
def
,
span
))
.map
(
mk_res
);
}
let
unqualified_def
=
self
.resolve_identifier_with_fallback
(
last_ident
,
namespace
,
false
);
let
unqualified_def
=
resolve_identifier_with_fallback
(
self
,
false
);
let
def
=
self
.resolve_module_relative_path
(
span
,
segments
,
namespace
);
match
(
def
,
unqualified_def
)
{
(
Some
(
d
),
Some
(
ref
ud
))
if
d
==
ud
.def
=>
{
...
...
@@ -2652,28 +2662,6 @@ pub fn resolve_path(&mut self,
def
.map
(
mk_res
)
}
// Resolve a single identifier with fallback to primitive types
fn
resolve_identifier_with_fallback
(
&
mut
self
,
identifier
:
hir
::
Ident
,
namespace
:
Namespace
,
check_ribs
:
bool
,
record_used
:
bool
)
->
Option
<
LocalDef
>
{
let
def
=
self
.resolve_identifier
(
identifier
,
namespace
,
check_ribs
,
record_used
);
match
def
{
None
|
Some
(
LocalDef
{
def
:
Def
::
Mod
(
..
),
..
})
if
namespace
==
TypeNS
=>
{
if
let
Some
(
&
prim_ty
)
=
self
.primitive_type_table
.primitive_types
.get
(
&
identifier
.unhygienic_name
)
{
Some
(
LocalDef
::
from_def
(
Def
::
PrimTy
(
prim_ty
)))
}
else
{
def
}
}
_
=>
def
}
}
// Resolve a single identifier
fn
resolve_identifier
(
&
mut
self
,
identifier
:
hir
::
Ident
,
...
...
src/test/run-pass/issue-20427.rs
浏览文件 @
b418cd23
...
...
@@ -9,6 +9,8 @@
// except according to those terms.
// aux-build:i8.rs
// ignore-pretty (#23623)
extern
crate
i8
;
use
std
::
string
as
i16
;
static
i32
:
i32
=
0
;
...
...
@@ -66,6 +68,17 @@ pub fn check<u16>() {
}
}
mod
guard
{
pub
fn
check
()
{
use
std
::
u8
;
// bring module u8 in scope
fn
f
()
->
u8
{
// OK, resolves to primitive u8, not to std::u8
u8
::
max_value
()
// OK, resolves to associated function <u8>::max_value,
// not to non-existent std::u8::max_value
}
assert_eq!
(
f
(),
u8
::
MAX
);
// OK, resolves to std::u8::MAX
}
}
fn
main
()
{
let
bool
=
true
;
let
_
=
match
bool
{
...
...
@@ -74,4 +87,5 @@ fn main() {
};
reuse
::
check
::
<
u64
>
();
guard
::
check
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录