Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ea2af704
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,发现更多精彩内容 >>
提交
ea2af704
编写于
3月 18, 2021
作者:
K
kadmin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update with comments
A bunch of nits fixed, and a new test for pretty printing the AST.
上级
9fe793ae
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
69 addition
and
17 deletion
+69
-17
compiler/rustc_ast_pretty/src/pprust/state.rs
compiler/rustc_ast_pretty/src/pprust/state.rs
+2
-3
compiler/rustc_infer/src/infer/error_reporting/mod.rs
compiler/rustc_infer/src/infer/error_reporting/mod.rs
+3
-2
compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
+1
-1
compiler/rustc_metadata/src/rmeta/mod.rs
compiler/rustc_metadata/src/rmeta/mod.rs
+1
-1
compiler/rustc_middle/src/ty/consts.rs
compiler/rustc_middle/src/ty/consts.rs
+1
-2
compiler/rustc_middle/src/ty/generics.rs
compiler/rustc_middle/src/ty/generics.rs
+4
-2
compiler/rustc_privacy/src/lib.rs
compiler/rustc_privacy/src/lib.rs
+2
-4
compiler/rustc_typeck/src/collect.rs
compiler/rustc_typeck/src/collect.rs
+2
-2
src/test/ui/const-generics/defaults/default-annotation.rs
src/test/ui/const-generics/defaults/default-annotation.rs
+20
-0
src/test/ui/const-generics/defaults/pretty-printing-ast.rs
src/test/ui/const-generics/defaults/pretty-printing-ast.rs
+13
-0
src/test/ui/const-generics/defaults/pretty-printing-ast.stdout
...est/ui/const-generics/defaults/pretty-printing-ast.stdout
+20
-0
未找到文件。
compiler/rustc_ast_pretty/src/pprust/state.rs
浏览文件 @
ea2af704
...
...
@@ -2660,11 +2660,10 @@ pub fn print_type_bounds(&mut self, prefix: &'static str, bounds: &[ast::Generic
s
.print_type
(
ty
);
s
.print_type_bounds
(
":"
,
&
param
.bounds
);
// FIXME(const_generic_defaults)
if
let
Some
(
ref
_
default
)
=
default
{
// FIXME(const_generics_defaults): print the `default` value here
if
let
Some
(
ref
default
)
=
default
{
s
.s
.space
();
s
.word_space
(
"="
);
// s.print_anon_const(&default
);
s
.print_expr
(
&
default
.value
);
}
}
}
...
...
compiler/rustc_infer/src/infer/error_reporting/mod.rs
浏览文件 @
ea2af704
...
...
@@ -963,10 +963,11 @@ fn strip_generic_default_params(
.rev
()
.filter_map
(|
param
|
match
param
.kind
{
ty
::
GenericParamDefKind
::
Lifetime
=>
None
,
ty
::
GenericParamDefKind
::
Const
{
has_default
}
|
ty
::
GenericParamDefKind
::
Type
{
has_default
,
..
}
=>
{
ty
::
GenericParamDefKind
::
Type
{
has_default
,
..
}
=>
{
Some
((
param
.def_id
,
has_default
))
}
// FIXME(const_generics:defaults)
ty
::
GenericParamDefKind
::
Const
{
has_default
:
_
has_default
}
=>
None
,
})
.peekable
();
let
has_default
=
{
...
...
compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
浏览文件 @
ea2af704
...
...
@@ -122,7 +122,7 @@ fn into_args(self) -> (DefId, DefId) {
promoted_mir
=>
{
tcx
.arena
.alloc
(
cdata
.get_promoted_mir
(
tcx
,
def_id
.index
))
}
mir_abstract_const
=>
{
cdata
.get_mir_abstract_const
(
tcx
,
def_id
.index
)
}
unused_generic_params
=>
{
cdata
.get_unused_generic_params
(
def_id
.index
)
}
const_param_default
=>
{
tcx
.
arena
.alloc
(
cdata
.get_const_param_default
(
tcx
,
def_id
.index
))
}
const_param_default
=>
{
tcx
.
mk_const
(
cdata
.get_const_param_default
(
tcx
,
def_id
.index
))
}
mir_const_qualif
=>
{
cdata
.mir_const_qualif
(
def_id
.index
)
}
fn_sig
=>
{
cdata
.fn_sig
(
def_id
.index
,
tcx
)
}
inherent_impls
=>
{
cdata
.get_inherent_implementations_for_type
(
tcx
,
def_id
.index
)
}
...
...
compiler/rustc_metadata/src/rmeta/mod.rs
浏览文件 @
ea2af704
...
...
@@ -307,6 +307,7 @@ fn encode(&self, buf: &mut Encoder) -> LazyTables<'tcx> {
mir_for_ctfe
:
Table
<
DefIndex
,
Lazy!
(
mir
::
Body
<
'tcx
>
)
>
,
promoted_mir
:
Table
<
DefIndex
,
Lazy!
(
IndexVec
<
mir
::
Promoted
,
mir
::
Body
<
'tcx
>>
)
>
,
mir_abstract_consts
:
Table
<
DefIndex
,
Lazy!
(
&
'tcx
[
mir
::
abstract_const
::
Node
<
'tcx
>
])
>
,
const_defaults
:
Table
<
DefIndex
,
Lazy
<
rustc_middle
::
ty
::
Const
<
'tcx
>>>
,
unused_generic_params
:
Table
<
DefIndex
,
Lazy
<
FiniteBitSet
<
u32
>>>
,
// `def_keys` and `def_path_hashes` represent a lazy version of a
// `DefPathTable`. This allows us to avoid deserializing an entire
...
...
@@ -314,7 +315,6 @@ fn encode(&self, buf: &mut Encoder) -> LazyTables<'tcx> {
// definitions from any given crate.
def_keys
:
Table
<
DefIndex
,
Lazy
<
DefKey
>>
,
def_path_hashes
:
Table
<
DefIndex
,
Lazy
<
DefPathHash
>>
,
const_defaults
:
Table
<
DefIndex
,
Lazy
<
rustc_middle
::
ty
::
Const
<
'tcx
>>>
,
}
#[derive(Copy,
Clone,
MetadataEncodable,
MetadataDecodable)]
...
...
compiler/rustc_middle/src/ty/consts.rs
浏览文件 @
ea2af704
...
...
@@ -206,8 +206,7 @@ pub fn eval_usize(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> u64 {
pub
fn
const_param_default
<
'tcx
>
(
tcx
:
TyCtxt
<
'tcx
>
,
def_id
:
DefId
)
->
&
'tcx
Const
<
'tcx
>
{
let
hir_id
=
tcx
.hir
()
.local_def_id_to_hir_id
(
def_id
.expect_local
());
let
default_def_id
=
match
tcx
.hir
()
.get
(
hir_id
)
{
hir
::
Node
::
AnonConst
(
ac
)
|
hir
::
Node
::
GenericParam
(
hir
::
GenericParam
{
hir
::
Node
::
GenericParam
(
hir
::
GenericParam
{
kind
:
hir
::
GenericParamKind
::
Const
{
ty
:
_
,
default
:
Some
(
ac
)
},
..
})
=>
tcx
.hir
()
.local_def_id
(
ac
.hir_id
),
...
...
compiler/rustc_middle/src/ty/generics.rs
浏览文件 @
ea2af704
...
...
@@ -120,10 +120,12 @@ pub fn own_defaults(&self) -> GenericParamCount {
for
param
in
&
self
.params
{
match
param
.kind
{
GenericParamDefKind
::
Lifetime
=>
(),
GenericParamDefKind
::
Type
{
has_default
,
..
}
|
GenericParamDefKind
::
Const
{
has_default
}
=>
{
GenericParamDefKind
::
Type
{
has_default
,
..
}
=>
{
own_defaults
.types
+=
has_default
as
usize
;
}
GenericParamDefKind
::
Const
{
has_default
}
=>
{
own_defaults
.consts
+=
has_default
as
usize
;
}
}
}
...
...
compiler/rustc_privacy/src/lib.rs
浏览文件 @
ea2af704
...
...
@@ -931,10 +931,7 @@ fn generics(&mut self) -> &mut Self {
GenericParamDefKind
::
Const
{
has_default
,
..
}
=>
{
self
.visit
(
self
.ev.tcx
.type_of
(
param
.def_id
));
if
has_default
{
// FIXME(const_generic_defaults)
// how should the error case be handled here?
// let default_const = self.ev.tcx.const_eval_poly(param.def_id).unwrap();
// self.visit(default_const);
self
.visit
(
self
.ev.tcx
.const_param_default
(
param
.def_id
));
}
}
}
...
...
@@ -1747,6 +1744,7 @@ fn generics(&mut self) -> &mut Self {
self
.visit
(
self
.tcx
.type_of
(
param
.def_id
));
}
}
// FIXME(const_evaluatable_checked): May want to look inside const here
GenericParamDefKind
::
Const
{
..
}
=>
{
self
.visit
(
self
.tcx
.type_of
(
param
.def_id
));
}
...
...
compiler/rustc_typeck/src/collect.rs
浏览文件 @
ea2af704
...
...
@@ -258,9 +258,9 @@ fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
let
def_id
=
self
.tcx
.hir
()
.local_def_id
(
param
.hir_id
);
self
.tcx
.ensure
()
.type_of
(
def_id
);
if
let
Some
(
default
)
=
default
{
let
def_id
=
self
.tcx
.hir
()
.local_def_id
(
default
.hir_id
);
let
def
ault_def
_id
=
self
.tcx
.hir
()
.local_def_id
(
default
.hir_id
);
// need to store default and type of default
self
.tcx
.ensure
()
.type_of
(
def_id
);
self
.tcx
.ensure
()
.type_of
(
def
ault_def
_id
);
self
.tcx
.ensure
()
.const_param_default
(
def_id
);
}
}
...
...
src/test/ui/const-generics/defaults/default-annotation.rs
0 → 100644
浏览文件 @
ea2af704
// run-pass
#![feature(staged_api)]
#![feature(const_generics)]
#![feature(const_generics_defaults)]
#![allow(incomplete_features)]
#![stable(feature
=
"const_default_test"
,
since=
"none"
)]
#[unstable(feature
=
"const_default_stable"
,
issue=
"none"
)]
pub
struct
ConstDefaultUnstable
<
const
N
:
usize
=
3
>
;
#[stable(feature
=
"const_default_unstable"
,
since=
"none"
)]
pub
struct
ConstDefaultStable
<
const
N
:
usize
=
{
#[stable(feature
=
"const_default_unstable_val"
,
since=
"none"
)]
3
}
>
;
fn
main
()
{}
src/test/ui/const-generics/defaults/pretty-printing-ast.rs
0 → 100644
浏览文件 @
ea2af704
// Test the AST pretty printer correctly handles default values for const generics
// check-pass
// compile-flags: -Z unpretty=expanded
#![crate_type
=
"lib"
]
#![feature(const_generics_defaults)]
#![allow(incomplete_features)]
trait
Foo
<
const
KIND
:
bool
=
true
>
{}
fn
foo
<
const
SIZE
:
usize
=
5
>
()
{}
struct
Range
<
const
FROM
:
usize
=
0
,
const
LEN
:
usize
=
0
,
const
TO
:
usize
=
{
FROM
+
LEN
}
>
;
src/test/ui/const-generics/defaults/pretty-printing-ast.stdout
0 → 100644
浏览文件 @
ea2af704
#![feature(prelude_import)]
#![no_std]
// Test the AST pretty printer correctly handles default values for const generics
// check-pass
// compile-flags: -Z unpretty=expanded
#![crate_type = "lib"]
#![feature(const_generics_defaults)]
#![allow(incomplete_features)]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
trait Foo<const KIND : bool = true> { }
fn foo<const SIZE : usize = 5>() { }
struct Range<const FROM : usize = 0, const LEN : usize = 0, const TO : usize =
{ FROM + LEN }>;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录