Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2f4e86b9
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
2f4e86b9
编写于
7月 30, 2021
作者:
C
Cameron Steffen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enforce diverging let...else
上级
cb4439a3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
5 deletion
+33
-5
compiler/rustc_infer/src/infer/error_reporting/mod.rs
compiler/rustc_infer/src/infer/error_reporting/mod.rs
+5
-0
compiler/rustc_middle/src/traits/mod.rs
compiler/rustc_middle/src/traits/mod.rs
+3
-0
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
...trait_selection/src/traits/error_reporting/suggestions.rs
+5
-4
compiler/rustc_typeck/src/check/expr.rs
compiler/rustc_typeck/src/check/expr.rs
+20
-1
未找到文件。
compiler/rustc_infer/src/infer/error_reporting/mod.rs
浏览文件 @
2f4e86b9
...
...
@@ -781,6 +781,10 @@ fn note_error_origin(
);
}
}
ObligationCauseCode
::
LetElse
=>
{
err
.help
(
"try adding a diverging expression, such as `return` or `panic!(..)`"
);
err
.help
(
"...or use `match` instead of `let...else`"
);
}
_
=>
(),
}
}
...
...
@@ -2592,6 +2596,7 @@ fn as_failure_code(&self, terr: &TypeError<'tcx>) -> FailureCode {
}
IfExpression
{
..
}
=>
Error0308
(
"`if` and `else` have incompatible types"
),
IfExpressionWithNoElse
=>
Error0317
(
"`if` may be missing an `else` clause"
),
LetElse
=>
Error0308
(
"`else` clause of `let...else` does not diverge"
),
MainFunctionType
=>
Error0580
(
"`main` function has wrong type"
),
StartFunctionType
=>
Error0308
(
"`#[start]` function has wrong type"
),
IntrinsicType
=>
Error0308
(
"intrinsic has wrong type"
),
...
...
compiler/rustc_middle/src/traits/mod.rs
浏览文件 @
2f4e86b9
...
...
@@ -305,6 +305,9 @@ pub enum ObligationCauseCode<'tcx> {
/// Intrinsic has wrong type
IntrinsicType
,
/// A let else block does not diverge
LetElse
,
/// Method receiver
MethodReceiver
,
...
...
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
浏览文件 @
2f4e86b9
...
...
@@ -1928,7 +1928,11 @@ fn note_obligation_cause_code<T>(
|
ObligationCauseCode
::
OpaqueType
|
ObligationCauseCode
::
MiscObligation
|
ObligationCauseCode
::
WellFormed
(
..
)
|
ObligationCauseCode
::
MatchImpl
(
..
)
=>
{}
|
ObligationCauseCode
::
MatchImpl
(
..
)
|
ObligationCauseCode
::
ReturnType
|
ObligationCauseCode
::
ReturnValue
(
_
)
|
ObligationCauseCode
::
BlockTailExpression
(
_
)
|
ObligationCauseCode
::
LetElse
=>
{}
ObligationCauseCode
::
SliceOrArrayElem
=>
{
err
.note
(
"slice and array elements must have `Sized` type"
);
}
...
...
@@ -2338,9 +2342,6 @@ fn note_obligation_cause_code<T>(
predicate
));
}
ObligationCauseCode
::
ReturnType
|
ObligationCauseCode
::
ReturnValue
(
_
)
|
ObligationCauseCode
::
BlockTailExpression
(
_
)
=>
(),
ObligationCauseCode
::
TrivialBound
=>
{
err
.help
(
"see issue #48214"
);
if
tcx
.sess.opts.unstable_features
.is_nightly_build
()
{
...
...
compiler/rustc_typeck/src/check/expr.rs
浏览文件 @
2f4e86b9
...
...
@@ -849,7 +849,26 @@ fn check_then_else(
coerce
.coerce
(
self
,
&
self
.misc
(
sp
),
then_expr
,
then_ty
);
if
let
Some
(
else_expr
)
=
opt_else_expr
{
let
else_ty
=
self
.check_expr_with_expectation
(
else_expr
,
expected
);
let
else_ty
=
if
sp
.desugaring_kind
()
==
Some
(
DesugaringKind
::
LetElse
)
{
// todo introduce `check_expr_with_expectation(.., Expectation::LetElse)`
// for errors that point to the offending expression rather than the entire block.
// We could use `check_expr_eq_type(.., tcx.types.never)`, but then there is no
// way to detect that the expected type originated from let-else and provide
// a customized error.
let
else_ty
=
self
.check_expr
(
else_expr
);
let
cause
=
self
.cause
(
else_expr
.span
,
ObligationCauseCode
::
LetElse
);
if
let
Some
(
mut
err
)
=
self
.demand_eqtype_with_origin
(
&
cause
,
self
.tcx.types.never
,
else_ty
)
{
err
.emit
();
self
.tcx
.ty_error
()
}
else
{
else_ty
}
}
else
{
self
.check_expr_with_expectation
(
else_expr
,
expected
)
};
let
else_diverges
=
self
.diverges
.get
();
let
opt_suggest_box_span
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录