Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b680b12e
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,发现更多精彩内容 >>
提交
b680b12e
编写于
7月 16, 2017
作者:
N
Niko Matsakis
提交者:
Sean Griffin
3月 01, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
kill supporting code from type-variable defaults
This was all unused anyway.
上级
047a8d01
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
18 addition
and
151 deletion
+18
-151
src/librustc/infer/combine.rs
src/librustc/infer/combine.rs
+1
-1
src/librustc/infer/mod.rs
src/librustc/infer/mod.rs
+2
-41
src/librustc/infer/type_variable.rs
src/librustc/infer/type_variable.rs
+13
-37
src/librustc/ty/error.rs
src/librustc/ty/error.rs
+1
-44
src/librustc/ty/structural_impls.rs
src/librustc/ty/structural_impls.rs
+1
-28
未找到文件。
src/librustc/infer/combine.rs
浏览文件 @
b680b12e
...
...
@@ -424,7 +424,7 @@ fn tys(&mut self, t: Ty<'tcx>, t2: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
}
let
origin
=
variables
.origin
(
vid
);
let
new_var_id
=
variables
.new_var
(
false
,
origin
,
None
);
let
new_var_id
=
variables
.new_var
(
false
,
origin
);
let
u
=
self
.tcx
()
.mk_var
(
new_var_id
);
debug!
(
"generalize: replacing original vid={:?} with new={:?}"
,
vid
,
u
);
...
...
src/librustc/infer/mod.rs
浏览文件 @
b680b12e
...
...
@@ -695,22 +695,6 @@ pub fn type_is_unconstrained_numeric(&'a self, ty: Ty) -> UnconstrainedNumeric {
}
}
/// Returns a type variable's default fallback if any exists. A default
/// must be attached to the variable when created, if it is created
/// without a default, this will return None.
///
/// This code does not apply to integral or floating point variables,
/// only to use declared defaults.
///
/// See `new_ty_var_with_default` to create a type variable with a default.
/// See `type_variable::Default` for details about what a default entails.
pub
fn
default
(
&
self
,
ty
:
Ty
<
'tcx
>
)
->
Option
<
type_variable
::
Default
<
'tcx
>>
{
match
ty
.sty
{
ty
::
TyInfer
(
ty
::
TyVar
(
vid
))
=>
self
.type_variables
.borrow
()
.default
(
vid
),
_
=>
None
}
}
pub
fn
unsolved_variables
(
&
self
)
->
Vec
<
Ty
<
'tcx
>>
{
let
mut
variables
=
Vec
::
new
();
...
...
@@ -1029,7 +1013,7 @@ pub fn region_outlives_predicate(&self,
pub
fn
next_ty_var_id
(
&
self
,
diverging
:
bool
,
origin
:
TypeVariableOrigin
)
->
TyVid
{
self
.type_variables
.borrow_mut
()
.new_var
(
diverging
,
origin
,
None
)
.new_var
(
diverging
,
origin
)
}
pub
fn
next_ty_var
(
&
self
,
origin
:
TypeVariableOrigin
)
->
Ty
<
'tcx
>
{
...
...
@@ -1098,8 +1082,7 @@ pub fn type_var_for_def(&self,
let
ty_var_id
=
self
.type_variables
.borrow_mut
()
.new_var
(
false
,
TypeVariableOrigin
::
TypeParameterDefinition
(
span
,
def
.name
),
None
);
TypeVariableOrigin
::
TypeParameterDefinition
(
span
,
def
.name
));
self
.tcx
.mk_var
(
ty_var_id
)
}
...
...
@@ -1389,28 +1372,6 @@ pub fn report_mismatched_types(&self,
self
.report_and_explain_type_error
(
trace
,
&
err
)
}
pub
fn
report_conflicting_default_types
(
&
self
,
span
:
Span
,
body_id
:
ast
::
NodeId
,
expected
:
type_variable
::
Default
<
'tcx
>
,
actual
:
type_variable
::
Default
<
'tcx
>
)
{
let
trace
=
TypeTrace
{
cause
:
ObligationCause
::
misc
(
span
,
body_id
),
values
:
Types
(
ExpectedFound
{
expected
:
expected
.ty
,
found
:
actual
.ty
})
};
self
.report_and_explain_type_error
(
trace
,
&
TypeError
::
TyParamDefaultMismatch
(
ExpectedFound
{
expected
,
found
:
actual
}))
.emit
();
}
pub
fn
replace_late_bound_regions_with_fresh_var
<
T
>
(
&
self
,
span
:
Span
,
...
...
src/librustc/infer/type_variable.rs
浏览文件 @
b680b12e
...
...
@@ -9,7 +9,6 @@
// except according to those terms.
use
self
::
TypeVariableValue
::
*
;
use
hir
::
def_id
::{
DefId
};
use
syntax
::
ast
;
use
syntax_pos
::
Span
;
use
ty
::{
self
,
Ty
};
...
...
@@ -82,20 +81,7 @@ enum TypeVariableValue<'tcx> {
Known
{
value
:
Ty
<
'tcx
>
},
Bounded
{
default
:
Option
<
Default
<
'tcx
>>
}
}
// We will use this to store the required information to recapitulate what happened when
// an error occurs.
#[derive(Copy,
Clone,
Debug,
PartialEq,
Eq,
Hash)]
pub
struct
Default
<
'tcx
>
{
pub
ty
:
Ty
<
'tcx
>
,
/// The span where the default was incurred
pub
origin_span
:
Span
,
/// The definition that the default originates from
pub
def_id
:
DefId
Unknown
,
}
pub
struct
Snapshot
{
...
...
@@ -104,9 +90,8 @@ pub struct Snapshot {
sub_snapshot
:
ut
::
Snapshot
<
ty
::
TyVid
>
,
}
struct
Instantiate
<
'tcx
>
{
struct
Instantiate
{
vid
:
ty
::
TyVid
,
default
:
Option
<
Default
<
'tcx
>>
,
}
struct
Delegate
<
'tcx
>
(
PhantomData
<&
'tcx
()
>
);
...
...
@@ -120,13 +105,6 @@ pub fn new() -> TypeVariableTable<'tcx> {
}
}
pub
fn
default
(
&
self
,
vid
:
ty
::
TyVid
)
->
Option
<
Default
<
'tcx
>>
{
match
&
self
.values
.get
(
vid
.index
as
usize
)
.value
{
&
Known
{
..
}
=>
None
,
&
Bounded
{
default
,
..
}
=>
default
,
}
}
pub
fn
var_diverges
<
'a
>
(
&
'a
self
,
vid
:
ty
::
TyVid
)
->
bool
{
self
.values
.get
(
vid
.index
as
usize
)
.diverging
}
...
...
@@ -167,8 +145,8 @@ pub fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'tcx>) {
};
match
old_value
{
TypeVariableValue
::
Bounded
{
default
}
=>
{
self
.values
.record
(
Instantiate
{
vid
:
vid
,
default
:
default
});
TypeVariableValue
::
Unknown
=>
{
self
.values
.record
(
Instantiate
{
vid
:
vid
});
}
TypeVariableValue
::
Known
{
value
:
old_ty
}
=>
{
bug!
(
"instantiating type variable `{:?}` twice: new-value = {:?}, old-value={:?}"
,
...
...
@@ -179,13 +157,13 @@ pub fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'tcx>) {
pub
fn
new_var
(
&
mut
self
,
diverging
:
bool
,
origin
:
TypeVariableOrigin
,
default
:
Option
<
Default
<
'tcx
>>
,)
->
ty
::
TyVid
{
origin
:
TypeVariableOrigin
)
->
ty
::
TyVid
{
debug!
(
"new_var(diverging={:?}, origin={:?})"
,
diverging
,
origin
);
self
.eq_relations
.new_key
(());
self
.sub_relations
.new_key
(());
let
index
=
self
.values
.push
(
TypeVariableData
{
value
:
Bounded
{
default
}
,
value
:
Unknown
,
origin
,
diverging
,
});
...
...
@@ -237,7 +215,7 @@ pub fn origin(&self, vid: ty::TyVid) -> TypeVariableOrigin {
pub
fn
probe_root
(
&
mut
self
,
vid
:
ty
::
TyVid
)
->
Option
<
Ty
<
'tcx
>>
{
debug_assert!
(
self
.root_var
(
vid
)
==
vid
);
match
self
.values
.get
(
vid
.index
as
usize
)
.value
{
Bounded
{
..
}
=>
None
,
Unknown
=>
None
,
Known
{
value
}
=>
Some
(
value
)
}
}
...
...
@@ -338,7 +316,7 @@ pub fn types_escaping_snapshot(&mut self, s: &Snapshot) -> Vec<Ty<'tcx>> {
// quick check to see if this variable was
// created since the snapshot started or not.
let
escaping_type
=
match
self
.values
.get
(
vid
.index
as
usize
)
.value
{
Bounded
{
..
}
=>
bug!
(),
Unknown
=>
bug!
(),
Known
{
value
}
=>
value
,
};
escaping_types
.push
(
escaping_type
);
...
...
@@ -369,12 +347,10 @@ pub fn unsolved_variables(&mut self) -> Vec<ty::TyVid> {
impl
<
'tcx
>
sv
::
SnapshotVecDelegate
for
Delegate
<
'tcx
>
{
type
Value
=
TypeVariableData
<
'tcx
>
;
type
Undo
=
Instantiate
<
'tcx
>
;
type
Undo
=
Instantiate
;
fn
reverse
(
values
:
&
mut
Vec
<
TypeVariableData
<
'tcx
>>
,
action
:
Instantiate
<
'tcx
>
)
{
let
Instantiate
{
vid
,
default
}
=
action
;
values
[
vid
.index
as
usize
]
.value
=
Bounded
{
default
,
};
fn
reverse
(
values
:
&
mut
Vec
<
TypeVariableData
<
'tcx
>>
,
action
:
Instantiate
)
{
let
Instantiate
{
vid
}
=
action
;
values
[
vid
.index
as
usize
]
.value
=
Unknown
;
}
}
src/librustc/ty/error.rs
浏览文件 @
b680b12e
...
...
@@ -9,9 +9,8 @@
// except according to those terms.
use
hir
::
def_id
::
DefId
;
use
infer
::
type_variable
;
use
middle
::
const_val
::
ConstVal
;
use
ty
::{
self
,
BoundRegion
,
DefIdTree
,
Region
,
Ty
,
TyCtxt
};
use
ty
::{
self
,
BoundRegion
,
Region
,
Ty
,
TyCtxt
};
use
std
::
fmt
;
use
syntax
::
abi
;
...
...
@@ -56,7 +55,6 @@ pub enum TypeError<'tcx> {
CyclicTy
(
Ty
<
'tcx
>
),
ProjectionMismatched
(
ExpectedFound
<
DefId
>
),
ProjectionBoundsLength
(
ExpectedFound
<
usize
>
),
TyParamDefaultMismatch
(
ExpectedFound
<
type_variable
::
Default
<
'tcx
>>
),
ExistentialMismatch
(
ExpectedFound
<&
'tcx
ty
::
Slice
<
ty
::
ExistentialPredicate
<
'tcx
>>>
),
OldStyleLUB
(
Box
<
TypeError
<
'tcx
>>
),
...
...
@@ -167,11 +165,6 @@ fn report_maybe_different(f: &mut fmt::Formatter,
values
.expected
,
values
.found
)
},
TyParamDefaultMismatch
(
ref
values
)
=>
{
write!
(
f
,
"conflicting type parameter defaults `{}` and `{}`"
,
values
.expected.ty
,
values
.found.ty
)
}
ExistentialMismatch
(
ref
values
)
=>
{
report_maybe_different
(
f
,
format!
(
"trait `{}`"
,
values
.expected
),
format!
(
"trait `{}`"
,
values
.found
))
...
...
@@ -265,42 +258,6 @@ pub fn note_and_explain_type_err(self,
db
.help
(
"consider boxing your closure and/or using it as a trait object"
);
}
},
TyParamDefaultMismatch
(
values
)
=>
{
let
expected
=
values
.expected
;
let
found
=
values
.found
;
db
.span_note
(
sp
,
&
format!
(
"conflicting type parameter defaults `{}` and `{}`"
,
expected
.ty
,
found
.ty
));
match
self
.hir
.span_if_local
(
expected
.def_id
)
{
Some
(
span
)
=>
{
db
.span_note
(
span
,
"a default was defined here..."
);
}
None
=>
{
let
item_def_id
=
self
.parent
(
expected
.def_id
)
.unwrap
();
db
.note
(
&
format!
(
"a default is defined on `{}`"
,
self
.item_path_str
(
item_def_id
)));
}
}
db
.span_note
(
expected
.origin_span
,
"...that was applied to an unconstrained type variable here"
);
match
self
.hir
.span_if_local
(
found
.def_id
)
{
Some
(
span
)
=>
{
db
.span_note
(
span
,
"a second default was defined here..."
);
}
None
=>
{
let
item_def_id
=
self
.parent
(
found
.def_id
)
.unwrap
();
db
.note
(
&
format!
(
"a second default is defined on `{}`"
,
self
.item_path_str
(
item_def_id
)));
}
}
db
.span_note
(
found
.origin_span
,
"...that also applies to the same type variable here"
);
}
OldStyleLUB
(
err
)
=>
{
db
.note
(
"this was previously accepted by the compiler but has been phased out"
);
db
.note
(
"for more information, see https://github.com/rust-lang/rust/issues/45852"
);
...
...
src/librustc/ty/structural_impls.rs
浏览文件 @
b680b12e
...
...
@@ -13,7 +13,6 @@
//! hand, though we've recently added some macros (e.g.,
//! `BraceStructLiftImpl!`) to help with the tedium.
use
infer
::
type_variable
;
use
middle
::
const_val
::{
self
,
ConstVal
,
ConstAggregate
,
ConstEvalErr
};
use
ty
::{
self
,
Lift
,
Ty
,
TyCtxt
};
use
ty
::
fold
::{
TypeFoldable
,
TypeFolder
,
TypeVisitor
};
...
...
@@ -548,13 +547,6 @@ fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lif
}
}
BraceStructLiftImpl!
{
impl
<
'a
,
'tcx
>
Lift
<
'tcx
>
for
type_variable
::
Default
<
'a
>
{
type
Lifted
=
type_variable
::
Default
<
'tcx
>
;
ty
,
origin_span
,
def_id
}
}
impl
<
'a
,
'tcx
>
Lift
<
'tcx
>
for
ty
::
error
::
TypeError
<
'a
>
{
type
Lifted
=
ty
::
error
::
TypeError
<
'tcx
>
;
fn
lift_to_tcx
<
'b
,
'gcx
>
(
&
self
,
tcx
:
TyCtxt
<
'b
,
'gcx
,
'tcx
>
)
->
Option
<
Self
::
Lifted
>
{
...
...
@@ -586,11 +578,8 @@ fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lif
ProjectionBoundsLength
(
x
)
=>
ProjectionBoundsLength
(
x
),
Sorts
(
ref
x
)
=>
return
tcx
.lift
(
x
)
.map
(
Sorts
),
TyParamDefaultMismatch
(
ref
x
)
=>
{
return
tcx
.lift
(
x
)
.map
(
TyParamDefaultMismatch
)
}
ExistentialMismatch
(
ref
x
)
=>
return
tcx
.lift
(
x
)
.map
(
ExistentialMismatch
),
OldStyleLUB
(
ref
x
)
=>
return
tcx
.lift
(
x
)
.map
(
OldStyleLUB
),
ExistentialMismatch
(
ref
x
)
=>
return
tcx
.lift
(
x
)
.map
(
ExistentialMismatch
)
})
}
}
...
...
@@ -1199,20 +1188,6 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
}
}
impl
<
'tcx
>
TypeFoldable
<
'tcx
>
for
type_variable
::
Default
<
'tcx
>
{
fn
super_fold_with
<
'gcx
:
'tcx
,
F
:
TypeFolder
<
'gcx
,
'tcx
>>
(
&
self
,
folder
:
&
mut
F
)
->
Self
{
type_variable
::
Default
{
ty
:
self
.ty
.fold_with
(
folder
),
origin_span
:
self
.origin_span
,
def_id
:
self
.def_id
}
}
fn
super_visit_with
<
V
:
TypeVisitor
<
'tcx
>>
(
&
self
,
visitor
:
&
mut
V
)
->
bool
{
self
.ty
.visit_with
(
visitor
)
}
}
impl
<
'tcx
,
T
:
TypeFoldable
<
'tcx
>
,
I
:
Idx
>
TypeFoldable
<
'tcx
>
for
IndexVec
<
I
,
T
>
{
fn
super_fold_with
<
'gcx
:
'tcx
,
F
:
TypeFolder
<
'gcx
,
'tcx
>>
(
&
self
,
folder
:
&
mut
F
)
->
Self
{
self
.iter
()
.map
(|
x
|
x
.fold_with
(
folder
))
.collect
()
...
...
@@ -1252,7 +1227,6 @@ fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F)
ProjectionMismatched
(
x
)
=>
ProjectionMismatched
(
x
),
ProjectionBoundsLength
(
x
)
=>
ProjectionBoundsLength
(
x
),
Sorts
(
x
)
=>
Sorts
(
x
.fold_with
(
folder
)),
TyParamDefaultMismatch
(
ref
x
)
=>
TyParamDefaultMismatch
(
x
.fold_with
(
folder
)),
ExistentialMismatch
(
x
)
=>
ExistentialMismatch
(
x
.fold_with
(
folder
)),
OldStyleLUB
(
ref
x
)
=>
OldStyleLUB
(
x
.fold_with
(
folder
)),
}
...
...
@@ -1273,7 +1247,6 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
},
Sorts
(
x
)
=>
x
.visit_with
(
visitor
),
OldStyleLUB
(
ref
x
)
=>
x
.visit_with
(
visitor
),
TyParamDefaultMismatch
(
ref
x
)
=>
x
.visit_with
(
visitor
),
ExistentialMismatch
(
x
)
=>
x
.visit_with
(
visitor
),
CyclicTy
(
t
)
=>
t
.visit_with
(
visitor
),
Mismatch
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录