Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ed871cb3
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,发现更多精彩内容 >>
提交
ed871cb3
编写于
1月 06, 2019
作者:
M
Matthew Jasper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use a struct for user type annotations
上级
5ca6bd50
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
70 addition
and
31 deletion
+70
-31
src/librustc/ich/impls_ty.rs
src/librustc/ich/impls_ty.rs
+6
-0
src/librustc/mir/mod.rs
src/librustc/mir/mod.rs
+1
-1
src/librustc/mir/visit.rs
src/librustc/mir/visit.rs
+10
-7
src/librustc/ty/context.rs
src/librustc/ty/context.rs
+21
-1
src/librustc/ty/mod.rs
src/librustc/ty/mod.rs
+1
-1
src/librustc_mir/borrow_check/nll/renumber.rs
src/librustc_mir/borrow_check/nll/renumber.rs
+3
-4
src/librustc_mir/borrow_check/nll/type_check/mod.rs
src/librustc_mir/borrow_check/nll/type_check/mod.rs
+5
-4
src/librustc_mir/build/expr/as_constant.rs
src/librustc_mir/build/expr/as_constant.rs
+5
-1
src/librustc_mir/build/expr/as_place.rs
src/librustc_mir/build/expr/as_place.rs
+3
-3
src/librustc_mir/build/expr/as_rvalue.rs
src/librustc_mir/build/expr/as_rvalue.rs
+5
-2
src/librustc_mir/build/matches/mod.rs
src/librustc_mir/build/matches/mod.rs
+5
-2
src/librustc_mir/hair/pattern/mod.rs
src/librustc_mir/hair/pattern/mod.rs
+3
-3
src/librustc_mir/util/pretty.rs
src/librustc_mir/util/pretty.rs
+2
-2
未找到文件。
src/librustc/ich/impls_ty.rs
浏览文件 @
ed871cb3
...
...
@@ -1240,6 +1240,12 @@ impl<'tcx, G> for struct traits::InEnvironment<'tcx, G> {
}
);
impl_stable_hash_for!
(
struct
ty
::
CanonicalUserTypeAnnotation
<
'tcx
>
{
user_ty
,
span
}
);
impl
<
'a
,
'gcx
>
HashStable
<
StableHashingContext
<
'a
>>
for
ty
::
UserType
<
'gcx
>
{
fn
hash_stable
<
W
:
StableHasherResult
>
(
&
self
,
hcx
:
&
mut
StableHashingContext
<
'a
>
,
...
...
src/librustc/mir/mod.rs
浏览文件 @
ed871cb3
...
...
@@ -31,7 +31,7 @@
use
ty
::
layout
::
VariantIdx
;
use
ty
::{
self
,
AdtDef
,
CanonicalUserTypeAnnotations
,
ClosureSubsts
,
GeneratorSubsts
,
Region
,
Ty
,
TyCtxt
,
UserTypeAnnotationIndex
,
UserType
,
UserTypeAnnotationIndex
,
};
use
util
::
ppaux
;
...
...
src/librustc/mir/visit.rs
浏览文件 @
ed871cb3
use
hir
::
def_id
::
DefId
;
use
infer
::
canonical
::
Canonical
;
use
ty
::
subst
::
Substs
;
use
ty
::{
ClosureSubsts
,
GeneratorSubsts
,
Region
,
Ty
};
use
ty
::{
C
anonicalUserTypeAnnotation
,
C
losureSubsts
,
GeneratorSubsts
,
Region
,
Ty
};
use
mir
::
*
;
use
syntax_pos
::
Span
;
...
...
@@ -221,7 +220,7 @@ fn visit_user_type_projection(
fn
visit_user_type_annotation
(
&
mut
self
,
index
:
UserTypeAnnotationIndex
,
ty
:
&
$
(
$mutability
)
*
Canonical
<
'tcx
,
UserType
<
'tcx
>
>
,
ty
:
&
$
(
$mutability
)
*
Canonical
UserTypeAnnotation
<
'tcx
>
,
)
{
self
.super_user_type_annotation
(
index
,
ty
);
}
...
...
@@ -309,12 +308,15 @@ fn super_mir(&mut self,
self
.visit_local_decl
(
local
,
&
$
(
$mutability
)
*
mir
.local_decls
[
local
]);
}
for
index
in
mir
.user_type_annotations
.indices
()
{
let
(
span
,
annotation
)
=
&
$
(
$mutability
)
*
mir
.user_type_annotations
[
index
];
macro_rules!
type_annotations
{
(
mut
)
=>
(
mir
.user_type_annotations
.iter_enumerated_mut
());
()
=>
(
mir
.user_type_annotations
.iter_enumerated
());
};
for
(
index
,
annotation
)
in
type_annotations!
(
$
(
$mutability
)
*
)
{
self
.visit_user_type_annotation
(
index
,
annotation
);
self
.visit_span
(
span
);
}
self
.visit_span
(
&
$
(
$mutability
)
*
mir
.span
);
...
...
@@ -882,8 +884,9 @@ fn super_user_type_projection(
fn
super_user_type_annotation
(
&
mut
self
,
_
index
:
UserTypeAnnotationIndex
,
_
ty
:
&
$
(
$mutability
)
*
Canonical
<
'tcx
,
UserType
<
'tcx
>
>
,
ty
:
&
$
(
$mutability
)
*
CanonicalUserTypeAnnotation
<
'tcx
>
,
)
{
self
.visit_span
(
&
$
(
$mutability
)
*
ty
.span
);
}
fn
super_ty
(
&
mut
self
,
_
ty
:
&
$
(
$mutability
)
*
Ty
<
'tcx
>
)
{
...
...
src/librustc/ty/context.rs
浏览文件 @
ed871cb3
...
...
@@ -807,7 +807,27 @@ pub struct UserTypeAnnotationIndex {
/// Mapping of type annotation indices to canonical user type annotations.
pub
type
CanonicalUserTypeAnnotations
<
'tcx
>
=
IndexVec
<
UserTypeAnnotationIndex
,
(
Span
,
CanonicalUserType
<
'tcx
>
)
>
;
IndexVec
<
UserTypeAnnotationIndex
,
CanonicalUserTypeAnnotation
<
'tcx
>>
;
#[derive(Copy,
Clone,
Debug,
PartialEq,
Eq,
Hash,
RustcEncodable,
RustcDecodable)]
pub
struct
CanonicalUserTypeAnnotation
<
'tcx
>
{
pub
user_ty
:
CanonicalUserType
<
'tcx
>
,
pub
span
:
Span
,
}
BraceStructTypeFoldableImpl!
{
impl
<
'tcx
>
TypeFoldable
<
'tcx
>
for
CanonicalUserTypeAnnotation
<
'tcx
>
{
user_ty
,
span
}
}
BraceStructLiftImpl!
{
impl
<
'a
,
'tcx
>
Lift
<
'tcx
>
for
CanonicalUserTypeAnnotation
<
'a
>
{
type
Lifted
=
CanonicalUserTypeAnnotation
<
'tcx
>
;
user_ty
,
span
}
}
/// Canonicalized user type annotation.
pub
type
CanonicalUserType
<
'gcx
>
=
Canonical
<
'gcx
,
UserType
<
'gcx
>>
;
...
...
src/librustc/ty/mod.rs
浏览文件 @
ed871cb3
...
...
@@ -74,7 +74,7 @@
pub
use
self
::
context
::{
Lift
,
TypeckTables
,
CtxtInterners
};
pub
use
self
::
context
::{
UserTypeAnnotationIndex
,
UserType
,
CanonicalUserType
,
CanonicalUserTypeAnnotations
,
CanonicalUserTypeAnnotation
,
CanonicalUserTypeAnnotation
s
,
};
pub
use
self
::
instance
::{
Instance
,
InstanceDef
};
...
...
src/librustc_mir/borrow_check/nll/renumber.rs
浏览文件 @
ed871cb3
use
rustc
::
infer
::
canonical
::
Canonical
;
use
rustc
::
ty
::
subst
::
Substs
;
use
rustc
::
ty
::{
self
,
ClosureSubsts
,
GeneratorSubsts
,
Ty
,
TypeFoldable
,
UserType
,
UserTypeAnnotationIndex
,
self
,
ClosureSubsts
,
GeneratorSubsts
,
Ty
,
TypeFoldable
,
UserTypeAnnotationIndex
,
CanonicalUserTypeAnnotation
};
use
rustc
::
mir
::{
Location
,
Mir
};
use
rustc
::
mir
::
visit
::{
MutVisitor
,
TyContext
};
...
...
@@ -62,7 +61,7 @@ fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
fn
visit_user_type_annotation
(
&
mut
self
,
_
index
:
UserTypeAnnotationIndex
,
_
ty
:
&
mut
Canonical
<
'tcx
,
UserType
<
'tcx
>>
,
_
ty
:
&
mut
Canonical
UserTypeAnnotation
,
)
{
// User type annotations represent the types that the user
// wrote in the progarm. We don't want to erase the regions
...
...
src/librustc_mir/borrow_check/nll/type_check/mod.rs
浏览文件 @
ed871cb3
...
...
@@ -38,7 +38,7 @@
use
rustc
::
ty
::
subst
::{
Subst
,
Substs
,
UnpackedKind
};
use
rustc
::
ty
::{
self
,
RegionVid
,
ToPolyTraitRef
,
Ty
,
TyCtxt
,
TyKind
,
UserType
,
UserTypeAnnotationIndex
,
CanonicalUserTypeAnnotation
,
UserTypeAnnotationIndex
,
};
use
rustc_data_structures
::
fx
::{
FxHashMap
,
FxHashSet
};
use
rustc_data_structures
::
indexed_vec
::{
IndexVec
,
Idx
};
...
...
@@ -920,13 +920,14 @@ fn instantiate_user_type_annotations(&mut self) {
self
.mir.user_type_annotations
);
for
annotation_index
in
self
.mir.user_type_annotations
.indices
()
{
let
(
span
,
canonical_annotation
)
=
&
self
.mir.user_type_annotations
[
annotation_index
];
let
CanonicalUserTypeAnnotation
{
span
,
ref
user_ty
}
=
self
.mir.user_type_annotations
[
annotation_index
];
let
(
mut
annotation
,
_
)
=
self
.infcx
.instantiate_canonical_with_fresh_inference_vars
(
*
span
,
&
canonical_annotation
span
,
user_ty
);
match
annotation
{
UserType
::
Ty
(
ref
mut
ty
)
=>
*
ty
=
self
.normalize
(
ty
,
Locations
::
All
(
*
span
)),
*
ty
=
self
.normalize
(
ty
,
Locations
::
All
(
span
)),
_
=>
{},
}
self
.instantiated_type_annotations
.insert
(
annotation_index
,
annotation
);
...
...
src/librustc_mir/build/expr/as_constant.rs
浏览文件 @
ed871cb3
...
...
@@ -3,6 +3,7 @@
use
build
::
Builder
;
use
hair
::
*
;
use
rustc
::
mir
::
*
;
use
rustc
::
ty
::
CanonicalUserTypeAnnotation
;
impl
<
'a
,
'gcx
,
'tcx
>
Builder
<
'a
,
'gcx
,
'tcx
>
{
/// Compile `expr`, yielding a compile-time constant. Assumes that
...
...
@@ -31,7 +32,10 @@ fn expr_as_constant(&mut self, expr: Expr<'tcx>) -> Constant<'tcx> {
}
=>
this
.as_constant
(
value
),
ExprKind
::
Literal
{
literal
,
user_ty
}
=>
{
let
user_ty
=
user_ty
.map
(|
ty
|
{
this
.canonical_user_type_annotations
.push
((
span
,
ty
))
this
.canonical_user_type_annotations
.push
(
CanonicalUserTypeAnnotation
{
span
,
user_ty
:
ty
,
})
});
Constant
{
span
,
...
...
src/librustc_mir/build/expr/as_place.rs
浏览文件 @
ed871cb3
...
...
@@ -6,7 +6,7 @@
use
hair
::
*
;
use
rustc
::
mir
::
interpret
::
EvalErrorKind
::
BoundsCheck
;
use
rustc
::
mir
::
*
;
use
rustc
::
ty
::
Variance
;
use
rustc
::
ty
::
{
CanonicalUserTypeAnnotation
,
Variance
}
;
use
rustc_data_structures
::
indexed_vec
::
Idx
;
...
...
@@ -134,7 +134,7 @@ fn expr_as_place(
let
place
=
unpack!
(
block
=
this
.as_place
(
block
,
source
));
if
let
Some
(
user_ty
)
=
user_ty
{
let
annotation_index
=
this
.canonical_user_type_annotations
.push
(
(
source_info
.span
,
user_ty
)
CanonicalUserTypeAnnotation
{
span
:
source_info
.span
,
user_ty
}
);
this
.cfg
.push
(
block
,
...
...
@@ -157,7 +157,7 @@ fn expr_as_place(
);
if
let
Some
(
user_ty
)
=
user_ty
{
let
annotation_index
=
this
.canonical_user_type_annotations
.push
(
(
source_info
.span
,
user_ty
)
CanonicalUserTypeAnnotation
{
span
:
source_info
.span
,
user_ty
}
);
this
.cfg
.push
(
block
,
...
...
src/librustc_mir/build/expr/as_rvalue.rs
浏览文件 @
ed871cb3
...
...
@@ -9,7 +9,7 @@
use
rustc
::
middle
::
region
;
use
rustc
::
mir
::
interpret
::
EvalErrorKind
;
use
rustc
::
mir
::
*
;
use
rustc
::
ty
::{
self
,
Ty
,
UpvarSubsts
};
use
rustc
::
ty
::{
self
,
CanonicalUserTypeAnnotation
,
Ty
,
UpvarSubsts
};
use
syntax_pos
::
Span
;
impl
<
'a
,
'gcx
,
'tcx
>
Builder
<
'a
,
'gcx
,
'tcx
>
{
...
...
@@ -332,7 +332,10 @@ fn expr_as_rvalue(
};
let
user_ty
=
user_ty
.map
(|
ty
|
{
this
.canonical_user_type_annotations
.push
((
expr_span
,
ty
))
this
.canonical_user_type_annotations
.push
(
CanonicalUserTypeAnnotation
{
span
:
source_info
.span
,
user_ty
:
ty
,
})
});
let
adt
=
box
AggregateKind
::
Adt
(
adt_def
,
...
...
src/librustc_mir/build/matches/mod.rs
浏览文件 @
ed871cb3
...
...
@@ -9,7 +9,7 @@
use
build
::{
GuardFrame
,
GuardFrameLocal
,
LocalsForNode
};
use
hair
::
*
;
use
rustc
::
mir
::
*
;
use
rustc
::
ty
::{
self
,
Ty
};
use
rustc
::
ty
::{
self
,
CanonicalUserTypeAnnotation
,
Ty
};
use
rustc
::
ty
::
layout
::
VariantIdx
;
use
rustc_data_structures
::
bit_set
::
BitSet
;
use
rustc_data_structures
::
fx
::
FxHashMap
;
...
...
@@ -570,7 +570,10 @@ pub(super) fn visit_bindings(
//
// Note that the variance doesn't apply here, as we are tracking the effect
// of `user_ty` on any bindings contained with subpattern.
let
annotation
=
(
user_ty_span
,
user_ty
.base
);
let
annotation
=
CanonicalUserTypeAnnotation
{
span
:
user_ty_span
,
user_ty
:
user_ty
.base
,
};
let
projection
=
UserTypeProjection
{
base
:
self
.canonical_user_type_annotations
.push
(
annotation
),
projs
:
user_ty
.projs
.clone
(),
...
...
src/librustc_mir/hair/pattern/mod.rs
浏览文件 @
ed871cb3
...
...
@@ -14,8 +14,8 @@
use
rustc
::
mir
::{
fmt_const_val
,
Field
,
BorrowKind
,
Mutability
};
use
rustc
::
mir
::{
ProjectionElem
,
UserTypeProjection
};
use
rustc
::
mir
::
interpret
::{
Scalar
,
GlobalId
,
ConstValue
,
sign_extend
};
use
rustc
::
ty
::{
self
,
Region
,
TyCtxt
,
AdtDef
,
Ty
,
Lift
};
use
rustc
::
ty
::{
CanonicalUserType
,
CanonicalUserTypeAnnotation
s
,
UserType
};
use
rustc
::
ty
::{
self
,
Region
,
TyCtxt
,
AdtDef
,
Ty
,
Lift
,
UserType
};
use
rustc
::
ty
::{
CanonicalUserType
,
CanonicalUserTypeAnnotation
,
CanonicalUserTypeAnnotations
};
use
rustc
::
ty
::
subst
::{
Substs
,
Kind
};
use
rustc
::
ty
::
layout
::
VariantIdx
;
use
rustc
::
hir
::{
self
,
PatKind
,
RangeEnd
};
...
...
@@ -78,7 +78,7 @@ pub(crate) fn user_ty(
span
:
Span
,
)
->
UserTypeProjection
<
'tcx
>
{
UserTypeProjection
{
base
:
annotations
.push
(
(
span
,
self
.base
)
),
base
:
annotations
.push
(
CanonicalUserTypeAnnotation
{
span
,
user_ty
:
self
.base
}
),
projs
:
self
.projs
}
}
...
...
src/librustc_mir/util/pretty.rs
浏览文件 @
ed871cb3
...
...
@@ -632,8 +632,8 @@ fn write_user_type_annotations(mir: &Mir, w: &mut dyn Write) -> io::Result<()> {
if
!
mir
.user_type_annotations
.is_empty
()
{
writeln!
(
w
,
"| User Type Annotations"
)
?
;
}
for
(
index
,
(
span
,
annotation
)
)
in
mir
.user_type_annotations
.iter_enumerated
()
{
writeln!
(
w
,
"| {:?}: {:?} at {:?}"
,
index
.index
(),
annotation
,
span
)
?
;
for
(
index
,
annotation
)
in
mir
.user_type_annotations
.iter_enumerated
()
{
writeln!
(
w
,
"| {:?}: {:?} at {:?}"
,
index
.index
(),
annotation
.user_ty
,
annotation
.
span
)
?
;
}
if
!
mir
.user_type_annotations
.is_empty
()
{
writeln!
(
w
,
"|"
)
?
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录