Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
33370fd9
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,发现更多精彩内容 >>
提交
33370fd9
编写于
3月 22, 2021
作者:
K
kadmin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update to not have extra match
上级
7116bb5c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
85 addition
and
28 deletion
+85
-28
compiler/rustc_infer/src/infer/error_reporting/mod.rs
compiler/rustc_infer/src/infer/error_reporting/mod.rs
+10
-28
src/test/ui/const-generics/defaults/mismatch.rs
src/test/ui/const-generics/defaults/mismatch.rs
+23
-0
src/test/ui/const-generics/defaults/mismatch.stderr
src/test/ui/const-generics/defaults/mismatch.stderr
+52
-0
未找到文件。
compiler/rustc_infer/src/infer/error_reporting/mod.rs
浏览文件 @
33370fd9
...
...
@@ -67,7 +67,7 @@
use
rustc_middle
::
ty
::
error
::
TypeError
;
use
rustc_middle
::
ty
::{
self
,
subst
::{
Subst
,
SubstsRef
},
subst
::{
GenericArgKind
,
Subst
,
SubstsRef
},
Region
,
Ty
,
TyCtxt
,
TypeFoldable
,
};
use
rustc_span
::{
sym
,
BytePos
,
DesugaringKind
,
Pos
,
Span
};
...
...
@@ -958,42 +958,24 @@ fn strip_generic_default_params(
let
generics
=
self
.tcx
.generics_of
(
def_id
);
let
mut
num_supplied_defaults
=
0
;
#[derive(PartialEq,
Eq,
Copy,
Clone)]
enum
Kind
{
Const
,
Type
,
}
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
))
}
ty
::
GenericParamDefKind
::
Type
{
has_default
:
true
,
..
}
=>
Some
(
param
.def_id
),
ty
::
GenericParamDefKind
::
Const
{
has_default
:
true
}
=>
Some
(
param
.def_id
),
_
=>
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
{
for
(
def_id
,
actual
)
in
default_params
.zip
(
substs
.iter
()
.rev
())
{
match
actual
.unpack
()
{
GenericArgKind
::
Const
(
c
)
=>
{
if
self
.tcx
.const_param_default
(
def_id
)
.subst
(
self
.tcx
,
substs
)
!=
c
{
break
;
}
}
Kind
::
Type
=>
{
if
let
Some
(
actual
)
=
types
.next
()
{
if
self
.tcx
.type_of
(
def_id
)
.subst
(
self
.tcx
,
substs
)
!=
actual
{
break
;
}
}
else
{
GenericArgKind
::
Type
(
ty
)
=>
{
if
self
.tcx
.type_of
(
def_id
)
.subst
(
self
.tcx
,
substs
)
!=
ty
{
break
;
}
}
_
=>
break
,
}
num_supplied_defaults
+=
1
;
}
...
...
src/test/ui/const-generics/defaults/mismatch.rs
0 → 100644
浏览文件 @
33370fd9
#![feature(const_generics)]
#![feature(const_generics_defaults)]
#![allow(incomplete_features)]
pub
struct
Example
<
const
N
:
usize
=
13
>
;
pub
struct
Example2
<
T
=
u32
,
const
N
:
usize
=
13
>
(
T
);
pub
struct
Example3
<
const
N
:
usize
=
13
,
T
=
u32
>
(
T
);
pub
struct
Example4
<
const
N
:
usize
=
13
,
const
M
:
usize
=
4
>
;
fn
main
()
{
let
e
:
Example
::
<
13
>
=
();
//~^ Error: mismatched types
let
e
:
Example2
::
<
u32
,
13
>
=
();
//~^ Error: mismatched types
let
e
:
Example3
::
<
13
,
u32
>
=
();
//~^ Error: mismatched types
let
e
:
Example3
::
<
7
>
=
();
//~^ Error: mismatched types
// FIXME(const_generics_defaults): There should be a note for the error below, but it is
// missing.
let
e
:
Example4
::
<
7
>
=
();
//~^ Error: mismatched types
}
src/test/ui/const-generics/defaults/mismatch.stderr
0 → 100644
浏览文件 @
33370fd9
error[E0308]: mismatched types
--> $DIR/mismatch.rs:11:26
|
LL | let e: Example::<13> = ();
| ------------- ^^ expected struct `Example`, found `()`
| |
| expected due to this
error[E0308]: mismatched types
--> $DIR/mismatch.rs:13:32
|
LL | let e: Example2::<u32, 13> = ();
| ------------------- ^^ expected struct `Example2`, found `()`
| |
| expected due to this
|
= note: expected struct `Example2`
found unit type `()`
error[E0308]: mismatched types
--> $DIR/mismatch.rs:15:32
|
LL | let e: Example3::<13, u32> = ();
| ------------------- ^^ expected struct `Example3`, found `()`
| |
| expected due to this
|
= note: expected struct `Example3`
found unit type `()`
error[E0308]: mismatched types
--> $DIR/mismatch.rs:17:26
|
LL | let e: Example3::<7> = ();
| ------------- ^^ expected struct `Example3`, found `()`
| |
| expected due to this
|
= note: expected struct `Example3<7_usize>`
found unit type `()`
error[E0308]: mismatched types
--> $DIR/mismatch.rs:21:26
|
LL | let e: Example4::<7> = ();
| ------------- ^^ expected struct `Example4`, found `()`
| |
| expected due to this
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0308`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录