Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
83710b44
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,发现更多精彩内容 >>
提交
83710b44
编写于
1月 08, 2016
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
permit coercions if `[error]` is found in either type
上级
a3cbfa58
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
30 deletion
+29
-30
src/librustc_typeck/check/coercion.rs
src/librustc_typeck/check/coercion.rs
+27
-28
src/test/compile-fail/issue-19692.rs
src/test/compile-fail/issue-19692.rs
+1
-1
src/test/compile-fail/issue-3973.rs
src/test/compile-fail/issue-3973.rs
+1
-1
未找到文件。
src/librustc_typeck/check/coercion.rs
浏览文件 @
83710b44
...
@@ -68,7 +68,7 @@
...
@@ -68,7 +68,7 @@
use
middle
::
ty
::
adjustment
::{
AutoAdjustment
,
AutoDerefRef
,
AdjustDerefRef
};
use
middle
::
ty
::
adjustment
::{
AutoAdjustment
,
AutoDerefRef
,
AdjustDerefRef
};
use
middle
::
ty
::
adjustment
::{
AutoPtr
,
AutoUnsafe
,
AdjustReifyFnPointer
};
use
middle
::
ty
::
adjustment
::{
AutoPtr
,
AutoUnsafe
,
AdjustReifyFnPointer
};
use
middle
::
ty
::
adjustment
::{
AdjustUnsafeFnPointer
};
use
middle
::
ty
::
adjustment
::{
AdjustUnsafeFnPointer
};
use
middle
::
ty
::{
self
,
LvaluePreference
,
TypeAndMut
,
Ty
};
use
middle
::
ty
::{
self
,
LvaluePreference
,
TypeAndMut
,
Ty
,
HasTypeFlags
};
use
middle
::
ty
::
error
::
TypeError
;
use
middle
::
ty
::
error
::
TypeError
;
use
middle
::
ty
::
relate
::
RelateResult
;
use
middle
::
ty
::
relate
::
RelateResult
;
use
util
::
common
::
indent
;
use
util
::
common
::
indent
;
...
@@ -110,10 +110,15 @@ fn coerce(&self,
...
@@ -110,10 +110,15 @@ fn coerce(&self,
a
,
a
,
b
);
b
);
let
a
=
self
.fcx
.infcx
()
.shallow_resolve
(
a
);
// Just ignore error types.
if
a
.references_error
()
||
b
.references_error
()
{
return
Ok
(
None
);
}
// Consider coercing the subtype to a DST
// Consider coercing the subtype to a DST
let
unsize
=
self
.unpack_actual_value
(
a
,
|
a
|
{
let
unsize
=
self
.coerce_unsized
(
a
,
b
);
self
.coerce_unsized
(
a
,
b
)
});
if
unsize
.is_ok
()
{
if
unsize
.is_ok
()
{
return
unsize
;
return
unsize
;
}
}
...
@@ -124,39 +129,33 @@ fn coerce(&self,
...
@@ -124,39 +129,33 @@ fn coerce(&self,
// See above for details.
// See above for details.
match
b
.sty
{
match
b
.sty
{
ty
::
TyRawPtr
(
mt_b
)
=>
{
ty
::
TyRawPtr
(
mt_b
)
=>
{
return
self
.unpack_actual_value
(
a
,
|
a
|
{
return
self
.coerce_unsafe_ptr
(
a
,
b
,
mt_b
.mutbl
);
self
.coerce_unsafe_ptr
(
a
,
b
,
mt_b
.mutbl
)
});
}
}
ty
::
TyRef
(
_
,
mt_b
)
=>
{
ty
::
TyRef
(
_
,
mt_b
)
=>
{
return
self
.unpack_actual_value
(
a
,
|
a
|
{
return
self
.coerce_borrowed_pointer
(
expr_a
,
a
,
b
,
mt_b
.mutbl
);
self
.coerce_borrowed_pointer
(
expr_a
,
a
,
b
,
mt_b
.mutbl
)
});
}
}
_
=>
{}
_
=>
{}
}
}
self
.unpack_actual_value
(
a
,
|
a
|
{
match
a
.sty
{
match
a
.sty
{
ty
::
TyBareFn
(
Some
(
_
),
a_f
)
=>
{
ty
::
TyBareFn
(
Some
(
_
),
a_f
)
=>
{
// Function items are coercible to any closure
// Function items are coercible to any closure
// type; function pointers are not (that would
// type; function pointers are not (that would
// require double indirection).
// require double indirection).
self
.coerce_from_fn_item
(
a
,
a_f
,
b
)
self
.coerce_from_fn_item
(
a
,
a_f
,
b
)
}
ty
::
TyBareFn
(
None
,
a_f
)
=>
{
// We permit coercion of fn pointers to drop the
// unsafe qualifier.
self
.coerce_from_fn_pointer
(
a
,
a_f
,
b
)
}
_
=>
{
// Otherwise, just use subtyping rules.
self
.subtype
(
a
,
b
)
}
}
}
})
ty
::
TyBareFn
(
None
,
a_f
)
=>
{
// We permit coercion of fn pointers to drop the
// unsafe qualifier.
self
.coerce_from_fn_pointer
(
a
,
a_f
,
b
)
}
_
=>
{
// Otherwise, just use subtyping rules.
self
.subtype
(
a
,
b
)
}
}
}
}
/// Reborrows `&mut A` to `&mut B` and `&(mut) A` to `&B`.
/// Reborrows `&mut A` to `&mut B` and `&(mut) A` to `&B`.
...
...
src/test/compile-fail/issue-19692.rs
浏览文件 @
83710b44
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
fn
akemi
(
homura
:
Homura
)
{
fn
akemi
(
homura
:
Homura
)
{
let
Some
(
ref
madoka
)
=
Some
(
homura
.kaname
());
//~ ERROR no method named `kaname` found
let
Some
(
ref
madoka
)
=
Some
(
homura
.kaname
());
//~ ERROR no method named `kaname` found
madoka
.clone
();
madoka
.clone
();
//~ ERROR the type of this value must be known
}
}
fn
main
()
{
}
fn
main
()
{
}
src/test/compile-fail/issue-3973.rs
浏览文件 @
83710b44
...
@@ -31,5 +31,5 @@ fn to_string(&self) -> String {
...
@@ -31,5 +31,5 @@ fn to_string(&self) -> String {
fn
main
()
{
fn
main
()
{
let
p
=
Point
::
new
(
0.0
,
0.0
);
let
p
=
Point
::
new
(
0.0
,
0.0
);
//~^ ERROR no associated item named `new` found for type `Point` in the current scope
//~^ ERROR no associated item named `new` found for type `Point` in the current scope
println!
(
"{}"
,
p
.to_string
());
println!
(
"{}"
,
p
.to_string
());
//~ ERROR type of this value must be known
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录