Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
eca0ead1
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,发现更多精彩内容 >>
提交
eca0ead1
编写于
3月 31, 2022
作者:
O
Oli Scherer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enforce well formedness for type alias impl trait's hidden type
上级
e50ff9b4
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
111 addition
and
2 deletion
+111
-2
compiler/rustc_typeck/src/check/check.rs
compiler/rustc_typeck/src/check/check.rs
+9
-1
compiler/rustc_typeck/src/check/regionck.rs
compiler/rustc_typeck/src/check/regionck.rs
+1
-1
src/test/ui/type-alias-impl-trait/underconstrained_generic.rs
...test/ui/type-alias-impl-trait/underconstrained_generic.rs
+28
-0
src/test/ui/type-alias-impl-trait/underconstrained_generic.stderr
.../ui/type-alias-impl-trait/underconstrained_generic.stderr
+19
-0
src/test/ui/type-alias-impl-trait/underconstrained_lifetime.rs
...est/ui/type-alias-impl-trait/underconstrained_lifetime.rs
+34
-0
src/test/ui/type-alias-impl-trait/underconstrained_lifetime.stderr
...ui/type-alias-impl-trait/underconstrained_lifetime.stderr
+20
-0
未找到文件。
compiler/rustc_typeck/src/check/check.rs
浏览文件 @
eca0ead1
...
...
@@ -12,12 +12,13 @@
use
rustc_hir
::{
def
::
Res
,
ItemKind
,
Node
,
PathSegment
};
use
rustc_infer
::
infer
::
type_variable
::{
TypeVariableOrigin
,
TypeVariableOriginKind
};
use
rustc_infer
::
infer
::{
RegionVariableOrigin
,
TyCtxtInferExt
};
use
rustc_infer
::
traits
::
Obligation
;
use
rustc_middle
::
hir
::
nested_filter
;
use
rustc_middle
::
ty
::
fold
::
TypeFoldable
;
use
rustc_middle
::
ty
::
layout
::{
LayoutError
,
MAX_SIMD_LANES
};
use
rustc_middle
::
ty
::
subst
::
GenericArgKind
;
use
rustc_middle
::
ty
::
util
::{
Discr
,
IntTypeExt
};
use
rustc_middle
::
ty
::{
self
,
ParamEnv
,
Ty
,
TyCtxt
};
use
rustc_middle
::
ty
::{
self
,
ParamEnv
,
T
oPredicate
,
T
y
,
TyCtxt
};
use
rustc_session
::
lint
::
builtin
::{
UNINHABITED_STATIC
,
UNSUPPORTED_CALLING_CONVENTIONS
};
use
rustc_span
::
symbol
::
sym
;
use
rustc_span
::{
self
,
MultiSpan
,
Span
};
...
...
@@ -674,6 +675,13 @@ fn check_opaque_meets_bounds<'tcx>(
}
}
// Additionally require the hidden type to be well-formed with only the generics of the opaque type.
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
// hidden type is well formed even without those bounds.
let
predicate
=
ty
::
Binder
::
dummy
(
ty
::
PredicateKind
::
WellFormed
(
hidden_type
.into
()))
.to_predicate
(
tcx
);
inh
.register_predicate
(
Obligation
::
new
(
misc_cause
,
param_env
,
predicate
));
// Check that all obligations are satisfied by the implementation's
// version.
let
errors
=
inh
.fulfillment_cx
.borrow_mut
()
.select_all_or_error
(
&
infcx
);
...
...
compiler/rustc_typeck/src/check/regionck.rs
浏览文件 @
eca0ead1
...
...
@@ -171,8 +171,8 @@ pub fn regionck_expr(&self, body: &'tcx hir::Body<'tcx>) {
/// Region checking during the WF phase for items. `wf_tys` are the
/// types from which we should derive implied bounds, if any.
#[instrument(level
=
"debug"
,
skip(self))]
pub
fn
regionck_item
(
&
self
,
item_id
:
hir
::
HirId
,
span
:
Span
,
wf_tys
:
FxHashSet
<
Ty
<
'tcx
>>
)
{
debug!
(
"regionck_item(item.id={:?}, wf_tys={:?})"
,
item_id
,
wf_tys
);
let
subject
=
self
.tcx
.hir
()
.local_def_id
(
item_id
);
let
mut
rcx
=
RegionCtxt
::
new
(
self
,
item_id
,
Subject
(
subject
),
self
.param_env
);
rcx
.outlives_environment
.add_implied_bounds
(
self
,
wf_tys
,
item_id
,
span
);
...
...
src/test/ui/type-alias-impl-trait/underconstrained_generic.rs
0 → 100644
浏览文件 @
eca0ead1
#![feature(type_alias_impl_trait)]
use
std
::
marker
::
PhantomData
;
trait
Trait
{
fn
foo
<
T
,
U
>
(
t
:
T
)
->
U
;
}
trait
ProofForConversion
<
X
>
{
fn
convert
<
T
,
U
>
(
_
:
PhantomData
<
Self
>
,
r
:
T
)
->
U
;
}
impl
<
X
:
Trait
>
ProofForConversion
<
X
>
for
()
{
fn
convert
<
T
,
U
>
(
_
:
PhantomData
<
Self
>
,
r
:
T
)
->
U
{
X
::
foo
(
r
)
}
}
type
Converter
<
T
>
=
impl
ProofForConversion
<
T
>
;
//~^ ERROR the trait bound `T: Trait` is not satisfied
fn
_
defining_use
<
T
:
Trait
>
()
->
Converter
<
T
>
{
()
}
fn
main
()
{
}
src/test/ui/type-alias-impl-trait/underconstrained_generic.stderr
0 → 100644
浏览文件 @
eca0ead1
error[E0277]: the trait bound `T: Trait` is not satisfied
--> $DIR/underconstrained_generic.rs:19:21
|
LL | type Converter<T> = impl ProofForConversion<T>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T`
|
note: required because of the requirements on the impl of `ProofForConversion<T>` for `()`
--> $DIR/underconstrained_generic.rs:13:16
|
LL | impl<X: Trait> ProofForConversion<X> for () {
| ^^^^^^^^^^^^^^^^^^^^^ ^^
help: consider restricting type parameter `T`
|
LL | type Converter<T: Trait> = impl ProofForConversion<T>;
| +++++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
src/test/ui/type-alias-impl-trait/underconstrained_lifetime.rs
0 → 100644
浏览文件 @
eca0ead1
#![feature(type_alias_impl_trait)]
use
std
::
marker
::
PhantomData
;
trait
ProofForConversion
<
'a
,
'b
>
{
fn
convert
<
T
:
?
Sized
>
(
_
:
PhantomData
<
Self
>
,
r
:
&
'a
T
)
->
&
'b
T
;
}
impl
<
'a
,
'b
>
ProofForConversion
<
'a
,
'b
>
for
&
'b
&
'a
()
{
fn
convert
<
T
:
?
Sized
>
(
_
:
PhantomData
<
Self
>
,
r
:
&
'a
T
)
->
&
'b
T
{
r
}
}
type
Converter
<
'a
,
'b
>
=
impl
ProofForConversion
<
'a
,
'b
>
;
//~^ ERROR reference has a longer lifetime than the data it references
// Even _defining_use with an explicit `'a: 'b` compiles fine, too.
fn
_
defining_use
<
'a
,
'b
>
(
x
:
&
'b
&
'a
())
->
Converter
<
'a
,
'b
>
{
x
}
fn
extend_lifetime
<
'a
,
'b
,
T
:
?
Sized
>
(
x
:
&
'a
T
)
->
&
'b
T
{
Converter
::
<
'a
,
'b
>
::
convert
(
PhantomData
,
x
)
}
fn
main
()
{
let
d
;
{
let
x
=
"Hello World"
.to_string
();
d
=
extend_lifetime
(
&
x
);
}
println!
(
"{}"
,
d
);
}
src/test/ui/type-alias-impl-trait/underconstrained_lifetime.stderr
0 → 100644
浏览文件 @
eca0ead1
error[E0491]: in type `&'b &'a ()`, reference has a longer lifetime than the data it references
--> $DIR/underconstrained_lifetime.rs:15:26
|
LL | type Converter<'a, 'b> = impl ProofForConversion<'a, 'b>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the pointer is valid for the lifetime `'b` as defined here
--> $DIR/underconstrained_lifetime.rs:15:20
|
LL | type Converter<'a, 'b> = impl ProofForConversion<'a, 'b>;
| ^^
note: but the referenced data is only valid for the lifetime `'a` as defined here
--> $DIR/underconstrained_lifetime.rs:15:16
|
LL | type Converter<'a, 'b> = impl ProofForConversion<'a, 'b>;
| ^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0491`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录