Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a3df1db8
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,发现更多精彩内容 >>
提交
a3df1db8
编写于
3月 30, 2020
作者:
B
Bastian Kauschke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update tests, improve variable names
上级
40c5eefd
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
40 addition
and
12 deletion
+40
-12
src/librustc_error_codes/error_codes/E0730.md
src/librustc_error_codes/error_codes/E0730.md
+2
-2
src/librustc_typeck/check/pat.rs
src/librustc_typeck/check/pat.rs
+2
-2
src/test/ui/array-slice-vec/match_arr_unknown_len.rs
src/test/ui/array-slice-vec/match_arr_unknown_len.rs
+11
-0
src/test/ui/array-slice-vec/match_arr_unknown_len.stderr
src/test/ui/array-slice-vec/match_arr_unknown_len.stderr
+20
-0
src/test/ui/error-codes/E0730.rs
src/test/ui/error-codes/E0730.rs
+1
-1
src/test/ui/error-codes/E0730.stderr
src/test/ui/error-codes/E0730.stderr
+4
-7
未找到文件。
src/librustc_error_codes/error_codes/E0730.md
浏览文件 @
a3df1db8
...
...
@@ -7,8 +7,8 @@ Example of erroneous code:
fn is_123<const N: usize>(x: [u32; N]) -> bool {
match x {
[1, 2,
3
] => true, // error: cannot pattern-match on an
// array without a fixed length
[1, 2,
..
] => true, // error: cannot pattern-match on an
// array without a fixed length
_ => false
}
}
...
...
src/librustc_typeck/check/pat.rs
浏览文件 @
a3df1db8
...
...
@@ -1355,7 +1355,7 @@ fn check_pat_slice(
)
->
Ty
<
'tcx
>
{
let
err
=
self
.tcx.types.err
;
let
expected
=
self
.structurally_resolved_type
(
span
,
expected
);
let
(
element_ty
,
slice_ty
,
expect
ed
)
=
match
expected
.kind
{
let
(
element_ty
,
slice_ty
,
inferr
ed
)
=
match
expected
.kind
{
// An array, so we might have something like `let [a, b, c] = [0, 1, 2];`.
ty
::
Array
(
element_ty
,
len
)
=>
{
let
min
=
before
.len
()
as
u64
+
after
.len
()
as
u64
;
...
...
@@ -1385,7 +1385,7 @@ fn check_pat_slice(
for
elt
in
after
{
self
.check_pat
(
&
elt
,
element_ty
,
def_bm
,
ti
);
}
expect
ed
inferr
ed
}
/// Type check the length of an array pattern.
...
...
src/test/ui/array-slice-vec/match_arr_unknown_len.rs
0 → 100644
浏览文件 @
a3df1db8
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
fn
is_123
<
const
N
:
usize
>
(
x
:
[
u32
;
N
])
->
bool
{
match
x
{
[
1
,
2
]
=>
true
,
//~ ERROR mismatched types
_
=>
false
}
}
fn
main
()
{}
src/test/ui/array-slice-vec/match_arr_unknown_len.stderr
0 → 100644
浏览文件 @
a3df1db8
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/match_arr_unknown_len.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> $DIR/match_arr_unknown_len.rs:6:9
|
LL | [1, 2] => true,
| ^^^^^^ expected `2usize`, found `N`
|
= note: expected array `[u32; 2]`
found array `[u32; _]`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
src/test/ui/error-codes/E0730.rs
浏览文件 @
a3df1db8
...
...
@@ -3,7 +3,7 @@
fn
is_123
<
const
N
:
usize
>
(
x
:
[
u32
;
N
])
->
bool
{
match
x
{
[
1
,
2
,
3
]
=>
true
,
//~ ERROR mismatched types
[
1
,
2
,
..
]
=>
true
,
//~ ERROR cannot pattern-match on an array without a fixed length
_
=>
false
}
}
...
...
src/test/ui/error-codes/E0730.stderr
浏览文件 @
a3df1db8
...
...
@@ -6,15 +6,12 @@ LL | #![feature(const_generics)]
|
= note: `#[warn(incomplete_features)]` on by default
error[E0
308]: mismatched types
error[E0
730]: cannot pattern-match on an array without a fixed length
--> $DIR/E0730.rs:6:9
|
LL | [1, 2, 3] => true,
| ^^^^^^^^^ expected `3usize`, found `N`
|
= note: expected array `[u32; 3]`
found array `[u32; _]`
LL | [1, 2, ..] => true,
| ^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0
308
`.
For more information about this error, try `rustc --explain E0
730
`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录