Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d5b760ba
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
d5b760ba
编写于
1月 09, 2021
作者:
M
Mark Rousskov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Bump rustfmt version
Also switches on formatting of the mir build module
上级
f6cb45ad
变更
30
隐藏空白更改
内联
并排
Showing
30 changed file
with
224 addition
and
164 deletion
+224
-164
compiler/rustc_ast_lowering/src/lib.rs
compiler/rustc_ast_lowering/src/lib.rs
+3
-1
compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
+1
-1
compiler/rustc_errors/src/diagnostic_builder.rs
compiler/rustc_errors/src/diagnostic_builder.rs
+1
-1
compiler/rustc_errors/src/snippet.rs
compiler/rustc_errors/src/snippet.rs
+10
-5
compiler/rustc_hir/src/hir.rs
compiler/rustc_hir/src/hir.rs
+4
-4
compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs
...rror_reporting/nice_region_error/trait_impl_difference.rs
+6
-1
compiler/rustc_middle/src/hir/map/mod.rs
compiler/rustc_middle/src/hir/map/mod.rs
+3
-3
compiler/rustc_middle/src/mir/mod.rs
compiler/rustc_middle/src/mir/mod.rs
+2
-4
compiler/rustc_middle/src/ty/diagnostics.rs
compiler/rustc_middle/src/ty/diagnostics.rs
+11
-7
compiler/rustc_middle/src/ty/error.rs
compiler/rustc_middle/src/ty/error.rs
+7
-4
compiler/rustc_middle/src/ty/sty.rs
compiler/rustc_middle/src/ty/sty.rs
+8
-2
compiler/rustc_mir_build/src/build/expr/as_place.rs
compiler/rustc_mir_build/src/build/expr/as_place.rs
+46
-40
compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
+31
-25
compiler/rustc_mir_build/src/build/expr/into.rs
compiler/rustc_mir_build/src/build/expr/into.rs
+13
-7
compiler/rustc_mir_build/src/build/matches/mod.rs
compiler/rustc_mir_build/src/build/matches/mod.rs
+10
-4
compiler/rustc_mir_build/src/build/matches/util.rs
compiler/rustc_mir_build/src/build/matches/util.rs
+1
-3
compiler/rustc_mir_build/src/build/mod.rs
compiler/rustc_mir_build/src/build/mod.rs
+3
-4
compiler/rustc_mir_build/src/build/scope.rs
compiler/rustc_mir_build/src/build/scope.rs
+4
-7
compiler/rustc_parse/src/parser/nonterminal.rs
compiler/rustc_parse/src/parser/nonterminal.rs
+10
-7
compiler/rustc_passes/src/stability.rs
compiler/rustc_passes/src/stability.rs
+2
-1
compiler/rustc_resolve/src/late/diagnostics.rs
compiler/rustc_resolve/src/late/diagnostics.rs
+16
-10
compiler/rustc_target/src/abi/call/mod.rs
compiler/rustc_target/src/abi/call/mod.rs
+1
-1
compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
...r/rustc_trait_selection/src/traits/error_reporting/mod.rs
+6
-3
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
...trait_selection/src/traits/error_reporting/suggestions.rs
+3
-3
compiler/rustc_typeck/src/astconv/generics.rs
compiler/rustc_typeck/src/astconv/generics.rs
+8
-7
compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
+7
-4
library/core/src/default.rs
library/core/src/default.rs
+4
-2
rustfmt.toml
rustfmt.toml
+1
-1
src/bootstrap/bin/main.rs
src/bootstrap/bin/main.rs
+1
-1
src/stage0.txt
src/stage0.txt
+1
-1
未找到文件。
compiler/rustc_ast_lowering/src/lib.rs
浏览文件 @
d5b760ba
...
...
@@ -506,7 +506,9 @@ fn visit_item(&mut self, item: &'tcx Item) {
let
count
=
generics
.params
.iter
()
.filter
(|
param
|
matches!
(
param
.kind
,
ast
::
GenericParamKind
::
Lifetime
{
..
}))
.filter
(|
param
|
{
matches!
(
param
.kind
,
ast
::
GenericParamKind
::
Lifetime
{
..
})
})
.count
();
self
.lctx.type_def_lifetime_params
.insert
(
def_id
.to_def_id
(),
count
);
}
...
...
compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
浏览文件 @
d5b760ba
...
...
@@ -598,7 +598,7 @@ fn create_derived_impl(
let
mut
ty_params
=
params
.iter
()
.filter
(|
param
|
matches!
(
param
.kind
,
ast
::
GenericParamKind
::
Type
{
..
}))
.filter
(|
param
|
matches!
(
param
.kind
,
ast
::
GenericParamKind
::
Type
{
..
}))
.peekable
();
if
ty_params
.peek
()
.is_some
()
{
...
...
compiler/rustc_errors/src/diagnostic_builder.rs
浏览文件 @
d5b760ba
...
...
@@ -36,7 +36,7 @@ struct DiagnosticBuilderInner<'a> {
(
$e:expr
=>
$i:item
)
=>
{
#[doc
=
$
e]
$i
}
}
;
}
/// In general, the `DiagnosticBuilder` uses deref to allow access to
...
...
compiler/rustc_errors/src/snippet.rs
浏览文件 @
d5b760ba
...
...
@@ -122,11 +122,13 @@ pub fn is_line(&self) -> bool {
}
pub
fn
is_multiline
(
&
self
)
->
bool
{
matches!
(
self
.annotation_type
,
matches!
(
self
.annotation_type
,
AnnotationType
::
Multiline
(
_
)
|
AnnotationType
::
MultilineStart
(
_
)
|
AnnotationType
::
MultilineLine
(
_
)
|
AnnotationType
::
MultilineEnd
(
_
))
|
AnnotationType
::
MultilineStart
(
_
)
|
AnnotationType
::
MultilineLine
(
_
)
|
AnnotationType
::
MultilineEnd
(
_
)
)
}
pub
fn
len
(
&
self
)
->
usize
{
...
...
@@ -158,7 +160,10 @@ pub fn has_label(&self) -> bool {
pub
fn
takes_space
(
&
self
)
->
bool
{
// Multiline annotations always have to keep vertical space.
matches!
(
self
.annotation_type
,
AnnotationType
::
MultilineStart
(
_
)
|
AnnotationType
::
MultilineEnd
(
_
))
matches!
(
self
.annotation_type
,
AnnotationType
::
MultilineStart
(
_
)
|
AnnotationType
::
MultilineEnd
(
_
)
)
}
}
...
...
compiler/rustc_hir/src/hir.rs
浏览文件 @
d5b760ba
...
...
@@ -1543,10 +1543,10 @@ pub fn is_range_literal(expr: &Expr<'_>) -> bool {
**
qpath
,
QPath
::
LangItem
(
LangItem
::
Range
|
LangItem
::
RangeTo
|
LangItem
::
RangeFrom
|
LangItem
::
RangeFull
|
LangItem
::
RangeToInclusive
,
|
LangItem
::
RangeTo
|
LangItem
::
RangeFrom
|
LangItem
::
RangeFull
|
LangItem
::
RangeToInclusive
,
_
,
)
),
...
...
compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs
浏览文件 @
d5b760ba
...
...
@@ -132,7 +132,12 @@ fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx>) {
[
segment
]
if
segment
.res
.map
(|
res
|
matches!
(
res
,
Res
::
SelfTy
(
_
,
_
)
|
Res
::
Def
(
hir
::
def
::
DefKind
::
TyParam
,
_
)))
.map
(|
res
|
{
matches!
(
res
,
Res
::
SelfTy
(
_
,
_
)
|
Res
::
Def
(
hir
::
def
::
DefKind
::
TyParam
,
_
)
)
})
.unwrap_or
(
false
)
=>
{
self
.types
.push
(
path
.span
);
...
...
compiler/rustc_middle/src/hir/map/mod.rs
浏览文件 @
d5b760ba
...
...
@@ -569,9 +569,9 @@ pub fn is_argument(&self, id: HirId) -> bool {
self
.find
(
self
.get_parent_node
(
id
)),
Some
(
Node
::
Item
(
_
)
|
Node
::
TraitItem
(
_
)
|
Node
::
ImplItem
(
_
)
|
Node
::
Expr
(
Expr
{
kind
:
ExprKind
::
Closure
(
..
),
..
}),
|
Node
::
TraitItem
(
_
)
|
Node
::
ImplItem
(
_
)
|
Node
::
Expr
(
Expr
{
kind
:
ExprKind
::
Closure
(
..
),
..
}),
)
)
}
...
...
compiler/rustc_middle/src/mir/mod.rs
浏览文件 @
d5b760ba
...
...
@@ -962,8 +962,7 @@ pub fn can_be_made_mutable(&self) -> bool {
opt_ty_info
:
_
,
opt_match_place
:
_
,
pat_span
:
_
,
})
|
BindingForm
::
ImplicitSelf
(
ImplicitSelfKind
::
Imm
),
})
|
BindingForm
::
ImplicitSelf
(
ImplicitSelfKind
::
Imm
),
)))
)
}
...
...
@@ -980,8 +979,7 @@ pub fn is_nonref_binding(&self) -> bool {
opt_ty_info
:
_
,
opt_match_place
:
_
,
pat_span
:
_
,
})
|
BindingForm
::
ImplicitSelf
(
_
),
})
|
BindingForm
::
ImplicitSelf
(
_
),
)))
)
}
...
...
compiler/rustc_middle/src/ty/diagnostics.rs
浏览文件 @
d5b760ba
...
...
@@ -12,13 +12,17 @@ impl<'tcx> TyS<'tcx> {
pub
fn
is_primitive_ty
(
&
self
)
->
bool
{
matches!
(
self
.kind
(),
Bool
|
Char
|
Str
|
Int
(
_
)
|
Uint
(
_
)
|
Float
(
_
)
|
Infer
(
InferTy
::
IntVar
(
_
)
|
InferTy
::
FloatVar
(
_
)
|
InferTy
::
FreshIntTy
(
_
)
|
InferTy
::
FreshFloatTy
(
_
)
)
Bool
|
Char
|
Str
|
Int
(
_
)
|
Uint
(
_
)
|
Float
(
_
)
|
Infer
(
InferTy
::
IntVar
(
_
)
|
InferTy
::
FloatVar
(
_
)
|
InferTy
::
FreshIntTy
(
_
)
|
InferTy
::
FreshFloatTy
(
_
)
)
)
}
...
...
compiler/rustc_middle/src/ty/error.rs
浏览文件 @
d5b760ba
...
...
@@ -646,11 +646,14 @@ fn expected_projection(
let
current_method_ident
=
body_owner
.and_then
(|
n
|
n
.ident
())
.map
(|
i
|
i
.name
);
// We don't want to suggest calling an assoc fn in a scope where that isn't feasible.
let
callable_scope
=
matches!
(
body_owner
,
Some
(
let
callable_scope
=
matches!
(
body_owner
,
Some
(
hir
::
Node
::
Item
(
hir
::
Item
{
kind
:
hir
::
ItemKind
::
Fn
(
..
),
..
})
|
hir
::
Node
::
TraitItem
(
hir
::
TraitItem
{
kind
:
hir
::
TraitItemKind
::
Fn
(
..
),
..
})
|
hir
::
Node
::
ImplItem
(
hir
::
ImplItem
{
kind
:
hir
::
ImplItemKind
::
Fn
(
..
),
..
}),
));
|
hir
::
Node
::
TraitItem
(
hir
::
TraitItem
{
kind
:
hir
::
TraitItemKind
::
Fn
(
..
),
..
})
|
hir
::
Node
::
ImplItem
(
hir
::
ImplItem
{
kind
:
hir
::
ImplItemKind
::
Fn
(
..
),
..
}),
)
);
let
impl_comparison
=
matches!
(
cause_code
,
ObligationCauseCode
::
CompareImplMethodObligation
{
..
}
...
...
compiler/rustc_middle/src/ty/sty.rs
浏览文件 @
d5b760ba
...
...
@@ -1871,8 +1871,14 @@ pub fn boxed_ty(&self) -> Ty<'tcx> {
pub
fn
is_scalar
(
&
self
)
->
bool
{
matches!
(
self
.kind
(),
Bool
|
Char
|
Int
(
_
)
|
Float
(
_
)
|
Uint
(
_
)
|
FnDef
(
..
)
|
FnPtr
(
_
)
|
RawPtr
(
_
)
|
Infer
(
IntVar
(
_
)
|
FloatVar
(
_
))
Bool
|
Char
|
Int
(
_
)
|
Float
(
_
)
|
Uint
(
_
)
|
FnDef
(
..
)
|
FnPtr
(
_
)
|
RawPtr
(
_
)
|
Infer
(
IntVar
(
_
)
|
FloatVar
(
_
))
)
}
...
...
compiler/rustc_mir_build/src/build/expr/as_place.rs
浏览文件 @
d5b760ba
...
...
@@ -6,8 +6,8 @@
use
crate
::
thir
::
*
;
use
rustc_hir
::
def_id
::
DefId
;
use
rustc_hir
::
HirId
;
use
rustc_middle
::
middle
::
region
;
use
rustc_middle
::
hir
::
place
::
ProjectionKind
as
HirProjectionKind
;
use
rustc_middle
::
middle
::
region
;
use
rustc_middle
::
mir
::
AssertKind
::
BoundsCheck
;
use
rustc_middle
::
mir
::
*
;
use
rustc_middle
::
ty
::{
self
,
CanonicalUserTypeAnnotation
,
Ty
,
TyCtxt
,
Variance
};
...
...
@@ -57,7 +57,8 @@
/// DefId of the closure
closure_def_id
:
DefId
,
/// The trait closure implements, `Fn`, `FnMut`, `FnOnce`
closure_kind
:
ty
::
ClosureKind
},
closure_kind
:
ty
::
ClosureKind
,
},
}
/// `PlaceBuilder` is used to create places during MIR construction. It allows you to "build up" a
...
...
@@ -81,8 +82,7 @@
fn
convert_to_hir_projections_and_truncate_for_capture
<
'tcx
>
(
mir_projections
:
&
[
PlaceElem
<
'tcx
>
],
)
->
Vec
<
HirProjectionKind
>
{
let
mut
hir_projections
=
Vec
::
new
();
let
mut
hir_projections
=
Vec
::
new
();
for
mir_projection
in
mir_projections
{
let
hir_projection
=
match
mir_projection
{
...
...
@@ -91,20 +91,20 @@ fn convert_to_hir_projections_and_truncate_for_capture<'tcx>(
// We will never encouter this for multivariant enums,
// read the comment for `Downcast`.
HirProjectionKind
::
Field
(
field
.index
()
as
u32
,
VariantIdx
::
new
(
0
))
}
,
}
ProjectionElem
::
Downcast
(
..
)
=>
{
// This projections exist only for enums that have
// multiple variants. Since such enums that are captured
// completely, we can stop here.
break
}
,
break
;
}
ProjectionElem
::
Index
(
..
)
|
ProjectionElem
::
ConstantIndex
{
..
}
|
ProjectionElem
::
Subslice
{
..
}
=>
{
// We don't capture array-access projections.
// We can stop here as arrays are captured completely.
break
}
,
break
;
}
};
hir_projections
.push
(
hir_projection
);
...
...
@@ -181,9 +181,9 @@ fn find_capture_matching_projections<'a, 'tcx>(
// If an ancestor is found, `idx` is the index within the list of captured places
// for root variable `var_hir_id` and `capture` is the `ty::CapturedPlace` itself.
let
(
idx
,
capture
)
=
root_variable_min_captures
.iter
()
.enumerate
()
.find
(|(
_
,
capture
)|
{
let
possible_ancestor_proj_kinds
=
capture
.place.projections
.iter
()
.map
(|
proj
|
proj
.kind
)
.collect
();
is_ancestor_or_same_capture
(
&
possible_ancestor_proj_kinds
,
&
hir_projections
)
let
possible_ancestor_proj_kinds
=
capture
.place.projections
.iter
()
.map
(|
proj
|
proj
.kind
)
.collect
();
is_ancestor_or_same_capture
(
&
possible_ancestor_proj_kinds
,
&
hir_projections
)
})
?
;
// Convert index to be from the presepective of the entire closure_min_captures map
...
...
@@ -213,35 +213,34 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
ty
::
ClosureKind
::
FnOnce
=>
{}
}
let
(
capture_index
,
capture
)
=
if
let
Some
(
capture_details
)
=
find_capture_matching_projections
(
let
(
capture_index
,
capture
)
=
if
let
Some
(
capture_details
)
=
find_capture_matching_projections
(
typeck_results
,
var_hir_id
,
closure_def_id
,
&
from_builder
.projection
,
)
{
capture_details
}
else
{
if
!
tcx
.features
()
.capture_disjoint_fields
{
bug!
(
"No associated capture found for {:?}[{:#?}] even though
\
capture_details
}
else
{
if
!
tcx
.features
()
.capture_disjoint_fields
{
bug!
(
"No associated capture found for {:?}[{:#?}] even though
\
capture_disjoint_fields isn't enabled"
,
var_hir_id
,
from_builder
.projection
)
}
else
{
// FIXME(project-rfc-2229#24): Handle this case properly
debug!
(
"No associated capture found for {:?}[{:#?}]"
,
var_hir_id
,
from_builder
.projection
,
);
}
return
Err
(
var_hir_id
);
};
var_hir_id
,
from_builder
.projection
)
}
else
{
// FIXME(project-rfc-2229#24): Handle this case properly
debug!
(
"No associated capture found for {:?}[{:#?}]"
,
var_hir_id
,
from_builder
.projection
,
);
}
return
Err
(
var_hir_id
);
};
let
closure_ty
=
typeck_results
.node_type
(
tcx
.hir
()
.local_def_id_to_hir_id
(
closure_def_id
.expect_local
()));
let
closure_ty
=
typeck_results
.node_type
(
tcx
.hir
()
.local_def_id_to_hir_id
(
closure_def_id
.expect_local
()));
let
substs
=
match
closure_ty
.kind
()
{
ty
::
Closure
(
_
,
substs
)
=>
ty
::
UpvarSubsts
::
Closure
(
substs
),
...
...
@@ -256,7 +255,8 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
// we know that the capture exists and is the `capture_index`-th capture.
let
var_ty
=
substs
.tupled_upvars_ty
()
.tuple_element_ty
(
capture_index
)
.unwrap
();
upvar_resolved_place_builder
=
upvar_resolved_place_builder
.field
(
Field
::
new
(
capture_index
),
var_ty
);
upvar_resolved_place_builder
=
upvar_resolved_place_builder
.field
(
Field
::
new
(
capture_index
),
var_ty
);
// If the variable is captured via ByRef(Immutable/Mutable) Borrow,
// we need to deref it
...
...
@@ -270,8 +270,9 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
// We used some of the projections to build the capture itself,
// now we apply the remaining to the upvar resolved place.
upvar_resolved_place_builder
.projection
.extend
(
curr_projections
.drain
(
next_projection
..
));
upvar_resolved_place_builder
.projection
.extend
(
curr_projections
.drain
(
next_projection
..
));
Ok
(
upvar_resolved_place_builder
)
}
...
...
@@ -356,7 +357,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// This is used when constructing a compound `Place`, so that we can avoid creating
/// intermediate `Place` values until we know the full set of projections.
crate
fn
as_place_builder
<
M
>
(
&
mut
self
,
block
:
BasicBlock
,
expr
:
M
)
->
BlockAnd
<
PlaceBuilder
<
'tcx
>>
crate
fn
as_place_builder
<
M
>
(
&
mut
self
,
block
:
BasicBlock
,
expr
:
M
,
)
->
BlockAnd
<
PlaceBuilder
<
'tcx
>>
where
M
:
Mirror
<
'tcx
,
Output
=
Expr
<
'tcx
>>
,
{
...
...
@@ -627,7 +632,8 @@ fn lower_index_expression(
if
is_outermost_index
{
self
.read_fake_borrows
(
block
,
fake_borrow_temps
,
source_info
)
}
else
{
base_place
=
base_place
.expect_upvars_resolved
(
self
.hir
.tcx
(),
self
.hir
.typeck_results
());
base_place
=
base_place
.expect_upvars_resolved
(
self
.hir
.tcx
(),
self
.hir
.typeck_results
());
self
.add_fake_borrows_of_base
(
&
base_place
,
block
,
...
...
@@ -679,7 +685,7 @@ fn add_fake_borrows_of_base(
let
tcx
=
self
.hir
.tcx
();
let
local
=
match
base_place
.base
{
PlaceBase
::
Local
(
local
)
=>
local
,
PlaceBase
::
Upvar
{
..
}
=>
bug!
(
"Expected PlacseBase::Local found Upvar"
)
PlaceBase
::
Upvar
{
..
}
=>
bug!
(
"Expected PlacseBase::Local found Upvar"
)
,
};
let
place_ty
=
Place
::
ty_from
(
local
,
&
base_place
.projection
,
&
self
.local_decls
,
tcx
);
...
...
compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
浏览文件 @
d5b760ba
...
...
@@ -2,9 +2,9 @@
use
rustc_index
::
vec
::
Idx
;
use
crate
::
build
::
expr
::
as_place
::
PlaceBase
;
use
crate
::
build
::
expr
::
category
::{
Category
,
RvalueFunc
};
use
crate
::
build
::{
BlockAnd
,
BlockAndExtension
,
Builder
};
use
crate
::
build
::
expr
::
as_place
::
PlaceBase
;
use
crate
::
thir
::
*
;
use
rustc_middle
::
middle
::
region
;
use
rustc_middle
::
mir
::
AssertKind
;
...
...
@@ -274,7 +274,10 @@ fn expr_as_rvalue(
|
ExprKind
::
ValueTypeAscription
{
..
}
=>
{
// these do not have corresponding `Rvalue` variants,
// so make an operand and then return that
debug_assert!
(
!
matches!
(
Category
::
of
(
&
expr
.kind
),
Some
(
Category
::
Rvalue
(
RvalueFunc
::
AsRvalue
))));
debug_assert!
(
!
matches!
(
Category
::
of
(
&
expr
.kind
),
Some
(
Category
::
Rvalue
(
RvalueFunc
::
AsRvalue
))
));
let
operand
=
unpack!
(
block
=
this
.as_operand
(
block
,
scope
,
expr
));
block
.and
(
Rvalue
::
Use
(
operand
))
}
...
...
@@ -401,34 +404,39 @@ fn limit_capture_mutability(
// We are capturing a path that starts off a local variable in the parent.
// The mutability of the current capture is same as the mutability
// of the local declaration in the parent.
PlaceBase
::
Local
(
local
)
=>
this
.local_decls
[
local
]
.mutability
,
PlaceBase
::
Local
(
local
)
=>
this
.local_decls
[
local
]
.mutability
,
// Parent is a closure and we are capturing a path that is captured
// by the parent itself. The mutability of the current capture
// is same as that of the capture in the parent closure.
PlaceBase
::
Upvar
{
..
}
=>
{
let
enclosing_upvars_resolved
=
arg_place_builder
.clone
()
.into_place
(
this
.hir
.tcx
(),
this
.hir
.typeck_results
());
let
enclosing_upvars_resolved
=
arg_place_builder
.clone
()
.into_place
(
this
.hir
.tcx
(),
this
.hir
.typeck_results
());
match
enclosing_upvars_resolved
.as_ref
()
{
PlaceRef
{
local
,
projection
:
&
[
ProjectionElem
::
Field
(
upvar_index
,
_
),
..
]
}
PlaceRef
{
local
,
projection
:
&
[
ProjectionElem
::
Field
(
upvar_index
,
_
),
..
],
}
|
PlaceRef
{
local
,
projection
:
&
[
ProjectionElem
::
Deref
,
ProjectionElem
::
Field
(
upvar_index
,
_
),
..
]
}
=>
{
// Not in a closure
debug_assert!
(
local
==
Local
::
new
(
1
),
"Expected local to be Local(1), found {:?}"
,
local
);
// Not in a closure
debug_assert!
(
this
.upvar_mutbls
.len
()
>
upvar_index
.index
(),
"Unexpected capture place, upvar_mutbls={:#?}, upvar_index={:?}"
,
this
.upvar_mutbls
,
upvar_index
);
this
.upvar_mutbls
[
upvar_index
.index
()]
}
projection
:
&
[
ProjectionElem
::
Deref
,
ProjectionElem
::
Field
(
upvar_index
,
_
),
..
],
}
=>
{
// Not in a closure
debug_assert!
(
local
==
Local
::
new
(
1
),
"Expected local to be Local(1), found {:?}"
,
local
);
// Not in a closure
debug_assert!
(
this
.upvar_mutbls
.len
()
>
upvar_index
.index
(),
"Unexpected capture place, upvar_mutbls={:#?}, upvar_index={:?}"
,
this
.upvar_mutbls
,
upvar_index
);
this
.upvar_mutbls
[
upvar_index
.index
()]
}
_
=>
bug!
(
"Unexpected capture place"
),
}
}
...
...
@@ -439,9 +447,7 @@ fn limit_capture_mutability(
Mutability
::
Mut
=>
BorrowKind
::
Mut
{
allow_two_phase_borrow
:
false
},
};
let
arg_place
=
arg_place_builder
.into_place
(
this
.hir
.tcx
(),
this
.hir
.typeck_results
());
let
arg_place
=
arg_place_builder
.into_place
(
this
.hir
.tcx
(),
this
.hir
.typeck_results
());
this
.cfg
.push_assign
(
block
,
...
...
compiler/rustc_mir_build/src/build/expr/into.rs
浏览文件 @
d5b760ba
...
...
@@ -10,7 +10,7 @@
use
rustc_hir
as
hir
;
use
rustc_middle
::
middle
::
region
;
use
rustc_middle
::
mir
::
*
;
use
rustc_middle
::
ty
::
{
CanonicalUserTypeAnnotation
}
;
use
rustc_middle
::
ty
::
CanonicalUserTypeAnnotation
;
use
std
::
slice
;
...
...
@@ -38,7 +38,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let
expr_span
=
expr
.span
;
let
source_info
=
this
.source_info
(
expr_span
);
let
expr_is_block_or_scope
=
matches!
(
expr
.kind
,
ExprKind
::
Block
{
..
}
|
ExprKind
::
Scope
{
..
});
let
expr_is_block_or_scope
=
matches!
(
expr
.kind
,
ExprKind
::
Block
{
..
}
|
ExprKind
::
Scope
{
..
});
let
schedule_drop
=
move
|
this
:
&
mut
Self
|
{
if
let
Some
(
drop_scope
)
=
scope
{
...
...
@@ -68,7 +69,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this
.match_expr
(
destination
,
scope
,
expr_span
,
block
,
scrutinee
,
arms
)
}
ExprKind
::
If
{
cond
,
then
,
else_opt
}
=>
{
let
place
=
unpack!
(
block
=
this
.as_temp
(
block
,
Some
(
this
.local_scope
()),
cond
,
Mutability
::
Mut
));
let
place
=
unpack!
(
block
=
this
.as_temp
(
block
,
Some
(
this
.local_scope
()),
cond
,
Mutability
::
Mut
)
);
let
operand
=
Operand
::
Move
(
Place
::
from
(
place
));
let
mut
then_block
=
this
.cfg
.start_new_block
();
...
...
@@ -100,14 +103,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
);
join_block
.unit
()
}
,
}
ExprKind
::
NeverToAny
{
source
}
=>
{
let
source
=
this
.hir
.mirror
(
source
);
let
is_call
=
matches!
(
source
.kind
,
ExprKind
::
Call
{
..
}
|
ExprKind
::
InlineAsm
{
..
});
let
is_call
=
matches!
(
source
.kind
,
ExprKind
::
Call
{
..
}
|
ExprKind
::
InlineAsm
{
..
});
// (#66975) Source could be a const of type `!`, so has to
// exist in the generated MIR.
unpack!
(
block
=
this
.as_temp
(
block
,
Some
(
this
.local_scope
()),
source
,
Mutability
::
Mut
,));
unpack!
(
block
=
this
.as_temp
(
block
,
Some
(
this
.local_scope
()),
source
,
Mutability
::
Mut
,)
);
// This is an optimization. If the expression was a call then we already have an
// unreachable block. Don't bother to terminate it and create a new one.
...
...
@@ -313,7 +319,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.field
(
n
,
ty
)
.into_place
(
this
.hir
.tcx
(),
this
.hir
.typeck_results
()),
)
}
,
}
})
.collect
()
}
else
{
...
...
compiler/rustc_mir_build/src/build/matches/mod.rs
浏览文件 @
d5b760ba
...
...
@@ -1692,15 +1692,21 @@ fn bind_and_guard_matched_candidate<'pat>(
let
e
=
self
.hir
.mirror
(
e
.clone
());
let
source_info
=
self
.source_info
(
e
.span
);
(
e
.span
,
self
.test_bool
(
block
,
e
,
source_info
))
}
,
}
Guard
::
IfLet
(
pat
,
scrutinee
)
=>
{
let
scrutinee_span
=
scrutinee
.span
();
let
scrutinee_place
=
unpack!
(
block
=
self
.lower_scrutinee
(
block
,
scrutinee
.clone
(),
scrutinee_span
));
let
scrutinee_place
=
unpack!
(
block
=
self
.lower_scrutinee
(
block
,
scrutinee
.clone
(),
scrutinee_span
)
);
let
mut
guard_candidate
=
Candidate
::
new
(
scrutinee_place
,
&
pat
,
false
);
let
wildcard
=
Pat
::
wildcard_from_ty
(
pat
.ty
);
let
mut
otherwise_candidate
=
Candidate
::
new
(
scrutinee_place
,
&
wildcard
,
false
);
let
fake_borrow_temps
=
self
.lower_match_tree
(
block
,
pat
.span
,
false
,
&
mut
[
&
mut
guard_candidate
,
&
mut
otherwise_candidate
]);
let
fake_borrow_temps
=
self
.lower_match_tree
(
block
,
pat
.span
,
false
,
&
mut
[
&
mut
guard_candidate
,
&
mut
otherwise_candidate
],
);
self
.declare_bindings
(
None
,
pat
.span
.to
(
arm_span
.unwrap
()),
...
...
compiler/rustc_mir_build/src/build/matches/util.rs
浏览文件 @
d5b760ba
...
...
@@ -32,9 +32,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
)
{
let
tcx
=
self
.hir
.tcx
();
let
(
min_length
,
exact_size
)
=
match
place
.ty
(
&
self
.local_decls
,
tcx
)
.ty
.kind
()
{
ty
::
Array
(
_
,
length
)
=>
{
(
length
.eval_usize
(
tcx
,
self
.hir.param_env
),
true
)
}
ty
::
Array
(
_
,
length
)
=>
(
length
.eval_usize
(
tcx
,
self
.hir.param_env
),
true
),
_
=>
((
prefix
.len
()
+
suffix
.len
())
.try_into
()
.unwrap
(),
false
),
};
...
...
compiler/rustc_mir_build/src/build/mod.rs
浏览文件 @
d5b760ba
...
...
@@ -838,9 +838,8 @@ fn args_and_body(
_
=>
span_bug!
(
self
.fn_span
,
"upvars with non-closure env ty {:?}"
,
closure_ty
),
};
let
capture_tys
=
upvar_substs
.upvar_tys
();
let
captures_with_tys
=
hir_typeck_results
.closure_min_captures_flattened
(
fn_def_id
)
.zip
(
capture_tys
);
let
captures_with_tys
=
hir_typeck_results
.closure_min_captures_flattened
(
fn_def_id
)
.zip
(
capture_tys
);
self
.upvar_mutbls
=
captures_with_tys
.enumerate
()
...
...
@@ -848,7 +847,7 @@ fn args_and_body(
let
capture
=
captured_place
.info.capture_kind
;
let
var_id
=
match
captured_place
.place.base
{
HirPlaceBase
::
Upvar
(
upvar_id
)
=>
upvar_id
.var_path.hir_id
,
_
=>
bug!
(
"Expected an upvar"
)
_
=>
bug!
(
"Expected an upvar"
)
,
};
let
mutability
=
captured_place
.mutability
;
...
...
compiler/rustc_mir_build/src/build/scope.rs
浏览文件 @
d5b760ba
...
...
@@ -931,10 +931,7 @@ fn unschedule_drop(&mut self, region_scope: region::Scope, local: Local) {
let
local_scope
=
self
.local_scope
();
let
scope
=
self
.scopes.scopes
.last_mut
()
.unwrap
();
assert_eq!
(
scope
.region_scope
,
local_scope
,
"local scope is not the topmost scope!"
,
);
assert_eq!
(
scope
.region_scope
,
local_scope
,
"local scope is not the topmost scope!"
,);
// look for moves of a local variable, like `MOVE(_X)`
let
locals_moved
=
operands
...
...
@@ -1046,9 +1043,9 @@ fn diverge_cleanup(&mut self) -> DropIdx {
matches!
(
self
.cfg
.block_data
(
start
)
.terminator
()
.kind
,
TerminatorKind
::
Assert
{
..
}
|
TerminatorKind
::
Call
{
..
}
|
TerminatorKind
::
DropAndReplace
{
..
}
|
TerminatorKind
::
FalseUnwind
{
..
}
|
TerminatorKind
::
Call
{
..
}
|
TerminatorKind
::
DropAndReplace
{
..
}
|
TerminatorKind
::
FalseUnwind
{
..
}
),
"diverge_from called on block with terminator that cannot unwind."
);
...
...
compiler/rustc_parse/src/parser/nonterminal.rs
浏览文件 @
d5b760ba
...
...
@@ -41,13 +41,16 @@ fn may_be_ident(nt: &token::Nonterminal) -> bool {
},
NonterminalKind
::
Block
=>
match
token
.kind
{
token
::
OpenDelim
(
token
::
Brace
)
=>
true
,
token
::
Interpolated
(
ref
nt
)
=>
!
matches!
(
**
nt
,
token
::
NtItem
(
_
)
|
token
::
NtPat
(
_
)
|
token
::
NtTy
(
_
)
|
token
::
NtIdent
(
..
)
|
token
::
NtMeta
(
_
)
|
token
::
NtPath
(
_
)
|
token
::
NtVis
(
_
)),
token
::
Interpolated
(
ref
nt
)
=>
!
matches!
(
**
nt
,
token
::
NtItem
(
_
)
|
token
::
NtPat
(
_
)
|
token
::
NtTy
(
_
)
|
token
::
NtIdent
(
..
)
|
token
::
NtMeta
(
_
)
|
token
::
NtPath
(
_
)
|
token
::
NtVis
(
_
)
),
_
=>
false
,
},
NonterminalKind
::
Path
|
NonterminalKind
::
Meta
=>
match
token
.kind
{
...
...
compiler/rustc_passes/src/stability.rs
浏览文件 @
d5b760ba
...
...
@@ -553,7 +553,8 @@ fn visit_item(&mut self, i: &'tcx Item<'tcx>) {
// optional. They inherit stability from their parents when unannotated.
if
!
matches!
(
i
.kind
,
hir
::
ItemKind
::
Impl
(
hir
::
Impl
{
of_trait
:
None
,
..
})
|
hir
::
ItemKind
::
ForeignMod
{
..
}
hir
::
ItemKind
::
Impl
(
hir
::
Impl
{
of_trait
:
None
,
..
})
|
hir
::
ItemKind
::
ForeignMod
{
..
}
)
{
self
.check_missing_stability
(
i
.hir_id
,
i
.span
);
}
...
...
compiler/rustc_resolve/src/late/diagnostics.rs
浏览文件 @
d5b760ba
...
...
@@ -1659,12 +1659,15 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
match
missing
{
MissingLifetimeSpot
::
Generics
(
generics
)
=>
{
let
(
span
,
sugg
)
=
if
let
Some
(
param
)
=
generics
.params
.iter
()
.find
(|
p
|
{
!
matches!
(
p
.kind
,
hir
::
GenericParamKind
::
Type
{
synthetic
:
Some
(
hir
::
SyntheticTyParamKind
::
ImplTrait
),
..
}
|
hir
::
GenericParamKind
::
Lifetime
{
kind
:
hir
::
LifetimeParamKind
::
Elided
,
})
!
matches!
(
p
.kind
,
hir
::
GenericParamKind
::
Type
{
synthetic
:
Some
(
hir
::
SyntheticTyParamKind
::
ImplTrait
),
..
}
|
hir
::
GenericParamKind
::
Lifetime
{
kind
:
hir
::
LifetimeParamKind
::
Elided
,
}
)
})
{
(
param
.span
.shrink_to_lo
(),
format!
(
"{}, "
,
lifetime_ref
))
}
else
{
...
...
@@ -1844,10 +1847,13 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
msg
=
"consider introducing a named lifetime parameter"
.to_string
();
should_break
=
true
;
if
let
Some
(
param
)
=
generics
.params
.iter
()
.find
(|
p
|
{
!
matches!
(
p
.kind
,
hir
::
GenericParamKind
::
Type
{
synthetic
:
Some
(
hir
::
SyntheticTyParamKind
::
ImplTrait
),
..
})
!
matches!
(
p
.kind
,
hir
::
GenericParamKind
::
Type
{
synthetic
:
Some
(
hir
::
SyntheticTyParamKind
::
ImplTrait
),
..
}
)
})
{
(
param
.span
.shrink_to_lo
(),
"'a, "
.to_string
())
}
else
{
...
...
compiler/rustc_target/src/abi/call/mod.rs
浏览文件 @
d5b760ba
...
...
@@ -526,7 +526,7 @@ pub fn pad_with(&mut self, reg: Reg) {
}
pub
fn
is_indirect
(
&
self
)
->
bool
{
matches!
(
self
.mode
,
PassMode
::
Indirect
{
..
})
matches!
(
self
.mode
,
PassMode
::
Indirect
{
..
})
}
pub
fn
is_sized_indirect
(
&
self
)
->
bool
{
...
...
compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
浏览文件 @
d5b760ba
...
...
@@ -1190,9 +1190,12 @@ fn report_projection_error(
normalized_ty
,
data
.ty
);
let
is_normalized_ty_expected
=
!
matches!
(
obligation
.cause.code
,
ObligationCauseCode
::
ItemObligation
(
_
)
|
ObligationCauseCode
::
BindingObligation
(
_
,
_
)
|
ObligationCauseCode
::
ObjectCastObligation
(
_
));
let
is_normalized_ty_expected
=
!
matches!
(
obligation
.cause.code
,
ObligationCauseCode
::
ItemObligation
(
_
)
|
ObligationCauseCode
::
BindingObligation
(
_
,
_
)
|
ObligationCauseCode
::
ObjectCastObligation
(
_
)
);
if
let
Err
(
error
)
=
self
.at
(
&
obligation
.cause
,
obligation
.param_env
)
.eq_exp
(
is_normalized_ty_expected
,
...
...
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
浏览文件 @
d5b760ba
...
...
@@ -290,9 +290,9 @@ fn suggest_restriction(
generics
.params
.iter
()
.filter
(
|
p
|
!
matches!
(
p
.kind
,
hir
::
GenericParamKind
::
Type
{
synthetic
:
Some
(
_
),
..
}),
)
.filter
(
|
p
|
{
!
matches!
(
p
.kind
,
hir
::
GenericParamKind
::
Type
{
synthetic
:
Some
(
_
),
..
})
}
)
.next
(),
super_traits
,
)
{
...
...
compiler/rustc_typeck/src/astconv/generics.rs
浏览文件 @
d5b760ba
...
...
@@ -496,14 +496,15 @@ pub(crate) fn check_impl_trait(
)
->
bool
{
let
explicit
=
!
seg
.infer_args
;
let
impl_trait
=
generics
.params
.iter
()
.any
(|
param
|
{
matches!
(
param
.kind
,
ty
::
GenericParamDefKind
::
Type
{
synthetic
:
Some
(
hir
::
SyntheticTyParamKind
::
ImplTrait
|
hir
::
SyntheticTyParamKind
::
FromAttr
,
matches!
(
param
.kind
,
ty
::
GenericParamDefKind
::
Type
{
synthetic
:
Some
(
hir
::
SyntheticTyParamKind
::
ImplTrait
|
hir
::
SyntheticTyParamKind
::
FromAttr
,
),
..
})
..
}
)
});
if
explicit
&&
impl_trait
{
...
...
compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
浏览文件 @
d5b760ba
...
...
@@ -274,10 +274,13 @@ pub fn apply_adjustments(&self, expr: &hir::Expr<'_>, adj: Vec<Adjustment<'tcx>>
}
let
autoborrow_mut
=
adj
.iter
()
.any
(|
adj
|
{
matches!
(
adj
,
&
Adjustment
{
kind
:
Adjust
::
Borrow
(
AutoBorrow
::
Ref
(
_
,
AutoBorrowMutability
::
Mut
{
..
})),
..
})
matches!
(
adj
,
&
Adjustment
{
kind
:
Adjust
::
Borrow
(
AutoBorrow
::
Ref
(
_
,
AutoBorrowMutability
::
Mut
{
..
})),
..
}
)
});
match
self
.typeck_results
.borrow_mut
()
.adjustments_mut
()
.entry
(
expr
.hir_id
)
{
...
...
library/core/src/default.rs
浏览文件 @
d5b760ba
...
...
@@ -173,9 +173,11 @@ pub fn default<T: Default>() -> T {
impl
Default
for
$t
{
#[inline]
#[doc
=
$
doc]
fn
default
()
->
$t
{
$v
}
fn
default
()
->
$t
{
$v
}
}
}
}
;
}
default_impl!
{
(),
(),
"Returns the default value of `()`"
}
...
...
rustfmt.toml
浏览文件 @
d5b760ba
...
...
@@ -6,7 +6,7 @@ merge_derives = false
# by default we ignore everything in the repository
# tidy only checks files which are not ignored, each entry follows gitignore style
ignore
=
[
"
build
"
,
"
/build/
"
,
"/vendor/"
,
# tests for now are not formatted, as they are sometimes pretty-printing constrained
...
...
src/bootstrap/bin/main.rs
浏览文件 @
d5b760ba
...
...
@@ -15,7 +15,7 @@ fn main() {
// check_version warnings are not printed during setup
let
changelog_suggestion
=
if
matches!
(
config
.cmd
,
Subcommand
::
Setup
{
..
})
{
None
}
else
{
check_version
(
&
config
)
};
if
matches!
(
config
.cmd
,
Subcommand
::
Setup
{
..
})
{
None
}
else
{
check_version
(
&
config
)
};
// NOTE: Since `./configure` generates a `config.toml`, distro maintainers will see the
// changelog warning, not the `x.py setup` message.
...
...
src/stage0.txt
浏览文件 @
d5b760ba
...
...
@@ -19,7 +19,7 @@ rustc: beta
# bootstrapping issues with use of new syntax in this repo. If you're looking at
# the beta/stable branch, this key should be omitted, as we don't want to depend
# on rustfmt from nightly there.
rustfmt: nightly-202
0-11-19
rustfmt: nightly-202
1-01-28
# When making a stable release the process currently looks like:
#
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录