Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
55621b61
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
55621b61
编写于
7月 24, 2015
作者:
J
Jared Roesch
提交者:
Jared Roesch
7月 25, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add feature gate
上级
9da04b2b
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
74 addition
and
10 deletion
+74
-10
src/doc/reference.md
src/doc/reference.md
+2
-0
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+39
-1
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+7
-2
src/test/compile-fail/default_ty_param_conflict.rs
src/test/compile-fail/default_ty_param_conflict.rs
+2
-0
src/test/compile-fail/default_ty_param_conflict_cross_crate.rs
...est/compile-fail/default_ty_param_conflict_cross_crate.rs
+3
-0
src/test/run-pass/default_ty_param_default_dependent_associated_type.rs
...ass/default_ty_param_default_dependent_associated_type.rs
+3
-0
src/test/run-pass/default_ty_param_dependent_defaults.rs
src/test/run-pass/default_ty_param_dependent_defaults.rs
+1
-0
src/test/run-pass/default_ty_param_method_call_test.rs
src/test/run-pass/default_ty_param_method_call_test.rs
+2
-0
src/test/run-pass/default_ty_param_struct.rs
src/test/run-pass/default_ty_param_struct.rs
+2
-0
src/test/run-pass/default_ty_param_struct_and_type_alias.rs
src/test/run-pass/default_ty_param_struct_and_type_alias.rs
+2
-0
src/test/run-pass/default_ty_param_trait_impl.rs
src/test/run-pass/default_ty_param_trait_impl.rs
+5
-3
src/test/run-pass/default_ty_param_trait_impl_simple.rs
src/test/run-pass/default_ty_param_trait_impl_simple.rs
+4
-4
src/test/run-pass/default_ty_param_type_alias.rs
src/test/run-pass/default_ty_param_type_alias.rs
+2
-0
未找到文件。
src/doc/reference.md
浏览文件 @
55621b61
...
...
@@ -2368,6 +2368,8 @@ The currently implemented features of the reference compiler are:
internally without imposing on callers
(i.e. making them behave like function calls in
terms of encapsulation).
* - `default_type_parameter_fallback` - Allows type parameter defaults to
influence type inference.
If a feature is promoted to a language feature, then all existing programs will
start to receive compilation warnings about `#![feature]` directives which enabled
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
55621b61
...
...
@@ -1709,10 +1709,47 @@ fn check_casts(&self) {
}
}
/// Apply "fallbacks" to some types
/// ! gets replaced with (), unconstrained ints with i32, and unconstrained floats with f64.
pub
fn
default_type_parameters
(
&
self
)
{
use
middle
::
ty
::
UnconstrainedNumeric
::{
UnconstrainedInt
,
UnconstrainedFloat
,
Neither
};
for
ty
in
&
self
.infcx
()
.unsolved_variables
()
{
let
resolved
=
self
.infcx
()
.resolve_type_vars_if_possible
(
ty
);
if
self
.infcx
()
.type_var_diverges
(
resolved
)
{
demand
::
eqtype
(
self
,
codemap
::
DUMMY_SP
,
*
ty
,
self
.tcx
()
.mk_nil
());
}
else
{
match
self
.infcx
()
.type_is_unconstrained_numeric
(
resolved
)
{
UnconstrainedInt
=>
{
demand
::
eqtype
(
self
,
codemap
::
DUMMY_SP
,
*
ty
,
self
.tcx
()
.types.i32
)
},
UnconstrainedFloat
=>
{
demand
::
eqtype
(
self
,
codemap
::
DUMMY_SP
,
*
ty
,
self
.tcx
()
.types.f64
)
}
Neither
=>
{
}
}
}
}
}
fn
select_all_obligations_and_apply_defaults
(
&
self
)
{
if
self
.tcx
()
.sess.features
.borrow
()
.default_type_parameter_fallback
{
self
.new_select_all_obligations_and_apply_defaults
();
}
else
{
self
.old_select_all_obligations_and_apply_defaults
();
}
}
// Implements old type inference fallback algorithm
fn
old_select_all_obligations_and_apply_defaults
(
&
self
)
{
self
.select_obligations_where_possible
();
self
.default_type_parameters
();
self
.select_obligations_where_possible
();
}
fn
new_select_all_obligations_and_apply_defaults
(
&
self
)
{
use
middle
::
ty
::
UnconstrainedNumeric
::{
UnconstrainedInt
,
UnconstrainedFloat
,
Neither
};
// For the time being this errs on the side of being memory wasteful but provides better
// For the time being this errs on the side of being memory wasteful but provides better
// error reporting.
// let type_variables = self.infcx().type_variables.clone();
...
...
@@ -1934,6 +1971,7 @@ fn select_all_obligations_or_error(&self) {
assert
!
(
self
.inh.deferred_call_resolutions
.borrow
()
.is_empty
());
self
.select_all_obligations_and_apply_defaults
();
let
mut
fulfillment_cx
=
self
.inh.infcx.fulfillment_cx
.borrow_mut
();
match
fulfillment_cx
.select_all_or_error
(
self
.infcx
())
{
Ok
(())
=>
{
}
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
55621b61
...
...
@@ -163,6 +163,8 @@
// Allows the definition recursive static items.
(
"static_recursion"
,
"1.3.0"
,
Active
),
// Allows default type parameters to influence type inference.
(
"default_type_parameter_fallback"
,
"1.3.0"
,
Active
)
];
// (changing above list without updating src/doc/reference.md makes @cmr sad)
...
...
@@ -341,7 +343,8 @@ pub struct Features {
/// #![feature] attrs for non-language (library) features
pub
declared_lib_features
:
Vec
<
(
InternedString
,
Span
)
>
,
pub
const_fn
:
bool
,
pub
static_recursion
:
bool
pub
static_recursion
:
bool
,
pub
default_type_parameter_fallback
:
bool
,
}
impl
Features
{
...
...
@@ -366,7 +369,8 @@ pub fn new() -> Features {
declared_stable_lang_features
:
Vec
::
new
(),
declared_lib_features
:
Vec
::
new
(),
const_fn
:
false
,
static_recursion
:
false
static_recursion
:
false
,
default_type_parameter_fallback
:
false
,
}
}
}
...
...
@@ -865,6 +869,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
declared_lib_features
:
unknown_features
,
const_fn
:
cx
.has_feature
(
"const_fn"
),
static_recursion
:
cx
.has_feature
(
"static_recursion"
)
default_type_parameter_fallback
:
cx
.has_feature
(
"default_type_parameter_fallback"
),
}
}
...
...
src/test/compile-fail/default_ty_param_conflict.rs
浏览文件 @
55621b61
...
...
@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(default_type_parameter_fallback)]
use
std
::
fmt
::
Debug
;
// Example from the RFC
...
...
src/test/compile-fail/default_ty_param_conflict_cross_crate.rs
浏览文件 @
55621b61
...
...
@@ -9,6 +9,9 @@
// except according to those terms.
//
//aux-build:default_ty_param_cross_crate_crate.rs
#![feature(default_type_parameter_fallback)]
extern
crate
default_param_test
;
use
default_param_test
::{
Foo
,
bleh
};
...
...
src/test/run-pass/default_ty_param_default_dependent_associated_type.rs
浏览文件 @
55621b61
...
...
@@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
#![feature(default_type_parameter_fallback)]
use
std
::
marker
::
PhantomData
;
trait
Id
{
...
...
src/test/run-pass/default_ty_param_dependent_defaults.rs
浏览文件 @
55621b61
...
...
@@ -9,6 +9,7 @@
// except according to those terms.
//
#![feature(default_type_parameter_fallback)]
use
std
::
marker
::
PhantomData
;
struct
Foo
<
T
,
U
=
T
>
{
t
:
T
,
data
:
PhantomData
<
U
>
}
...
...
src/test/run-pass/default_ty_param_method_call_test.rs
浏览文件 @
55621b61
...
...
@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(default_type_parameter_fallback)]
struct
Foo
;
impl
Foo
{
...
...
src/test/run-pass/default_ty_param_struct.rs
浏览文件 @
55621b61
...
...
@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(default_type_parameter_fallback)]
struct
Foo
<
A
>
(
A
);
impl
<
A
:
Default
=
i32
>
Foo
<
A
>
{
...
...
src/test/run-pass/default_ty_param_struct_and_type_alias.rs
浏览文件 @
55621b61
...
...
@@ -9,6 +9,8 @@
// except according to those terms.
//
#![feature(default_type_parameter_fallback)]
use
std
::
marker
::
PhantomData
;
struct
DeterministicHasher
;
...
...
src/test/run-pass/default_ty_param_trait_impl.rs
浏览文件 @
55621b61
...
...
@@ -8,14 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(default_type_parameter_fallback)]
// Another example from the RFC
trait
Foo
{
}
trait
Bar
{
}
impl
<
T
:
Bar
=
usize
>
Foo
for
Vec
<
T
>
{}
// Impl 1
impl
Bar
for
usize
{
}
// Impl 2
impl
<
T
:
Bar
=
usize
>
Foo
for
Vec
<
T
>
{}
impl
Bar
for
usize
{
}
fn
takes_foo
<
F
:
Foo
>
(
f
:
F
)
{
}
fn
takes_foo
<
F
:
Foo
>
(
f
:
F
)
{}
fn
main
()
{
let
x
=
Vec
::
new
();
// x: Vec<$0>
...
...
src/test/run-pass/default_ty_param_trait_impl_simple.rs
浏览文件 @
55621b61
...
...
@@ -8,17 +8,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(default_type_parameter_fallback)]
// An example from the RFC
trait
Foo
{
fn
takes_foo
(
&
self
);
}
trait
Bar
{
}
impl
<
T
:
Bar
=
usize
>
Foo
for
Vec
<
T
>
{
fn
takes_foo
(
&
self
)
{}
}
// Impl 1
impl
Bar
for
usize
{
}
// Impl 2
}
// fn takes_foo<F:Foo>(f: F) {
}
impl
Bar
for
usize
{
}
fn
main
()
{
let
x
=
Vec
::
new
();
// x: Vec<$0>
...
...
src/test/run-pass/default_ty_param_type_alias.rs
浏览文件 @
55621b61
...
...
@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(default_type_parameter_fallback)]
use
std
::
collections
::
HashMap
;
type
IntMap
<
K
=
usize
>
=
HashMap
<
K
,
usize
>
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录