Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
82b52056
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,发现更多精彩内容 >>
提交
82b52056
编写于
2月 10, 2023
作者:
M
Michael Goulet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Check that built-in callable types validate their output type is `Sized` (in new solver)
上级
3eb5c458
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
80 addition
and
14 deletion
+80
-14
compiler/rustc_trait_selection/src/solve/assembly.rs
compiler/rustc_trait_selection/src/solve/assembly.rs
+12
-0
compiler/rustc_trait_selection/src/solve/project_goals.rs
compiler/rustc_trait_selection/src/solve/project_goals.rs
+15
-7
compiler/rustc_trait_selection/src/solve/trait_goals.rs
compiler/rustc_trait_selection/src/solve/trait_goals.rs
+18
-7
tests/ui/traits/new-solver/builtin-fn-must-return-sized.rs
tests/ui/traits/new-solver/builtin-fn-must-return-sized.rs
+17
-0
tests/ui/traits/new-solver/builtin-fn-must-return-sized.stderr
.../ui/traits/new-solver/builtin-fn-must-return-sized.stderr
+18
-0
未找到文件。
compiler/rustc_trait_selection/src/solve/assembly.rs
浏览文件 @
82b52056
...
...
@@ -96,10 +96,22 @@ fn consider_impl_candidate(
impl_def_id
:
DefId
,
)
->
QueryResult
<
'tcx
>
;
// Consider a predicate we know holds (`assumption`) against a goal we're trying to prove.
fn
consider_assumption
(
ecx
:
&
mut
EvalCtxt
<
'_
,
'tcx
>
,
goal
:
Goal
<
'tcx
,
Self
>
,
assumption
:
ty
::
Predicate
<
'tcx
>
,
)
->
QueryResult
<
'tcx
>
{
Self
::
consider_assumption_with_certainty
(
ecx
,
goal
,
assumption
,
Certainty
::
Yes
)
}
// Consider a predicate we know holds (`assumption`) against a goal, unifying with
// the `assumption_certainty` if it satisfies the goal.
fn
consider_assumption_with_certainty
(
ecx
:
&
mut
EvalCtxt
<
'_
,
'tcx
>
,
goal
:
Goal
<
'tcx
,
Self
>
,
assumption
:
ty
::
Predicate
<
'tcx
>
,
assumption_certainty
:
Certainty
,
)
->
QueryResult
<
'tcx
>
;
// A type implements an `auto trait` if its components do as well. These components
...
...
compiler/rustc_trait_selection/src/solve/project_goals.rs
浏览文件 @
82b52056
...
...
@@ -260,10 +260,11 @@ fn consider_impl_candidate(
})
}
fn
consider_assumption
(
fn
consider_assumption
_with_certainty
(
ecx
:
&
mut
EvalCtxt
<
'_
,
'tcx
>
,
goal
:
Goal
<
'tcx
,
Self
>
,
assumption
:
ty
::
Predicate
<
'tcx
>
,
assumption_certainty
:
Certainty
,
)
->
QueryResult
<
'tcx
>
{
if
let
Some
(
poly_projection_pred
)
=
assumption
.to_opt_poly_projection_pred
()
&&
poly_projection_pred
.projection_def_id
()
==
goal
.predicate
.def_id
()
...
...
@@ -280,7 +281,7 @@ fn consider_assumption(
ecx
.eq_term_and_make_canonical_response
(
goal
,
subst_certainty
,
subst_certainty
.unify_and
(
assumption_certainty
)
,
assumption_projection_pred
.term
,
)
})
...
...
@@ -329,22 +330,29 @@ fn consider_builtin_fn_trait_candidates(
goal
:
Goal
<
'tcx
,
Self
>
,
goal_kind
:
ty
::
ClosureKind
,
)
->
QueryResult
<
'tcx
>
{
let
tcx
=
ecx
.tcx
();
if
let
Some
(
tupled_inputs_and_output
)
=
structural_traits
::
extract_tupled_inputs_and_output_from_callable
(
ecx
.tcx
()
,
tcx
,
goal
.predicate
.self_ty
(),
goal_kind
,
)
?
{
// A built-in `Fn` trait needs to check that its output is `Sized`
// (FIXME: technically we only need to check this if the type is a fn ptr...)
let
output_is_sized_pred
=
tupled_inputs_and_output
.map_bound
(|(
_
,
output
)|
tcx
.at
(
DUMMY_SP
)
.mk_trait_ref
(
LangItem
::
Sized
,
[
output
]));
let
(
_
,
output_is_sized_certainty
)
=
ecx
.evaluate_goal
(
goal
.with
(
tcx
,
output_is_sized_pred
))
?
;
let
pred
=
tupled_inputs_and_output
.map_bound
(|(
inputs
,
output
)|
ty
::
ProjectionPredicate
{
projection_ty
:
ecx
.tcx
()
projection_ty
:
tcx
.mk_alias_ty
(
goal
.predicate
.def_id
(),
[
goal
.predicate
.self_ty
(),
inputs
]),
term
:
output
.into
(),
})
.to_predicate
(
ecx
.tcx
()
);
Self
::
consider_assumption
(
ecx
,
goal
,
pred
)
.to_predicate
(
tcx
);
Self
::
consider_assumption
_with_certainty
(
ecx
,
goal
,
pred
,
output_is_sized_certainty
)
}
else
{
ecx
.make_canonical_response
(
Certainty
::
AMBIGUOUS
)
}
...
...
compiler/rustc_trait_selection/src/solve/trait_goals.rs
浏览文件 @
82b52056
...
...
@@ -6,6 +6,7 @@
use
super
::
infcx_ext
::
InferCtxtExt
;
use
super
::{
CanonicalResponse
,
Certainty
,
EvalCtxt
,
Goal
,
QueryResult
};
use
rustc_hir
::
def_id
::
DefId
;
use
rustc_hir
::
LangItem
;
use
rustc_infer
::
infer
::
InferCtxt
;
use
rustc_infer
::
traits
::
query
::
NoSolution
;
use
rustc_infer
::
traits
::
util
::
supertraits
;
...
...
@@ -61,10 +62,11 @@ fn consider_impl_candidate(
})
}
fn
consider_assumption
(
fn
consider_assumption
_with_certainty
(
ecx
:
&
mut
EvalCtxt
<
'_
,
'tcx
>
,
goal
:
Goal
<
'tcx
,
Self
>
,
assumption
:
ty
::
Predicate
<
'tcx
>
,
assumption_certainty
:
Certainty
,
)
->
QueryResult
<
'tcx
>
{
if
let
Some
(
poly_trait_pred
)
=
assumption
.to_opt_poly_trait_pred
()
&&
poly_trait_pred
.def_id
()
==
goal
.predicate
.def_id
()
...
...
@@ -78,7 +80,9 @@ fn consider_assumption(
goal
.predicate.trait_ref
,
assumption_trait_pred
.trait_ref
,
)
?
;
ecx
.evaluate_all_and_make_canonical_response
(
nested_goals
)
ecx
.evaluate_all
(
nested_goals
)
.and_then
(|
certainty
|
{
ecx
.make_canonical_response
(
certainty
.unify_and
(
assumption_certainty
))
})
})
}
else
{
Err
(
NoSolution
)
...
...
@@ -173,20 +177,27 @@ fn consider_builtin_fn_trait_candidates(
goal
:
Goal
<
'tcx
,
Self
>
,
goal_kind
:
ty
::
ClosureKind
,
)
->
QueryResult
<
'tcx
>
{
let
tcx
=
ecx
.tcx
();
if
let
Some
(
tupled_inputs_and_output
)
=
structural_traits
::
extract_tupled_inputs_and_output_from_callable
(
ecx
.tcx
()
,
tcx
,
goal
.predicate
.self_ty
(),
goal_kind
,
)
?
{
// A built-in `Fn` trait needs to check that its output is `Sized`
// (FIXME: technically we only need to check this if the type is a fn ptr...)
let
output_is_sized_pred
=
tupled_inputs_and_output
.map_bound
(|(
_
,
output
)|
tcx
.at
(
DUMMY_SP
)
.mk_trait_ref
(
LangItem
::
Sized
,
[
output
]));
let
(
_
,
output_is_sized_certainty
)
=
ecx
.evaluate_goal
(
goal
.with
(
tcx
,
output_is_sized_pred
))
?
;
let
pred
=
tupled_inputs_and_output
.map_bound
(|(
inputs
,
_
)|
{
ecx
.tcx
()
.mk_trait_ref
(
goal
.predicate
.def_id
(),
[
goal
.predicate
.self_ty
(),
inputs
])
tcx
.mk_trait_ref
(
goal
.predicate
.def_id
(),
[
goal
.predicate
.self_ty
(),
inputs
])
})
.to_predicate
(
ecx
.tcx
()
);
Self
::
consider_assumption
(
ecx
,
goal
,
pred
)
.to_predicate
(
tcx
);
Self
::
consider_assumption
_with_certainty
(
ecx
,
goal
,
pred
,
output_is_sized_certainty
)
}
else
{
ecx
.make_canonical_response
(
Certainty
::
AMBIGUOUS
)
}
...
...
tests/ui/traits/new-solver/builtin-fn-must-return-sized.rs
0 → 100644
浏览文件 @
82b52056
// compile-flags: -Ztrait-solver=next
#![feature(fn_traits)]
#![feature(unboxed_closures)]
#![feature(tuple_trait)]
use
std
::
ops
::
Fn
;
use
std
::
marker
::
Tuple
;
fn
foo
<
F
:
Fn
<
T
>
,
T
:
Tuple
>
(
f
:
Option
<
F
>
,
t
:
T
)
{
let
y
=
(
f
.unwrap
())
.call
(
t
);
}
fn
main
()
{
foo
::
<
fn
()
->
str
,
_
>
(
None
,
());
//~^ expected a `Fn<_>` closure, found `fn() -> str`
}
tests/ui/traits/new-solver/builtin-fn-must-return-sized.stderr
0 → 100644
浏览文件 @
82b52056
error[E0277]: expected a `Fn<_>` closure, found `fn() -> str`
--> $DIR/builtin-fn-must-return-sized.rs:15:27
|
LL | foo::<fn() -> str, _>(None, ());
| --------------------- ^^^^ expected an `Fn<_>` closure, found `fn() -> str`
| |
| required by a bound introduced by this call
|
= help: the trait `Fn<_>` is not implemented for `fn() -> str`
note: required by a bound in `foo`
--> $DIR/builtin-fn-must-return-sized.rs:10:11
|
LL | fn foo<F: Fn<T>, T: Tuple>(f: Option<F>, t: T) {
| ^^^^^ required by this bound in `foo`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录