Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1e9e798c
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,发现更多精彩内容 >>
提交
1e9e798c
编写于
8月 07, 2016
作者:
K
Keith Yeung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move E0379 check from typeck to ast validation
上级
e17d6db8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
37 addition
and
34 deletion
+37
-34
src/librustc_passes/ast_validation.rs
src/librustc_passes/ast_validation.rs
+21
-0
src/librustc_passes/diagnostics.rs
src/librustc_passes/diagnostics.rs
+7
-0
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+2
-24
src/librustc_typeck/diagnostics.rs
src/librustc_typeck/diagnostics.rs
+0
-7
src/test/compile-fail/const-fn-mismatch.rs
src/test/compile-fail/const-fn-mismatch.rs
+1
-1
src/test/compile-fail/const-fn-not-in-trait.rs
src/test/compile-fail/const-fn-not-in-trait.rs
+6
-2
未找到文件。
src/librustc_passes/ast_validation.rs
浏览文件 @
1e9e798c
...
...
@@ -69,6 +69,17 @@ fn check_decl_no_pat<ReportFn: Fn(Span, bool)>(&self, decl: &FnDecl, report_err:
}
}
}
fn
check_trait_fn_not_const
(
&
self
,
span
:
Span
,
constness
:
Constness
)
{
match
constness
{
Constness
::
Const
=>
{
struct_span_err!
(
self
.session
,
span
,
E0379
,
"trait fns cannot be declared const"
)
.span_label
(
span
,
&
format!
(
"trait fns cannot be const"
))
.emit
();
}
_
=>
{}
}
}
}
impl
<
'a
>
Visitor
for
AstValidator
<
'a
>
{
...
...
@@ -146,6 +157,9 @@ fn visit_item(&mut self, item: &Item) {
self
.invalid_visibility
(
&
item
.vis
,
item
.span
,
None
);
for
impl_item
in
impl_items
{
self
.invalid_visibility
(
&
impl_item
.vis
,
impl_item
.span
,
None
);
if
let
ImplItemKind
::
Method
(
ref
sig
,
_
)
=
impl_item
.node
{
self
.check_trait_fn_not_const
(
impl_item
.span
,
sig
.constness
);
}
}
}
ItemKind
::
Impl
(
_
,
_
,
_
,
None
,
_
,
_
)
=>
{
...
...
@@ -169,6 +183,13 @@ fn visit_item(&mut self, item: &Item) {
}
}
}
ItemKind
::
Trait
(
_
,
_
,
_
,
ref
trait_items
)
=>
{
for
trait_item
in
trait_items
{
if
let
TraitItemKind
::
Method
(
ref
sig
,
_
)
=
trait_item
.node
{
self
.check_trait_fn_not_const
(
trait_item
.span
,
sig
.constness
);
}
}
}
ItemKind
::
Mod
(
_
)
=>
{
// Ensure that `path` attributes on modules are recorded as used (c.f. #35584).
attr
::
first_attr_value_str_by_name
(
&
item
.attrs
,
"path"
);
...
...
src/librustc_passes/diagnostics.rs
浏览文件 @
1e9e798c
...
...
@@ -176,6 +176,13 @@ fn some_func() {
```
"##
,
E0379
:
r##"
Trait methods cannot be declared `const` by design. For more information, see
[RFC 911].
[RFC 911]: https://github.com/rust-lang/rfcs/pull/911
"##
,
E0449
:
r##"
A visibility qualifier was used when it was unnecessary. Erroneous code
examples:
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
1e9e798c
...
...
@@ -836,13 +836,9 @@ pub fn check_item_body<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) {
check_const
(
ccx
,
&
expr
,
trait_item
.id
)
}
hir
::
MethodTraitItem
(
ref
sig
,
Some
(
ref
body
))
=>
{
check_trait_fn_not_const
(
ccx
,
trait_item
.span
,
sig
.constness
);
check_bare_fn
(
ccx
,
&
sig
.decl
,
body
,
trait_item
.id
);
}
hir
::
MethodTraitItem
(
ref
sig
,
None
)
=>
{
check_trait_fn_not_const
(
ccx
,
trait_item
.span
,
sig
.constness
);
}
hir
::
MethodTraitItem
(
_
,
None
)
|
hir
::
ConstTraitItem
(
_
,
None
)
|
hir
::
TypeTraitItem
(
..
)
=>
{
// Nothing to do.
...
...
@@ -854,22 +850,6 @@ pub fn check_item_body<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) {
}
}
fn
check_trait_fn_not_const
<
'a
,
'tcx
>
(
ccx
:
&
CrateCtxt
<
'a
,
'tcx
>
,
span
:
Span
,
constness
:
hir
::
Constness
)
{
match
constness
{
hir
::
Constness
::
NotConst
=>
{
// good
}
hir
::
Constness
::
Const
=>
{
struct_span_err!
(
ccx
.tcx.sess
,
span
,
E0379
,
"trait fns cannot be declared const"
)
.span_label
(
span
,
&
format!
(
"trait fns cannot be const"
))
.emit
()
}
}
}
fn
check_on_unimplemented
<
'a
,
'tcx
>
(
ccx
:
&
CrateCtxt
<
'a
,
'tcx
>
,
def_id
:
DefId
,
item
:
&
hir
::
Item
)
{
...
...
@@ -1027,9 +1007,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
err
.emit
()
}
}
hir
::
ImplItemKind
::
Method
(
ref
sig
,
ref
body
)
=>
{
check_trait_fn_not_const
(
ccx
,
impl_item
.span
,
sig
.constness
);
hir
::
ImplItemKind
::
Method
(
_
,
ref
body
)
=>
{
let
impl_method
=
match
ty_impl_item
{
ty
::
MethodTraitItem
(
ref
mti
)
=>
mti
,
_
=>
span_bug!
(
impl_item
.span
,
"non-method impl-item for method"
)
...
...
src/librustc_typeck/diagnostics.rs
浏览文件 @
1e9e798c
...
...
@@ -3422,13 +3422,6 @@ impl<T, U> CoerceUnsized<Foo<U>> for Foo<T> where T: CoerceUnsized<U> {}
struct.
"##
,
E0379
:
r##"
Trait methods cannot be declared `const` by design. For more information, see
[RFC 911].
[RFC 911]: https://github.com/rust-lang/rfcs/pull/911
"##
,
E0380
:
r##"
Default impls are only allowed for traits with no methods or associated items.
For more information see the [opt-in builtin traits RFC](https://github.com/rust
...
...
src/test/compile-fail/const-fn-mismatch.rs
浏览文件 @
1e9e798c
...
...
@@ -21,7 +21,7 @@ trait Foo {
impl
Foo
for
u32
{
const
fn
f
()
->
u32
{
22
}
//~^ ERROR
E0379
//~^ ERROR
trait fns cannot be declared const
//~| NOTE trait fns cannot be const
}
...
...
src/test/compile-fail/const-fn-not-in-trait.rs
浏览文件 @
1e9e798c
...
...
@@ -14,8 +14,12 @@
#![feature(const_fn)]
trait
Foo
{
const
fn
f
()
->
u32
;
//~ ERROR trait fns cannot be declared const
const
fn
g
()
->
u32
{
0
}
//~ ERROR trait fns cannot be declared const
const
fn
f
()
->
u32
;
//~^ ERROR trait fns cannot be declared const
//~| NOTE trait fns cannot be const
const
fn
g
()
->
u32
{
0
}
//~^ ERROR trait fns cannot be declared const
//~| NOTE trait fns cannot be const
}
fn
main
()
{
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录