Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
85cc4710
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,发现更多精彩内容 >>
提交
85cc4710
编写于
1月 19, 2022
作者:
M
Mara Bos
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add more tests for mismatched Option/Result return types.
上级
003c892f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
68 addition
and
8 deletion
+68
-8
src/test/ui/did_you_mean/compatible-variants.rs
src/test/ui/did_you_mean/compatible-variants.rs
+15
-0
src/test/ui/did_you_mean/compatible-variants.stderr
src/test/ui/did_you_mean/compatible-variants.stderr
+53
-8
未找到文件。
src/test/ui/did_you_mean/compatible-variants.rs
浏览文件 @
85cc4710
...
...
@@ -23,6 +23,21 @@ fn b() -> Result<(), ()> {
//~| HELP try adding an expression
}
fn
c
()
->
Option
<
()
>
{
for
_
in
[
1
,
2
]
{
//~^ ERROR mismatched types
f
();
}
//~^ HELP try adding an expression
}
fn
d
()
->
Option
<
()
>
{
c
()
?
//~^ ERROR incompatible types
//~| HELP try removing this `?`
//~| HELP try adding an expression
}
fn
main
()
{
let
_
:
Option
<
()
>
=
while
false
{};
//~^ ERROR mismatched types
...
...
src/test/ui/did_you_mean/compatible-variants.stderr
浏览文件 @
85cc4710
...
...
@@ -37,7 +37,52 @@ LL + Ok(())
|
error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:27:25
--> $DIR/compatible-variants.rs:27:5
|
LL | fn c() -> Option<()> {
| ---------- expected `Option<()>` because of return type
LL | / for _ in [1, 2] {
LL | |
LL | | f();
LL | | }
| |_____^ expected enum `Option`, found `()`
|
= note: expected enum `Option<()>`
found unit type `()`
help: try adding an expression at the end of the block
|
LL ~ }
LL + None
|
LL ~ }
LL + Some(())
|
error[E0308]: `?` operator has incompatible types
--> $DIR/compatible-variants.rs:35:5
|
LL | c()?
| ^^^^ expected enum `Option`, found `()`
|
= note: `?` operator cannot convert from `()` to `Option<()>`
= note: expected enum `Option<()>`
found unit type `()`
help: try removing this `?`
|
LL - c()?
LL + c()
|
help: try adding an expression at the end of the block
|
LL ~ c()?;
LL + None
|
LL ~ c()?;
LL + Some(())
|
error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:42:25
|
LL | let _: Option<()> = while false {};
| ---------- ^^^^^^^^^^^^^^ expected enum `Option`, found `()`
...
...
@@ -52,7 +97,7 @@ LL | let _: Option<()> = Some(while false {});
| +++++ +
error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:
31
:9
--> $DIR/compatible-variants.rs:
46
:9
|
LL | while false {}
| ^^^^^^^^^^^^^^ expected enum `Option`, found `()`
...
...
@@ -69,7 +114,7 @@ LL + Some(())
|
error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:
35
:31
--> $DIR/compatible-variants.rs:
50
:31
|
LL | let _: Result<i32, i32> = 1;
| ---------------- ^ expected enum `Result`, found integer
...
...
@@ -86,7 +131,7 @@ LL | let _: Result<i32, i32> = Err(1);
| ++++ +
error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:
38
:26
--> $DIR/compatible-variants.rs:
53
:26
|
LL | let _: Option<i32> = 1;
| ----------- ^ expected enum `Option`, found integer
...
...
@@ -101,7 +146,7 @@ LL | let _: Option<i32> = Some(1);
| +++++ +
error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:
41
:28
--> $DIR/compatible-variants.rs:
56
:28
|
LL | let _: Hey<i32, i32> = 1;
| ------------- ^ expected enum `Hey`, found integer
...
...
@@ -118,7 +163,7 @@ LL | let _: Hey<i32, i32> = Hey::B(1);
| +++++++ +
error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:
44
:29
--> $DIR/compatible-variants.rs:
59
:29
|
LL | let _: Hey<i32, bool> = false;
| -------------- ^^^^^ expected enum `Hey`, found `bool`
...
...
@@ -133,7 +178,7 @@ LL | let _: Hey<i32, bool> = Hey::B(false);
| +++++++ +
error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:
48
:19
--> $DIR/compatible-variants.rs:
63
:19
|
LL | let _ = Foo { bar };
| ^^^ expected enum `Option`, found `i32`
...
...
@@ -145,6 +190,6 @@ help: try wrapping the expression in `Some`
LL | let _ = Foo { bar: Some(bar) };
| ++++++++++ +
error: aborting due to
9
previous errors
error: aborting due to
11
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录