Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
021a140d
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,发现更多精彩内容 >>
提交
021a140d
编写于
2月 22, 2019
作者:
L
ljedrz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
hir: remove NodeId from Block
上级
63b4dd91
变更
24
隐藏空白更改
内联
并排
Showing
24 changed file
with
121 addition
and
135 deletion
+121
-135
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+3
-6
src/librustc/hir/mod.rs
src/librustc/hir/mod.rs
+0
-1
src/librustc/ich/impls_hir.rs
src/librustc/ich/impls_hir.rs
+0
-1
src/librustc/middle/expr_use_visitor.rs
src/librustc/middle/expr_use_visitor.rs
+1
-1
src/librustc/middle/liveness.rs
src/librustc/middle/liveness.rs
+3
-2
src/librustc/middle/region.rs
src/librustc/middle/region.rs
+1
-1
src/librustc/mir/interpret/error.rs
src/librustc/mir/interpret/error.rs
+7
-7
src/librustc/mir/mod.rs
src/librustc/mir/mod.rs
+6
-6
src/librustc/traits/object_safety.rs
src/librustc/traits/object_safety.rs
+2
-1
src/librustc/ty/context.rs
src/librustc/ty/context.rs
+2
-2
src/librustc_driver/pretty.rs
src/librustc_driver/pretty.rs
+2
-2
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/mod.rs
+1
-1
src/librustc_mir/build/block.rs
src/librustc_mir/build/block.rs
+3
-3
src/librustc_mir/build/mod.rs
src/librustc_mir/build/mod.rs
+2
-2
src/librustc_mir/build/scope.rs
src/librustc_mir/build/scope.rs
+3
-9
src/librustc_mir/const_eval.rs
src/librustc_mir/const_eval.rs
+3
-3
src/librustc_mir/hair/cx/block.rs
src/librustc_mir/hair/cx/block.rs
+1
-1
src/librustc_mir/hair/cx/mod.rs
src/librustc_mir/hair/cx/mod.rs
+9
-10
src/librustc_mir/hair/mod.rs
src/librustc_mir/hair/mod.rs
+2
-2
src/librustc_mir/transform/check_unsafety.rs
src/librustc_mir/transform/check_unsafety.rs
+29
-30
src/librustc_mir/transform/const_prop.rs
src/librustc_mir/transform/const_prop.rs
+3
-3
src/librustc_typeck/check/closure.rs
src/librustc_typeck/check/closure.rs
+1
-1
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+35
-36
src/librustc_typeck/check/regionck.rs
src/librustc_typeck/check/regionck.rs
+2
-4
未找到文件。
src/librustc/hir/lowering.rs
浏览文件 @
021a140d
...
...
@@ -2804,10 +2804,9 @@ fn lower_block(&mut self, b: &Block, targeted_by_break: bool) -> P<hir::Block> {
}
}
let
LoweredNodeId
{
node_id
,
hir_id
}
=
self
.lower_node_id
(
b
.id
);
let
LoweredNodeId
{
node_id
:
_
,
hir_id
}
=
self
.lower_node_id
(
b
.id
);
P
(
hir
::
Block
{
id
:
node_id
,
hir_id
,
stmts
:
stmts
.into
(),
expr
,
...
...
@@ -3887,11 +3886,10 @@ fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
// Wrap the `if let` expr in a block.
let
span
=
els
.span
;
let
els
=
P
(
self
.lower_expr
(
els
));
let
LoweredNodeId
{
node_id
,
hir_id
}
=
self
.next_id
();
let
LoweredNodeId
{
node_id
:
_
,
hir_id
}
=
self
.next_id
();
let
blk
=
P
(
hir
::
Block
{
stmts
:
hir_vec!
[],
expr
:
Some
(
els
),
id
:
node_id
,
hir_id
,
rules
:
hir
::
DefaultBlock
,
span
,
...
...
@@ -4965,12 +4963,11 @@ fn block_all(
stmts
:
hir
::
HirVec
<
hir
::
Stmt
>
,
expr
:
Option
<
P
<
hir
::
Expr
>>
,
)
->
hir
::
Block
{
let
LoweredNodeId
{
node_id
,
hir_id
}
=
self
.next_id
();
let
LoweredNodeId
{
node_id
:
_
,
hir_id
}
=
self
.next_id
();
hir
::
Block
{
stmts
,
expr
,
id
:
node_id
,
hir_id
,
rules
:
hir
::
DefaultBlock
,
span
,
...
...
src/librustc/hir/mod.rs
浏览文件 @
021a140d
...
...
@@ -822,7 +822,6 @@ pub struct Block {
/// An expression at the end of the block
/// without a semicolon, if any.
pub
expr
:
Option
<
P
<
Expr
>>
,
pub
id
:
NodeId
,
pub
hir_id
:
HirId
,
/// Distinguishes between `unsafe { ... }` and `{ ... }`.
pub
rules
:
BlockCheckMode
,
...
...
src/librustc/ich/impls_hir.rs
浏览文件 @
021a140d
...
...
@@ -415,7 +415,6 @@ fn hash_stable<W: StableHasherResult>(&self,
impl_stable_hash_for!
(
struct
hir
::
Block
{
stmts
,
expr
,
id
->
_
,
hir_id
->
_
,
rules
,
span
,
...
...
src/librustc/middle/expr_use_visitor.rs
浏览文件 @
021a140d
...
...
@@ -629,7 +629,7 @@ fn walk_local(&mut self, local: &hir::Local) {
/// Indicates that the value of `blk` will be consumed, meaning either copied or moved
/// depending on its type.
fn
walk_block
(
&
mut
self
,
blk
:
&
hir
::
Block
)
{
debug!
(
"walk_block(blk.
id={})"
,
blk
.
id
);
debug!
(
"walk_block(blk.
hir_id={})"
,
blk
.hir_
id
);
for
stmt
in
&
blk
.stmts
{
self
.walk_stmt
(
stmt
);
...
...
src/librustc/middle/liveness.rs
浏览文件 @
021a140d
...
...
@@ -950,7 +950,8 @@ fn compute(&mut self, body: &hir::Expr) -> LiveNode {
fn
propagate_through_block
(
&
mut
self
,
blk
:
&
hir
::
Block
,
succ
:
LiveNode
)
->
LiveNode
{
if
blk
.targeted_by_break
{
self
.break_ln
.insert
(
blk
.id
,
succ
);
let
node_id
=
self
.ir.tcx
.hir
()
.hir_to_node_id
(
blk
.hir_id
);
self
.break_ln
.insert
(
node_id
,
succ
);
}
let
succ
=
self
.propagate_through_opt_expr
(
blk
.expr
.as_ref
()
.map
(|
e
|
&**
e
),
succ
);
blk
.stmts
.iter
()
.rev
()
.fold
(
succ
,
|
succ
,
stmt
|
{
...
...
@@ -1386,7 +1387,7 @@ fn propagate_through_loop(&mut self,
}
}
debug!
(
"propagate_through_loop: using id for loop body {} {}"
,
expr
.id
,
self
.ir.tcx
.hir
()
.
node_to_pretty_string
(
body
.
id
));
expr
.id
,
self
.ir.tcx
.hir
()
.
hir_to_pretty_string
(
body
.hir_
id
));
self
.break_ln
.insert
(
expr
.id
,
succ
);
...
...
src/librustc/middle/region.rs
浏览文件 @
021a140d
...
...
@@ -745,7 +745,7 @@ fn record_var_lifetime(visitor: &mut RegionResolutionVisitor<'_, '_>,
}
fn
resolve_block
<
'a
,
'tcx
>
(
visitor
:
&
mut
RegionResolutionVisitor
<
'a
,
'tcx
>
,
blk
:
&
'tcx
hir
::
Block
)
{
debug!
(
"resolve_block(blk.
id={:?})"
,
blk
.
id
);
debug!
(
"resolve_block(blk.
hir_id={:?})"
,
blk
.hir_
id
);
let
prev_cx
=
visitor
.cx
;
...
...
src/librustc/mir/interpret/error.rs
浏览文件 @
021a140d
use
std
::{
fmt
,
env
};
use
crate
::
hir
;
use
crate
::
hir
::
map
::
definitions
::
DefPathData
;
use
crate
::
mir
;
use
crate
::
ty
::{
self
,
Ty
,
layout
};
...
...
@@ -14,7 +15,6 @@
use
errors
::
DiagnosticBuilder
;
use
syntax_pos
::{
Pos
,
Span
};
use
syntax
::
ast
;
use
syntax
::
symbol
::
Symbol
;
#[derive(Debug,
Copy,
Clone,
PartialEq,
Eq)]
...
...
@@ -50,7 +50,7 @@ pub struct ConstEvalErr<'tcx> {
pub
struct
FrameInfo
<
'tcx
>
{
pub
call_site
:
Span
,
// this span is in the caller!
pub
instance
:
ty
::
Instance
<
'tcx
>
,
pub
lint_root
:
Option
<
ast
::
Node
Id
>
,
pub
lint_root
:
Option
<
hir
::
Hir
Id
>
,
}
impl
<
'tcx
>
fmt
::
Display
for
FrameInfo
<
'tcx
>
{
...
...
@@ -98,7 +98,7 @@ pub fn report_as_error(&self,
pub
fn
report_as_lint
(
&
self
,
tcx
:
TyCtxtAt
<
'a
,
'gcx
,
'tcx
>
,
message
:
&
str
,
lint_root
:
ast
::
Node
Id
,
lint_root
:
hir
::
Hir
Id
,
)
->
ErrorHandled
{
let
lint
=
self
.struct_generic
(
tcx
,
...
...
@@ -118,7 +118,7 @@ fn struct_generic(
&
self
,
tcx
:
TyCtxtAt
<
'a
,
'gcx
,
'tcx
>
,
message
:
&
str
,
lint_root
:
Option
<
ast
::
Node
Id
>
,
lint_root
:
Option
<
hir
::
Hir
Id
>
,
)
->
Result
<
DiagnosticBuilder
<
'tcx
>
,
ErrorHandled
>
{
match
self
.error
{
EvalErrorKind
::
Layout
(
LayoutError
::
Unknown
(
_
))
|
...
...
@@ -129,15 +129,15 @@ fn struct_generic(
}
trace!
(
"reporting const eval failure at {:?}"
,
self
.span
);
let
mut
err
=
if
let
Some
(
lint_root
)
=
lint_root
{
let
node
_id
=
self
.stacktrace
let
hir
_id
=
self
.stacktrace
.iter
()
.rev
()
.filter_map
(|
frame
|
frame
.lint_root
)
.next
()
.unwrap_or
(
lint_root
);
tcx
.struct_span_lint_
node
(
tcx
.struct_span_lint_
hir
(
crate
::
rustc
::
lint
::
builtin
::
CONST_ERR
,
node
_id
,
hir
_id
,
tcx
.span
,
message
,
)
...
...
src/librustc/mir/mod.rs
浏览文件 @
021a140d
...
...
@@ -413,7 +413,7 @@ pub enum Safety {
/// Unsafe because of an unsafe fn
FnUnsafe
,
/// Unsafe because of an `unsafe` block
ExplicitUnsafe
(
ast
::
Node
Id
),
ExplicitUnsafe
(
hir
::
Hir
Id
),
}
impl_stable_hash_for!
(
struct
Mir
<
'tcx
>
{
...
...
@@ -2098,8 +2098,8 @@ pub struct SourceScopeData {
#[derive(Clone,
Debug,
RustcEncodable,
RustcDecodable)]
pub
struct
SourceScopeLocalData
{
/// A
Node
Id with lint levels equivalent to this scope's lint levels.
pub
lint_root
:
ast
::
Node
Id
,
/// A
Hir
Id with lint levels equivalent to this scope's lint levels.
pub
lint_root
:
hir
::
Hir
Id
,
/// The unsafe block that contains this node.
pub
safety
:
Safety
,
}
...
...
@@ -2849,8 +2849,8 @@ pub enum UnsafetyViolationKind {
General
,
/// Permitted in const fn and regular fns.
GeneralAndConstFn
,
ExternStatic
(
ast
::
Node
Id
),
BorrowPacked
(
ast
::
Node
Id
),
ExternStatic
(
hir
::
Hir
Id
),
BorrowPacked
(
hir
::
Hir
Id
),
}
#[derive(Copy,
Clone,
Debug,
PartialEq,
Eq,
Hash,
RustcEncodable,
RustcDecodable)]
...
...
@@ -2867,7 +2867,7 @@ pub struct UnsafetyCheckResult {
pub
violations
:
Lrc
<
[
UnsafetyViolation
]
>
,
/// unsafe blocks in this function, along with whether they are used. This is
/// used for the "unused_unsafe" lint.
pub
unsafe_blocks
:
Lrc
<
[(
ast
::
Node
Id
,
bool
)]
>
,
pub
unsafe_blocks
:
Lrc
<
[(
hir
::
Hir
Id
,
bool
)]
>
,
}
/// The layout of generator state
...
...
src/librustc/traits/object_safety.rs
浏览文件 @
021a140d
...
...
@@ -10,6 +10,7 @@
use
super
::
elaborate_predicates
;
use
crate
::
hir
;
use
crate
::
hir
::
def_id
::
DefId
;
use
crate
::
lint
;
use
crate
::
traits
::{
self
,
Obligation
,
ObligationCause
};
...
...
@@ -129,7 +130,7 @@ fn object_safety_violations_for_trait(self, trait_def_id: DefId)
// It's also hard to get a use site span, so we use the method definition span.
self
.lint_node_note
(
lint
::
builtin
::
WHERE_CLAUSES_OBJECT_SAFETY
,
ast
::
CRATE_NODE
_ID
,
hir
::
CRATE_HIR
_ID
,
*
span
,
&
format!
(
"the trait `{}` cannot be made into an object"
,
self
.item_path_str
(
trait_def_id
)),
...
...
src/librustc/ty/context.rs
浏览文件 @
021a140d
...
...
@@ -2859,11 +2859,11 @@ pub fn lint_hir_note<S: Into<MultiSpan>>(self,
pub
fn
lint_node_note
<
S
:
Into
<
MultiSpan
>>
(
self
,
lint
:
&
'static
Lint
,
id
:
Node
Id
,
id
:
hir
::
Hir
Id
,
span
:
S
,
msg
:
&
str
,
note
:
&
str
)
{
let
mut
err
=
self
.struct_span_lint_
node
(
lint
,
id
,
span
.into
(),
msg
);
let
mut
err
=
self
.struct_span_lint_
hir
(
lint
,
id
,
span
.into
(),
msg
);
err
.note
(
note
);
err
.emit
()
}
...
...
src/librustc_driver/pretty.rs
浏览文件 @
021a140d
...
...
@@ -420,8 +420,8 @@ fn post(&self, s: &mut pprust_hir::State, node: pprust_hir::AnnNode) -> io::Resu
}
pprust_hir
::
AnnNode
::
Block
(
blk
)
=>
{
s
.s
.space
()
?
;
s
.synth_comment
(
format!
(
"block
node
_id: {} hir local_id: {}"
,
blk
.id
,
blk
.hir_id.local_id
.as_u32
()))
s
.synth_comment
(
format!
(
"block
hir
_id: {} hir local_id: {}"
,
blk
.
hir_
id
,
blk
.hir_id.local_id
.as_u32
()))
}
pprust_hir
::
AnnNode
::
Expr
(
expr
)
=>
{
s
.s
.space
()
?
;
...
...
src/librustc_mir/borrow_check/mod.rs
浏览文件 @
021a140d
...
...
@@ -301,7 +301,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
}
let
mut_span
=
tcx
.sess
.source_map
()
.span_until_non_whitespace
(
span
);
tcx
.struct_span_lint_
node
(
tcx
.struct_span_lint_
hir
(
UNUSED_MUT
,
vsi
[
local_decl
.source_info.scope
]
.lint_root
,
span
,
...
...
src/librustc_mir/build/block.rs
浏览文件 @
021a140d
...
...
@@ -206,14 +206,14 @@ fn update_source_scope_for_safety_mode(&mut self,
debug!
(
"update_source_scope_for({:?}, {:?})"
,
span
,
safety_mode
);
let
new_unsafety
=
match
safety_mode
{
BlockSafety
::
Safe
=>
None
,
BlockSafety
::
ExplicitUnsafe
(
node
_id
)
=>
{
BlockSafety
::
ExplicitUnsafe
(
hir
_id
)
=>
{
assert_eq!
(
self
.push_unsafe_count
,
0
);
match
self
.unpushed_unsafe
{
Safety
::
Safe
=>
{}
_
=>
return
}
self
.unpushed_unsafe
=
Safety
::
ExplicitUnsafe
(
node
_id
);
Some
(
Safety
::
ExplicitUnsafe
(
node
_id
))
self
.unpushed_unsafe
=
Safety
::
ExplicitUnsafe
(
hir
_id
);
Some
(
Safety
::
ExplicitUnsafe
(
hir
_id
))
}
BlockSafety
::
PushUnsafe
=>
{
self
.push_unsafe_count
+=
1
;
...
...
src/librustc_mir/build/mod.rs
浏览文件 @
021a140d
...
...
@@ -72,13 +72,13 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
};
tcx
.infer_ctxt
()
.enter
(|
infcx
|
{
let
cx
=
Cx
::
new
(
&
infcx
,
id
);
let
fn_hir_id
=
tcx
.hir
()
.node_to_hir_id
(
id
);
let
cx
=
Cx
::
new
(
&
infcx
,
fn_hir_id
);
let
mut
mir
=
if
cx
.tables
()
.tainted_by_errors
{
build
::
construct_error
(
cx
,
body_id
)
}
else
if
cx
.body_owner_kind
.is_fn_or_closure
()
{
// fetch the fully liberated fn signature (that is, all bound
// types/lifetimes replaced)
let
fn_hir_id
=
tcx
.hir
()
.node_to_hir_id
(
id
);
let
fn_sig
=
cx
.tables
()
.liberated_fn_sigs
()[
fn_hir_id
]
.clone
();
let
fn_def_id
=
tcx
.hir
()
.local_def_id
(
id
);
...
...
src/librustc_mir/build/scope.rs
浏览文件 @
021a140d
...
...
@@ -308,17 +308,11 @@ pub fn in_scope<F, R>(&mut self,
debug!
(
"in_scope(region_scope={:?}, block={:?})"
,
region_scope
,
block
);
let
source_scope
=
self
.source_scope
;
let
tcx
=
self
.hir
.tcx
();
if
let
LintLevel
::
Explicit
(
node
_id
)
=
lint_level
{
if
let
LintLevel
::
Explicit
(
current_hir
_id
)
=
lint_level
{
let
same_lint_scopes
=
tcx
.dep_graph
.with_ignore
(||
{
let
sets
=
tcx
.lint_levels
(
LOCAL_CRATE
);
let
parent_hir_id
=
tcx
.hir
()
.definitions
()
.node_to_hir_id
(
self
.source_scope_local_data
[
source_scope
]
.lint_root
);
let
current_hir_id
=
tcx
.hir
()
.definitions
()
.node_to_hir_id
(
node_id
);
sets
.lint_level_set
(
parent_hir_id
)
==
sets
.lint_level_set
(
current_hir_id
)
let
parent_hir_id
=
self
.source_scope_local_data
[
source_scope
]
.lint_root
;
sets
.lint_level_set
(
parent_hir_id
)
==
sets
.lint_level_set
(
current_hir_id
)
});
if
!
same_lint_scopes
{
...
...
src/librustc_mir/const_eval.rs
浏览文件 @
021a140d
...
...
@@ -663,11 +663,11 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
// because any code that existed before validation could not have failed validation
// thus preventing such a hard error from being a backwards compatibility hazard
Some
(
Def
::
Const
(
_
))
|
Some
(
Def
::
AssociatedConst
(
_
))
=>
{
let
node_id
=
tcx
.hir
()
.as_local_node
_id
(
def_id
)
.unwrap
();
let
hir_id
=
tcx
.hir
()
.as_local_hir
_id
(
def_id
)
.unwrap
();
err
.report_as_lint
(
tcx
.at
(
tcx
.def_span
(
def_id
)),
"any use of this value will cause an error"
,
node
_id
,
hir
_id
,
)
},
// promoting runtime code is only allowed to error if it references broken constants
...
...
@@ -683,7 +683,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
err
.report_as_lint
(
tcx
.at
(
span
),
"reaching this expression at runtime will panic or abort"
,
tcx
.hir
()
.as_local_
node
_id
(
def_id
)
.unwrap
(),
tcx
.hir
()
.as_local_
hir
_id
(
def_id
)
.unwrap
(),
)
}
// anything else (array lengths, enum initializers, constant patterns) are reported
...
...
src/librustc_mir/hair/cx/block.rs
浏览文件 @
021a140d
...
...
@@ -30,7 +30,7 @@ fn make_mirror<'a, 'gcx>(self, cx: &mut Cx<'a, 'gcx, 'tcx>) -> Block<'tcx> {
hir
::
BlockCheckMode
::
DefaultBlock
=>
BlockSafety
::
Safe
,
hir
::
BlockCheckMode
::
UnsafeBlock
(
..
)
=>
BlockSafety
::
ExplicitUnsafe
(
self
.id
),
BlockSafety
::
ExplicitUnsafe
(
self
.
hir_
id
),
hir
::
BlockCheckMode
::
PushUnsafeBlock
(
..
)
=>
BlockSafety
::
PushUnsafe
,
hir
::
BlockCheckMode
::
PopUnsafeBlock
(
..
)
=>
...
...
src/librustc_mir/hair/cx/mod.rs
浏览文件 @
021a140d
...
...
@@ -26,7 +26,7 @@ pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
tcx
:
TyCtxt
<
'a
,
'gcx
,
'tcx
>
,
infcx
:
&
'a
InferCtxt
<
'a
,
'gcx
,
'tcx
>
,
pub
root_lint_level
:
ast
::
Node
Id
,
pub
root_lint_level
:
hir
::
Hir
Id
,
pub
param_env
:
ty
::
ParamEnv
<
'gcx
>
,
/// Identity `Substs` for use with const-evaluation.
...
...
@@ -51,10 +51,10 @@ pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
impl
<
'a
,
'gcx
,
'tcx
>
Cx
<
'a
,
'gcx
,
'tcx
>
{
pub
fn
new
(
infcx
:
&
'a
InferCtxt
<
'a
,
'gcx
,
'tcx
>
,
src_id
:
ast
::
Node
Id
)
->
Cx
<
'a
,
'gcx
,
'tcx
>
{
src_id
:
hir
::
Hir
Id
)
->
Cx
<
'a
,
'gcx
,
'tcx
>
{
let
tcx
=
infcx
.tcx
;
let
src_def_id
=
tcx
.hir
()
.local_def_id
(
src_id
);
let
body_owner_kind
=
tcx
.hir
()
.body_owner_kind
(
src_id
);
let
src_def_id
=
tcx
.hir
()
.local_def_id
_from_hir_id
(
src_id
);
let
body_owner_kind
=
tcx
.hir
()
.body_owner_kind
_by_hir_id
(
src_id
);
let
constness
=
match
body_owner_kind
{
hir
::
BodyOwnerKind
::
Const
|
...
...
@@ -63,7 +63,7 @@ pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
hir
::
BodyOwnerKind
::
Fn
=>
hir
::
Constness
::
NotConst
,
};
let
attrs
=
tcx
.hir
()
.attrs
(
src_id
);
let
attrs
=
tcx
.hir
()
.attrs
_by_hir_id
(
src_id
);
// Some functions always have overflow checks enabled,
// however, they may not get codegen'd, depending on
...
...
@@ -204,7 +204,7 @@ fn lint_level_of(&self, node_id: ast::NodeId) -> LintLevel {
});
if
has_lint_level
{
LintLevel
::
Explicit
(
node
_id
)
LintLevel
::
Explicit
(
hir
_id
)
}
else
{
LintLevel
::
Inherited
}
...
...
@@ -237,7 +237,7 @@ fn tables(&self) -> &ty::TypeckTables<'tcx> {
}
}
fn
lint_level_for_hir_id
(
tcx
:
TyCtxt
<
'_
,
'_
,
'_
>
,
mut
id
:
ast
::
NodeId
)
->
ast
::
Node
Id
{
fn
lint_level_for_hir_id
(
tcx
:
TyCtxt
<
'_
,
'_
,
'_
>
,
mut
id
:
hir
::
HirId
)
->
hir
::
Hir
Id
{
// Right now we insert a `with_ignore` node in the dep graph here to
// ignore the fact that `lint_levels` below depends on the entire crate.
// For now this'll prevent false positives of recompiling too much when
...
...
@@ -249,11 +249,10 @@ fn lint_level_for_hir_id(tcx: TyCtxt<'_, '_, '_>, mut id: ast::NodeId) -> ast::N
tcx
.dep_graph
.with_ignore
(||
{
let
sets
=
tcx
.lint_levels
(
LOCAL_CRATE
);
loop
{
let
hir_id
=
tcx
.hir
()
.definitions
()
.node_to_hir_id
(
id
);
if
sets
.lint_level_set
(
hir_id
)
.is_some
()
{
if
sets
.lint_level_set
(
id
)
.is_some
()
{
return
id
}
let
next
=
tcx
.hir
()
.get_parent_node
(
id
);
let
next
=
tcx
.hir
()
.get_parent_node
_by_hir_id
(
id
);
if
next
==
id
{
bug!
(
"lint traversal reached the root of the crate"
);
}
...
...
src/librustc_mir/hair/mod.rs
浏览文件 @
021a140d
...
...
@@ -28,7 +28,7 @@
#[derive(Copy,
Clone,
Debug)]
pub
enum
LintLevel
{
Inherited
,
Explicit
(
ast
::
Node
Id
)
Explicit
(
hir
::
Hir
Id
)
}
impl
LintLevel
{
...
...
@@ -54,7 +54,7 @@ pub struct Block<'tcx> {
#[derive(Copy,
Clone,
Debug)]
pub
enum
BlockSafety
{
Safe
,
ExplicitUnsafe
(
ast
::
Node
Id
),
ExplicitUnsafe
(
hir
::
Hir
Id
),
PushUnsafe
,
PopUnsafe
}
...
...
src/librustc_mir/transform/check_unsafety.rs
浏览文件 @
021a140d
...
...
@@ -12,7 +12,6 @@
use
rustc
::
mir
::
*
;
use
rustc
::
mir
::
visit
::{
PlaceContext
,
Visitor
,
MutatingUseContext
};
use
syntax
::
ast
;
use
syntax
::
symbol
::
Symbol
;
use
std
::
ops
::
Bound
;
...
...
@@ -29,8 +28,8 @@ pub struct UnsafetyChecker<'a, 'tcx: 'a> {
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
/// Mark an `unsafe` block as used, so we don't lint it.
used_unsafe
:
FxHashSet
<
ast
::
Node
Id
>
,
inherited_blocks
:
Vec
<
(
ast
::
Node
Id
,
bool
)
>
,
used_unsafe
:
FxHashSet
<
hir
::
Hir
Id
>
,
inherited_blocks
:
Vec
<
(
hir
::
Hir
Id
,
bool
)
>
,
}
impl
<
'a
,
'gcx
,
'tcx
>
UnsafetyChecker
<
'a
,
'tcx
>
{
...
...
@@ -349,7 +348,7 @@ fn require_unsafe(
fn
register_violations
(
&
mut
self
,
violations
:
&
[
UnsafetyViolation
],
unsafe_blocks
:
&
[(
ast
::
Node
Id
,
bool
)])
{
unsafe_blocks
:
&
[(
hir
::
Hir
Id
,
bool
)])
{
let
safety
=
self
.source_scope_local_data
[
self
.source_info.scope
]
.safety
;
let
within_unsafe
=
match
safety
{
// `unsafe` blocks are required in safe code
...
...
@@ -375,10 +374,10 @@ fn register_violations(&mut self,
}
// `unsafe` function bodies allow unsafe without additional unsafe blocks
Safety
::
BuiltinUnsafe
|
Safety
::
FnUnsafe
=>
true
,
Safety
::
ExplicitUnsafe
(
node
_id
)
=>
{
Safety
::
ExplicitUnsafe
(
hir
_id
)
=>
{
// mark unsafe block as used if there are any unsafe operations inside
if
!
violations
.is_empty
()
{
self
.used_unsafe
.insert
(
node
_id
);
self
.used_unsafe
.insert
(
hir
_id
);
}
// only some unsafety is allowed in const fn
if
self
.min_const_fn
{
...
...
@@ -405,8 +404,8 @@ fn register_violations(&mut self,
true
}
};
self
.inherited_blocks
.extend
(
unsafe_blocks
.iter
()
.map
(|
&
(
node
_id
,
is_used
)|
{
(
node
_id
,
is_used
&&
!
within_unsafe
)
self
.inherited_blocks
.extend
(
unsafe_blocks
.iter
()
.map
(|
&
(
hir
_id
,
is_used
)|
{
(
hir
_id
,
is_used
&&
!
within_unsafe
)
}));
}
fn
check_mut_borrowing_layout_constrained_field
(
...
...
@@ -467,8 +466,8 @@ pub(crate) fn provide(providers: &mut Providers<'_>) {
}
struct
UnusedUnsafeVisitor
<
'a
>
{
used_unsafe
:
&
'a
FxHashSet
<
ast
::
Node
Id
>
,
unsafe_blocks
:
&
'a
mut
Vec
<
(
ast
::
Node
Id
,
bool
)
>
,
used_unsafe
:
&
'a
FxHashSet
<
hir
::
Hir
Id
>
,
unsafe_blocks
:
&
'a
mut
Vec
<
(
hir
::
Hir
Id
,
bool
)
>
,
}
impl
<
'a
,
'tcx
>
hir
::
intravisit
::
Visitor
<
'tcx
>
for
UnusedUnsafeVisitor
<
'a
>
{
...
...
@@ -482,19 +481,19 @@ fn visit_block(&mut self, block: &'tcx hir::Block) {
hir
::
intravisit
::
walk_block
(
self
,
block
);
if
let
hir
::
UnsafeBlock
(
hir
::
UserProvided
)
=
block
.rules
{
self
.unsafe_blocks
.push
((
block
.
id
,
self
.used_unsafe
.contains
(
&
block
.
id
)));
self
.unsafe_blocks
.push
((
block
.
hir_id
,
self
.used_unsafe
.contains
(
&
block
.hir_
id
)));
}
}
}
fn
check_unused_unsafe
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
def_id
:
DefId
,
used_unsafe
:
&
FxHashSet
<
ast
::
Node
Id
>
,
unsafe_blocks
:
&
'a
mut
Vec
<
(
ast
::
Node
Id
,
bool
)
>
)
used_unsafe
:
&
FxHashSet
<
hir
::
Hir
Id
>
,
unsafe_blocks
:
&
'a
mut
Vec
<
(
hir
::
Hir
Id
,
bool
)
>
)
{
let
body_id
=
tcx
.hir
()
.as_local_
node_id
(
def_id
)
.and_then
(|
node
_id
|
{
tcx
.hir
()
.maybe_body_owned_by
(
node
_id
)
tcx
.hir
()
.as_local_
hir_id
(
def_id
)
.and_then
(|
hir
_id
|
{
tcx
.hir
()
.maybe_body_owned_by
_by_hir_id
(
hir
_id
)
});
let
body_id
=
match
body_id
{
...
...
@@ -574,18 +573,18 @@ fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: D
&
message
);
}
/// Returns the `
Node
Id` for an enclosing scope that is also `unsafe`.
/// Returns the `
Hir
Id` for an enclosing scope that is also `unsafe`.
fn
is_enclosed
(
tcx
:
TyCtxt
<
'_
,
'_
,
'_
>
,
used_unsafe
:
&
FxHashSet
<
ast
::
Node
Id
>
,
id
:
ast
::
NodeId
)
->
Option
<
(
String
,
ast
::
Node
Id
)
>
{
let
parent_id
=
tcx
.hir
()
.get_parent_node
(
id
);
used_unsafe
:
&
FxHashSet
<
hir
::
Hir
Id
>
,
id
:
hir
::
HirId
)
->
Option
<
(
String
,
hir
::
Hir
Id
)
>
{
let
parent_id
=
tcx
.hir
()
.get_parent_node
_by_hir_id
(
id
);
if
parent_id
!=
id
{
if
used_unsafe
.contains
(
&
parent_id
)
{
Some
((
"block"
.to_string
(),
parent_id
))
}
else
if
let
Some
(
Node
::
Item
(
&
hir
::
Item
{
node
:
hir
::
ItemKind
::
Fn
(
_
,
header
,
_
,
_
),
..
}))
=
tcx
.hir
()
.find
(
parent_id
)
{
}))
=
tcx
.hir
()
.find
_by_hir_id
(
parent_id
)
{
match
header
.unsafety
{
hir
::
Unsafety
::
Unsafe
=>
Some
((
"fn"
.to_string
(),
parent_id
)),
hir
::
Unsafety
::
Normal
=>
None
,
...
...
@@ -599,14 +598,14 @@ fn is_enclosed(tcx: TyCtxt<'_, '_, '_>,
}
fn
report_unused_unsafe
(
tcx
:
TyCtxt
<
'_
,
'_
,
'_
>
,
used_unsafe
:
&
FxHashSet
<
ast
::
Node
Id
>
,
id
:
ast
::
Node
Id
)
{
let
span
=
tcx
.sess
.source_map
()
.def_span
(
tcx
.hir
()
.span
(
id
));
used_unsafe
:
&
FxHashSet
<
hir
::
Hir
Id
>
,
id
:
hir
::
Hir
Id
)
{
let
span
=
tcx
.sess
.source_map
()
.def_span
(
tcx
.hir
()
.span
_by_hir_id
(
id
));
let
msg
=
"unnecessary `unsafe` block"
;
let
mut
db
=
tcx
.struct_span_lint_
node
(
UNUSED_UNSAFE
,
id
,
span
,
msg
);
let
mut
db
=
tcx
.struct_span_lint_
hir
(
UNUSED_UNSAFE
,
id
,
span
,
msg
);
db
.span_label
(
span
,
msg
);
if
let
Some
((
kind
,
id
))
=
is_enclosed
(
tcx
,
used_unsafe
,
id
)
{
db
.span_label
(
tcx
.sess
.source_map
()
.def_span
(
tcx
.hir
()
.span
(
id
)),
db
.span_label
(
tcx
.sess
.source_map
()
.def_span
(
tcx
.hir
()
.span
_by_hir_id
(
id
)),
format!
(
"because it's nested under this `unsafe` {}"
,
kind
));
}
db
.emit
();
...
...
@@ -655,20 +654,20 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
.note
(
&
details
.as_str
()[
..
])
.emit
();
}
UnsafetyViolationKind
::
ExternStatic
(
lint_
node
_id
)
=>
{
UnsafetyViolationKind
::
ExternStatic
(
lint_
hir
_id
)
=>
{
tcx
.lint_node_note
(
SAFE_EXTERN_STATICS
,
lint_
node
_id
,
lint_
hir
_id
,
source_info
.span
,
&
format!
(
"{} is unsafe and requires unsafe function or block
\
(error E0133)"
,
&
description
.as_str
()[
..
]),
&
details
.as_str
()[
..
]);
}
UnsafetyViolationKind
::
BorrowPacked
(
lint_
node
_id
)
=>
{
UnsafetyViolationKind
::
BorrowPacked
(
lint_
hir
_id
)
=>
{
if
let
Some
(
impl_def_id
)
=
builtin_derive_def_id
(
tcx
,
def_id
)
{
tcx
.unsafe_derive_on_repr_packed
(
impl_def_id
);
}
else
{
tcx
.lint_node_note
(
SAFE_PACKED_BORROWS
,
lint_
node
_id
,
lint_
hir
_id
,
source_info
.span
,
&
format!
(
"{} is unsafe and requires unsafe function or block
\
(error E0133)"
,
&
description
.as_str
()[
..
]),
...
...
@@ -679,7 +678,7 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
}
let
mut
unsafe_blocks
:
Vec
<
_
>
=
unsafe_blocks
.into_iter
()
.collect
();
unsafe_blocks
.sort
(
);
unsafe_blocks
.sort
_by_cached_key
(|(
hir_id
,
_
)|
tcx
.hir
()
.hir_to_node_id
(
*
hir_id
)
);
let
used_unsafe
:
FxHashSet
<
_
>
=
unsafe_blocks
.iter
()
.flat_map
(|
&&
(
id
,
used
)|
if
used
{
Some
(
id
)
}
else
{
None
})
.collect
();
...
...
src/librustc_mir/transform/const_prop.rs
浏览文件 @
021a140d
...
...
@@ -430,10 +430,10 @@ fn const_prop(
}
else
{
"left"
};
let
node
_id
=
source_scope_local_data
[
source_info
.scope
]
.lint_root
;
self
.tcx
.lint_
node
(
let
hir
_id
=
source_scope_local_data
[
source_info
.scope
]
.lint_root
;
self
.tcx
.lint_
hir
(
::
rustc
::
lint
::
builtin
::
EXCEEDING_BITSHIFTS
,
node
_id
,
hir
_id
,
span
,
&
format!
(
"attempt to shift {} with overflow"
,
dir
));
return
None
;
...
...
src/librustc_typeck/check/closure.rs
浏览文件 @
021a140d
...
...
@@ -86,7 +86,7 @@ fn check_closure(
self
.param_env
,
liberated_sig
,
decl
,
expr
.id
,
expr
.
hir_
id
,
body
,
gen
,
)
.1
;
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
021a140d
...
...
@@ -388,14 +388,14 @@ fn maybe_mut_place(m: hir::Mutability) -> Self {
#[derive(Copy,
Clone)]
pub
struct
UnsafetyState
{
pub
def
:
ast
::
Node
Id
,
pub
def
:
hir
::
Hir
Id
,
pub
unsafety
:
hir
::
Unsafety
,
pub
unsafe_push_count
:
u32
,
from_fn
:
bool
}
impl
UnsafetyState
{
pub
fn
function
(
unsafety
:
hir
::
Unsafety
,
def
:
ast
::
Node
Id
)
->
UnsafetyState
{
pub
fn
function
(
unsafety
:
hir
::
Unsafety
,
def
:
hir
::
Hir
Id
)
->
UnsafetyState
{
UnsafetyState
{
def
:
def
,
unsafety
:
unsafety
,
unsafe_push_count
:
0
,
from_fn
:
true
}
}
...
...
@@ -410,11 +410,11 @@ pub fn recurse(&mut self, blk: &hir::Block) -> UnsafetyState {
unsafety
=>
{
let
(
unsafety
,
def
,
count
)
=
match
blk
.rules
{
hir
::
PushUnsafeBlock
(
..
)
=>
(
unsafety
,
blk
.id
,
self
.unsafe_push_count
.checked_add
(
1
)
.unwrap
()),
(
unsafety
,
blk
.
hir_
id
,
self
.unsafe_push_count
.checked_add
(
1
)
.unwrap
()),
hir
::
PopUnsafeBlock
(
..
)
=>
(
unsafety
,
blk
.id
,
self
.unsafe_push_count
.checked_sub
(
1
)
.unwrap
()),
(
unsafety
,
blk
.
hir_
id
,
self
.unsafe_push_count
.checked_sub
(
1
)
.unwrap
()),
hir
::
UnsafeBlock
(
..
)
=>
(
hir
::
Unsafety
::
Unsafe
,
blk
.id
,
self
.unsafe_push_count
),
(
hir
::
Unsafety
::
Unsafe
,
blk
.
hir_
id
,
self
.unsafe_push_count
),
hir
::
DefaultBlock
=>
(
unsafety
,
self
.def
,
self
.unsafe_push_count
),
};
...
...
@@ -770,10 +770,10 @@ fn adt_destructor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
/// (notably closures), `typeck_tables(def_id)` would wind up
/// redirecting to the owning function.
fn
primary_body_of
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
id
:
ast
::
Node
Id
)
id
:
hir
::
Hir
Id
)
->
Option
<
(
hir
::
BodyId
,
Option
<&
'tcx
hir
::
FnDecl
>
)
>
{
match
tcx
.hir
()
.get
(
id
)
{
match
tcx
.hir
()
.get
_by_hir_id
(
id
)
{
Node
::
Item
(
item
)
=>
{
match
item
.node
{
hir
::
ItemKind
::
Const
(
_
,
body
)
|
...
...
@@ -820,7 +820,7 @@ fn has_typeck_tables<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
return
tcx
.has_typeck_tables
(
outer_def_id
);
}
let
id
=
tcx
.hir
()
.as_local_
node
_id
(
def_id
)
.unwrap
();
let
id
=
tcx
.hir
()
.as_local_
hir
_id
(
def_id
)
.unwrap
();
primary_body_of
(
tcx
,
id
)
.is_some
()
}
...
...
@@ -840,8 +840,8 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
return
tcx
.typeck_tables_of
(
outer_def_id
);
}
let
id
=
tcx
.hir
()
.as_local_
node
_id
(
def_id
)
.unwrap
();
let
span
=
tcx
.hir
()
.span
(
id
);
let
id
=
tcx
.hir
()
.as_local_
hir
_id
(
def_id
)
.unwrap
();
let
span
=
tcx
.hir
()
.span
_by_hir_id
(
id
);
// Figure out what primary body this item has.
let
(
body_id
,
fn_decl
)
=
primary_body_of
(
tcx
,
id
)
.unwrap_or_else
(||
{
...
...
@@ -925,8 +925,8 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// Consistency check our TypeckTables instance can hold all ItemLocalIds
// it will need to hold.
assert_eq!
(
tables
.local_id_root
,
Some
(
DefId
::
local
(
tcx
.hir
()
.definitions
()
.node_to_hir_id
(
id
)
.owner
)));
assert_eq!
(
tables
.local_id_root
,
Some
(
DefId
::
local
(
id
.owner
)));
tables
}
...
...
@@ -939,7 +939,7 @@ fn check_abi<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span, abi: Abi) {
struct
GatherLocalsVisitor
<
'a
,
'gcx
:
'a
+
'tcx
,
'tcx
:
'a
>
{
fcx
:
&
'a
FnCtxt
<
'a
,
'gcx
,
'tcx
>
,
parent_id
:
ast
::
Node
Id
,
parent_id
:
hir
::
Hir
Id
,
}
impl
<
'a
,
'gcx
,
'tcx
>
GatherLocalsVisitor
<
'a
,
'gcx
,
'tcx
>
{
...
...
@@ -1051,7 +1051,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
fn_sig
:
ty
::
FnSig
<
'tcx
>
,
decl
:
&
'gcx
hir
::
FnDecl
,
fn_id
:
ast
::
Node
Id
,
fn_id
:
hir
::
Hir
Id
,
body
:
&
'gcx
hir
::
Body
,
can_be_generator
:
Option
<
hir
::
GeneratorMovability
>
)
->
(
FnCtxt
<
'a
,
'gcx
,
'tcx
>
,
Option
<
GeneratorTypes
<
'tcx
>>
)
...
...
@@ -1085,9 +1085,9 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
fcx
.yield_ty
=
Some
(
yield_ty
);
}
let
outer_def_id
=
fcx
.tcx
.closure_base_def_id
(
fcx
.tcx
.hir
()
.local_def_id
(
fn_id
));
let
outer_
node_id
=
fcx
.tcx
.hir
()
.as_local_node
_id
(
outer_def_id
)
.unwrap
();
GatherLocalsVisitor
{
fcx
:
&
fcx
,
parent_id
:
outer_
node
_id
,
}
.visit_body
(
body
);
let
outer_def_id
=
fcx
.tcx
.closure_base_def_id
(
fcx
.tcx
.hir
()
.local_def_id
_from_hir_id
(
fn_id
));
let
outer_
hir_id
=
fcx
.tcx
.hir
()
.as_local_hir
_id
(
outer_def_id
)
.unwrap
();
GatherLocalsVisitor
{
fcx
:
&
fcx
,
parent_id
:
outer_
hir
_id
,
}
.visit_body
(
body
);
// Add formal parameters.
for
(
arg_ty
,
arg
)
in
fn_sig
.inputs
()
.iter
()
.zip
(
&
body
.arguments
)
{
...
...
@@ -1110,8 +1110,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
fcx
.write_ty
(
arg
.hir_id
,
arg_ty
);
}
let
fn_hir_id
=
fcx
.tcx
.hir
()
.node_to_hir_id
(
fn_id
);
inherited
.tables
.borrow_mut
()
.liberated_fn_sigs_mut
()
.insert
(
fn_hir_id
,
fn_sig
);
inherited
.tables
.borrow_mut
()
.liberated_fn_sigs_mut
()
.insert
(
fn_id
,
fn_sig
);
fcx
.check_return_expr
(
&
body
.value
);
...
...
@@ -1164,14 +1163,13 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
// Check that the main return type implements the termination trait.
if
let
Some
(
term_id
)
=
fcx
.tcx
.lang_items
()
.termination
()
{
if
let
Some
((
def_id
,
EntryFnType
::
Main
))
=
fcx
.tcx
.entry_fn
(
LOCAL_CRATE
)
{
let
main_id
=
fcx
.tcx
.hir
()
.as_local_
node
_id
(
def_id
)
.unwrap
();
let
main_id
=
fcx
.tcx
.hir
()
.as_local_
hir
_id
(
def_id
)
.unwrap
();
if
main_id
==
fn_id
{
let
substs
=
fcx
.tcx
.mk_substs_trait
(
declared_ret_ty
,
&
[]);
let
trait_ref
=
ty
::
TraitRef
::
new
(
term_id
,
substs
);
let
return_ty_span
=
decl
.output
.span
();
let
fn_hir_id
=
fcx
.tcx
.hir
()
.node_to_hir_id
(
fn_id
);
let
cause
=
traits
::
ObligationCause
::
new
(
return_ty_span
,
fn_
hir_
id
,
ObligationCauseCode
::
MainFunctionType
);
return_ty_span
,
fn_id
,
ObligationCauseCode
::
MainFunctionType
);
inherited
.register_predicate
(
traits
::
Obligation
::
new
(
...
...
@@ -1182,7 +1180,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
// Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !`
if
let
Some
(
panic_impl_did
)
=
fcx
.tcx
.lang_items
()
.panic_impl
()
{
if
panic_impl_did
==
fcx
.tcx
.hir
()
.local_def_id
(
fn_id
)
{
if
panic_impl_did
==
fcx
.tcx
.hir
()
.local_def_id
_from_hir_id
(
fn_id
)
{
if
let
Some
(
panic_info_did
)
=
fcx
.tcx
.lang_items
()
.panic_info
()
{
// at this point we don't care if there are duplicate handlers or if the handler has
// the wrong signature as this value we'll be used when writing metadata and that
...
...
@@ -1197,7 +1195,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
}
let
inputs
=
fn_sig
.inputs
();
let
span
=
fcx
.tcx
.hir
()
.span
(
fn_id
);
let
span
=
fcx
.tcx
.hir
()
.span
_by_hir_id
(
fn_id
);
if
inputs
.len
()
==
1
{
let
arg_is_panic_info
=
match
inputs
[
0
]
.sty
{
ty
::
Ref
(
region
,
ty
,
mutbl
)
=>
match
ty
.sty
{
...
...
@@ -1218,7 +1216,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
);
}
if
let
Node
::
Item
(
item
)
=
fcx
.tcx
.hir
()
.get
(
fn_id
)
{
if
let
Node
::
Item
(
item
)
=
fcx
.tcx
.hir
()
.get
_by_hir_id
(
fn_id
)
{
if
let
ItemKind
::
Fn
(
_
,
_
,
ref
generics
,
_
)
=
item
.node
{
if
!
generics
.params
.is_empty
()
{
fcx
.tcx.sess
.span_err
(
...
...
@@ -1240,7 +1238,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
// Check that a function marked as `#[alloc_error_handler]` has signature `fn(Layout) -> !`
if
let
Some
(
alloc_error_handler_did
)
=
fcx
.tcx
.lang_items
()
.oom
()
{
if
alloc_error_handler_did
==
fcx
.tcx
.hir
()
.local_def_id
(
fn_id
)
{
if
alloc_error_handler_did
==
fcx
.tcx
.hir
()
.local_def_id
_from_hir_id
(
fn_id
)
{
if
let
Some
(
alloc_layout_did
)
=
fcx
.tcx
.lang_items
()
.alloc_layout
()
{
if
declared_ret_ty
.sty
!=
ty
::
Never
{
fcx
.tcx.sess
.span_err
(
...
...
@@ -1250,7 +1248,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
}
let
inputs
=
fn_sig
.inputs
();
let
span
=
fcx
.tcx
.hir
()
.span
(
fn_id
);
let
span
=
fcx
.tcx
.hir
()
.span
_by_hir_id
(
fn_id
);
if
inputs
.len
()
==
1
{
let
arg_is_alloc_layout
=
match
inputs
[
0
]
.sty
{
ty
::
Adt
(
ref
adt
,
_
)
=>
{
...
...
@@ -1266,7 +1264,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
);
}
if
let
Node
::
Item
(
item
)
=
fcx
.tcx
.hir
()
.get
(
fn_id
)
{
if
let
Node
::
Item
(
item
)
=
fcx
.tcx
.hir
()
.get
_by_hir_id
(
fn_id
)
{
if
let
ItemKind
::
Fn
(
_
,
_
,
ref
generics
,
_
)
=
item
.node
{
if
!
generics
.params
.is_empty
()
{
fcx
.tcx.sess
.span_err
(
...
...
@@ -2030,7 +2028,7 @@ pub fn new(inh: &'a Inherited<'a, 'gcx, 'tcx>,
ret_coercion_span
:
RefCell
::
new
(
None
),
yield_ty
:
None
,
ps
:
RefCell
::
new
(
UnsafetyState
::
function
(
hir
::
Unsafety
::
Normal
,
ast
::
CRATE_NODE
_ID
)),
hir
::
CRATE_HIR
_ID
)),
diverges
:
Cell
::
new
(
Diverges
::
Maybe
),
has_errors
:
Cell
::
new
(
false
),
enclosing_breakables
:
RefCell
::
new
(
EnclosingBreakables
{
...
...
@@ -2339,10 +2337,10 @@ fn instantiate_bounds(&self, span: Span, def_id: DefId, substs: &Substs<'tcx>)
/// `InferCtxt::instantiate_opaque_types` for more details.
fn
instantiate_opaque_types_from_value
<
T
:
TypeFoldable
<
'tcx
>>
(
&
self
,
parent_id
:
ast
::
Node
Id
,
parent_id
:
hir
::
Hir
Id
,
value
:
&
T
,
)
->
T
{
let
parent_def_id
=
self
.tcx
.hir
()
.local_def_id
(
parent_id
);
let
parent_def_id
=
self
.tcx
.hir
()
.local_def_id
_from_hir_id
(
parent_id
);
debug!
(
"instantiate_opaque_types_from_value(parent_def_id={:?}, value={:?})"
,
parent_def_id
,
value
);
...
...
@@ -4937,7 +4935,8 @@ fn check_block_with_expected(&self,
may_break
:
false
,
};
let
(
ctxt
,
())
=
self
.with_breakable_ctxt
(
blk
.id
,
ctxt
,
||
{
let
blk_node_id
=
self
.tcx
.hir
()
.hir_to_node_id
(
blk
.hir_id
);
let
(
ctxt
,
())
=
self
.with_breakable_ctxt
(
blk_node_id
,
ctxt
,
||
{
for
s
in
&
blk
.stmts
{
self
.check_stmt
(
s
);
}
...
...
@@ -4947,12 +4946,12 @@ fn check_block_with_expected(&self,
let
tail_expr_ty
=
tail_expr
.map
(|
t
|
self
.check_expr_with_expectation
(
t
,
expected
));
let
mut
enclosing_breakables
=
self
.enclosing_breakables
.borrow_mut
();
let
ctxt
=
enclosing_breakables
.find_breakable
(
blk
.
id
);
let
ctxt
=
enclosing_breakables
.find_breakable
(
blk
_node_
id
);
let
coerce
=
ctxt
.coerce
.as_mut
()
.unwrap
();
if
let
Some
(
tail_expr_ty
)
=
tail_expr_ty
{
let
tail_expr
=
tail_expr
.unwrap
();
let
cause
=
self
.cause
(
tail_expr
.span
,
ObligationCauseCode
::
BlockTailExpression
(
blk
.
id
));
ObligationCauseCode
::
BlockTailExpression
(
blk
_node_
id
));
coerce
.coerce
(
self
,
&
cause
,
tail_expr
,
...
...
@@ -4976,9 +4975,9 @@ fn check_block_with_expected(&self,
// that highlight errors inline.
let
mut
sp
=
blk
.span
;
let
mut
fn_span
=
None
;
if
let
Some
((
decl
,
ident
))
=
self
.get_parent_fn_decl
(
blk
.
id
)
{
if
let
Some
((
decl
,
ident
))
=
self
.get_parent_fn_decl
(
blk
_node_
id
)
{
let
ret_sp
=
decl
.output
.span
();
if
let
Some
(
block_sp
)
=
self
.parent_item_span
(
blk
.
id
)
{
if
let
Some
(
block_sp
)
=
self
.parent_item_span
(
blk
_node_
id
)
{
// HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the
// output would otherwise be incorrect and even misleading. Make sure
// the span we're aiming at correspond to a `fn` body.
...
...
src/librustc_typeck/check/regionck.rs
浏览文件 @
021a140d
...
...
@@ -90,7 +90,6 @@
use
std
::
mem
;
use
std
::
ops
::
Deref
;
use
std
::
rc
::
Rc
;
use
syntax
::
ast
;
use
syntax_pos
::
Span
;
// a variation on try that just returns unit
...
...
@@ -163,7 +162,7 @@ pub fn regionck_item(&self, item_id: hir::HirId, span: Span, wf_tys: &[Ty<'tcx>]
/// rest of type check and because sometimes we need type
/// inference to have completed before we can determine which
/// constraints to add.
pub
fn
regionck_fn
(
&
self
,
fn_id
:
ast
::
Node
Id
,
body
:
&
'gcx
hir
::
Body
)
{
pub
fn
regionck_fn
(
&
self
,
fn_id
:
hir
::
Hir
Id
,
body
:
&
'gcx
hir
::
Body
)
{
debug!
(
"regionck_fn(id={})"
,
fn_id
);
let
subject
=
self
.tcx
.hir
()
.body_owner_def_id
(
body
.id
());
let
hir_id
=
body
.value.hir_id
;
...
...
@@ -176,9 +175,8 @@ pub fn regionck_fn(&self, fn_id: ast::NodeId, body: &'gcx hir::Body) {
);
if
self
.err_count_since_creation
()
==
0
{
let
fn_hir_id
=
self
.tcx
.hir
()
.node_to_hir_id
(
fn_id
);
// regionck assumes typeck succeeded
rcx
.visit_fn_body
(
fn_
hir_id
,
body
,
self
.tcx
.hir
()
.span_by_hir_id
(
fn_hir
_id
));
rcx
.visit_fn_body
(
fn_
id
,
body
,
self
.tcx
.hir
()
.span_by_hir_id
(
fn
_id
));
}
rcx
.resolve_regions_and_report_errors
(
SuppressRegionErrors
::
when_nll_is_enabled
(
self
.tcx
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录