Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
8e89184a
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,发现更多精彩内容 >>
提交
8e89184a
编写于
11月 20, 2018
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename `type_moves_by_default` to `type_is_copy_modulo_regions`
上级
4c8fd2e8
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
55 addition
and
46 deletion
+55
-46
src/librustc/infer/mod.rs
src/librustc/infer/mod.rs
+4
-3
src/librustc/middle/expr_use_visitor.rs
src/librustc/middle/expr_use_visitor.rs
+1
-1
src/librustc/middle/mem_categorization.rs
src/librustc/middle/mem_categorization.rs
+8
-7
src/librustc/ty/query/mod.rs
src/librustc/ty/query/mod.rs
+1
-1
src/librustc/ty/util.rs
src/librustc/ty/util.rs
+9
-9
src/librustc_lint/builtin.rs
src/librustc_lint/builtin.rs
+1
-1
src/librustc_mir/borrow_check/nll/type_check/mod.rs
src/librustc_mir/borrow_check/nll/type_check/mod.rs
+11
-7
src/librustc_mir/build/misc.rs
src/librustc_mir/build/misc.rs
+1
-1
src/librustc_mir/hair/cx/mod.rs
src/librustc_mir/hair/cx/mod.rs
+2
-2
src/librustc_mir/hair/pattern/check_match.rs
src/librustc_mir/hair/pattern/check_match.rs
+1
-1
src/librustc_mir/shim.rs
src/librustc_mir/shim.rs
+1
-1
src/librustc_mir/transform/check_unsafety.rs
src/librustc_mir/transform/check_unsafety.rs
+5
-2
src/librustc_typeck/check/demand.rs
src/librustc_typeck/check/demand.rs
+3
-3
src/librustc_typeck/check/op.rs
src/librustc_typeck/check/op.rs
+6
-6
src/test/ui/coherence/coherence-subtyping.stderr
src/test/ui/coherence/coherence-subtyping.stderr
+1
-1
未找到文件。
src/librustc/infer/mod.rs
浏览文件 @
8e89184a
...
...
@@ -1400,18 +1400,19 @@ pub fn verify_generic_bound(
.verify_generic_bound
(
origin
,
kind
,
a
,
bound
);
}
pub
fn
type_
moves_by_default
(
pub
fn
type_
is_copy_modulo_regions
(
&
self
,
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
ty
:
Ty
<
'tcx
>
,
span
:
Span
,
)
->
bool
{
let
ty
=
self
.resolve_type_vars_if_possible
(
&
ty
);
// Even if the type may have no inference variables, during
// type-checking closure types are in local tables only.
if
!
self
.in_progress_tables
.is_some
()
||
!
ty
.has_closure_types
()
{
if
let
Some
((
param_env
,
ty
))
=
self
.tcx
.lift_to_global
(
&
(
param_env
,
ty
))
{
return
ty
.
moves_by_default
(
self
.tcx
.global_tcx
(),
param_env
,
span
);
return
ty
.
is_copy_modulo_regions
(
self
.tcx
.global_tcx
(),
param_env
,
span
);
}
}
...
...
@@ -1421,7 +1422,7 @@ pub fn type_moves_by_default(
// rightly refuses to work with inference variables, but
// moves_by_default has a cache, which we want to use in other
// cases.
!
traits
::
type_known_to_meet_bound_modulo_regions
(
self
,
param_env
,
ty
,
copy_def_id
,
span
)
traits
::
type_known_to_meet_bound_modulo_regions
(
self
,
param_env
,
ty
,
copy_def_id
,
span
)
}
/// Obtains the latest type of the given closure; this may be a
...
...
src/librustc/middle/expr_use_visitor.rs
浏览文件 @
8e89184a
...
...
@@ -976,7 +976,7 @@ fn copy_or_move<'a, 'gcx, 'tcx>(mc: &mc::MemCategorizationContext<'a, 'gcx, 'tcx
move_reason
:
MoveReason
)
->
ConsumeMode
{
if
mc
.type_moves_by_default
(
param_env
,
cmt
.ty
,
cmt
.span
)
{
if
!
mc
.type_is_copy_modulo_regions
(
param_env
,
cmt
.ty
,
cmt
.span
)
{
Move
(
move_reason
)
}
else
{
Copy
...
...
src/librustc/middle/mem_categorization.rs
浏览文件 @
8e89184a
...
...
@@ -443,15 +443,16 @@ pub fn with_infer(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
}
}
pub
fn
type_moves_by_default
(
&
self
,
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
ty
:
Ty
<
'tcx
>
,
span
:
Span
)
->
bool
{
self
.infcx
.map
(|
infcx
|
infcx
.type_moves_by_default
(
param_env
,
ty
,
span
))
pub
fn
type_is_copy_modulo_regions
(
&
self
,
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
ty
:
Ty
<
'tcx
>
,
span
:
Span
,
)
->
bool
{
self
.infcx
.map
(|
infcx
|
infcx
.type_is_copy_modulo_regions
(
param_env
,
ty
,
span
))
.or_else
(||
{
self
.tcx
.lift_to_global
(
&
(
param_env
,
ty
))
.map
(|(
param_env
,
ty
)|
{
ty
.
moves_by_default
(
self
.tcx
.global_tcx
(),
param_env
,
span
)
ty
.
is_copy_modulo_regions
(
self
.tcx
.global_tcx
(),
param_env
,
span
)
})
})
.unwrap_or
(
true
)
...
...
src/librustc/ty/query/mod.rs
浏览文件 @
8e89184a
...
...
@@ -382,7 +382,7 @@
/// might want to use `reveal_all()` method to change modes.
[]
fn
param_env
:
ParamEnv
(
DefId
)
->
ty
::
ParamEnv
<
'tcx
>
,
/// Trait selection queries. These are best used by invoking `ty.
moves_by_default
()`,
/// Trait selection queries. These are best used by invoking `ty.
is_copy_modulo_regions
()`,
/// `ty.is_copy()`, etc, since that will prune the environment where possible.
[]
fn
is_copy_raw
:
is_copy_dep_node
(
ty
::
ParamEnvAnd
<
'tcx
,
Ty
<
'tcx
>>
)
->
bool
,
[]
fn
is_sized_raw
:
is_sized_dep_node
(
ty
::
ParamEnvAnd
<
'tcx
,
Ty
<
'tcx
>>
)
->
bool
,
...
...
src/librustc/ty/util.rs
浏览文件 @
8e89184a
...
...
@@ -203,7 +203,7 @@ pub fn can_type_implement_copy<'a>(self,
let
cause
=
ObligationCause
{
span
,
..
ObligationCause
::
dummy
()
};
let
ctx
=
traits
::
FulfillmentContext
::
new
();
match
traits
::
fully_normalize
(
&
infcx
,
ctx
,
cause
,
self
,
&
ty
)
{
Ok
(
ty
)
=>
if
infcx
.type_moves_by_default
(
self
,
ty
,
span
)
{
Ok
(
ty
)
=>
if
!
infcx
.type_is_copy_modulo_regions
(
self
,
ty
,
span
)
{
infringing
.push
(
field
);
}
Err
(
errors
)
=>
{
...
...
@@ -628,12 +628,12 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
/// does copies even when the type actually doesn't satisfy the
/// full requirements for the `Copy` trait (cc #29149) -- this
/// winds up being reported as an error during NLL borrow check.
pub
fn
moves_by_default
(
&
'tcx
self
,
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
span
:
Span
)
->
bool
{
!
tcx
.at
(
span
)
.is_copy_raw
(
param_env
.and
(
self
))
pub
fn
is_copy_modulo_regions
(
&
'tcx
self
,
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
span
:
Span
)
->
bool
{
tcx
.at
(
span
)
.is_copy_raw
(
param_env
.and
(
self
))
}
/// Checks whether values of this type `T` have a size known at
...
...
@@ -947,11 +947,11 @@ fn needs_drop_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// `ManuallyDrop` doesn't have a destructor regardless of field types.
ty
::
Adt
(
def
,
_
)
if
Some
(
def
.did
)
==
tcx
.lang_items
()
.manually_drop
()
=>
false
,
// Issue #22536: We first query
type_moves_by_default
. It sees a
// Issue #22536: We first query
`is_copy_modulo_regions`
. It sees a
// normalized version of the type, and therefore will definitely
// know whether the type implements Copy (and thus needs no
// cleanup/drop/zeroing) ...
_
if
!
ty
.moves_by_default
(
tcx
,
param_env
,
DUMMY_SP
)
=>
false
,
_
if
ty
.is_copy_modulo_regions
(
tcx
,
param_env
,
DUMMY_SP
)
=>
false
,
// ... (issue #22536 continued) but as an optimization, still use
// prior logic of asking for the structural "may drop".
...
...
src/librustc_lint/builtin.rs
浏览文件 @
8e89184a
...
...
@@ -540,7 +540,7 @@ fn check_item(&mut self, cx: &LateContext, item: &hir::Item) {
return
;
}
let
param_env
=
ty
::
ParamEnv
::
empty
();
if
!
ty
.moves_by_default
(
cx
.tcx
,
param_env
,
item
.span
)
{
if
ty
.is_copy_modulo_regions
(
cx
.tcx
,
param_env
,
item
.span
)
{
return
;
}
if
param_env
.can_type_implement_copy
(
cx
.tcx
,
ty
)
.is_ok
()
{
...
...
src/librustc_mir/borrow_check/nll/type_check/mod.rs
浏览文件 @
8e89184a
...
...
@@ -503,13 +503,17 @@ fn sanitize_place(
substs
:
tcx
.mk_substs_trait
(
place_ty
.to_ty
(
tcx
),
&
[]),
};
// In order to have a Copy operand, the type T of the value must be Copy. Note that we
// prove that T: Copy, rather than using the type_moves_by_default test. This is
// important because type_moves_by_default ignores the resulting region obligations and
// assumes they pass. This can result in bounds from Copy impls being unsoundly ignored
// (e.g., #29149). Note that we decide to use Copy before knowing whether the bounds
// fully apply: in effect, the rule is that if a value of some type could implement
// Copy, then it must.
// In order to have a Copy operand, the type T of the
// value must be Copy. Note that we prove that T: Copy,
// rather than using the `is_copy_modulo_regions`
// test. This is important because
// `is_copy_modulo_regions` ignores the resulting region
// obligations and assumes they pass. This can result in
// bounds from Copy impls being unsoundly ignored (e.g.,
// #29149). Note that we decide to use Copy before knowing
// whether the bounds fully apply: in effect, the rule is
// that if a value of some type could implement Copy, then
// it must.
self
.cx
.prove_trait_ref
(
trait_ref
,
location
.to_locations
(),
...
...
src/librustc_mir/build/misc.rs
浏览文件 @
8e89184a
...
...
@@ -71,7 +71,7 @@ pub fn push_usize(&mut self,
pub
fn
consume_by_copy_or_move
(
&
self
,
place
:
Place
<
'tcx
>
)
->
Operand
<
'tcx
>
{
let
tcx
=
self
.hir
.tcx
();
let
ty
=
place
.ty
(
&
self
.local_decls
,
tcx
)
.to_ty
(
tcx
);
if
self
.hir
.type_moves_by_default
(
ty
,
DUMMY_SP
)
{
if
!
self
.hir
.type_is_copy_modulo_regions
(
ty
,
DUMMY_SP
)
{
Operand
::
Move
(
place
)
}
else
{
Operand
::
Copy
(
place
)
...
...
src/librustc_mir/hair/cx/mod.rs
浏览文件 @
8e89184a
...
...
@@ -223,8 +223,8 @@ pub fn check_overflow(&self) -> bool {
self
.check_overflow
}
pub
fn
type_
moves_by_default
(
&
self
,
ty
:
Ty
<
'tcx
>
,
span
:
Span
)
->
bool
{
self
.infcx
.type_
moves_by_default
(
self
.param_env
,
ty
,
span
)
pub
fn
type_
is_copy_modulo_regions
(
&
self
,
ty
:
Ty
<
'tcx
>
,
span
:
Span
)
->
bool
{
self
.infcx
.type_
is_copy_modulo_regions
(
self
.param_env
,
ty
,
span
)
}
}
...
...
src/librustc_mir/hair/pattern/check_match.rs
浏览文件 @
8e89184a
...
...
@@ -545,7 +545,7 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
match
bm
{
ty
::
BindByValue
(
..
)
=>
{
let
pat_ty
=
cx
.tables
.node_id_to_type
(
p
.hir_id
);
if
pat_ty
.moves_by_default
(
cx
.tcx
,
cx
.param_env
,
pat
.span
)
{
if
!
pat_ty
.is_copy_modulo_regions
(
cx
.tcx
,
cx
.param_env
,
pat
.span
)
{
check_move
(
p
,
sub
.as_ref
()
.map
(|
p
|
&**
p
),
span_vec
);
}
}
...
...
src/librustc_mir/shim.rs
浏览文件 @
8e89184a
...
...
@@ -310,7 +310,7 @@ fn build_clone_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
debug!
(
"build_clone_shim(def_id={:?})"
,
def_id
);
let
mut
builder
=
CloneShimBuilder
::
new
(
tcx
,
def_id
,
self_ty
);
let
is_copy
=
!
self_ty
.moves_by_default
(
tcx
,
tcx
.param_env
(
def_id
),
builder
.span
);
let
is_copy
=
self_ty
.is_copy_modulo_regions
(
tcx
,
tcx
.param_env
(
def_id
),
builder
.span
);
let
dest
=
Place
::
Local
(
RETURN_PLACE
);
let
src
=
Place
::
Local
(
Local
::
new
(
1
+
0
))
.deref
();
...
...
src/librustc_mir/transform/check_unsafety.rs
浏览文件 @
8e89184a
...
...
@@ -224,8 +224,11 @@ fn visit_place(&mut self,
"non-field projection {:?} from union?"
,
place
)
};
if
elem_ty
.moves_by_default
(
self
.tcx
,
self
.param_env
,
self
.source_info.span
)
{
if
!
elem_ty
.is_copy_modulo_regions
(
self
.tcx
,
self
.param_env
,
self
.source_info.span
,
)
{
self
.require_unsafe
(
"assignment to non-`Copy` union field"
,
"the previous content of the field will be dropped, which
\
...
...
src/librustc_typeck/check/demand.rs
浏览文件 @
8e89184a
...
...
@@ -353,9 +353,9 @@ pub fn check_ref(&self,
// Maybe add `*`? Only if `T: Copy`.
_
=>
{
if
!
self
.infcx
.type_moves_by_default
(
self
.param_env
,
checked
,
sp
)
{
if
self
.infcx
.type_is_copy_modulo_regions
(
self
.param_env
,
checked
,
sp
)
{
// do not suggest if the span comes from a macro (#52783)
if
let
(
Ok
(
code
),
true
)
=
(
cm
.span_to_snippet
(
sp
),
sp
==
expr
.span
)
{
...
...
src/librustc_typeck/check/op.rs
浏览文件 @
8e89184a
...
...
@@ -262,9 +262,9 @@ fn check_overloaded_binop(&self,
let
mut
suggested_deref
=
false
;
if
let
Ref
(
_
,
mut
rty
,
_
)
=
lhs_ty
.sty
{
if
{
!
self
.infcx
.type_moves_by_default
(
self
.param_env
,
rty
,
lhs_expr
.span
)
&&
self
.infcx
.type_is_copy_modulo_regions
(
self
.param_env
,
rty
,
lhs_expr
.span
)
&&
self
.lookup_op_method
(
rty
,
&
[
rhs_ty
],
Op
::
Binary
(
op
,
is_assign
))
...
...
@@ -334,9 +334,9 @@ fn check_overloaded_binop(&self,
let
mut
suggested_deref
=
false
;
if
let
Ref
(
_
,
mut
rty
,
_
)
=
lhs_ty
.sty
{
if
{
!
self
.infcx
.type_moves_by_default
(
self
.param_env
,
rty
,
lhs_expr
.span
)
&&
self
.infcx
.type_is_copy_modulo_regions
(
self
.param_env
,
rty
,
lhs_expr
.span
)
&&
self
.lookup_op_method
(
rty
,
&
[
rhs_ty
],
Op
::
Binary
(
op
,
is_assign
))
...
...
src/test/ui/coherence/coherence-subtyping.stderr
浏览文件 @
8e89184a
...
...
@@ -7,7 +7,7 @@ LL | impl TheTrait for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
LL | impl TheTrait for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`
|
= note: this behavior recently changed as a result of a bug fix; see
#XXX
for details
= note: this behavior recently changed as a result of a bug fix; see
rust-lang/rust#56105
for details
error: aborting due to previous error
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录