Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c976e073
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,发现更多精彩内容 >>
提交
c976e073
编写于
7月 01, 2016
作者:
E
Eduard Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: don't reveal specializable polymorphic projections.
上级
ab26dbb9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
35 deletion
+48
-35
src/librustc/traits/project.rs
src/librustc/traits/project.rs
+36
-35
src/test/compile-fail/transmute-different-sizes.rs
src/test/compile-fail/transmute-different-sizes.rs
+12
-0
未找到文件。
src/librustc/traits/project.rs
浏览文件 @
c976e073
...
...
@@ -93,7 +93,7 @@ pub enum Reveal {
/// }
NotSpecializable
,
/// At trans time, all projections will succeed.
/// At trans time, all
monomorphic
projections will succeed.
All
,
}
...
...
@@ -878,7 +878,7 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>(
candidate_set
.vec
.push
(
ProjectionTyCandidate
::
Select
);
}
super
::
VtableImpl
(
ref
impl_data
)
if
selcx
.projection_mode
()
!=
Reveal
::
All
=>
{
super
::
VtableImpl
(
ref
impl_data
)
=>
{
// We have to be careful when projecting out of an
// impl because of specialization. If we are not in
// trans (i.e., projection mode is not "any"), and the
...
...
@@ -902,37 +902,43 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>(
impl_data
.impl_def_id
,
obligation
.predicate.item_name
);
let
new_candidate
=
if
let
Some
(
node_item
)
=
opt_node_item
{
if
node_item
.node
.is_from_trait
()
{
if
node_item
.item.ty
.is_some
()
{
// The impl inherited a `type Foo =
// Bar` given in the trait, which is
// implicitly default. No candidate.
None
}
else
{
// The impl did not specify `type` and neither
// did the trait:
//
// ```rust
// trait Foo { type T; }
// impl Foo for Bar { }
// ```
//
// This is an error, but it will be
// reported in `check_impl_items_against_trait`.
// We accept it here but will flag it as
// an error when we confirm the candidate
// (which will ultimately lead to `normalize_to_error`
// being invoked).
let
is_default
=
if
node_item
.node
.is_from_trait
()
{
// If true, the impl inherited a `type Foo = Bar`
// given in the trait, which is implicitly default.
// Otherwise, the impl did not specify `type` and
// neither did the trait:
//
// ```rust
// trait Foo { type T; }
// impl Foo for Bar { }
// ```
//
// This is an error, but it will be
// reported in `check_impl_items_against_trait`.
// We accept it here but will flag it as
// an error when we confirm the candidate
// (which will ultimately lead to `normalize_to_error`
// being invoked).
node_item
.item.ty
.is_some
()
}
else
{
node_item
.item.defaultness
.is_default
()
};
// Only reveal a specializable default if we're past type-checking
// and the obligations is monomorphic, otherwise passes such as
// transmute checking and polymorphic MIR optimizations could
// get a result which isn't correct for all monomorphizations.
if
!
is_default
{
Some
(
ProjectionTyCandidate
::
Select
)
}
else
if
selcx
.projection_mode
()
==
Reveal
::
All
{
assert
!
(
!
poly_trait_ref
.needs_infer
());
if
!
poly_trait_ref
.needs_subst
()
{
Some
(
ProjectionTyCandidate
::
Select
)
}
else
{
None
}
}
else
if
node_item
.item.defaultness
.is_default
()
{
// The impl specified `default type Foo =
// Bar`. No candidate.
None
}
else
{
// The impl specified `type Foo = Bar`
// with no default. Add a candidate.
Some
(
ProjectionTyCandidate
::
Select
)
None
}
}
else
{
// This is saying that neither the trait nor
...
...
@@ -982,11 +988,6 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>(
};
candidate_set
.vec
.extend
(
new_candidate
);
}
super
::
VtableImpl
(
_
)
=>
{
// In trans mode, we can just project out of impls, no prob.
assert
!
(
selcx
.projection_mode
()
==
Reveal
::
All
);
candidate_set
.vec
.push
(
ProjectionTyCandidate
::
Select
);
}
super
::
VtableParam
(
..
)
=>
{
// This case tell us nothing about the value of an
// associated type. Consider:
...
...
src/test/compile-fail/transmute-different-sizes.rs
浏览文件 @
c976e073
...
...
@@ -11,6 +11,7 @@
// Tests that `transmute` cannot be called on types of different size.
#![allow(warnings)]
#![feature(specialization)]
use
std
::
mem
::
transmute
;
...
...
@@ -24,4 +25,15 @@ unsafe fn g<T>(x: &T) {
//~^ ERROR transmute called with differently sized types
}
trait
Specializable
{
type
Output
;
}
impl
<
T
>
Specializable
for
T
{
default
type
Output
=
u16
;
}
unsafe
fn
specializable
<
T
>
(
x
:
u16
)
->
<
T
as
Specializable
>
::
Output
{
transmute
(
x
)
//~^ ERROR transmute called with differently sized types
}
fn
main
()
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录