Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7294f49d
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,发现更多精彩内容 >>
未验证
提交
7294f49d
编写于
6月 07, 2021
作者:
S
Santiago Pastorino
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove ResolvedOpaqueTy and just use Ty, SubstsRef is already there
上级
7f8cad20
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
40 addition
and
69 deletion
+40
-69
compiler/rustc_middle/src/mir/query.rs
compiler/rustc_middle/src/mir/query.rs
+1
-1
compiler/rustc_middle/src/ty/context.rs
compiler/rustc_middle/src/ty/context.rs
+1
-12
compiler/rustc_middle/src/ty/mod.rs
compiler/rustc_middle/src/ty/mod.rs
+1
-1
compiler/rustc_mir/src/borrow_check/nll.rs
compiler/rustc_mir/src/borrow_check/nll.rs
+3
-3
compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs
...r/rustc_mir/src/borrow_check/region_infer/opaque_types.rs
+6
-8
compiler/rustc_mir/src/borrow_check/type_check/mod.rs
compiler/rustc_mir/src/borrow_check/type_check/mod.rs
+9
-16
compiler/rustc_typeck/src/check/writeback.rs
compiler/rustc_typeck/src/check/writeback.rs
+7
-10
compiler/rustc_typeck/src/collect/type_of.rs
compiler/rustc_typeck/src/collect/type_of.rs
+12
-18
未找到文件。
compiler/rustc_middle/src/mir/query.rs
浏览文件 @
7294f49d
...
...
@@ -211,7 +211,7 @@ pub struct BorrowCheckResult<'tcx> {
/// All the opaque types that are restricted to concrete types
/// by this function. Unlike the value in `TypeckResults`, this has
/// unerased regions.
pub
concrete_opaque_types
:
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
ty
::
ResolvedOpaque
Ty
<
'tcx
>>
,
pub
concrete_opaque_types
:
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
Ty
<
'tcx
>>
,
pub
closure_requirements
:
Option
<
ClosureRegionRequirements
<
'tcx
>>
,
pub
used_mut_upvars
:
SmallVec
<
[
Field
;
8
]
>
,
}
...
...
compiler/rustc_middle/src/ty/context.rs
浏览文件 @
7294f49d
...
...
@@ -288,17 +288,6 @@ pub fn remove(&mut self, id: hir::HirId) -> Option<V> {
}
}
/// All information necessary to validate and reveal an `impl Trait`.
#[derive(TyEncodable,
TyDecodable,
Debug,
HashStable)]
pub
struct
ResolvedOpaqueTy
<
'tcx
>
{
/// The revealed type as seen by this function.
pub
concrete_type
:
Ty
<
'tcx
>
,
/// Generic parameters on the opaque type as passed by this function.
/// For `type Foo<A, B> = impl Bar<A, B>; fn foo<T, U>() -> Foo<T, U> { .. }`
/// this is `[T, U]`, not `[A, B]`.
pub
substs
:
SubstsRef
<
'tcx
>
,
}
/// Whenever a value may be live across a generator yield, the type of that value winds up in the
/// `GeneratorInteriorTypeCause` struct. This struct adds additional information about such
/// captured types that can be useful for diagnostics. In particular, it stores the span that
...
...
@@ -426,7 +415,7 @@ pub struct TypeckResults<'tcx> {
/// All the opaque types that are restricted to concrete types
/// by this function.
pub
concrete_opaque_types
:
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
ResolvedOpaque
Ty
<
'tcx
>>
,
pub
concrete_opaque_types
:
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
Ty
<
'tcx
>>
,
/// Tracks the minimum captures required for a closure;
/// see `MinCaptureInformationMap` for more details.
...
...
compiler/rustc_middle/src/ty/mod.rs
浏览文件 @
7294f49d
...
...
@@ -58,7 +58,7 @@
pub
use
self
::
context
::{
tls
,
CanonicalUserType
,
CanonicalUserTypeAnnotation
,
CanonicalUserTypeAnnotations
,
CtxtInterners
,
DelaySpanBugEmitted
,
FreeRegionInfo
,
GeneratorInteriorTypeCause
,
GlobalCtxt
,
Lift
,
ResolvedOpaqueTy
,
TyCtxt
,
TypeckResults
,
UserType
,
UserTypeAnnotationIndex
,
Lift
,
TyCtxt
,
TypeckResults
,
UserType
,
UserTypeAnnotationIndex
,
};
pub
use
self
::
instance
::{
Instance
,
InstanceDef
};
pub
use
self
::
list
::
List
;
...
...
compiler/rustc_mir/src/borrow_check/nll.rs
浏览文件 @
7294f49d
...
...
@@ -8,7 +8,7 @@
BasicBlock
,
Body
,
ClosureOutlivesSubject
,
ClosureRegionRequirements
,
LocalKind
,
Location
,
Promoted
,
};
use
rustc_middle
::
ty
::{
self
,
OpaqueTypeKey
,
RegionKind
,
RegionVid
};
use
rustc_middle
::
ty
::{
self
,
OpaqueTypeKey
,
RegionKind
,
RegionVid
,
Ty
};
use
rustc_span
::
symbol
::
sym
;
use
std
::
env
;
use
std
::
fmt
::
Debug
;
...
...
@@ -46,7 +46,7 @@
/// closure requirements to propagate, and any generated errors.
crate
struct
NllOutput
<
'tcx
>
{
pub
regioncx
:
RegionInferenceContext
<
'tcx
>
,
pub
opaque_type_values
:
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
ty
::
ResolvedOpaque
Ty
<
'tcx
>>
,
pub
opaque_type_values
:
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
Ty
<
'tcx
>>
,
pub
polonius_output
:
Option
<
Rc
<
PoloniusOutput
>>
,
pub
opt_closure_req
:
Option
<
ClosureRegionRequirements
<
'tcx
>>
,
pub
nll_errors
:
RegionErrors
<
'tcx
>
,
...
...
@@ -366,7 +366,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
body
:
&
Body
<
'tcx
>
,
regioncx
:
&
RegionInferenceContext
<
'tcx
>
,
closure_region_requirements
:
&
Option
<
ClosureRegionRequirements
<
'_
>>
,
opaque_type_values
:
&
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
ty
::
ResolvedOpaque
Ty
<
'tcx
>>
,
opaque_type_values
:
&
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
Ty
<
'tcx
>>
,
errors_buffer
:
&
mut
Vec
<
Diagnostic
>
,
)
{
let
tcx
=
infcx
.tcx
;
...
...
compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs
浏览文件 @
7294f49d
use
rustc_data_structures
::
vec_map
::
VecMap
;
use
rustc_infer
::
infer
::
InferCtxt
;
use
rustc_middle
::
ty
::{
self
,
OpaqueTypeKey
,
TyCtxt
,
TypeFoldable
};
use
rustc_middle
::
ty
::{
self
,
OpaqueTypeKey
,
Ty
,
Ty
Ctxt
,
TypeFoldable
};
use
rustc_span
::
Span
;
use
rustc_trait_selection
::
opaque_types
::
InferCtxtExt
;
...
...
@@ -50,12 +50,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
pub
(
in
crate
::
borrow_check
)
fn
infer_opaque_types
(
&
self
,
infcx
:
&
InferCtxt
<
'_
,
'tcx
>
,
opaque_ty_decls
:
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
ty
::
ResolvedOpaque
Ty
<
'tcx
>>
,
opaque_ty_decls
:
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
Ty
<
'tcx
>>
,
span
:
Span
,
)
->
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
ty
::
ResolvedOpaque
Ty
<
'tcx
>>
{
)
->
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
Ty
<
'tcx
>>
{
opaque_ty_decls
.into_iter
()
.map
(|(
opaque_type_key
,
ty
::
ResolvedOpaqueTy
{
concrete_type
,
substs
})|
{
.map
(|(
opaque_type_key
,
concrete_type
)|
{
let
substs
=
opaque_type_key
.substs
;
debug!
(
?
concrete_type
,
?
substs
);
let
mut
subst_regions
=
vec!
[
self
.universal_regions.fr_static
];
...
...
@@ -116,10 +117,7 @@ pub(in crate::borrow_check) fn infer_opaque_types(
universal_concrete_type
,
span
,
);
(
opaque_type_key
,
ty
::
ResolvedOpaqueTy
{
concrete_type
:
remapped_type
,
substs
:
universal_substs
},
)
(
opaque_type_key
,
remapped_type
)
})
.collect
()
}
...
...
compiler/rustc_mir/src/borrow_check/type_check/mod.rs
浏览文件 @
7294f49d
...
...
@@ -819,7 +819,7 @@ struct TypeChecker<'a, 'tcx> {
reported_errors
:
FxHashSet
<
(
Ty
<
'tcx
>
,
Span
)
>
,
borrowck_context
:
&
'a
mut
BorrowCheckContext
<
'a
,
'tcx
>
,
universal_region_relations
:
&
'a
UniversalRegionRelations
<
'tcx
>
,
opaque_type_values
:
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
ty
::
ResolvedOpaque
Ty
<
'tcx
>>
,
opaque_type_values
:
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
Ty
<
'tcx
>>
,
}
struct
BorrowCheckContext
<
'a
,
'tcx
>
{
...
...
@@ -834,7 +834,7 @@ struct BorrowCheckContext<'a, 'tcx> {
crate
struct
MirTypeckResults
<
'tcx
>
{
crate
constraints
:
MirTypeckRegionConstraints
<
'tcx
>
,
pub
(
in
crate
::
borrow_check
)
universal_region_relations
:
Frozen
<
UniversalRegionRelations
<
'tcx
>>
,
crate
opaque_type_values
:
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
ty
::
ResolvedOpaque
Ty
<
'tcx
>>
,
crate
opaque_type_values
:
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
Ty
<
'tcx
>>
,
}
/// A collection of region constraints that must be satisfied for the
...
...
@@ -1292,10 +1292,10 @@ fn eq_opaque_type_and_type(
let
opaque_type_key
=
OpaqueTypeKey
{
def_id
:
opaque_def_id
,
substs
:
opaque_decl
.substs
};
let
opaque_defn
_ty
=
match
concrete_opaque_types
let
concrete
_ty
=
match
concrete_opaque_types
.iter
()
.find
(|(
opaque_type_key
,
_
)|
opaque_type_key
.def_id
==
opaque_def_id
)
.map
(|(
_
,
resolved_opaque_ty
)|
resolved_opaqu
e_ty
)
.map
(|(
_
,
concrete_ty
)|
concret
e_ty
)
{
None
=>
{
if
!
concrete_is_opaque
{
...
...
@@ -1309,17 +1309,16 @@ fn eq_opaque_type_and_type(
}
continue
;
}
Some
(
opaque_defn_ty
)
=>
opaque_defn
_ty
,
Some
(
concrete_ty
)
=>
concrete
_ty
,
};
debug!
(
"opaque_defn_ty = {:?}"
,
opaque_defn_ty
);
let
subst_opaque_defn_ty
=
opaque_defn_ty
.concrete_type
.subst
(
tcx
,
opaque_decl
.substs
);
debug!
(
"concrete_ty = {:?}"
,
concrete_ty
);
let
subst_opaque_defn_ty
=
concrete_ty
.subst
(
tcx
,
opaque_decl
.substs
);
let
renumbered_opaque_defn_ty
=
renumber
::
renumber_regions
(
infcx
,
subst_opaque_defn_ty
);
debug!
(
"eq_opaque_type_and_type: concrete_ty={:?}={:?} opaque_defn_ty={:?}"
,
opaque_decl
.
concrete_ty
,
resolved_ty
,
renumbered_opaque_defn_ty
,
concrete_ty
,
resolved_ty
,
renumbered_opaque_defn_ty
,
);
if
!
concrete_is_opaque
{
...
...
@@ -1330,13 +1329,7 @@ fn eq_opaque_type_and_type(
.at
(
&
ObligationCause
::
dummy
(),
param_env
)
.eq
(
opaque_decl
.concrete_ty
,
renumbered_opaque_defn_ty
)
?
,
);
opaque_type_values
.insert
(
opaque_type_key
,
ty
::
ResolvedOpaqueTy
{
concrete_type
:
renumbered_opaque_defn_ty
,
substs
:
opaque_decl
.substs
,
},
);
opaque_type_values
.insert
(
opaque_type_key
,
renumbered_opaque_defn_ty
);
}
else
{
// We're using an opaque `impl Trait` type without
// 'revealing' it. For example, code like this:
...
...
compiler/rustc_typeck/src/check/writeback.rs
浏览文件 @
7294f49d
...
...
@@ -522,16 +522,13 @@ fn visit_opaque_types(&mut self, span: Span) {
// in some other location, or we'll end up emitting an error due
// to the lack of defining usage
if
!
skip_add
{
let
new
=
ty
::
ResolvedOpaqueTy
{
concrete_type
:
definition_ty
,
substs
:
opaque_defn
.substs
,
};
let
opaque_type_key
=
OpaqueTypeKey
{
def_id
,
substs
:
opaque_defn
.substs
};
let
old
=
self
.typeck_results.concrete_opaque_types
.insert
(
opaque_type_key
,
new
);
if
let
Some
(
old
)
=
old
{
if
old
.concrete_type
!=
definition_ty
||
old
.substs
!=
opaque_defn
.substs
{
let
old_concrete_ty
=
self
.typeck_results
.concrete_opaque_types
.insert
(
opaque_type_key
,
definition_ty
);
if
let
Some
(
old_concrete_ty
)
=
old_concrete_ty
{
if
old_concrete_ty
!=
definition_ty
{
span_bug!
(
span
,
"`visit_opaque_types` tried to write different types for the same
\
...
...
@@ -539,7 +536,7 @@ fn visit_opaque_types(&mut self, span: Span) {
def_id
,
definition_ty
,
opaque_defn
,
old
,
old
_concrete_ty
,
);
}
}
...
...
compiler/rustc_typeck/src/collect/type_of.rs
浏览文件 @
7294f49d
...
...
@@ -10,9 +10,7 @@
use
rustc_middle
::
hir
::
map
::
Map
;
use
rustc_middle
::
ty
::
subst
::{
GenericArgKind
,
InternalSubsts
};
use
rustc_middle
::
ty
::
util
::
IntTypeExt
;
use
rustc_middle
::
ty
::{
self
,
DefIdTree
,
OpaqueTypeKey
,
ResolvedOpaqueTy
,
Ty
,
TyCtxt
,
TypeFoldable
,
};
use
rustc_middle
::
ty
::{
self
,
DefIdTree
,
OpaqueTypeKey
,
Ty
,
TyCtxt
,
TypeFoldable
};
use
rustc_span
::
symbol
::
Ident
;
use
rustc_span
::{
Span
,
DUMMY_SP
};
...
...
@@ -353,7 +351,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
&
tcx
.mir_borrowck
(
owner
.expect_local
())
.concrete_opaque_types
,
def_id
.to_def_id
(),
)
.map
(|
opaque
|
opaque
.concrete_type
)
.map
(|
&
(
_
,
concrete_ty
)|
concrete_ty
)
.unwrap_or_else
(||
{
tcx
.sess
.delay_span_bug
(
DUMMY_SP
,
...
...
@@ -531,14 +529,13 @@ fn check(&mut self, def_id: LocalDefId) {
return
;
}
// Use borrowck to get the type with unerased regions.
let
ty
=
find_concrete_ty_from_def_id
(
&
self
.tcx
.mir_borrowck
(
def_id
)
.concrete_opaque_types
,
self
.def_id
,
);
if
let
Some
(
ty
::
ResolvedOpaqueTy
{
concrete_type
,
substs
})
=
ty
{
let
concrete_opaque_types
=
&
self
.tcx
.mir_borrowck
(
def_id
)
.concrete_opaque_types
;
if
let
Some
((
opaque_type_key
,
concrete_type
))
=
find_concrete_ty_from_def_id
(
concrete_opaque_types
,
self
.def_id
)
{
debug!
(
"find_opaque_ty_constraints: found constraint for `{:?}` at `{:?}`: {:?}"
,
self
.def_id
,
def_id
,
ty
,
self
.def_id
,
def_id
,
concrete_type
,
);
// FIXME(oli-obk): trace the actual span from inference to improve errors.
...
...
@@ -549,7 +546,7 @@ fn check(&mut self, def_id: LocalDefId) {
// using `delay_span_bug`, just in case `wfcheck` slips up.
let
opaque_generics
=
self
.tcx
.generics_of
(
self
.def_id
);
let
mut
used_params
:
FxHashSet
<
_
>
=
FxHashSet
::
default
();
for
(
i
,
arg
)
in
substs
.iter
()
.enumerate
()
{
for
(
i
,
arg
)
in
opaque_type_key
.
substs
.iter
()
.enumerate
()
{
let
arg_is_param
=
match
arg
.unpack
()
{
GenericArgKind
::
Type
(
ty
)
=>
matches!
(
ty
.kind
(),
ty
::
Param
(
_
)),
GenericArgKind
::
Lifetime
(
lt
)
=>
{
...
...
@@ -710,7 +707,7 @@ fn let_position_impl_trait_type(tcx: TyCtxt<'_>, opaque_ty_id: LocalDefId) -> Ty
let
owner_typeck_results
=
tcx
.typeck
(
scope_def_id
);
let
concrete_ty
=
find_concrete_ty_from_def_id
(
&
owner_typeck_results
.concrete_opaque_types
,
opaque_ty_def_id
)
.map
(|
opaque
|
opaque
.concrete_type
)
.map
(|
&
(
_
,
concrete_ty
)|
concrete_ty
)
.unwrap_or_else
(||
{
tcx
.sess
.delay_span_bug
(
DUMMY_SP
,
...
...
@@ -808,11 +805,8 @@ fn check_feature_inherent_assoc_ty(tcx: TyCtxt<'_>, span: Span) {
}
fn
find_concrete_ty_from_def_id
<
'tcx
>
(
concrete_opaque_types
:
&
'tcx
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
ResolvedOpaque
Ty
<
'tcx
>>
,
concrete_opaque_types
:
&
'tcx
VecMap
<
OpaqueTypeKey
<
'tcx
>
,
Ty
<
'tcx
>>
,
def_id
:
DefId
,
)
->
Option
<&
'tcx
ResolvedOpaqueTy
<
'tcx
>>
{
concrete_opaque_types
.iter
()
.find
(|(
opaque_type_key
,
_
)|
opaque_type_key
.def_id
==
def_id
)
.map
(|(
_
,
resolved_opaque_ty
)|
resolved_opaque_ty
)
)
->
Option
<&
'tcx
(
OpaqueTypeKey
<
'tcx
>
,
Ty
<
'tcx
>
)
>
{
concrete_opaque_types
.iter
()
.find
(|(
opaque_type_key
,
_
)|
opaque_type_key
.def_id
==
def_id
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录