Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
38587a7b
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,发现更多精彩内容 >>
提交
38587a7b
编写于
1月 31, 2018
作者:
K
kennytm
提交者:
GitHub
1月 31, 2018
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #47876 - GuillaumeGomez:associated-const-error, r=nikomatsakis
Update associated constants error message Fixes #47570.
上级
6c0d5f58
f6a6d840
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
24 addition
and
5 deletion
+24
-5
src/librustc_const_eval/check_match.rs
src/librustc_const_eval/check_match.rs
+9
-2
src/librustc_const_eval/pattern.rs
src/librustc_const_eval/pattern.rs
+10
-1
src/test/compile-fail/associated-const-type-parameter-arms.rs
...test/compile-fail/associated-const-type-parameter-arms.rs
+5
-2
未找到文件。
src/librustc_const_eval/check_match.rs
浏览文件 @
38587a7b
...
...
@@ -127,13 +127,16 @@ fn visit_body(&mut self, body: &'tcx hir::Body) {
}
}
impl
<
'a
,
'tcx
>
PatternContext
<
'a
,
'tcx
>
{
fn
report_inlining_errors
(
&
self
,
pat_span
:
Span
)
{
for
error
in
&
self
.errors
{
match
*
error
{
PatternError
::
StaticInPattern
(
span
)
=>
{
span_err!
(
self
.tcx.sess
,
span
,
E0158
,
"statics cannot be referenced in patterns"
);
self
.span_e0158
(
span
,
"statics cannot be referenced in patterns"
)
}
PatternError
::
AssociatedConstInPattern
(
span
)
=>
{
self
.span_e0158
(
span
,
"associated consts cannot be referenced in patterns"
)
}
PatternError
::
ConstEval
(
ref
err
)
=>
{
err
.report
(
self
.tcx
,
pat_span
,
"pattern"
);
...
...
@@ -141,6 +144,10 @@ fn report_inlining_errors(&self, pat_span: Span) {
}
}
}
fn
span_e0158
(
&
self
,
span
:
Span
,
text
:
&
str
)
{
span_err!
(
self
.tcx.sess
,
span
,
E0158
,
"{}"
,
text
)
}
}
impl
<
'a
,
'tcx
>
MatchVisitor
<
'a
,
'tcx
>
{
...
...
src/librustc_const_eval/pattern.rs
浏览文件 @
38587a7b
...
...
@@ -27,6 +27,7 @@
#[derive(Clone,
Debug)]
pub
enum
PatternError
<
'tcx
>
{
AssociatedConstInPattern
(
Span
),
StaticInPattern
(
Span
),
ConstEval
(
ConstEvalErr
<
'tcx
>
),
}
...
...
@@ -635,6 +636,10 @@ fn lower_path(&mut self,
->
Pattern
<
'tcx
>
{
let
ty
=
self
.tables
.node_id_to_type
(
id
);
let
def
=
self
.tables
.qpath_def
(
qpath
,
id
);
let
is_associated_const
=
match
def
{
Def
::
AssociatedConst
(
_
)
=>
true
,
_
=>
false
,
};
let
kind
=
match
def
{
Def
::
Const
(
def_id
)
|
Def
::
AssociatedConst
(
def_id
)
=>
{
let
substs
=
self
.tables
.node_substs
(
id
);
...
...
@@ -656,7 +661,11 @@ fn lower_path(&mut self,
return
pat
;
}
None
=>
{
self
.errors
.push
(
PatternError
::
StaticInPattern
(
span
));
self
.errors
.push
(
if
is_associated_const
{
PatternError
::
AssociatedConstInPattern
(
span
)
}
else
{
PatternError
::
StaticInPattern
(
span
)
});
PatternKind
::
Wild
}
}
...
...
src/test/compile-fail/associated-const-type-parameter-arms.rs
浏览文件 @
38587a7b
...
...
@@ -16,6 +16,7 @@ pub trait Foo {
}
struct
Abc
;
impl
Foo
for
Abc
{
const
X
:
EFoo
=
EFoo
::
B
;
}
...
...
@@ -27,8 +28,10 @@ impl Foo for Def {
pub
fn
test
<
A
:
Foo
,
B
:
Foo
>
(
arg
:
EFoo
)
{
match
arg
{
A
::
X
=>
println!
(
"A::X"
),
//~ error: statics cannot be referenced in patterns [E0158]
B
::
X
=>
println!
(
"B::X"
),
//~ error: statics cannot be referenced in patterns [E0158]
A
::
X
=>
println!
(
"A::X"
),
//~^ error: associated consts cannot be referenced in patterns [E0158]
B
::
X
=>
println!
(
"B::X"
),
//~^ error: associated consts cannot be referenced in patterns [E0158]
_
=>
(),
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录