Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f475e880
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,发现更多精彩内容 >>
提交
f475e880
编写于
7月 01, 2022
作者:
L
lcnr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
`InferSource::GenericArg`, check for contains
上级
7952d2ed
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
42 addition
and
30 deletion
+42
-30
compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
...r/rustc_infer/src/infer/error_reporting/need_type_info.rs
+20
-17
src/test/ui/inference/cannot-infer-partial-try-return.rs
src/test/ui/inference/cannot-infer-partial-try-return.rs
+1
-1
src/test/ui/inference/cannot-infer-partial-try-return.stderr
src/test/ui/inference/cannot-infer-partial-try-return.stderr
+7
-8
src/test/ui/issues/issue-23041.stderr
src/test/ui/issues/issue-23041.stderr
+7
-2
src/test/ui/issues/issue-24013.stderr
src/test/ui/issues/issue-24013.stderr
+7
-2
未找到文件。
compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
浏览文件 @
f475e880
...
...
@@ -533,18 +533,19 @@ enum InferSourceKind<'tcx> {
}
impl
<
'tcx
>
InferSource
<
'tcx
>
{
/// Returns the span where we're going to insert our suggestion.
///
/// Used when computing the cost of this infer source to check whether
/// we're inside of a macro expansion.
fn
main_insert_span
(
&
self
)
->
Span
{
match
self
.kind
{
InferSourceKind
::
LetBinding
{
insert_span
,
..
}
=>
insert_span
,
InferSourceKind
::
ClosureArg
{
insert_span
,
..
}
=>
insert_span
,
InferSourceKind
::
GenericArg
{
insert_span
,
..
}
=>
insert_span
,
InferSourceKind
::
FullyQualifiedMethodCall
{
receiver
,
..
}
=>
receiver
.span
,
InferSourceKind
::
ClosureReturn
{
data
,
..
}
=>
data
.span
(),
}
fn
from_expansion
(
&
self
)
->
bool
{
let
source_from_expansion
=
match
self
.kind
{
InferSourceKind
::
LetBinding
{
insert_span
,
..
}
|
InferSourceKind
::
ClosureArg
{
insert_span
,
..
}
|
InferSourceKind
::
GenericArg
{
insert_span
,
..
}
=>
insert_span
.from_expansion
(),
InferSourceKind
::
FullyQualifiedMethodCall
{
receiver
,
..
}
=>
{
receiver
.span
.from_expansion
()
}
InferSourceKind
::
ClosureReturn
{
data
,
should_wrap_expr
,
..
}
=>
{
data
.span
()
.from_expansion
()
||
should_wrap_expr
.map_or
(
false
,
Span
::
from_expansion
)
}
};
source_from_expansion
||
self
.span
.from_expansion
()
}
}
...
...
@@ -631,7 +632,7 @@ fn arg_cost(self, arg: GenericArg<'tcx>) -> usize {
}
}
fn
ty_cost
(
self
,
ty
:
Ty
<
'tcx
>
)
->
usize
{
match
ty
.kind
()
{
match
*
ty
.kind
()
{
ty
::
Closure
(
..
)
=>
1000
,
ty
::
FnDef
(
..
)
=>
150
,
ty
::
FnPtr
(
..
)
=>
30
,
...
...
@@ -645,6 +646,7 @@ fn ty_cost(self, ty: Ty<'tcx>) -> usize {
.sum
::
<
usize
>
()
}
ty
::
Tuple
(
args
)
=>
5
+
args
.iter
()
.map
(|
arg
|
self
.ty_cost
(
arg
))
.sum
::
<
usize
>
(),
ty
::
Ref
(
_
,
ty
,
_
)
=>
2
+
self
.ty_cost
(
ty
),
ty
::
Infer
(
..
)
=>
0
,
_
=>
1
,
}
...
...
@@ -673,8 +675,7 @@ fn ty_cost(self, ty: Ty<'tcx>) -> usize {
}
};
let
suggestion_may_apply
=
if
source
.main_insert_span
()
.can_be_used_for_suggestions
()
{
0
}
else
{
10000
};
let
suggestion_may_apply
=
if
source
.from_expansion
()
{
10000
}
else
{
0
};
base_cost
+
suggestion_may_apply
}
...
...
@@ -1022,8 +1023,10 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
debug!
(
?
args
);
let
InsertableGenericArgs
{
insert_span
,
substs
,
generics_def_id
,
def_id
}
=
args
;
let
generics
=
tcx
.generics_of
(
generics_def_id
);
if
let
Some
(
argument_index
)
=
generics
.own_substs
(
substs
)
.iter
()
.position
(|
&
arg
|
self
.generic_arg_is_target
(
arg
))
if
let
Some
(
argument_index
)
=
generics
.own_substs
(
substs
)
.iter
()
.position
(|
&
arg
|
self
.generic_arg_contains_target
(
arg
))
{
let
substs
=
self
.infcx
.resolve_vars_if_possible
(
substs
);
let
generic_args
=
&
generics
.own_substs_no_defaults
(
tcx
,
substs
)
...
...
src/test/ui/inference/cannot-infer-partial-try-return.rs
浏览文件 @
f475e880
...
...
@@ -16,8 +16,8 @@ fn infallible() -> Result<(), std::convert::Infallible> {
fn
main
()
{
let
x
=
||
->
Result
<
_
,
QualifiedError
<
_
>>
{
//~^ ERROR type annotations needed for `Result<(), QualifiedError<_>>`
infallible
()
?
;
Ok
(())
//~^ ERROR type annotations needed
};
}
src/test/ui/inference/cannot-infer-partial-try-return.stderr
浏览文件 @
f475e880
error[E0282]: type annotations needed
for `Result<(), QualifiedError<_>>`
--> $DIR/cannot-infer-partial-try-return.rs:
18:13
error[E0282]: type annotations needed
--> $DIR/cannot-infer-partial-try-return.rs:
20:9
|
LL | let x = || -> Result<_, QualifiedError<_>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | infallible()?;
| ------------- type must be known at this point
LL | Ok(())
| ^^ cannot infer type of the type parameter `E` declared on the enum `Result`
|
help:
try giving this closure an explicit return type
help:
consider specifying the generic arguments
|
LL |
let x = || -> Result<(), QualifiedError<_>> {
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL |
Ok::<(), QualifiedError<_>>(())
|
+++++++++++++++++++++++++
error: aborting due to previous error
...
...
src/test/ui/issues/issue-23041.stderr
浏览文件 @
f475e880
error[E0282]: type annotations needed
--> $DIR/issue-23041.rs:6:
22
--> $DIR/issue-23041.rs:6:
7
|
LL | b.downcast_ref::<fn(_)->_>();
| ^^^^^^^^ cannot infer type
| ^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the associated function `downcast_ref`
|
help: consider specifying the generic arguments
|
LL | b.downcast_ref::<fn(_) -> _>();
| ~~~~~~~~~~~~~~
error: aborting due to previous error
...
...
src/test/ui/issues/issue-24013.stderr
浏览文件 @
f475e880
error[E0282]: type annotations needed
--> $DIR/issue-24013.rs:5:
20
--> $DIR/issue-24013.rs:5:
13
|
LL | unsafe {swap::<&mut _>(transmute(&a), transmute(&b))};
| ^^^^^^ cannot infer type
| ^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `swap`
|
help: consider specifying the generic arguments
|
LL | unsafe {swap::<&mut _>(transmute(&a), transmute(&b))};
| ~~~~~~~~~~
error: aborting due to previous error
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录