Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b8dad484
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,发现更多精彩内容 >>
提交
b8dad484
编写于
9月 03, 2015
作者:
A
Andrew Paseltiner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix multiple mutable autoderefs with `Box`
Closes #26205.
上级
16619470
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
93 addition
and
50 deletion
+93
-50
src/librustc/middle/check_match.rs
src/librustc/middle/check_match.rs
+1
-1
src/librustc/middle/mem_categorization.rs
src/librustc/middle/mem_categorization.rs
+3
-3
src/librustc/middle/ty.rs
src/librustc/middle/ty.rs
+22
-3
src/librustc_trans/trans/consts.rs
src/librustc_trans/trans/consts.rs
+5
-4
src/librustc_trans/trans/expr.rs
src/librustc_trans/trans/expr.rs
+3
-2
src/librustc_typeck/check/_match.rs
src/librustc_typeck/check/_match.rs
+5
-5
src/librustc_typeck/check/callee.rs
src/librustc_typeck/check/callee.rs
+1
-2
src/librustc_typeck/check/coercion.rs
src/librustc_typeck/check/coercion.rs
+2
-2
src/librustc_typeck/check/method/confirm.rs
src/librustc_typeck/check/method/confirm.rs
+3
-3
src/librustc_typeck/check/method/probe.rs
src/librustc_typeck/check/method/probe.rs
+2
-2
src/librustc_typeck/check/method/suggest.rs
src/librustc_typeck/check/method/suggest.rs
+1
-1
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+4
-19
src/librustc_typeck/check/op.rs
src/librustc_typeck/check/op.rs
+1
-2
src/librustc_typeck/check/regionck.rs
src/librustc_typeck/check/regionck.rs
+1
-1
src/test/run-pass/issue-26205.rs
src/test/run-pass/issue-26205.rs
+39
-0
未找到文件。
src/librustc/middle/check_match.rs
浏览文件 @
b8dad484
...
...
@@ -664,7 +664,7 @@ fn is_useful(cx: &MatchCheckCtxt,
match
real_pat
.node
{
hir
::
PatIdent
(
hir
::
BindByRef
(
..
),
_
,
_
)
=>
{
left_ty
.builtin_deref
(
false
)
.unwrap
()
.ty
left_ty
.builtin_deref
(
false
,
NoPreference
)
.unwrap
()
.ty
}
_
=>
left_ty
,
}
...
...
src/librustc/middle/mem_categorization.rs
浏览文件 @
b8dad484
...
...
@@ -400,7 +400,7 @@ fn pat_ty(&self, pat: &hir::Pat) -> McResult<Ty<'tcx>> {
// a bind-by-ref means that the base_ty will be the type of the ident itself,
// but what we want here is the type of the underlying value being borrowed.
// So peel off one-level, turning the &T into T.
match
base_ty
.builtin_deref
(
false
)
{
match
base_ty
.builtin_deref
(
false
,
ty
::
NoPreference
)
{
Some
(
t
)
=>
t
.ty
,
None
=>
{
return
Err
(());
}
}
...
...
@@ -897,7 +897,7 @@ fn cat_deref<N:ast_node>(&self,
None
=>
base_cmt
};
let
base_cmt_ty
=
base_cmt
.ty
;
match
base_cmt_ty
.builtin_deref
(
true
)
{
match
base_cmt_ty
.builtin_deref
(
true
,
ty
::
NoPreference
)
{
Some
(
mt
)
=>
{
let
ret
=
self
.cat_deref_common
(
node
,
base_cmt
,
deref_cnt
,
mt
.ty
,
...
...
@@ -1044,7 +1044,7 @@ fn deref_vec<N:ast_node>(&self,
span
:
elt
.span
(),
cat
:
cat_deref
(
base_cmt
.clone
(),
0
,
ptr
),
mutbl
:
m
,
ty
:
match
base_cmt
.ty
.builtin_deref
(
false
)
{
ty
:
match
base_cmt
.ty
.builtin_deref
(
false
,
ty
::
NoPreference
)
{
Some
(
mt
)
=>
mt
.ty
,
None
=>
self
.tcx
()
.sess
.bug
(
"Found non-derefable type"
)
},
...
...
src/librustc/middle/ty.rs
浏览文件 @
b8dad484
...
...
@@ -29,6 +29,7 @@
pub
use
self
::
TypeVariants
::
*
;
pub
use
self
::
IntVarValue
::
*
;
pub
use
self
::
CopyImplementationError
::
*
;
pub
use
self
::
LvaluePreference
::
*
;
pub
use
self
::
BuiltinBound
::
Send
as
BoundSend
;
pub
use
self
::
BuiltinBound
::
Sized
as
BoundSized
;
...
...
@@ -4828,6 +4829,21 @@ fn is_sized_uncached<'a>(&'tcx self, param_env: &ParameterEnvironment<'a,'tcx>,
}
}
#[derive(Copy,
Clone,
Debug,
PartialEq,
Eq)]
pub
enum
LvaluePreference
{
PreferMutLvalue
,
NoPreference
}
impl
LvaluePreference
{
pub
fn
from_mutbl
(
m
:
hir
::
Mutability
)
->
Self
{
match
m
{
hir
::
MutMutable
=>
PreferMutLvalue
,
hir
::
MutImmutable
=>
NoPreference
,
}
}
}
/// Describes whether a type is representable. For types that are not
/// representable, 'SelfRecursive' and 'ContainsRecursive' are used to
/// distinguish between types that are recursive with themselves and types that
...
...
@@ -5073,12 +5089,15 @@ pub fn is_machine(&self) -> bool {
//
// The parameter `explicit` indicates if this is an *explicit* dereference.
// Some types---notably unsafe ptrs---can only be dereferenced explicitly.
pub
fn
builtin_deref
(
&
self
,
explicit
:
bool
)
->
Option
<
TypeAndMut
<
'tcx
>>
{
pub
fn
builtin_deref
(
&
self
,
explicit
:
bool
,
pref
:
LvaluePreference
)
->
Option
<
TypeAndMut
<
'tcx
>>
{
match
self
.sty
{
TyBox
(
ty
)
=>
{
Some
(
TypeAndMut
{
ty
:
ty
,
mutbl
:
hir
::
MutImmutable
,
mutbl
:
if
pref
==
PreferMutLvalue
{
hir
::
MutMutable
}
else
{
hir
::
MutImmutable
},
})
},
TyRef
(
_
,
mt
)
=>
Some
(
mt
),
...
...
@@ -5183,7 +5202,7 @@ pub fn adjust<F>(&'tcx self, cx: &ctxt<'tcx>,
}
None
=>
{}
}
match
adjusted_ty
.builtin_deref
(
true
)
{
match
adjusted_ty
.builtin_deref
(
true
,
NoPreference
)
{
Some
(
mt
)
=>
{
adjusted_ty
=
mt
.ty
;
}
None
=>
{
cx
.sess
.span_bug
(
...
...
src/librustc_trans/trans/consts.rs
浏览文件 @
b8dad484
...
...
@@ -155,7 +155,7 @@ fn const_deref<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
v
:
ValueRef
,
ty
:
Ty
<
'tcx
>
)
->
(
ValueRef
,
Ty
<
'tcx
>
)
{
match
ty
.builtin_deref
(
true
)
{
match
ty
.builtin_deref
(
true
,
ty
::
NoPreference
)
{
Some
(
mt
)
=>
{
if
type_is_sized
(
cx
.tcx
(),
mt
.ty
)
{
(
const_deref_ptr
(
cx
,
v
),
mt
.ty
)
...
...
@@ -329,7 +329,7 @@ pub fn const_expr<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
param_substs
,
&
target
);
let
pointee_ty
=
ty
.builtin_deref
(
true
)
let
pointee_ty
=
ty
.builtin_deref
(
true
,
ty
::
NoPreference
)
.expect
(
"consts: unsizing got non-pointer type"
)
.ty
;
let
(
base
,
old_info
)
=
if
!
type_is_sized
(
cx
.tcx
(),
pointee_ty
)
{
// Normally, the source is a thin pointer and we are
...
...
@@ -344,7 +344,7 @@ pub fn const_expr<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
(
llconst
,
None
)
};
let
unsized_ty
=
target
.builtin_deref
(
true
)
let
unsized_ty
=
target
.builtin_deref
(
true
,
ty
::
NoPreference
)
.expect
(
"consts: unsizing got non-pointer target type"
)
.ty
;
let
ptr_ty
=
type_of
::
in_memory_type_of
(
cx
,
unsized_ty
)
.ptr_to
();
let
base
=
ptrcast
(
base
,
ptr_ty
);
...
...
@@ -642,7 +642,8 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
}
if
type_is_fat_ptr
(
cx
.tcx
(),
t_expr
)
{
// Fat pointer casts.
let
t_cast_inner
=
t_cast
.builtin_deref
(
true
)
.expect
(
"cast to non-pointer"
)
.ty
;
let
t_cast_inner
=
t_cast
.builtin_deref
(
true
,
ty
::
NoPreference
)
.expect
(
"cast to non-pointer"
)
.ty
;
let
ptr_ty
=
type_of
::
in_memory_type_of
(
cx
,
t_cast_inner
)
.ptr_to
();
let
addr
=
ptrcast
(
const_get_elt
(
cx
,
v
,
&
[
abi
::
FAT_PTR_ADDR
as
u32
]),
ptr_ty
);
...
...
src/librustc_trans/trans/expr.rs
浏览文件 @
b8dad484
...
...
@@ -780,7 +780,7 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let
ref_ty
=
// invoked methods have LB regions instantiated:
bcx
.tcx
()
.no_late_bound_regions
(
&
method_ty
.fn_ret
())
.unwrap
()
.unwrap
();
let
elt_ty
=
match
ref_ty
.builtin_deref
(
true
)
{
let
elt_ty
=
match
ref_ty
.builtin_deref
(
true
,
ty
::
NoPreference
)
{
None
=>
{
bcx
.tcx
()
.sess
.span_bug
(
index_expr
.span
,
"index method didn't return a
\
...
...
@@ -1971,7 +1971,8 @@ pub fn cast_is_noop<'tcx>(tcx: &ty::ctxt<'tcx>,
return
true
;
}
match
(
t_in
.builtin_deref
(
true
),
t_out
.builtin_deref
(
true
))
{
match
(
t_in
.builtin_deref
(
true
,
ty
::
NoPreference
),
t_out
.builtin_deref
(
true
,
ty
::
NoPreference
))
{
(
Some
(
ty
::
TypeAndMut
{
ty
:
t_in
,
..
}),
Some
(
ty
::
TypeAndMut
{
ty
:
t_out
,
..
}))
=>
{
t_in
==
t_out
}
...
...
src/librustc_typeck/check/_match.rs
浏览文件 @
b8dad484
...
...
@@ -15,10 +15,10 @@
use
middle
::
pat_util
::
pat_is_resolved_const
;
use
middle
::
privacy
::{
AllPublic
,
LastMod
};
use
middle
::
subst
::
Substs
;
use
middle
::
ty
::{
self
,
Ty
,
HasTypeFlags
};
use
middle
::
ty
::{
self
,
Ty
,
HasTypeFlags
,
LvaluePreference
};
use
check
::{
check_expr
,
check_expr_has_type
,
check_expr_with_expectation
};
use
check
::{
check_expr_coercable_to_type
,
demand
,
FnCtxt
,
Expectation
};
use
check
::{
check_expr_with_lvalue_pref
,
LvaluePreference
};
use
check
::{
check_expr_with_lvalue_pref
};
use
check
::{
instantiate_path
,
resolve_ty_and_def_ufcs
,
structurally_resolved_type
};
use
require_same_types
;
use
util
::
nodemap
::
FnvHashMap
;
...
...
@@ -292,7 +292,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
let
region
=
fcx
.infcx
()
.next_region_var
(
infer
::
PatternRegion
(
pat
.span
));
tcx
.mk_ref
(
tcx
.mk_region
(
region
),
ty
::
TypeAndMut
{
ty
:
tcx
.mk_slice
(
inner_ty
),
mutbl
:
expected_ty
.builtin_deref
(
true
)
.map
(|
mt
|
mt
.mutbl
)
mutbl
:
expected_ty
.builtin_deref
(
true
,
ty
::
NoPreference
)
.map
(|
mt
|
mt
.mutbl
)
.unwrap_or
(
hir
::
MutImmutable
)
})
}
...
...
@@ -310,7 +310,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
}
if
let
Some
(
ref
slice
)
=
*
slice
{
let
region
=
fcx
.infcx
()
.next_region_var
(
infer
::
PatternRegion
(
pat
.span
));
let
mutbl
=
expected_ty
.builtin_deref
(
true
)
let
mutbl
=
expected_ty
.builtin_deref
(
true
,
ty
::
NoPreference
)
.map_or
(
hir
::
MutImmutable
,
|
mt
|
mt
.mutbl
);
let
slice_ty
=
tcx
.mk_ref
(
tcx
.mk_region
(
region
),
ty
::
TypeAndMut
{
...
...
@@ -399,7 +399,7 @@ pub fn check_dereferencable<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
let
tcx
=
pcx
.fcx.ccx.tcx
;
if
pat_is_binding
(
&
tcx
.def_map
,
inner
)
{
let
expected
=
fcx
.infcx
()
.shallow_resolve
(
expected
);
expected
.builtin_deref
(
true
)
.map_or
(
true
,
|
mt
|
match
mt
.ty.sty
{
expected
.builtin_deref
(
true
,
ty
::
NoPreference
)
.map_or
(
true
,
|
mt
|
match
mt
.ty.sty
{
ty
::
TyTrait
(
_
)
=>
{
// This is "x = SomeTrait" being reduced from
// "let &x = &SomeTrait" or "let box x = Box<SomeTrait>", an error.
...
...
src/librustc_typeck/check/callee.rs
浏览文件 @
b8dad484
...
...
@@ -18,7 +18,6 @@
use
super
::
Expectation
;
use
super
::
expected_types_for_fn_args
;
use
super
::
FnCtxt
;
use
super
::
LvaluePreference
;
use
super
::
method
;
use
super
::
structurally_resolved_type
;
use
super
::
TupleArgumentsFlag
;
...
...
@@ -28,7 +27,7 @@
use
CrateCtxt
;
use
middle
::
def_id
::{
DefId
,
LOCAL_CRATE
};
use
middle
::
infer
;
use
middle
::
ty
::{
self
,
Ty
};
use
middle
::
ty
::{
self
,
LvaluePreference
,
Ty
};
use
syntax
::
codemap
::
Span
;
use
syntax
::
parse
::
token
;
use
syntax
::
ptr
::
P
;
...
...
src/librustc_typeck/check/coercion.rs
浏览文件 @
b8dad484
...
...
@@ -60,13 +60,13 @@
//! sort of a minor point so I've opted to leave it for later---after all
//! we may want to adjust precisely when coercions occur.
use
check
::{
autoderef
,
FnCtxt
,
LvaluePreference
,
UnresolvedTypeAction
};
use
check
::{
autoderef
,
FnCtxt
,
UnresolvedTypeAction
};
use
middle
::
infer
::{
self
,
Coercion
};
use
middle
::
traits
::{
self
,
ObligationCause
};
use
middle
::
traits
::{
predicate_for_trait_def
,
report_selection_error
};
use
middle
::
ty
::{
AutoDerefRef
,
AdjustDerefRef
};
use
middle
::
ty
::{
self
,
TypeAndMut
,
Ty
,
TypeError
};
use
middle
::
ty
::{
self
,
LvaluePreference
,
TypeAndMut
,
Ty
,
TypeError
};
use
middle
::
ty_relate
::
RelateResult
;
use
util
::
common
::
indent
;
...
...
src/librustc_typeck/check/method/confirm.rs
浏览文件 @
b8dad484
...
...
@@ -10,12 +10,12 @@
use
super
::
probe
;
use
check
::{
self
,
FnCtxt
,
NoPreference
,
PreferMutLvalue
,
callee
,
demand
};
use
check
::{
self
,
FnCtxt
,
callee
,
demand
};
use
check
::
UnresolvedTypeAction
;
use
middle
::
def_id
::
DefId
;
use
middle
::
subst
::{
self
};
use
middle
::
traits
;
use
middle
::
ty
::{
self
,
Ty
};
use
middle
::
ty
::{
self
,
NoPreference
,
PreferMutLvalue
,
Ty
};
use
middle
::
ty_fold
::
TypeFoldable
;
use
middle
::
infer
;
use
middle
::
infer
::
InferCtxt
;
...
...
@@ -534,7 +534,7 @@ fn fixup_derefs_on_method_receiver_if_necessary(&self,
}
Some
(
ty
::
AutoPtr
(
_
,
_
))
=>
{
(
adr
.autoderefs
,
adr
.unsize
.map
(|
target
|
{
target
.builtin_deref
(
false
)
target
.builtin_deref
(
false
,
NoPreference
)
.expect
(
"fixup: AutoPtr is not &T"
)
.ty
}))
}
...
...
src/librustc_typeck/check/method/probe.rs
浏览文件 @
b8dad484
...
...
@@ -14,13 +14,13 @@
use
super
::
suggest
;
use
check
;
use
check
::{
FnCtxt
,
NoPreference
,
UnresolvedTypeAction
};
use
check
::{
FnCtxt
,
UnresolvedTypeAction
};
use
middle
::
def_id
::
DefId
;
use
middle
::
fast_reject
;
use
middle
::
subst
;
use
middle
::
subst
::
Subst
;
use
middle
::
traits
;
use
middle
::
ty
::{
self
,
RegionEscape
,
Ty
,
ToPolyTraitRef
,
TraitRef
};
use
middle
::
ty
::{
self
,
NoPreference
,
RegionEscape
,
Ty
,
ToPolyTraitRef
,
TraitRef
};
use
middle
::
ty
::
HasTypeFlags
;
use
middle
::
ty_fold
::
TypeFoldable
;
use
middle
::
infer
;
...
...
src/librustc_typeck/check/method/suggest.rs
浏览文件 @
b8dad484
...
...
@@ -324,7 +324,7 @@ fn is_local(ty: Ty) -> bool {
}
check
::
autoderef
(
fcx
,
span
,
rcvr_ty
,
None
,
check
::
UnresolvedTypeAction
::
Ignore
,
check
::
NoPreference
,
check
::
UnresolvedTypeAction
::
Ignore
,
ty
::
NoPreference
,
|
ty
,
_
|
{
if
is_local
(
ty
)
{
Some
(())
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
b8dad484
...
...
@@ -76,7 +76,6 @@
*/
pub
use
self
::
LvaluePreference
::
*
;
pub
use
self
::
Expectation
::
*
;
pub
use
self
::
compare_method
::{
compare_impl_method
,
compare_const_impl
};
use
self
::
TupleArgumentsFlag
::
*
;
...
...
@@ -95,6 +94,7 @@
use
middle
::
traits
::{
self
,
report_fulfillment_errors
};
use
middle
::
ty
::{
FnSig
,
GenericPredicates
,
TypeScheme
};
use
middle
::
ty
::{
Disr
,
ParamTy
,
ParameterEnvironment
};
use
middle
::
ty
::{
LvaluePreference
,
NoPreference
,
PreferMutLvalue
};
use
middle
::
ty
::{
self
,
HasTypeFlags
,
RegionEscape
,
ToPolyTraitRef
,
Ty
};
use
middle
::
ty
::{
MethodCall
,
MethodCallee
};
use
middle
::
ty_fold
::{
TypeFolder
,
TypeFoldable
};
...
...
@@ -2086,21 +2086,6 @@ fn anon_regions(&self, span: Span, count: usize)
}
}
#[derive(Copy,
Clone,
Debug,
PartialEq,
Eq)]
pub
enum
LvaluePreference
{
PreferMutLvalue
,
NoPreference
}
impl
LvaluePreference
{
pub
fn
from_mutbl
(
m
:
hir
::
Mutability
)
->
Self
{
match
m
{
hir
::
MutMutable
=>
PreferMutLvalue
,
hir
::
MutImmutable
=>
NoPreference
,
}
}
}
/// Whether `autoderef` requires types to resolve.
#[derive(Copy,
Clone,
Debug,
PartialEq,
Eq)]
pub
enum
UnresolvedTypeAction
{
...
...
@@ -2156,7 +2141,7 @@ pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>,
}
// Otherwise, deref if type is derefable:
let
mt
=
match
resolved_t
.builtin_deref
(
false
)
{
let
mt
=
match
resolved_t
.builtin_deref
(
false
,
lvalue_pref
)
{
Some
(
mt
)
=>
Some
(
mt
),
None
=>
{
let
method_call
=
...
...
@@ -2245,7 +2230,7 @@ fn make_overloaded_lvalue_return_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
}
// method returns &T, but the type as visible to user is T, so deref
ret_ty
.builtin_deref
(
true
)
ret_ty
.builtin_deref
(
true
,
NoPreference
)
}
None
=>
None
,
}
...
...
@@ -3293,7 +3278,7 @@ fn check_expr_struct<'a, 'tcx>(fcx: &FnCtxt<'a,'tcx>,
}
hir
::
UnDeref
=>
{
oprnd_t
=
structurally_resolved_type
(
fcx
,
expr
.span
,
oprnd_t
);
oprnd_t
=
match
oprnd_t
.builtin_deref
(
true
)
{
oprnd_t
=
match
oprnd_t
.builtin_deref
(
true
,
NoPreference
)
{
Some
(
mt
)
=>
mt
.ty
,
None
=>
match
try_overloaded_deref
(
fcx
,
expr
.span
,
Some
(
MethodCall
::
expr
(
expr
.id
)),
...
...
src/librustc_typeck/check/op.rs
浏览文件 @
b8dad484
...
...
@@ -17,12 +17,11 @@
demand
,
method
,
FnCtxt
,
PreferMutLvalue
,
structurally_resolved_type
,
};
use
middle
::
def_id
::
DefId
;
use
middle
::
traits
;
use
middle
::
ty
::{
Ty
,
HasTypeFlags
};
use
middle
::
ty
::{
Ty
,
HasTypeFlags
,
PreferMutLvalue
};
use
syntax
::
ast
;
use
syntax
::
parse
::
token
;
use
rustc_front
::
hir
;
...
...
src/librustc_typeck/check/regionck.rs
浏览文件 @
b8dad484
...
...
@@ -1031,7 +1031,7 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
r_deref_expr
,
*
r_ptr
);
}
match
derefd_ty
.builtin_deref
(
true
)
{
match
derefd_ty
.builtin_deref
(
true
,
ty
::
NoPreference
)
{
Some
(
mt
)
=>
derefd_ty
=
mt
.ty
,
/* if this type can't be dereferenced, then there's already an error
in the session saying so. Just bail out for now */
...
...
src/test/run-pass/issue-26205.rs
0 → 100644
浏览文件 @
b8dad484
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
std
::
ops
::{
Deref
,
DerefMut
};
struct
Foo
;
impl
Foo
{
fn
foo_mut
(
&
mut
self
)
{}
}
struct
Bar
(
Foo
);
impl
Deref
for
Bar
{
type
Target
=
Foo
;
fn
deref
(
&
self
)
->
&
Foo
{
&
self
.0
}
}
impl
DerefMut
for
Bar
{
fn
deref_mut
(
&
mut
self
)
->
&
mut
Foo
{
&
mut
self
.0
}
}
fn
test
(
mut
bar
:
Box
<
Bar
>
)
{
bar
.foo_mut
();
}
fn
main
()
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录