Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b87e8eae
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,发现更多精彩内容 >>
提交
b87e8eae
编写于
5月 10, 2020
作者:
M
Matthew Jasper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Check associated opaque types in check_opaque_types
上级
50c0192c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
58 addition
and
27 deletion
+58
-27
src/librustc_mir/borrow_check/type_check/free_region_relations.rs
...ustc_mir/borrow_check/type_check/free_region_relations.rs
+7
-1
src/librustc_typeck/check/wfcheck.rs
src/librustc_typeck/check/wfcheck.rs
+15
-8
src/test/ui/type-alias-impl-trait/impl-with-unconstrained-param.rs
...ui/type-alias-impl-trait/impl-with-unconstrained-param.rs
+18
-0
src/test/ui/type-alias-impl-trait/impl-with-unconstrained-param.stderr
...ype-alias-impl-trait/impl-with-unconstrained-param.stderr
+15
-0
src/test/ui/type-alias-impl-trait/issue-60564.rs
src/test/ui/type-alias-impl-trait/issue-60564.rs
+2
-5
src/test/ui/type-alias-impl-trait/issue-60564.stderr
src/test/ui/type-alias-impl-trait/issue-60564.stderr
+1
-13
未找到文件。
src/librustc_mir/borrow_check/type_check/free_region_relations.rs
浏览文件 @
b87e8eae
...
...
@@ -259,7 +259,13 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
.param_env
.and
(
type_op
::
normalize
::
Normalize
::
new
(
ty
))
.fully_perform
(
self
.infcx
)
.unwrap_or_else
(|
_
|
bug!
(
"failed to normalize {:?}"
,
ty
));
.unwrap_or_else
(|
_
|
{
self
.infcx
.tcx
.sess
.delay_span_bug
(
DUMMY_SP
,
&
format!
(
"failed to normalize {:?}"
,
ty
));
(
self
.infcx.tcx.types.err
,
None
)
});
let
constraints2
=
self
.add_implied_bounds
(
ty
);
normalized_inputs_and_output
.push
(
ty
);
constraints1
.into_iter
()
.chain
(
constraints2
)
...
...
src/librustc_typeck/check/wfcheck.rs
浏览文件 @
b87e8eae
...
...
@@ -806,7 +806,11 @@ fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> bool {
let
mut
predicates
=
predicates
.instantiate_identity
(
fcx
.tcx
);
if
let
Some
((
return_ty
,
span
))
=
return_ty
{
if
let
Some
((
mut
return_ty
,
span
))
=
return_ty
{
if
return_ty
.has_infer_types_or_consts
()
{
fcx
.select_obligations_where_possible
(
false
,
|
_
|
{});
return_ty
=
fcx
.resolve_vars_if_possible
(
&
return_ty
);
}
let
opaque_types
=
check_opaque_types
(
tcx
,
fcx
,
def_id
.expect_local
(),
span
,
return_ty
);
for
_
in
0
..
opaque_types
.len
()
{
predicates
.spans
.push
(
span
);
...
...
@@ -893,10 +897,16 @@ fn check_opaque_types<'fcx, 'tcx>(
trace!
(
"check_opaque_types: opaque_ty, {:?}, {:?}"
,
def_id
,
substs
);
let
generics
=
tcx
.generics_of
(
def_id
);
// Only check named `impl Trait` types defined in this crate.
// FIXME(eddyb) is `generics.parent.is_none()` correct? It seems
// potentially risky wrt associated types in `impl`s.
if
generics
.parent
.is_none
()
&&
def_id
.is_local
()
{
if
!
def_id
.is_local
()
{
return
ty
;
}
let
opaque_hir_id
=
tcx
.hir
()
.as_local_hir_id
(
def_id
.expect_local
());
if
let
hir
::
ItemKind
::
OpaqueTy
(
hir
::
OpaqueTy
{
impl_trait_fn
:
Some
(
_
),
..
})
=
tcx
.hir
()
.expect_item
(
opaque_hir_id
)
.kind
{
// Don't check return position impl trait.
return
ty
;
}
if
may_define_opaque_type
(
tcx
,
fn_def_id
,
opaque_hir_id
)
{
trace!
(
"check_opaque_types: may define, generics={:#?}"
,
generics
);
let
mut
seen_params
:
FxHashMap
<
_
,
Vec
<
_
>>
=
FxHashMap
::
default
();
...
...
@@ -924,9 +934,7 @@ fn check_opaque_types<'fcx, 'tcx>(
true
}
GenericArgKind
::
Const
(
ct
)
=>
{
matches!
(
ct
.val
,
ty
::
ConstKind
::
Param
(
_
))
}
GenericArgKind
::
Const
(
ct
)
=>
matches!
(
ct
.val
,
ty
::
ConstKind
::
Param
(
_
)),
};
if
arg_is_param
{
...
...
@@ -988,7 +996,6 @@ fn check_opaque_types<'fcx, 'tcx>(
substituted_predicates
.push
(
substituted_pred
);
}
}
}
// if is_named_opaque_type
}
// if let Opaque
ty
},
...
...
src/test/ui/type-alias-impl-trait/impl-with-unconstrained-param.rs
0 → 100644
浏览文件 @
b87e8eae
// Ensure that we don't ICE if associated type impl trait is used in an impl
// with an unconstrained type parameter.
#![feature(type_alias_impl_trait)]
trait
X
{
type
I
;
fn
f
()
->
Self
::
I
;
}
impl
<
T
>
X
for
()
{
type
I
=
impl
Sized
;
//~^ ERROR could not find defining uses
fn
f
()
->
Self
::
I
{}
//~^ ERROR type annotations needed
}
fn
main
()
{}
src/test/ui/type-alias-impl-trait/impl-with-unconstrained-param.stderr
0 → 100644
浏览文件 @
b87e8eae
error[E0282]: type annotations needed
--> $DIR/impl-with-unconstrained-param.rs:14:23
|
LL | fn f() -> Self::I {}
| ^^ cannot infer type for type parameter `T`
error: could not find defining uses
--> $DIR/impl-with-unconstrained-param.rs:12:14
|
LL | type I = impl Sized;
| ^^^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0282`.
src/test/ui/type-alias-impl-trait/issue-60564.rs
浏览文件 @
b87e8eae
...
...
@@ -17,11 +17,8 @@ impl<T: Copy, E> IterBits for T
{
type
BitsIter
=
IterBitsIter
<
T
,
E
,
u8
>
;
fn
iter_bits
(
self
,
n
:
u8
)
->
Self
::
BitsIter
{
//~^ ERROR non-defining opaque type use in defining scope
//~| ERROR non-defining opaque type use in defining scope
(
0u8
..
n
)
.rev
()
.map
(
move
|
shift
|
((
self
>>
T
::
from
(
shift
))
&
T
::
from
(
1
))
.try_into
()
.unwrap
())
//~^ ERROR non-defining opaque type use in defining scope
(
0u8
..
n
)
.rev
()
.map
(
move
|
shift
|
((
self
>>
T
::
from
(
shift
))
&
T
::
from
(
1
))
.try_into
()
.unwrap
())
}
}
...
...
src/test/ui/type-alias-impl-trait/issue-60564.stderr
浏览文件 @
b87e8eae
error: non-defining opaque type use in defining scope
--> $DIR/issue-60564.rs:19:34
|
LL | fn iter_bits(self, n: u8) -> Self::BitsIter {
| ^^^^^^^^^^^^^^
|
note: used non-generic type `_` for generic parameter
--> $DIR/issue-60564.rs:8:22
|
LL | type IterBitsIter<T, E, I> = impl std::iter::Iterator<Item = I>;
| ^
error: non-defining opaque type use in defining scope
--> $DIR/issue-60564.rs:19:34
|
...
...
@@ -22,5 +10,5 @@ note: used non-generic type `u8` for generic parameter
LL | type IterBitsIter<T, E, I> = impl std::iter::Iterator<Item = I>;
| ^
error: aborting due to
2 previous errors
error: aborting due to
previous error
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录