Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
bb73ea67
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,发现更多精彩内容 >>
未验证
提交
bb73ea67
编写于
11月 21, 2020
作者:
D
Dylan DPC
提交者:
GitHub
11月 21, 2020
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #79231 - wusyong:issue-79137, r=lcnr
Exhaustively match in variant count instrinsic Fix #79137
上级
5d428cae
bc433802
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
81 addition
and
7 deletion
+81
-7
compiler/rustc_mir/src/interpret/intrinsics.rs
compiler/rustc_mir/src/interpret/intrinsics.rs
+29
-7
src/test/ui/consts/issue-79137-monomorphic.rs
src/test/ui/consts/issue-79137-monomorphic.rs
+19
-0
src/test/ui/consts/issue-79137-toogeneric.rs
src/test/ui/consts/issue-79137-toogeneric.rs
+19
-0
src/test/ui/consts/issue-79137-toogeneric.stderr
src/test/ui/consts/issue-79137-toogeneric.stderr
+14
-0
未找到文件。
compiler/rustc_mir/src/interpret/intrinsics.rs
浏览文件 @
bb73ea67
...
...
@@ -75,13 +75,35 @@ fn numeric_intrinsic<'tcx, Tag>(
ensure_monomorphic_enough
(
tcx
,
tp_ty
)
?
;
ConstValue
::
from_u64
(
tcx
.type_id_hash
(
tp_ty
))
}
sym
::
variant_count
=>
{
if
let
ty
::
Adt
(
ref
adt
,
_
)
=
tp_ty
.kind
()
{
ConstValue
::
from_machine_usize
(
adt
.variants
.len
()
as
u64
,
&
tcx
)
}
else
{
ConstValue
::
from_machine_usize
(
0u64
,
&
tcx
)
}
}
sym
::
variant_count
=>
match
tp_ty
.kind
()
{
ty
::
Adt
(
ref
adt
,
_
)
=>
ConstValue
::
from_machine_usize
(
adt
.variants
.len
()
as
u64
,
&
tcx
),
ty
::
Projection
(
_
)
|
ty
::
Opaque
(
_
,
_
)
|
ty
::
Param
(
_
)
|
ty
::
Bound
(
_
,
_
)
|
ty
::
Placeholder
(
_
)
|
ty
::
Infer
(
_
)
=>
throw_inval!
(
TooGeneric
),
ty
::
Bool
|
ty
::
Char
|
ty
::
Int
(
_
)
|
ty
::
Uint
(
_
)
|
ty
::
Float
(
_
)
|
ty
::
Foreign
(
_
)
|
ty
::
Str
|
ty
::
Array
(
_
,
_
)
|
ty
::
Slice
(
_
)
|
ty
::
RawPtr
(
_
)
|
ty
::
Ref
(
_
,
_
,
_
)
|
ty
::
FnDef
(
_
,
_
)
|
ty
::
FnPtr
(
_
)
|
ty
::
Dynamic
(
_
,
_
)
|
ty
::
Closure
(
_
,
_
)
|
ty
::
Generator
(
_
,
_
,
_
)
|
ty
::
GeneratorWitness
(
_
)
|
ty
::
Never
|
ty
::
Tuple
(
_
)
|
ty
::
Error
(
_
)
=>
ConstValue
::
from_machine_usize
(
0u64
,
&
tcx
),
},
other
=>
bug!
(
"`{}` is not a zero arg intrinsic"
,
other
),
})
}
...
...
src/test/ui/consts/issue-79137-monomorphic.rs
0 → 100644
浏览文件 @
bb73ea67
// check-pass
// Verify that variant count intrinsic can still evaluate for types like `Option<T>`.
#![feature(variant_count)]
pub
struct
GetVariantCount
<
T
>
(
T
);
impl
<
T
>
GetVariantCount
<
T
>
{
pub
const
VALUE
:
usize
=
std
::
mem
::
variant_count
::
<
T
>
();
}
const
fn
check_variant_count
<
T
>
()
->
bool
{
matches!
(
GetVariantCount
::
<
Option
<
T
>>
::
VALUE
,
GetVariantCount
::
<
Option
<
()
>>
::
VALUE
)
}
fn
main
()
{
assert
!
(
check_variant_count
::
<
()
>
());
}
src/test/ui/consts/issue-79137-toogeneric.rs
0 → 100644
浏览文件 @
bb73ea67
// Test that `variant_count` only gets evaluated once the type is concrete enough.
#![feature(variant_count)]
pub
struct
GetVariantCount
<
T
>
(
T
);
impl
<
T
>
GetVariantCount
<
T
>
{
pub
const
VALUE
:
usize
=
std
::
mem
::
variant_count
::
<
T
>
();
}
const
fn
check_variant_count
<
T
>
()
->
bool
{
matches!
(
GetVariantCount
::
<
T
>
::
VALUE
,
GetVariantCount
::
<
T
>
::
VALUE
)
//~^ ERROR constant pattern depends on a generic parameter
//~| ERROR constant pattern depends on a generic parameter
}
fn
main
()
{
assert
!
(
check_variant_count
::
<
Option
<
()
>>
());
}
src/test/ui/consts/issue-79137-toogeneric.stderr
0 → 100644
浏览文件 @
bb73ea67
error: constant pattern depends on a generic parameter
--> $DIR/issue-79137-toogeneric.rs:12:43
|
LL | matches!(GetVariantCount::<T>::VALUE, GetVariantCount::<T>::VALUE)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: constant pattern depends on a generic parameter
--> $DIR/issue-79137-toogeneric.rs:12:43
|
LL | matches!(GetVariantCount::<T>::VALUE, GetVariantCount::<T>::VALUE)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录