Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
aaeae4c7
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,发现更多精彩内容 >>
提交
aaeae4c7
编写于
12月 13, 2017
作者:
A
Alex Burka
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
error for impl trait alias
上级
435fe5b7
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
24 addition
and
12 deletion
+24
-12
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+21
-11
src/test/compile-fail/trait-alias.rs
src/test/compile-fail/trait-alias.rs
+3
-1
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
aaeae4c7
...
@@ -390,12 +390,18 @@ fn descr(self) -> &'static str {
...
@@ -390,12 +390,18 @@ fn descr(self) -> &'static str {
}
}
}
}
#[derive(Copy,
Clone,
PartialEq,
Eq,
Debug)]
enum
AliasPossibility
{
No
,
Maybe
,
}
#[derive(Copy,
Clone,
PartialEq,
Eq,
Debug)]
#[derive(Copy,
Clone,
PartialEq,
Eq,
Debug)]
enum
PathSource
<
'a
>
{
enum
PathSource
<
'a
>
{
// Type paths `Path`.
// Type paths `Path`.
Type
,
Type
,
// Trait paths in bounds or impls.
// Trait paths in bounds or impls.
Trait
,
Trait
(
AliasPossibility
)
,
// Expression paths `path`, with optional parent context.
// Expression paths `path`, with optional parent context.
Expr
(
Option
<&
'a
Expr
>
),
Expr
(
Option
<&
'a
Expr
>
),
// Paths in path patterns `Path`.
// Paths in path patterns `Path`.
...
@@ -415,7 +421,7 @@ enum PathSource<'a> {
...
@@ -415,7 +421,7 @@ enum PathSource<'a> {
impl
<
'a
>
PathSource
<
'a
>
{
impl
<
'a
>
PathSource
<
'a
>
{
fn
namespace
(
self
)
->
Namespace
{
fn
namespace
(
self
)
->
Namespace
{
match
self
{
match
self
{
PathSource
::
Type
|
PathSource
::
Trait
|
PathSource
::
Struct
|
PathSource
::
Type
|
PathSource
::
Trait
(
_
)
|
PathSource
::
Struct
|
PathSource
::
Visibility
|
PathSource
::
ImportPrefix
=>
TypeNS
,
PathSource
::
Visibility
|
PathSource
::
ImportPrefix
=>
TypeNS
,
PathSource
::
Expr
(
..
)
|
PathSource
::
Pat
|
PathSource
::
TupleStruct
=>
ValueNS
,
PathSource
::
Expr
(
..
)
|
PathSource
::
Pat
|
PathSource
::
TupleStruct
=>
ValueNS
,
PathSource
::
TraitItem
(
ns
)
=>
ns
,
PathSource
::
TraitItem
(
ns
)
=>
ns
,
...
@@ -427,7 +433,7 @@ fn global_by_default(self) -> bool {
...
@@ -427,7 +433,7 @@ fn global_by_default(self) -> bool {
PathSource
::
Visibility
|
PathSource
::
ImportPrefix
=>
true
,
PathSource
::
Visibility
|
PathSource
::
ImportPrefix
=>
true
,
PathSource
::
Type
|
PathSource
::
Expr
(
..
)
|
PathSource
::
Pat
|
PathSource
::
Type
|
PathSource
::
Expr
(
..
)
|
PathSource
::
Pat
|
PathSource
::
Struct
|
PathSource
::
TupleStruct
|
PathSource
::
Struct
|
PathSource
::
TupleStruct
|
PathSource
::
Trait
|
PathSource
::
TraitItem
(
..
)
=>
false
,
PathSource
::
Trait
(
_
)
|
PathSource
::
TraitItem
(
..
)
=>
false
,
}
}
}
}
...
@@ -435,7 +441,7 @@ fn defer_to_typeck(self) -> bool {
...
@@ -435,7 +441,7 @@ fn defer_to_typeck(self) -> bool {
match
self
{
match
self
{
PathSource
::
Type
|
PathSource
::
Expr
(
..
)
|
PathSource
::
Pat
|
PathSource
::
Type
|
PathSource
::
Expr
(
..
)
|
PathSource
::
Pat
|
PathSource
::
Struct
|
PathSource
::
TupleStruct
=>
true
,
PathSource
::
Struct
|
PathSource
::
TupleStruct
=>
true
,
PathSource
::
Trait
|
PathSource
::
TraitItem
(
..
)
|
PathSource
::
Trait
(
_
)
|
PathSource
::
TraitItem
(
..
)
|
PathSource
::
Visibility
|
PathSource
::
ImportPrefix
=>
false
,
PathSource
::
Visibility
|
PathSource
::
ImportPrefix
=>
false
,
}
}
}
}
...
@@ -443,7 +449,7 @@ fn defer_to_typeck(self) -> bool {
...
@@ -443,7 +449,7 @@ fn defer_to_typeck(self) -> bool {
fn
descr_expected
(
self
)
->
&
'static
str
{
fn
descr_expected
(
self
)
->
&
'static
str
{
match
self
{
match
self
{
PathSource
::
Type
=>
"type"
,
PathSource
::
Type
=>
"type"
,
PathSource
::
Trait
=>
"trait"
,
PathSource
::
Trait
(
_
)
=>
"trait"
,
PathSource
::
Pat
=>
"unit struct/variant or constant"
,
PathSource
::
Pat
=>
"unit struct/variant or constant"
,
PathSource
::
Struct
=>
"struct, variant or union type"
,
PathSource
::
Struct
=>
"struct, variant or union type"
,
PathSource
::
TupleStruct
=>
"tuple struct/variant"
,
PathSource
::
TupleStruct
=>
"tuple struct/variant"
,
...
@@ -472,7 +478,11 @@ fn is_expected(self, def: Def) -> bool {
...
@@ -472,7 +478,11 @@ fn is_expected(self, def: Def) -> bool {
Def
::
TyForeign
(
..
)
=>
true
,
Def
::
TyForeign
(
..
)
=>
true
,
_
=>
false
,
_
=>
false
,
},
},
PathSource
::
Trait
=>
match
def
{
PathSource
::
Trait
(
AliasPossibility
::
No
)
=>
match
def
{
Def
::
Trait
(
..
)
=>
true
,
_
=>
false
,
},
PathSource
::
Trait
(
AliasPossibility
::
Maybe
)
=>
match
def
{
Def
::
Trait
(
..
)
=>
true
,
Def
::
Trait
(
..
)
=>
true
,
Def
::
TraitAlias
(
..
)
=>
true
,
Def
::
TraitAlias
(
..
)
=>
true
,
_
=>
false
,
_
=>
false
,
...
@@ -531,8 +541,8 @@ fn error_code(self, has_unexpected_resolution: bool) -> &'static str {
...
@@ -531,8 +541,8 @@ fn error_code(self, has_unexpected_resolution: bool) -> &'static str {
__
diagnostic_used!
(
E0577
);
__
diagnostic_used!
(
E0577
);
__
diagnostic_used!
(
E0578
);
__
diagnostic_used!
(
E0578
);
match
(
self
,
has_unexpected_resolution
)
{
match
(
self
,
has_unexpected_resolution
)
{
(
PathSource
::
Trait
,
true
)
=>
"E0404"
,
(
PathSource
::
Trait
(
_
)
,
true
)
=>
"E0404"
,
(
PathSource
::
Trait
,
false
)
=>
"E0405"
,
(
PathSource
::
Trait
(
_
)
,
false
)
=>
"E0405"
,
(
PathSource
::
Type
,
true
)
=>
"E0573"
,
(
PathSource
::
Type
,
true
)
=>
"E0573"
,
(
PathSource
::
Type
,
false
)
=>
"E0412"
,
(
PathSource
::
Type
,
false
)
=>
"E0412"
,
(
PathSource
::
Struct
,
true
)
=>
"E0574"
,
(
PathSource
::
Struct
,
true
)
=>
"E0574"
,
...
@@ -694,7 +704,7 @@ fn visit_poly_trait_ref(&mut self,
...
@@ -694,7 +704,7 @@ fn visit_poly_trait_ref(&mut self,
tref
:
&
'tcx
ast
::
PolyTraitRef
,
tref
:
&
'tcx
ast
::
PolyTraitRef
,
m
:
&
'tcx
ast
::
TraitBoundModifier
)
{
m
:
&
'tcx
ast
::
TraitBoundModifier
)
{
self
.smart_resolve_path
(
tref
.trait_ref.ref_id
,
None
,
self
.smart_resolve_path
(
tref
.trait_ref.ref_id
,
None
,
&
tref
.trait_ref.path
,
PathSource
::
Trait
);
&
tref
.trait_ref.path
,
PathSource
::
Trait
(
AliasPossibility
::
Maybe
)
);
visit
::
walk_poly_trait_ref
(
self
,
tref
,
m
);
visit
::
walk_poly_trait_ref
(
self
,
tref
,
m
);
}
}
fn
visit_variant
(
&
mut
self
,
fn
visit_variant
(
&
mut
self
,
...
@@ -2095,7 +2105,7 @@ fn with_optional_trait_ref<T, F>(&mut self, opt_trait_ref: Option<&TraitRef>, f:
...
@@ -2095,7 +2105,7 @@ fn with_optional_trait_ref<T, F>(&mut self, opt_trait_ref: Option<&TraitRef>, f:
&
path
,
&
path
,
trait_ref
.path.span
,
trait_ref
.path.span
,
trait_ref
.path.segments
.last
()
.unwrap
()
.span
,
trait_ref
.path.segments
.last
()
.unwrap
()
.span
,
PathSource
::
Trait
)
PathSource
::
Trait
(
AliasPossibility
::
No
)
)
.base_def
();
.base_def
();
if
def
!=
Def
::
Err
{
if
def
!=
Def
::
Err
{
new_id
=
Some
(
def
.def_id
());
new_id
=
Some
(
def
.def_id
());
...
@@ -2647,7 +2657,7 @@ fn smart_resolve_path_fragment(&mut self,
...
@@ -2647,7 +2657,7 @@ fn smart_resolve_path_fragment(&mut self,
err
.span_label
(
span
,
format!
(
"did you mean `{}!(...)`?"
,
path_str
));
err
.span_label
(
span
,
format!
(
"did you mean `{}!(...)`?"
,
path_str
));
return
(
err
,
candidates
);
return
(
err
,
candidates
);
}
}
(
Def
::
TyAlias
(
..
),
PathSource
::
Trait
)
=>
{
(
Def
::
TyAlias
(
..
),
PathSource
::
Trait
(
_
)
)
=>
{
err
.span_label
(
span
,
"type aliases cannot be used for traits"
);
err
.span_label
(
span
,
"type aliases cannot be used for traits"
);
return
(
err
,
candidates
);
return
(
err
,
candidates
);
}
}
...
...
src/test/compile-fail/trait-alias.rs
浏览文件 @
aaeae4c7
...
@@ -18,7 +18,9 @@
...
@@ -18,7 +18,9 @@
//~^^^ERROR trait aliases are not yet fully implemented
//~^^^ERROR trait aliases are not yet fully implemented
impl
Alias1
{
//~ERROR expected type, found trait alias
impl
Alias1
{
//~ERROR expected type, found trait alias
fn
foo
()
{}
}
impl
Alias1
for
()
{
//~ERROR expected trait, found trait alias
}
}
fn
main
()
{}
fn
main
()
{}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录