Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
64db4289
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,发现更多精彩内容 >>
提交
64db4289
编写于
4月 12, 2020
作者:
D
Dylan MacKenzie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't use `*` for deref-coercion
上级
884ba4f1
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
77 addition
and
78 deletion
+77
-78
src/librustc_codegen_ssa/mir/analyze.rs
src/librustc_codegen_ssa/mir/analyze.rs
+1
-1
src/librustc_codegen_ssa/mir/block.rs
src/librustc_codegen_ssa/mir/block.rs
+2
-2
src/librustc_codegen_ssa/mir/place.rs
src/librustc_codegen_ssa/mir/place.rs
+1
-1
src/librustc_codegen_ssa/mir/rvalue.rs
src/librustc_codegen_ssa/mir/rvalue.rs
+3
-3
src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs
src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs
+5
-5
src/librustc_mir/borrow_check/diagnostics/mod.rs
src/librustc_mir/borrow_check/diagnostics/mod.rs
+3
-4
src/librustc_mir/borrow_check/diagnostics/move_errors.rs
src/librustc_mir/borrow_check/diagnostics/move_errors.rs
+4
-4
src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs
...ibrustc_mir/borrow_check/diagnostics/mutability_errors.rs
+4
-4
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/mod.rs
+2
-2
src/librustc_mir/borrow_check/prefixes.rs
src/librustc_mir/borrow_check/prefixes.rs
+1
-1
src/librustc_mir/borrow_check/type_check/mod.rs
src/librustc_mir/borrow_check/type_check/mod.rs
+19
-19
src/librustc_mir/const_eval/machine.rs
src/librustc_mir/const_eval/machine.rs
+1
-1
src/librustc_mir/transform/check_consts/qualifs.rs
src/librustc_mir/transform/check_consts/qualifs.rs
+3
-3
src/librustc_mir/transform/check_consts/resolver.rs
src/librustc_mir/transform/check_consts/resolver.rs
+1
-1
src/librustc_mir/transform/check_consts/validation.rs
src/librustc_mir/transform/check_consts/validation.rs
+14
-14
src/librustc_mir/transform/inline.rs
src/librustc_mir/transform/inline.rs
+3
-3
src/librustc_mir/transform/promote_consts.rs
src/librustc_mir/transform/promote_consts.rs
+10
-10
未找到文件。
src/librustc_codegen_ssa/mir/analyze.rs
浏览文件 @
64db4289
...
...
@@ -120,7 +120,7 @@ fn process_place(
};
if
is_consume
{
let
base_ty
=
mir
::
Place
::
ty_from
(
place_ref
.local
,
proj_base
,
*
self
.fx.mir
,
cx
.tcx
());
mir
::
Place
::
ty_from
(
place_ref
.local
,
proj_base
,
self
.fx.mir
,
cx
.tcx
());
let
base_ty
=
self
.fx
.monomorphize
(
&
base_ty
);
// ZSTs don't require any actual memory access.
...
...
src/librustc_codegen_ssa/mir/block.rs
浏览文件 @
64db4289
...
...
@@ -306,7 +306,7 @@ fn codegen_drop_terminator(
target
:
mir
::
BasicBlock
,
unwind
:
Option
<
mir
::
BasicBlock
>
,
)
{
let
ty
=
location
.ty
(
*
self
.mir
,
bx
.tcx
())
.ty
;
let
ty
=
location
.ty
(
self
.mir
,
bx
.tcx
())
.ty
;
let
ty
=
self
.monomorphize
(
&
ty
);
let
drop_fn
=
Instance
::
resolve_drop_in_place
(
bx
.tcx
(),
ty
);
...
...
@@ -572,7 +572,7 @@ fn codegen_call_terminator(
let
extra_args
=
extra_args
.iter
()
.map
(|
op_arg
|
{
let
op_ty
=
op_arg
.ty
(
*
self
.mir
,
bx
.tcx
());
let
op_ty
=
op_arg
.ty
(
self
.mir
,
bx
.tcx
());
self
.monomorphize
(
&
op_ty
)
})
.collect
::
<
Vec
<
_
>>
();
...
...
src/librustc_codegen_ssa/mir/place.rs
浏览文件 @
64db4289
...
...
@@ -497,7 +497,7 @@ pub fn codegen_place(
pub
fn
monomorphized_place_ty
(
&
self
,
place_ref
:
mir
::
PlaceRef
<
'tcx
>
)
->
Ty
<
'tcx
>
{
let
tcx
=
self
.cx
.tcx
();
let
place_ty
=
mir
::
Place
::
ty_from
(
place_ref
.local
,
place_ref
.projection
,
*
self
.mir
,
tcx
);
let
place_ty
=
mir
::
Place
::
ty_from
(
place_ref
.local
,
place_ref
.projection
,
self
.mir
,
tcx
);
self
.monomorphize
(
&
place_ty
.ty
)
}
}
src/librustc_codegen_ssa/mir/rvalue.rs
浏览文件 @
64db4289
...
...
@@ -473,7 +473,7 @@ pub fn codegen_rvalue_operand(
}
mir
::
Rvalue
::
Discriminant
(
ref
place
)
=>
{
let
discr_ty
=
rvalue
.ty
(
*
self
.mir
,
bx
.tcx
());
let
discr_ty
=
rvalue
.ty
(
self
.mir
,
bx
.tcx
());
let
discr
=
self
.codegen_place
(
&
mut
bx
,
place
.as_ref
())
.codegen_get_discr
(
&
mut
bx
,
discr_ty
);
...
...
@@ -529,7 +529,7 @@ pub fn codegen_rvalue_operand(
mir
::
Rvalue
::
Repeat
(
..
)
|
mir
::
Rvalue
::
Aggregate
(
..
)
=>
{
// According to `rvalue_creates_operand`, only ZST
// aggregate rvalues are allowed to be operands.
let
ty
=
rvalue
.ty
(
*
self
.mir
,
self
.cx
.tcx
());
let
ty
=
rvalue
.ty
(
self
.mir
,
self
.cx
.tcx
());
let
operand
=
OperandRef
::
new_zst
(
&
mut
bx
,
self
.cx
.layout_of
(
self
.monomorphize
(
&
ty
)));
(
bx
,
operand
)
...
...
@@ -749,7 +749,7 @@ pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>, span: Span) ->
true
,
mir
::
Rvalue
::
Repeat
(
..
)
|
mir
::
Rvalue
::
Aggregate
(
..
)
=>
{
let
ty
=
rvalue
.ty
(
*
self
.mir
,
self
.cx
.tcx
());
let
ty
=
rvalue
.ty
(
self
.mir
,
self
.cx
.tcx
());
let
ty
=
self
.monomorphize
(
&
ty
);
self
.cx
.spanned_layout_of
(
ty
,
span
)
.is_zst
()
}
...
...
src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs
浏览文件 @
64db4289
...
...
@@ -186,7 +186,7 @@ pub(in crate::borrow_check) fn report_use_of_moved_or_uninitialized(
}
let
ty
=
Place
::
ty_from
(
used_place
.local
,
used_place
.projection
,
*
self
.body
,
self
.infcx.tcx
)
Place
::
ty_from
(
used_place
.local
,
used_place
.projection
,
self
.body
,
self
.infcx.tcx
)
.ty
;
let
needs_note
=
match
ty
.kind
{
ty
::
Closure
(
id
,
_
)
=>
{
...
...
@@ -202,7 +202,7 @@ pub(in crate::borrow_check) fn report_use_of_moved_or_uninitialized(
let
mpi
=
self
.move_data.moves
[
move_out_indices
[
0
]]
.path
;
let
place
=
&
self
.move_data.move_paths
[
mpi
]
.place
;
let
ty
=
place
.ty
(
*
self
.body
,
self
.infcx.tcx
)
.ty
;
let
ty
=
place
.ty
(
self
.body
,
self
.infcx.tcx
)
.ty
;
let
opt_name
=
self
.describe_place_with_options
(
place
.as_ref
(),
IncludingDowncast
(
true
));
let
note_msg
=
match
opt_name
{
...
...
@@ -591,7 +591,7 @@ pub(in crate::borrow_check) fn describe_place_for_conflicting_borrow(
// Define a small closure that we can use to check if the type of a place
// is a union.
let
union_ty
=
|
place_base
,
place_projection
|
{
let
ty
=
Place
::
ty_from
(
place_base
,
place_projection
,
*
self
.body
,
self
.infcx.tcx
)
.ty
;
let
ty
=
Place
::
ty_from
(
place_base
,
place_projection
,
self
.body
,
self
.infcx.tcx
)
.ty
;
ty
.ty_adt_def
()
.filter
(|
adt
|
adt
.is_union
())
.map
(|
_
|
ty
)
};
...
...
@@ -1486,7 +1486,7 @@ fn classify_drop_access_kind(&self, place: PlaceRef<'tcx>) -> StorageDeadOrDrop<
StorageDeadOrDrop
::
LocalStorageDead
|
StorageDeadOrDrop
::
BoxedStorageDead
=>
{
assert
!
(
Place
::
ty_from
(
place
.local
,
proj_base
,
*
self
.body
,
tcx
)
.ty
.is_box
(),
Place
::
ty_from
(
place
.local
,
proj_base
,
self
.body
,
tcx
)
.ty
.is_box
(),
"Drop of value behind a reference or raw pointer"
);
StorageDeadOrDrop
::
BoxedStorageDead
...
...
@@ -1494,7 +1494,7 @@ fn classify_drop_access_kind(&self, place: PlaceRef<'tcx>) -> StorageDeadOrDrop<
StorageDeadOrDrop
::
Destructor
(
_
)
=>
base_access
,
},
ProjectionElem
::
Field
(
..
)
|
ProjectionElem
::
Downcast
(
..
)
=>
{
let
base_ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
*
self
.body
,
tcx
)
.ty
;
let
base_ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
self
.body
,
tcx
)
.ty
;
match
base_ty
.kind
{
ty
::
Adt
(
def
,
_
)
if
def
.has_dtor
(
tcx
)
=>
{
// Report the outermost adt with a destructor
...
...
src/librustc_mir/borrow_check/diagnostics/mod.rs
浏览文件 @
64db4289
...
...
@@ -331,8 +331,7 @@ fn describe_field(&self, place: PlaceRef<'tcx>, field: Field) -> String {
}
ProjectionElem
::
Downcast
(
_
,
variant_index
)
=>
{
let
base_ty
=
Place
::
ty_from
(
place
.local
,
place
.projection
,
*
self
.body
,
self
.infcx.tcx
)
.ty
;
Place
::
ty_from
(
place
.local
,
place
.projection
,
self
.body
,
self
.infcx.tcx
)
.ty
;
self
.describe_field_from_ty
(
&
base_ty
,
field
,
Some
(
*
variant_index
))
}
ProjectionElem
::
Field
(
_
,
field_type
)
=>
{
...
...
@@ -449,7 +448,7 @@ pub(super) fn borrowed_content_source(
})
=
bbd
.terminator
{
if
let
Some
(
source
)
=
BorrowedContentSource
::
from_call
(
func
.ty
(
*
self
.body
,
tcx
),
tcx
)
BorrowedContentSource
::
from_call
(
func
.ty
(
self
.body
,
tcx
),
tcx
)
{
return
source
;
}
...
...
@@ -462,7 +461,7 @@ pub(super) fn borrowed_content_source(
// If we didn't find an overloaded deref or index, then assume it's a
// built in deref and check the type of the base.
let
base_ty
=
Place
::
ty_from
(
deref_base
.local
,
deref_base
.projection
,
*
self
.body
,
tcx
)
.ty
;
let
base_ty
=
Place
::
ty_from
(
deref_base
.local
,
deref_base
.projection
,
self
.body
,
tcx
)
.ty
;
if
base_ty
.is_unsafe_ptr
()
{
BorrowedContentSource
::
DerefRawPointer
}
else
if
base_ty
.is_mutable_ptr
()
{
...
...
src/librustc_mir/borrow_check/diagnostics/move_errors.rs
浏览文件 @
64db4289
...
...
@@ -296,7 +296,7 @@ fn report_cannot_move_from_borrowed_content(
// Inspect the type of the content behind the
// borrow to provide feedback about why this
// was a move rather than a copy.
let
ty
=
deref_target_place
.ty
(
*
self
.body
,
self
.infcx.tcx
)
.ty
;
let
ty
=
deref_target_place
.ty
(
self
.body
,
self
.infcx.tcx
)
.ty
;
let
upvar_field
=
self
.prefixes
(
move_place
.as_ref
(),
PrefixSet
::
All
)
.find_map
(|
p
|
self
.is_upvar_field_projection
(
p
));
...
...
@@ -385,7 +385,7 @@ fn report_cannot_move_from_borrowed_content(
}
};
if
let
Ok
(
snippet
)
=
self
.infcx.tcx.sess
.source_map
()
.span_to_snippet
(
span
)
{
let
def_id
=
match
move_place
.ty
(
*
self
.body
,
self
.infcx.tcx
)
.ty.kind
{
let
def_id
=
match
move_place
.ty
(
self
.body
,
self
.infcx.tcx
)
.ty.kind
{
ty
::
Adt
(
self_def
,
_
)
=>
self_def
.did
,
ty
::
Foreign
(
def_id
)
|
ty
::
FnDef
(
def_id
,
_
)
...
...
@@ -441,7 +441,7 @@ fn add_move_hints(
}
if
binds_to
.is_empty
()
{
let
place_ty
=
move_from
.ty
(
*
self
.body
,
self
.infcx.tcx
)
.ty
;
let
place_ty
=
move_from
.ty
(
self
.body
,
self
.infcx.tcx
)
.ty
;
let
place_desc
=
match
self
.describe_place
(
move_from
.as_ref
())
{
Some
(
desc
)
=>
format!
(
"`{}`"
,
desc
),
None
=>
"value"
.to_string
(),
...
...
@@ -464,7 +464,7 @@ fn add_move_hints(
// No binding. Nothing to suggest.
GroupedMoveError
::
OtherIllegalMove
{
ref
original_path
,
use_spans
,
..
}
=>
{
let
span
=
use_spans
.var_or_use
();
let
place_ty
=
original_path
.ty
(
*
self
.body
,
self
.infcx.tcx
)
.ty
;
let
place_ty
=
original_path
.ty
(
self
.body
,
self
.infcx.tcx
)
.ty
;
let
place_desc
=
match
self
.describe_place
(
original_path
.as_ref
())
{
Some
(
desc
)
=>
format!
(
"`{}`"
,
desc
),
None
=>
"value"
.to_string
(),
...
...
src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs
浏览文件 @
64db4289
...
...
@@ -58,7 +58,7 @@ pub(crate) fn report_mutability_error(
projection
:
[
proj_base
@
..
,
ProjectionElem
::
Field
(
upvar_index
,
_
)],
}
=>
{
debug_assert!
(
is_closure_or_generator
(
Place
::
ty_from
(
local
,
proj_base
,
*
self
.body
,
self
.infcx.tcx
)
.ty
Place
::
ty_from
(
local
,
proj_base
,
self
.body
,
self
.infcx.tcx
)
.ty
));
item_msg
=
format!
(
"`{}`"
,
access_place_desc
.unwrap
());
...
...
@@ -104,7 +104,7 @@ pub(crate) fn report_mutability_error(
Place
::
ty_from
(
the_place_err
.local
,
the_place_err
.projection
,
*
self
.body
,
self
.body
,
self
.infcx.tcx
)
.ty
...
...
@@ -197,7 +197,7 @@ pub(crate) fn report_mutability_error(
if
let
Some
((
span
,
message
))
=
annotate_struct_field
(
self
.infcx.tcx
,
Place
::
ty_from
(
local
,
proj_base
,
*
self
.body
,
self
.infcx.tcx
)
.ty
,
Place
::
ty_from
(
local
,
proj_base
,
self
.body
,
self
.infcx.tcx
)
.ty
,
field
,
)
{
err
.span_suggestion
(
...
...
@@ -273,7 +273,7 @@ pub(crate) fn report_mutability_error(
projection
:
[
proj_base
@
..
,
ProjectionElem
::
Field
(
upvar_index
,
_
)],
}
=>
{
debug_assert!
(
is_closure_or_generator
(
Place
::
ty_from
(
local
,
proj_base
,
*
self
.body
,
self
.infcx.tcx
)
.ty
Place
::
ty_from
(
local
,
proj_base
,
self
.body
,
self
.infcx.tcx
)
.ty
));
err
.span_label
(
span
,
format!
(
"cannot {ACT}"
,
ACT
=
act
));
...
...
src/librustc_mir/borrow_check/mod.rs
浏览文件 @
64db4289
...
...
@@ -619,7 +619,7 @@ fn visit_terminator(
let
tcx
=
self
.infcx.tcx
;
// Compute the type with accurate region information.
let
drop_place_ty
=
drop_place
.ty
(
*
self
.body
,
self
.infcx.tcx
);
let
drop_place_ty
=
drop_place
.ty
(
self
.body
,
self
.infcx.tcx
);
// Erase the regions.
let
drop_place_ty
=
self
.infcx.tcx
.erase_regions
(
&
drop_place_ty
)
.ty
;
...
...
@@ -871,7 +871,7 @@ fn as_verb_in_past_tense(self) -> &'static str {
impl
<
'cx
,
'tcx
>
MirBorrowckCtxt
<
'cx
,
'tcx
>
{
fn
body
(
&
self
)
->
&
'cx
Body
<
'tcx
>
{
*
self
.body
self
.body
}
/// Checks an access to the given place to see if it is allowed. Examines the set of borrows
...
...
src/librustc_mir/borrow_check/prefixes.rs
浏览文件 @
64db4289
...
...
@@ -120,7 +120,7 @@ fn next(&mut self) -> Option<Self::Item> {
// derefs, except we stop at the deref of a shared
// reference.
let
ty
=
Place
::
ty_from
(
cursor
.local
,
proj_base
,
*
self
.body
,
self
.tcx
)
.ty
;
let
ty
=
Place
::
ty_from
(
cursor
.local
,
proj_base
,
self
.body
,
self
.tcx
)
.ty
;
match
ty
.kind
{
ty
::
RawPtr
(
_
)
|
ty
::
Ref
(
_
/*rgn*/
,
_
/*ty*/
,
hir
::
Mutability
::
Not
)
=>
{
// don't continue traversing over derefs of raw pointers or shared
...
...
src/librustc_mir/borrow_check/type_check/mod.rs
浏览文件 @
64db4289
...
...
@@ -200,7 +200,7 @@ fn type_check_internal<'a, 'tcx, R>(
)
->
R
{
let
mut
checker
=
TypeChecker
::
new
(
infcx
,
*
body
,
body
,
mir_def_id
,
param_env
,
region_bound_pairs
,
...
...
@@ -209,7 +209,7 @@ fn type_check_internal<'a, 'tcx, R>(
universal_region_relations
,
);
let
errors_reported
=
{
let
mut
verifier
=
TypeVerifier
::
new
(
&
mut
checker
,
*
body
,
promoted
);
let
mut
verifier
=
TypeVerifier
::
new
(
&
mut
checker
,
body
,
promoted
);
verifier
.visit_body
(
&
body
);
verifier
.errors_reported
};
...
...
@@ -341,11 +341,11 @@ fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
};
if
!
self
.errors_reported
{
let
promoted_body
=
self
.promoted
[
promoted
];
let
promoted_body
=
&
self
.promoted
[
promoted
];
self
.sanitize_promoted
(
promoted_body
,
location
);
let
promoted_ty
=
promoted_body
.return_ty
();
check_err
(
self
,
&
promoted_body
,
ty
,
promoted_ty
);
check_err
(
self
,
promoted_body
,
ty
,
promoted_ty
);
}
}
else
{
if
let
Err
(
terr
)
=
self
.cx
.fully_perform_op
(
...
...
@@ -534,7 +534,7 @@ fn sanitize_promoted(
// checker on the promoted MIR, then transfer the constraints back to
// the main MIR, changing the locations to the provided location.
let
parent_body
=
mem
::
replace
(
&
mut
self
.body
,
*
promoted_body
);
let
parent_body
=
mem
::
replace
(
&
mut
self
.body
,
promoted_body
);
// Use new sets of constraints and closure bounds so that we can
// modify their locations.
...
...
@@ -1433,9 +1433,9 @@ fn check_stmt(
_
=>
ConstraintCategory
::
Assignment
,
};
let
place_ty
=
place
.ty
(
*
body
,
tcx
)
.ty
;
let
place_ty
=
place
.ty
(
body
,
tcx
)
.ty
;
let
place_ty
=
self
.normalize
(
place_ty
,
location
);
let
rv_ty
=
rv
.ty
(
*
body
,
tcx
);
let
rv_ty
=
rv
.ty
(
body
,
tcx
);
let
rv_ty
=
self
.normalize
(
rv_ty
,
location
);
if
let
Err
(
terr
)
=
self
.sub_types_or_anon
(
rv_ty
,
place_ty
,
location
.to_locations
(),
category
)
...
...
@@ -1484,7 +1484,7 @@ fn check_stmt(
}
}
StatementKind
::
SetDiscriminant
{
ref
place
,
variant_index
}
=>
{
let
place_type
=
place
.ty
(
*
body
,
tcx
)
.ty
;
let
place_type
=
place
.ty
(
body
,
tcx
)
.ty
;
let
adt
=
match
place_type
.kind
{
ty
::
Adt
(
adt
,
_
)
if
adt
.is_enum
()
=>
adt
,
_
=>
{
...
...
@@ -1506,7 +1506,7 @@ fn check_stmt(
};
}
StatementKind
::
AscribeUserType
(
box
(
ref
place
,
ref
projection
),
variance
)
=>
{
let
place_ty
=
place
.ty
(
*
body
,
tcx
)
.ty
;
let
place_ty
=
place
.ty
(
body
,
tcx
)
.ty
;
if
let
Err
(
terr
)
=
self
.relate_type_and_user_type
(
place_ty
,
variance
,
...
...
@@ -1996,7 +1996,7 @@ fn check_rvalue(
// While this is located in `nll::typeck` this error is not an NLL error, it's
// a required check to make sure that repeated elements implement `Copy`.
let
span
=
body
.source_info
(
location
)
.span
;
let
ty
=
operand
.ty
(
*
body
,
tcx
);
let
ty
=
operand
.ty
(
body
,
tcx
);
if
!
self
.infcx
.type_is_copy_modulo_regions
(
self
.param_env
,
ty
,
span
)
{
// To determine if `const_in_array_repeat_expressions` feature gate should
// be mentioned, need to check if the rvalue is promotable.
...
...
@@ -2060,7 +2060,7 @@ fn check_rvalue(
Rvalue
::
Cast
(
cast_kind
,
op
,
ty
)
=>
{
match
cast_kind
{
CastKind
::
Pointer
(
PointerCast
::
ReifyFnPointer
)
=>
{
let
fn_sig
=
op
.ty
(
*
body
,
tcx
)
.fn_sig
(
tcx
);
let
fn_sig
=
op
.ty
(
body
,
tcx
)
.fn_sig
(
tcx
);
// The type that we see in the fcx is like
// `foo::<'a, 'b>`, where `foo` is the path to a
...
...
@@ -2089,7 +2089,7 @@ fn check_rvalue(
}
CastKind
::
Pointer
(
PointerCast
::
ClosureFnPointer
(
unsafety
))
=>
{
let
sig
=
match
op
.ty
(
*
body
,
tcx
)
.kind
{
let
sig
=
match
op
.ty
(
body
,
tcx
)
.kind
{
ty
::
Closure
(
_
,
substs
)
=>
substs
.as_closure
()
.sig
(),
_
=>
bug!
(),
};
...
...
@@ -2113,7 +2113,7 @@ fn check_rvalue(
}
CastKind
::
Pointer
(
PointerCast
::
UnsafeFnPointer
)
=>
{
let
fn_sig
=
op
.ty
(
*
body
,
tcx
)
.fn_sig
(
tcx
);
let
fn_sig
=
op
.ty
(
body
,
tcx
)
.fn_sig
(
tcx
);
// The type that we see in the fcx is like
// `foo::<'a, 'b>`, where `foo` is the path to a
...
...
@@ -2145,7 +2145,7 @@ fn check_rvalue(
let
&
ty
=
ty
;
let
trait_ref
=
ty
::
TraitRef
{
def_id
:
tcx
.lang_items
()
.coerce_unsized_trait
()
.unwrap
(),
substs
:
tcx
.mk_substs_trait
(
op
.ty
(
*
body
,
tcx
),
&
[
ty
.into
()]),
substs
:
tcx
.mk_substs_trait
(
op
.ty
(
body
,
tcx
),
&
[
ty
.into
()]),
};
self
.prove_trait_ref
(
...
...
@@ -2156,7 +2156,7 @@ fn check_rvalue(
}
CastKind
::
Pointer
(
PointerCast
::
MutToConstPointer
)
=>
{
let
ty_from
=
match
op
.ty
(
*
body
,
tcx
)
.kind
{
let
ty_from
=
match
op
.ty
(
body
,
tcx
)
.kind
{
ty
::
RawPtr
(
ty
::
TypeAndMut
{
ty
:
ty_from
,
mutbl
:
hir
::
Mutability
::
Mut
,
...
...
@@ -2204,7 +2204,7 @@ fn check_rvalue(
}
CastKind
::
Pointer
(
PointerCast
::
ArrayToPointer
)
=>
{
let
ty_from
=
op
.ty
(
*
body
,
tcx
);
let
ty_from
=
op
.ty
(
body
,
tcx
);
let
opt_ty_elem
=
match
ty_from
.kind
{
ty
::
RawPtr
(
ty
::
TypeAndMut
{
...
...
@@ -2264,7 +2264,7 @@ fn check_rvalue(
}
CastKind
::
Misc
=>
{
let
ty_from
=
op
.ty
(
*
body
,
tcx
);
let
ty_from
=
op
.ty
(
body
,
tcx
);
let
cast_ty_from
=
CastTy
::
from_ty
(
ty_from
);
let
cast_ty_to
=
CastTy
::
from_ty
(
ty
);
match
(
cast_ty_from
,
cast_ty_to
)
{
...
...
@@ -2295,9 +2295,9 @@ fn check_rvalue(
left
,
right
,
)
=>
{
let
ty_left
=
left
.ty
(
*
body
,
tcx
);
let
ty_left
=
left
.ty
(
body
,
tcx
);
if
let
ty
::
RawPtr
(
_
)
|
ty
::
FnPtr
(
_
)
=
ty_left
.kind
{
let
ty_right
=
right
.ty
(
*
body
,
tcx
);
let
ty_right
=
right
.ty
(
body
,
tcx
);
let
common_ty
=
self
.infcx
.next_ty_var
(
TypeVariableOrigin
{
kind
:
TypeVariableOriginKind
::
MiscVariable
,
span
:
body
.source_info
(
location
)
.span
,
...
...
src/librustc_mir/const_eval/machine.rs
浏览文件 @
64db4289
...
...
@@ -226,7 +226,7 @@ fn find_mir_or_eval_fn(
}
// This is a const fn. Call it.
Ok
(
Some
(
match
ecx
.load_mir
(
instance
.def
,
None
)
{
Ok
(
body
)
=>
*
body
,
Ok
(
body
)
=>
body
,
Err
(
err
)
=>
{
if
let
err_unsup!
(
NoMirFor
(
did
))
=
err
.kind
{
let
path
=
ecx
.tcx
.def_path_str
(
did
);
...
...
src/librustc_mir/transform/check_consts/qualifs.rs
浏览文件 @
64db4289
...
...
@@ -113,7 +113,7 @@ pub fn in_rvalue<Q, F>(cx: &ConstCx<'_, 'tcx>, in_local: &mut F, rvalue: &Rvalue
F
:
FnMut
(
Local
)
->
bool
,
{
match
rvalue
{
Rvalue
::
NullaryOp
(
..
)
=>
Q
::
in_any_value_of_ty
(
cx
,
rvalue
.ty
(
*
cx
.body
,
cx
.tcx
)),
Rvalue
::
NullaryOp
(
..
)
=>
Q
::
in_any_value_of_ty
(
cx
,
rvalue
.ty
(
cx
.body
,
cx
.tcx
)),
Rvalue
::
Discriminant
(
place
)
|
Rvalue
::
Len
(
place
)
=>
{
in_place
::
<
Q
,
_
>
(
cx
,
in_local
,
place
.as_ref
())
...
...
@@ -131,7 +131,7 @@ pub fn in_rvalue<Q, F>(cx: &ConstCx<'_, 'tcx>, in_local: &mut F, rvalue: &Rvalue
Rvalue
::
Ref
(
_
,
_
,
place
)
|
Rvalue
::
AddressOf
(
_
,
place
)
=>
{
// Special-case reborrows to be more like a copy of the reference.
if
let
&
[
ref
proj_base
@
..
,
ProjectionElem
::
Deref
]
=
place
.projection
.as_ref
()
{
let
base_ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
*
cx
.body
,
cx
.tcx
)
.ty
;
let
base_ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
cx
.body
,
cx
.tcx
)
.ty
;
if
let
ty
::
Ref
(
..
)
=
base_ty
.kind
{
return
in_place
::
<
Q
,
_
>
(
cx
,
...
...
@@ -178,7 +178,7 @@ pub fn in_place<Q, F>(cx: &ConstCx<'_, 'tcx>, in_local: &mut F, place: PlaceRef<
|
ProjectionElem
::
Index
(
_
)
=>
{}
}
let
base_ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
*
cx
.body
,
cx
.tcx
);
let
base_ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
cx
.body
,
cx
.tcx
);
let
proj_ty
=
base_ty
.projection_ty
(
cx
.tcx
,
proj_elem
)
.ty
;
if
!
Q
::
in_any_value_of_ty
(
cx
,
proj_ty
)
{
return
false
;
...
...
src/librustc_mir/transform/check_consts/resolver.rs
浏览文件 @
64db4289
...
...
@@ -72,7 +72,7 @@ fn apply_call_return_effect(
)
{
// We cannot reason about another function's internals, so use conservative type-based
// qualification for the result of a function call.
let
return_ty
=
return_place
.ty
(
*
self
.item.body
,
self
.item.tcx
)
.ty
;
let
return_ty
=
return_place
.ty
(
self
.item.body
,
self
.item.tcx
)
.ty
;
let
qualif
=
Q
::
in_any_value_of_ty
(
self
.item
,
return_ty
);
if
!
return_place
.is_indirect
()
{
...
...
src/librustc_mir/transform/check_consts/validation.rs
浏览文件 @
64db4289
...
...
@@ -39,9 +39,9 @@ struct QualifCursor<'a, 'mir, 'tcx, Q: Qualif> {
impl
<
Q
:
Qualif
>
QualifCursor
<
'a
,
'mir
,
'tcx
,
Q
>
{
pub
fn
new
(
q
:
Q
,
item
:
&
'a
Item
<
'mir
,
'tcx
>
)
->
Self
{
let
cursor
=
FlowSensitiveAnalysis
::
new
(
q
,
item
)
.into_engine
(
item
.tcx
,
&
item
.body
,
item
.def_id
)
.into_engine
(
item
.tcx
,
item
.body
,
item
.def_id
)
.iterate_to_fixpoint
()
.into_results_cursor
(
*
item
.body
);
.into_results_cursor
(
item
.body
);
let
mut
in_any_value_of_ty
=
BitSet
::
new_empty
(
item
.body.local_decls
.len
());
for
(
local
,
decl
)
in
item
.body.local_decls
.iter_enumerated
()
{
...
...
@@ -148,11 +148,11 @@ pub fn new(item: &'a Item<'mir, 'tcx>) -> Self {
//
// FIXME(ecstaticmorse): Someday we want to allow custom drop impls. How do we do this
// without breaking stable code?
let
indirectly_mutable
=
MaybeMutBorrowedLocals
::
mut_borrows_only
(
tcx
,
*
body
,
param_env
)
let
indirectly_mutable
=
MaybeMutBorrowedLocals
::
mut_borrows_only
(
tcx
,
body
,
param_env
)
.unsound_ignore_borrow_on_drop
()
.into_engine
(
tcx
,
*
body
,
def_id
)
.into_engine
(
tcx
,
body
,
def_id
)
.iterate_to_fixpoint
()
.into_results_cursor
(
*
body
);
.into_results_cursor
(
body
);
let
qualifs
=
Qualifs
{
needs_drop
,
has_mut_interior
,
indirectly_mutable
};
...
...
@@ -261,7 +261,7 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
// Special-case reborrows to be more like a copy of a reference.
match
*
rvalue
{
Rvalue
::
Ref
(
_
,
kind
,
place
)
=>
{
if
let
Some
(
reborrowed_proj
)
=
place_as_reborrow
(
self
.tcx
,
*
self
.body
,
place
)
{
if
let
Some
(
reborrowed_proj
)
=
place_as_reborrow
(
self
.tcx
,
self
.body
,
place
)
{
let
ctx
=
match
kind
{
BorrowKind
::
Shared
=>
{
PlaceContext
::
NonMutatingUse
(
NonMutatingUseContext
::
SharedBorrow
)
...
...
@@ -282,7 +282,7 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
}
}
Rvalue
::
AddressOf
(
mutbl
,
place
)
=>
{
if
let
Some
(
reborrowed_proj
)
=
place_as_reborrow
(
self
.tcx
,
*
self
.body
,
place
)
{
if
let
Some
(
reborrowed_proj
)
=
place_as_reborrow
(
self
.tcx
,
self
.body
,
place
)
{
let
ctx
=
match
mutbl
{
Mutability
::
Not
=>
{
PlaceContext
::
NonMutatingUse
(
NonMutatingUseContext
::
AddressOf
)
...
...
@@ -313,7 +313,7 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
Rvalue
::
Ref
(
_
,
kind
@
BorrowKind
::
Mut
{
..
},
ref
place
)
|
Rvalue
::
Ref
(
_
,
kind
@
BorrowKind
::
Unique
,
ref
place
)
=>
{
let
ty
=
place
.ty
(
*
self
.body
,
self
.tcx
)
.ty
;
let
ty
=
place
.ty
(
self
.body
,
self
.tcx
)
.ty
;
let
is_allowed
=
match
ty
.kind
{
// Inside a `static mut`, `&mut [...]` is allowed.
ty
::
Array
(
..
)
|
ty
::
Slice
(
_
)
if
self
.const_kind
()
==
ConstKind
::
StaticMut
=>
{
...
...
@@ -355,7 +355,7 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
}
Rvalue
::
Cast
(
CastKind
::
Misc
,
ref
operand
,
cast_ty
)
=>
{
let
operand_ty
=
operand
.ty
(
*
self
.body
,
self
.tcx
);
let
operand_ty
=
operand
.ty
(
self
.body
,
self
.tcx
);
let
cast_in
=
CastTy
::
from_ty
(
operand_ty
)
.expect
(
"bad input type for cast"
);
let
cast_out
=
CastTy
::
from_ty
(
cast_ty
)
.expect
(
"bad output type for cast"
);
...
...
@@ -365,7 +365,7 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
}
Rvalue
::
BinaryOp
(
op
,
ref
lhs
,
_
)
=>
{
if
let
ty
::
RawPtr
(
_
)
|
ty
::
FnPtr
(
..
)
=
lhs
.ty
(
*
self
.body
,
self
.tcx
)
.kind
{
if
let
ty
::
RawPtr
(
_
)
|
ty
::
FnPtr
(
..
)
=
lhs
.ty
(
self
.body
,
self
.tcx
)
.kind
{
assert
!
(
op
==
BinOp
::
Eq
||
op
==
BinOp
::
Ne
...
...
@@ -426,7 +426,7 @@ fn visit_projection_elem(
match
elem
{
ProjectionElem
::
Deref
=>
{
let
base_ty
=
Place
::
ty_from
(
place_local
,
proj_base
,
*
self
.body
,
self
.tcx
)
.ty
;
let
base_ty
=
Place
::
ty_from
(
place_local
,
proj_base
,
self
.body
,
self
.tcx
)
.ty
;
if
let
ty
::
RawPtr
(
_
)
=
base_ty
.kind
{
if
proj_base
.is_empty
()
{
if
let
(
local
,
[])
=
(
place_local
,
proj_base
)
{
...
...
@@ -450,7 +450,7 @@ fn visit_projection_elem(
|
ProjectionElem
::
Subslice
{
..
}
|
ProjectionElem
::
Field
(
..
)
|
ProjectionElem
::
Index
(
_
)
=>
{
let
base_ty
=
Place
::
ty_from
(
place_local
,
proj_base
,
*
self
.body
,
self
.tcx
)
.ty
;
let
base_ty
=
Place
::
ty_from
(
place_local
,
proj_base
,
self
.body
,
self
.tcx
)
.ty
;
match
base_ty
.ty_adt_def
()
{
Some
(
def
)
if
def
.is_union
()
=>
{
self
.check_op
(
ops
::
UnionAccess
);
...
...
@@ -498,7 +498,7 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
match
&
terminator
.kind
{
TerminatorKind
::
Call
{
func
,
..
}
=>
{
let
fn_ty
=
func
.ty
(
*
self
.body
,
self
.tcx
);
let
fn_ty
=
func
.ty
(
self
.body
,
self
.tcx
);
let
(
def_id
,
substs
)
=
match
fn_ty
.kind
{
ty
::
FnDef
(
def_id
,
substs
)
=>
(
def_id
,
substs
),
...
...
@@ -553,7 +553,7 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
// Check to see if the type of this place can ever have a drop impl. If not, this
// `Drop` terminator is frivolous.
let
ty_needs_drop
=
dropped_place
.ty
(
*
self
.body
,
self
.tcx
)
.ty
.needs_drop
(
self
.tcx
,
self
.param_env
);
dropped_place
.ty
(
self
.body
,
self
.tcx
)
.ty
.needs_drop
(
self
.tcx
,
self
.param_env
);
if
!
ty_needs_drop
{
return
;
...
...
src/librustc_mir/transform/inline.rs
浏览文件 @
64db4289
...
...
@@ -468,7 +468,7 @@ fn dest_needs_borrow(place: Place<'_>) -> bool {
destination
.0
,
);
let
ty
=
dest
.ty
(
&**
caller_body
,
self
.tcx
);
let
ty
=
dest
.ty
(
caller_body
,
self
.tcx
);
let
temp
=
LocalDecl
::
new_temp
(
ty
,
callsite
.location.span
);
...
...
@@ -568,7 +568,7 @@ fn make_call_args(
assert
!
(
args
.next
()
.is_none
());
let
tuple
=
Place
::
from
(
tuple
);
let
tuple_tys
=
if
let
ty
::
Tuple
(
s
)
=
tuple
.ty
(
&**
caller_body
,
tcx
)
.ty.kind
{
let
tuple_tys
=
if
let
ty
::
Tuple
(
s
)
=
tuple
.ty
(
caller_body
,
tcx
)
.ty.kind
{
s
}
else
{
bug!
(
"Closure arguments are not passed as a tuple"
);
...
...
@@ -619,7 +619,7 @@ fn create_temp_if_necessary(
// Otherwise, create a temporary for the arg
let
arg
=
Rvalue
::
Use
(
arg
);
let
ty
=
arg
.ty
(
&**
caller_body
,
self
.tcx
);
let
ty
=
arg
.ty
(
caller_body
,
self
.tcx
);
let
arg_tmp
=
LocalDecl
::
new_temp
(
ty
,
callsite
.location.span
);
let
arg_tmp
=
caller_body
.local_decls
.push
(
arg_tmp
);
...
...
src/librustc_mir/transform/promote_consts.rs
浏览文件 @
64db4289
...
...
@@ -329,7 +329,7 @@ fn validate_candidate(&self, candidate: Candidate) -> Result<(), Unpromotable> {
// FIXME(eddyb) this is probably excessive, with
// the exception of `union` member accesses.
let
ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
*
self
.body
,
self
.tcx
)
Place
::
ty_from
(
place
.local
,
proj_base
,
self
.body
,
self
.tcx
)
.projection_ty
(
self
.tcx
,
elem
)
.ty
;
if
ty
.is_freeze
(
self
.tcx
,
self
.param_env
,
DUMMY_SP
)
{
...
...
@@ -350,7 +350,7 @@ fn validate_candidate(&self, candidate: Candidate) -> Result<(), Unpromotable> {
}
if
let
BorrowKind
::
Mut
{
..
}
=
kind
{
let
ty
=
place
.ty
(
*
self
.body
,
self
.tcx
)
.ty
;
let
ty
=
place
.ty
(
self
.body
,
self
.tcx
)
.ty
;
// In theory, any zero-sized value could be borrowed
// mutably without consequences. However, only &mut []
...
...
@@ -494,7 +494,7 @@ fn validate_place(&self, place: PlaceRef<'tcx>) -> Result<(), Unpromotable> {
ProjectionElem
::
Field
(
..
)
=>
{
if
self
.const_kind
.is_none
()
{
let
base_ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
*
self
.body
,
self
.tcx
)
.ty
;
Place
::
ty_from
(
place
.local
,
proj_base
,
self
.body
,
self
.tcx
)
.ty
;
if
let
Some
(
def
)
=
base_ty
.ty_adt_def
()
{
// No promotion of union field accesses.
if
def
.is_union
()
{
...
...
@@ -539,7 +539,7 @@ fn validate_operand(&self, operand: &Operand<'tcx>) -> Result<(), Unpromotable>
fn
validate_rvalue
(
&
self
,
rvalue
:
&
Rvalue
<
'tcx
>
)
->
Result
<
(),
Unpromotable
>
{
match
*
rvalue
{
Rvalue
::
Cast
(
CastKind
::
Misc
,
ref
operand
,
cast_ty
)
if
self
.const_kind
.is_none
()
=>
{
let
operand_ty
=
operand
.ty
(
*
self
.body
,
self
.tcx
);
let
operand_ty
=
operand
.ty
(
self
.body
,
self
.tcx
);
let
cast_in
=
CastTy
::
from_ty
(
operand_ty
)
.expect
(
"bad input type for cast"
);
let
cast_out
=
CastTy
::
from_ty
(
cast_ty
)
.expect
(
"bad output type for cast"
);
match
(
cast_in
,
cast_out
)
{
...
...
@@ -552,7 +552,7 @@ fn validate_rvalue(&self, rvalue: &Rvalue<'tcx>) -> Result<(), Unpromotable> {
}
Rvalue
::
BinaryOp
(
op
,
ref
lhs
,
_
)
if
self
.const_kind
.is_none
()
=>
{
if
let
ty
::
RawPtr
(
_
)
|
ty
::
FnPtr
(
..
)
=
lhs
.ty
(
*
self
.body
,
self
.tcx
)
.kind
{
if
let
ty
::
RawPtr
(
_
)
|
ty
::
FnPtr
(
..
)
=
lhs
.ty
(
self
.body
,
self
.tcx
)
.kind
{
assert
!
(
op
==
BinOp
::
Eq
||
op
==
BinOp
::
Ne
...
...
@@ -592,7 +592,7 @@ fn validate_rvalue(&self, rvalue: &Rvalue<'tcx>) -> Result<(), Unpromotable> {
// Raw reborrows can come from reference to pointer coercions,
// so are allowed.
if
let
[
proj_base
@
..
,
ProjectionElem
::
Deref
]
=
place
.projection
.as_ref
()
{
let
base_ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
*
self
.body
,
self
.tcx
)
.ty
;
let
base_ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
self
.body
,
self
.tcx
)
.ty
;
if
let
ty
::
Ref
(
..
)
=
base_ty
.kind
{
return
self
.validate_place
(
PlaceRef
{
local
:
place
.local
,
...
...
@@ -605,7 +605,7 @@ fn validate_rvalue(&self, rvalue: &Rvalue<'tcx>) -> Result<(), Unpromotable> {
Rvalue
::
Ref
(
_
,
kind
,
place
)
=>
{
if
let
BorrowKind
::
Mut
{
..
}
=
kind
{
let
ty
=
place
.ty
(
*
self
.body
,
self
.tcx
)
.ty
;
let
ty
=
place
.ty
(
self
.body
,
self
.tcx
)
.ty
;
// In theory, any zero-sized value could be borrowed
// mutably without consequences. However, only &mut []
...
...
@@ -631,7 +631,7 @@ fn validate_rvalue(&self, rvalue: &Rvalue<'tcx>) -> Result<(), Unpromotable> {
// Special-case reborrows to be more like a copy of the reference.
let
mut
place
=
place
.as_ref
();
if
let
[
proj_base
@
..
,
ProjectionElem
::
Deref
]
=
&
place
.projection
{
let
base_ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
*
self
.body
,
self
.tcx
)
.ty
;
let
base_ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
self
.body
,
self
.tcx
)
.ty
;
if
let
ty
::
Ref
(
..
)
=
base_ty
.kind
{
place
=
PlaceRef
{
local
:
place
.local
,
projection
:
proj_base
};
}
...
...
@@ -650,7 +650,7 @@ fn validate_rvalue(&self, rvalue: &Rvalue<'tcx>) -> Result<(), Unpromotable> {
while
let
[
proj_base
@
..
,
elem
]
=
place_projection
{
// FIXME(eddyb) this is probably excessive, with
// the exception of `union` member accesses.
let
ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
*
self
.body
,
self
.tcx
)
let
ty
=
Place
::
ty_from
(
place
.local
,
proj_base
,
self
.body
,
self
.tcx
)
.projection_ty
(
self
.tcx
,
elem
)
.ty
;
if
ty
.is_freeze
(
self
.tcx
,
self
.param_env
,
DUMMY_SP
)
{
...
...
@@ -683,7 +683,7 @@ fn validate_call(
callee
:
&
Operand
<
'tcx
>
,
args
:
&
[
Operand
<
'tcx
>
],
)
->
Result
<
(),
Unpromotable
>
{
let
fn_ty
=
callee
.ty
(
*
self
.body
,
self
.tcx
);
let
fn_ty
=
callee
.ty
(
self
.body
,
self
.tcx
);
if
!
self
.explicit
&&
self
.const_kind
.is_none
()
{
if
let
ty
::
FnDef
(
def_id
,
_
)
=
fn_ty
.kind
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录