Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7116bb5c
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
7116bb5c
编写于
3月 20, 2021
作者:
K
kadmin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update with comments
上级
ea2af704
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
72 addition
and
33 deletion
+72
-33
compiler/rustc_ast_pretty/src/pprust/state.rs
compiler/rustc_ast_pretty/src/pprust/state.rs
+0
-1
compiler/rustc_infer/src/infer/error_reporting/mod.rs
compiler/rustc_infer/src/infer/error_reporting/mod.rs
+36
-25
compiler/rustc_metadata/src/rmeta/encoder.rs
compiler/rustc_metadata/src/rmeta/encoder.rs
+0
-1
compiler/rustc_middle/src/query/mod.rs
compiler/rustc_middle/src/query/mod.rs
+1
-1
compiler/rustc_middle/src/ty/consts.rs
compiler/rustc_middle/src/ty/consts.rs
+1
-1
compiler/rustc_typeck/src/check/wfcheck.rs
compiler/rustc_typeck/src/check/wfcheck.rs
+1
-1
src/test/ui/const-generics/min_const_generics/const_default_first.rs
.../const-generics/min_const_generics/const_default_first.rs
+9
-0
src/test/ui/const-generics/min_const_generics/const_default_first.stderr
...st-generics/min_const_generics/const_default_first.stderr
+8
-0
src/test/ui/const-generics/min_const_generics/type_and_const_defaults.rs
...st-generics/min_const_generics/type_and_const_defaults.rs
+16
-3
未找到文件。
compiler/rustc_ast_pretty/src/pprust/state.rs
浏览文件 @
7116bb5c
...
...
@@ -2659,7 +2659,6 @@ pub fn print_type_bounds(&mut self, prefix: &'static str, bounds: &[ast::Generic
s
.word_space
(
":"
);
s
.print_type
(
ty
);
s
.print_type_bounds
(
":"
,
&
param
.bounds
);
// FIXME(const_generic_defaults)
if
let
Some
(
ref
default
)
=
default
{
s
.s
.space
();
s
.word_space
(
"="
);
...
...
compiler/rustc_infer/src/infer/error_reporting/mod.rs
浏览文件 @
7116bb5c
...
...
@@ -957,35 +957,46 @@ fn strip_generic_default_params(
)
->
SubstsRef
<
'tcx
>
{
let
generics
=
self
.tcx
.generics_of
(
def_id
);
let
mut
num_supplied_defaults
=
0
;
let
mut
type_params
=
generics
.params
.iter
()
.rev
()
.filter_map
(|
param
|
match
param
.kind
{
ty
::
GenericParamDefKind
::
Lifetime
=>
None
,
ty
::
GenericParamDefKind
::
Type
{
has_default
,
..
}
=>
{
Some
((
param
.def_id
,
has_default
))
#[derive(PartialEq,
Eq,
Copy,
Clone)]
enum
Kind
{
Const
,
Type
,
}
// FIXME(const_generics:defaults)
ty
::
GenericParamDefKind
::
Const
{
has_default
:
_
has_default
}
=>
None
,
})
.peekable
();
let
has_default
=
{
let
has_default
=
type_params
.peek
()
.map
(|(
_
,
has_default
)|
has_default
);
*
has_default
.unwrap_or
(
&
false
)
};
if
has_default
{
let
types
=
substs
.types
()
.rev
();
for
((
def_id
,
has_default
),
actual
)
in
type_params
.zip
(
types
)
{
if
!
has_default
{
let
default_params
=
generics
.params
.iter
()
.rev
()
.filter_map
(|
param
|
match
param
.kind
{
ty
::
GenericParamDefKind
::
Type
{
has_default
:
true
,
..
}
=>
{
Some
((
param
.def_id
,
Kind
::
Type
))
}
ty
::
GenericParamDefKind
::
Const
{
has_default
:
true
}
=>
{
Some
((
param
.def_id
,
Kind
::
Const
))
}
_
=>
None
,
});
let
mut
types
=
substs
.types
()
.rev
();
let
mut
consts
=
substs
.consts
()
.rev
();
for
(
def_id
,
kind
)
in
default_params
{
match
kind
{
Kind
::
Const
=>
{
if
let
Some
(
actual
)
=
consts
.next
()
{
if
ty
::
Const
::
from_anon_const
(
self
.tcx
,
def_id
.expect_local
())
!=
actual
{
break
;
}
}
else
{
break
;
}
}
Kind
::
Type
=>
{
if
let
Some
(
actual
)
=
types
.next
()
{
if
self
.tcx
.type_of
(
def_id
)
.subst
(
self
.tcx
,
substs
)
!=
actual
{
break
;
}
num_supplied_defaults
+=
1
;
}
else
{
break
;
}
}
}
num_supplied_defaults
+=
1
;
}
let
len
=
generics
.params
.len
();
let
mut
generics
=
generics
.clone
();
generics
.params
.truncate
(
len
-
num_supplied_defaults
);
...
...
compiler/rustc_metadata/src/rmeta/encoder.rs
浏览文件 @
7116bb5c
...
...
@@ -1880,7 +1880,6 @@ fn encode_info_for_generics(&mut self, generics: &hir::Generics<'tcx>) {
let
def_id
=
def_id
.to_def_id
();
self
.encode_info_for_generic_param
(
def_id
,
EntryKind
::
ConstParam
,
true
);
if
default
.is_some
()
{
self
.encode_stability
(
def_id
);
record!
(
self
.tables.const_defaults
[
def_id
]
<-
self
.tcx
.const_param_default
(
def_id
))
}
}
...
...
compiler/rustc_middle/src/query/mod.rs
浏览文件 @
7116bb5c
...
...
@@ -94,7 +94,7 @@
}
/// Given the def_id of a const-generic parameter, computes the associated default const
/// parameter.
i.e. `fn example<const N: usize=3>` called on N would return 3
.
/// parameter.
e.g. `fn example<const N: usize=3>` called on `N` would return `3`
.
query
const_param_default
(
param
:
DefId
)
->
&
'tcx
ty
::
Const
<
'tcx
>
{
desc
{
|
tcx
|
"compute const default for a given parameter `{}`"
,
tcx
.def_path_str
(
param
)
}
}
...
...
compiler/rustc_middle/src/ty/consts.rs
浏览文件 @
7116bb5c
...
...
@@ -212,7 +212,7 @@ pub fn const_param_default<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Cons
})
=>
tcx
.hir
()
.local_def_id
(
ac
.hir_id
),
_
=>
span_bug!
(
tcx
.def_span
(
def_id
),
"
const_param_defaults
expected a generic parameter with a constant"
"
`const_param_default`
expected a generic parameter with a constant"
),
};
Const
::
from_anon_const
(
tcx
,
default_def_id
)
...
...
compiler/rustc_typeck/src/check/wfcheck.rs
浏览文件 @
7116bb5c
...
...
@@ -775,7 +775,7 @@ fn check_where_clauses<'tcx, 'fcx>(
GenericParamDefKind
::
Const
{
..
}
=>
{
if
is_our_default
(
param
)
{
let
default_ct
=
tcx
.const_param_default
(
param
.def_id
);
// Const params
have to currently
be concrete.
// Const params
currently have to
be concrete.
assert
!
(
!
default_ct
.needs_subst
());
default_ct
.into
()
}
else
{
...
...
src/test/ui/const-generics/min_const_generics/const_default_first.rs
0 → 100644
浏览文件 @
7116bb5c
#![crate_type
=
"lib"
]
#![feature(const_generics)]
#![feature(const_generics_defaults)]
#![allow(incomplete_features,
dead_code)]
struct
Both
<
const
N
:
usize
=
3
,
T
>
{
//~^ ERROR: generic parameters with a default must be
v
:
T
}
src/test/ui/const-generics/min_const_generics/const_default_first.stderr
0 → 100644
浏览文件 @
7116bb5c
error: generic parameters with a default must be trailing
--> $DIR/const_default_first.rs:6:19
|
LL | struct Both<const N: usize=3, T> {
| ^
error: aborting due to previous error
src/test/ui/const-generics/min_const_generics/type_and_const_defaults.rs
浏览文件 @
7116bb5c
//
check
-pass
#![
crate_type
=
"lib"
]
//
run
-pass
#![
feature(const_generics)
]
#![feature(const_generics_defaults)]
#![allow(incomplete_features)]
#![allow(incomplete_features
,
dead_code
)]
struct
Both
<
T
=
u32
,
const
N
:
usize
=
3
>
{
arr
:
[
T
;
N
]
...
...
@@ -12,3 +12,16 @@ trait BothTrait<T=u32, const N: usize=3> {}
enum
BothEnum
<
T
=
u32
,
const
N
:
usize
=
3
>
{
Dummy
([
T
;
N
])
}
struct
OppOrder
<
const
N
:
usize
=
3
,
T
=
u32
>
{
arr
:
[
T
;
N
]
}
fn
main
()
{
let
_
=
OppOrder
::
<
3
,
u32
>
{
arr
:
[
0
,
0
,
0
],
};
let
_
=
Both
::
<
u8
,
1
>
{
arr
:
[
0
],
};
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录