Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3fcdb8ba
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,发现更多精彩内容 >>
提交
3fcdb8ba
编写于
8月 08, 2017
作者:
E
Esteban Küber
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Only refer to return type when it matches
上级
d96f9d47
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
27 addition
and
13 deletion
+27
-13
src/librustc/hir/map/mod.rs
src/librustc/hir/map/mod.rs
+1
-1
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+22
-5
src/test/ui/block-result/block-must-not-have-result-res.stderr
...est/ui/block-result/block-must-not-have-result-res.stderr
+1
-1
src/test/ui/block-result/issue-13624.stderr
src/test/ui/block-result/issue-13624.stderr
+1
-1
src/test/ui/block-result/issue-22645.stderr
src/test/ui/block-result/issue-22645.stderr
+1
-1
src/test/ui/block-result/issue-5500.stderr
src/test/ui/block-result/issue-5500.stderr
+1
-1
src/test/ui/impl-trait/equality.stderr
src/test/ui/impl-trait/equality.stderr
+0
-3
未找到文件。
src/librustc/hir/map/mod.rs
浏览文件 @
3fcdb8ba
...
@@ -664,7 +664,7 @@ pub fn get_return_block(&self, id: NodeId) -> Option<NodeId> {
...
@@ -664,7 +664,7 @@ pub fn get_return_block(&self, id: NodeId) -> Option<NodeId> {
match
*
node
{
match
*
node
{
NodeExpr
(
ref
expr
)
=>
{
NodeExpr
(
ref
expr
)
=>
{
match
expr
.node
{
match
expr
.node
{
ExprWhile
(
..
)
|
ExprLoop
(
..
)
|
ExprIf
(
..
)
=>
true
,
ExprWhile
(
..
)
|
ExprLoop
(
..
)
=>
true
,
_
=>
false
,
_
=>
false
,
}
}
}
}
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
3fcdb8ba
...
@@ -95,7 +95,7 @@
...
@@ -95,7 +95,7 @@
use
rustc
::
ty
::
subst
::{
Kind
,
Subst
,
Substs
};
use
rustc
::
ty
::
subst
::{
Kind
,
Subst
,
Substs
};
use
rustc
::
traits
::{
self
,
FulfillmentContext
,
ObligationCause
,
ObligationCauseCode
};
use
rustc
::
traits
::{
self
,
FulfillmentContext
,
ObligationCause
,
ObligationCauseCode
};
use
rustc
::
ty
::{
ParamTy
,
LvaluePreference
,
NoPreference
,
PreferMutLvalue
};
use
rustc
::
ty
::{
ParamTy
,
LvaluePreference
,
NoPreference
,
PreferMutLvalue
};
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
,
Visibility
};
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
,
Visibility
,
TypeVariants
};
use
rustc
::
ty
::
adjustment
::{
Adjust
,
Adjustment
,
AutoBorrow
};
use
rustc
::
ty
::
adjustment
::{
Adjust
,
Adjustment
,
AutoBorrow
};
use
rustc
::
ty
::
fold
::{
BottomUpFolder
,
TypeFoldable
};
use
rustc
::
ty
::
fold
::{
BottomUpFolder
,
TypeFoldable
};
use
rustc
::
ty
::
maps
::
Providers
;
use
rustc
::
ty
::
maps
::
Providers
;
...
@@ -4302,7 +4302,6 @@ fn suggest_missing_return_type(&self,
...
@@ -4302,7 +4302,6 @@ fn suggest_missing_return_type(&self,
expected
:
Ty
<
'tcx
>
,
expected
:
Ty
<
'tcx
>
,
found
:
Ty
<
'tcx
>
,
found
:
Ty
<
'tcx
>
,
can_suggest
:
bool
)
{
can_suggest
:
bool
)
{
// Only suggest changing the return type for methods that
// Only suggest changing the return type for methods that
// haven't set a return type at all (and aren't `fn main()` or an impl).
// haven't set a return type at all (and aren't `fn main()` or an impl).
match
(
&
fn_decl
.output
,
found
.is_suggestable
(),
can_suggest
)
{
match
(
&
fn_decl
.output
,
found
.is_suggestable
(),
can_suggest
)
{
...
@@ -4316,13 +4315,31 @@ fn suggest_missing_return_type(&self,
...
@@ -4316,13 +4315,31 @@ fn suggest_missing_return_type(&self,
}
}
(
&
hir
::
FunctionRetTy
::
DefaultReturn
(
span
),
_
,
_
)
=>
{
(
&
hir
::
FunctionRetTy
::
DefaultReturn
(
span
),
_
,
_
)
=>
{
// `fn main()` must return `()`, do not suggest changing return type
// `fn main()` must return `()`, do not suggest changing return type
err
.span_label
(
span
,
"expected
`()`
because of default return type"
);
err
.span_label
(
span
,
"expected
()
because of default return type"
);
}
}
(
&
hir
::
FunctionRetTy
::
Return
(
ref
ty
),
_
,
_
)
=>
{
(
&
hir
::
FunctionRetTy
::
Return
(
ref
ty
),
_
,
_
)
=>
{
// Only point to return type if the expected type is the return type, as if they
// Only point to return type if the expected type is the return type, as if they
// are not, the expectation must have been caused by something else.
// are not, the expectation must have been caused by something else.
err
.span_label
(
ty
.span
,
debug!
(
"suggest_missing_return_type: return type {:?} node {:?}"
,
ty
,
ty
.node
);
format!
(
"expected `{}` because of return type"
,
expected
));
let
sp
=
ty
.span
;
let
ty
=
AstConv
::
ast_ty_to_ty
(
self
,
ty
);
debug!
(
"suggest_missing_return_type: return type sty {:?}"
,
ty
.sty
);
debug!
(
"suggest_missing_return_type: expected type sty {:?}"
,
ty
.sty
);
if
ty
.sty
==
expected
.sty
{
let
quote
=
if
let
TypeVariants
::
TyTuple
(
ref
slice
,
_
)
=
expected
.sty
{
if
slice
.len
()
==
0
{
// don't use backtics for ()
""
}
else
{
"`"
}
}
else
{
"`"
};
err
.span_label
(
sp
,
format!
(
"expected {}{}{} because of return type"
,
quote
,
expected
,
quote
));
}
}
}
}
}
}
}
...
...
src/test/ui/block-result/block-must-not-have-result-res.stderr
浏览文件 @
3fcdb8ba
...
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
...
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/block-must-not-have-result-res.rs:15:9
--> $DIR/block-must-not-have-result-res.rs:15:9
|
|
14 | fn drop(&mut self) {
14 | fn drop(&mut self) {
| - expected
`()`
because of default return type
| - expected
()
because of default return type
15 | true //~ ERROR mismatched types
15 | true //~ ERROR mismatched types
| ^^^^ expected (), found bool
| ^^^^ expected (), found bool
|
|
...
...
src/test/ui/block-result/issue-13624.stderr
浏览文件 @
3fcdb8ba
...
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
...
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-13624.rs:17:5
--> $DIR/issue-13624.rs:17:5
|
|
16 | pub fn get_enum_struct_variant() -> () {
16 | pub fn get_enum_struct_variant() -> () {
| -- expected
`()`
because of return type
| -- expected
()
because of return type
17 | Enum::EnumStructVariant { x: 1, y: 2, z: 3 }
17 | Enum::EnumStructVariant { x: 1, y: 2, z: 3 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found enum `a::Enum`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found enum `a::Enum`
|
|
...
...
src/test/ui/block-result/issue-22645.stderr
浏览文件 @
3fcdb8ba
...
@@ -12,7 +12,7 @@ error[E0308]: mismatched types
...
@@ -12,7 +12,7 @@ error[E0308]: mismatched types
--> $DIR/issue-22645.rs:25:3
--> $DIR/issue-22645.rs:25:3
|
|
23 | fn main() {
23 | fn main() {
| - expected
`()`
because of default return type
| - expected
()
because of default return type
24 | let b = Bob + 3.5;
24 | let b = Bob + 3.5;
25 | b + 3 //~ ERROR E0277
25 | b + 3 //~ ERROR E0277
| ^^^^^ expected (), found struct `Bob`
| ^^^^^ expected (), found struct `Bob`
...
...
src/test/ui/block-result/issue-5500.stderr
浏览文件 @
3fcdb8ba
...
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
...
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-5500.rs:12:5
--> $DIR/issue-5500.rs:12:5
|
|
11 | fn main() {
11 | fn main() {
| - expected
`()`
because of default return type
| - expected
()
because of default return type
12 | &panic!()
12 | &panic!()
| ^^^^^^^^^ expected (), found reference
| ^^^^^^^^^ expected (), found reference
|
|
...
...
src/test/ui/impl-trait/equality.stderr
浏览文件 @
3fcdb8ba
error[E0308]: mismatched types
error[E0308]: mismatched types
--> $DIR/equality.rs:25:5
--> $DIR/equality.rs:25:5
|
|
21 | fn two(x: bool) -> impl Foo {
| -------- expected `_` because of return type
...
25 | 0_u32
25 | 0_u32
| ^^^^^ expected i32, found u32
| ^^^^^ expected i32, found u32
|
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录