Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d00f94ff
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,发现更多精彩内容 >>
提交
d00f94ff
编写于
4月 17, 2020
作者:
E
Eduard-Mihai Burtescu
提交者:
mark
4月 24, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove redundant `descr`/`descriptive_variant` methods from HIR.
上级
18be5a08
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
34 addition
and
81 deletion
+34
-81
src/librustc_hir/hir.rs
src/librustc_hir/hir.rs
+0
-31
src/librustc_passes/dead.rs
src/librustc_passes/dead.rs
+8
-26
src/librustc_passes/stability.rs
src/librustc_passes/stability.rs
+12
-10
src/test/ui/associated-const/associated-const-dead-code.rs
src/test/ui/associated-const/associated-const-dead-code.rs
+1
-1
src/test/ui/associated-const/associated-const-dead-code.stderr
...est/ui/associated-const/associated-const-dead-code.stderr
+1
-1
src/test/ui/issues/issue-17718-const-naming.rs
src/test/ui/issues/issue-17718-const-naming.rs
+1
-1
src/test/ui/issues/issue-17718-const-naming.stderr
src/test/ui/issues/issue-17718-const-naming.stderr
+1
-1
src/test/ui/lint/dead-code/lint-dead-code-1.rs
src/test/ui/lint/dead-code/lint-dead-code-1.rs
+2
-2
src/test/ui/lint/dead-code/lint-dead-code-1.stderr
src/test/ui/lint/dead-code/lint-dead-code-1.stderr
+2
-2
src/test/ui/lint/dead-code/lint-dead-code-3.rs
src/test/ui/lint/dead-code/lint-dead-code-3.rs
+2
-2
src/test/ui/lint/dead-code/lint-dead-code-3.stderr
src/test/ui/lint/dead-code/lint-dead-code-3.stderr
+2
-2
src/test/ui/stability-attribute/missing-stability-attr-at-top-level.rs
...tability-attribute/missing-stability-attr-at-top-level.rs
+1
-1
src/test/ui/stability-attribute/missing-stability-attr-at-top-level.stderr
...lity-attribute/missing-stability-attr-at-top-level.stderr
+1
-1
未找到文件。
src/librustc_hir/hir.rs
浏览文件 @
d00f94ff
...
...
@@ -2452,27 +2452,6 @@ pub enum ItemKind<'hir> {
}
impl
ItemKind
<
'_
>
{
pub
fn
descr
(
&
self
)
->
&
str
{
match
*
self
{
ItemKind
::
ExternCrate
(
..
)
=>
"extern crate"
,
ItemKind
::
Use
(
..
)
=>
"`use` import"
,
ItemKind
::
Static
(
..
)
=>
"static item"
,
ItemKind
::
Const
(
..
)
=>
"constant item"
,
ItemKind
::
Fn
(
..
)
=>
"function"
,
ItemKind
::
Mod
(
..
)
=>
"module"
,
ItemKind
::
ForeignMod
(
..
)
=>
"extern block"
,
ItemKind
::
GlobalAsm
(
..
)
=>
"global asm item"
,
ItemKind
::
TyAlias
(
..
)
=>
"type alias"
,
ItemKind
::
OpaqueTy
(
..
)
=>
"opaque type"
,
ItemKind
::
Enum
(
..
)
=>
"enum"
,
ItemKind
::
Struct
(
..
)
=>
"struct"
,
ItemKind
::
Union
(
..
)
=>
"union"
,
ItemKind
::
Trait
(
..
)
=>
"trait"
,
ItemKind
::
TraitAlias
(
..
)
=>
"trait alias"
,
ItemKind
::
Impl
{
..
}
=>
"implementation"
,
}
}
pub
fn
generics
(
&
self
)
->
Option
<&
Generics
<
'_
>>
{
Some
(
match
*
self
{
ItemKind
::
Fn
(
_
,
ref
generics
,
_
)
...
...
@@ -2551,16 +2530,6 @@ pub enum ForeignItemKind<'hir> {
Type
,
}
impl
ForeignItemKind
<
'hir
>
{
pub
fn
descriptive_variant
(
&
self
)
->
&
str
{
match
*
self
{
ForeignItemKind
::
Fn
(
..
)
=>
"foreign function"
,
ForeignItemKind
::
Static
(
..
)
=>
"foreign static item"
,
ForeignItemKind
::
Type
=>
"foreign type"
,
}
}
}
/// A variable captured by a closure.
#[derive(Debug,
Copy,
Clone,
RustcEncodable,
RustcDecodable,
HashStable_Generic)]
pub
struct
Upvar
{
...
...
src/librustc_passes/dead.rs
浏览文件 @
d00f94ff
...
...
@@ -553,12 +553,13 @@ fn warn_dead_code(
id
:
hir
::
HirId
,
span
:
rustc_span
::
Span
,
name
:
ast
::
Name
,
node_type
:
&
str
,
participle
:
&
str
,
)
{
if
!
name
.as_str
()
.starts_with
(
'_'
)
{
self
.tcx
.struct_span_lint_hir
(
lint
::
builtin
::
DEAD_CODE
,
id
,
span
,
|
lint
|
{
lint
.build
(
&
format!
(
"{} is never {}: `{}`"
,
node_type
,
participle
,
name
))
.emit
()
let
def_id
=
self
.tcx
.hir
()
.local_def_id
(
id
);
let
descr
=
self
.tcx
.def_kind
(
def_id
)
.descr
(
def_id
);
lint
.build
(
&
format!
(
"{} is never {}: `{}`"
,
descr
,
participle
,
name
))
.emit
()
});
}
}
...
...
@@ -604,7 +605,7 @@ fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
hir
::
ItemKind
::
Struct
(
..
)
=>
"constructed"
,
// Issue #52325
_
=>
"used"
,
};
self
.warn_dead_code
(
item
.hir_id
,
span
,
item
.ident.name
,
item
.kind
.descr
(),
participle
);
self
.warn_dead_code
(
item
.hir_id
,
span
,
item
.ident.name
,
participle
);
}
else
{
// Only continue if we didn't warn
intravisit
::
walk_item
(
self
,
item
);
...
...
@@ -618,13 +619,7 @@ fn visit_variant(
id
:
hir
::
HirId
,
)
{
if
self
.should_warn_about_variant
(
&
variant
)
{
self
.warn_dead_code
(
variant
.id
,
variant
.span
,
variant
.ident.name
,
"variant"
,
"constructed"
,
);
self
.warn_dead_code
(
variant
.id
,
variant
.span
,
variant
.ident.name
,
"constructed"
);
}
else
{
intravisit
::
walk_variant
(
self
,
variant
,
g
,
id
);
}
...
...
@@ -632,20 +627,14 @@ fn visit_variant(
fn
visit_foreign_item
(
&
mut
self
,
fi
:
&
'tcx
hir
::
ForeignItem
<
'tcx
>
)
{
if
self
.should_warn_about_foreign_item
(
fi
)
{
self
.warn_dead_code
(
fi
.hir_id
,
fi
.span
,
fi
.ident.name
,
fi
.kind
.descriptive_variant
(),
"used"
,
);
self
.warn_dead_code
(
fi
.hir_id
,
fi
.span
,
fi
.ident.name
,
"used"
);
}
intravisit
::
walk_foreign_item
(
self
,
fi
);
}
fn
visit_struct_field
(
&
mut
self
,
field
:
&
'tcx
hir
::
StructField
<
'tcx
>
)
{
if
self
.should_warn_about_field
(
&
field
)
{
self
.warn_dead_code
(
field
.hir_id
,
field
.span
,
field
.ident.name
,
"
field"
,
"
read"
);
self
.warn_dead_code
(
field
.hir_id
,
field
.span
,
field
.ident.name
,
"read"
);
}
intravisit
::
walk_struct_field
(
self
,
field
);
}
...
...
@@ -658,7 +647,6 @@ fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
impl_item
.hir_id
,
impl_item
.span
,
impl_item
.ident.name
,
"associated const"
,
"used"
,
);
}
...
...
@@ -667,13 +655,7 @@ fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
hir
::
ImplItemKind
::
Fn
(
_
,
body_id
)
=>
{
if
!
self
.symbol_is_live
(
impl_item
.hir_id
)
{
let
span
=
self
.tcx.sess
.source_map
()
.guess_head_span
(
impl_item
.span
);
self
.warn_dead_code
(
impl_item
.hir_id
,
span
,
impl_item
.ident.name
,
"method"
,
"used"
,
);
self
.warn_dead_code
(
impl_item
.hir_id
,
span
,
impl_item
.ident.name
,
"used"
);
}
self
.visit_nested_body
(
body_id
)
}
...
...
src/librustc_passes/stability.rs
浏览文件 @
d00f94ff
...
...
@@ -337,12 +337,14 @@ struct MissingStabilityAnnotations<'a, 'tcx> {
}
impl
<
'a
,
'tcx
>
MissingStabilityAnnotations
<
'a
,
'tcx
>
{
fn
check_missing_stability
(
&
self
,
hir_id
:
HirId
,
span
:
Span
,
name
:
&
str
)
{
fn
check_missing_stability
(
&
self
,
hir_id
:
HirId
,
span
:
Span
)
{
let
stab
=
self
.tcx
.stability
()
.local_stability
(
hir_id
);
let
is_error
=
!
self
.tcx.sess.opts.test
&&
stab
.is_none
()
&&
self
.access_levels
.is_reachable
(
hir_id
);
if
is_error
{
self
.tcx.sess
.span_err
(
span
,
&
format!
(
"{} has missing stability attribute"
,
name
));
let
def_id
=
self
.tcx
.hir
()
.local_def_id
(
hir_id
);
let
descr
=
self
.tcx
.def_kind
(
def_id
)
.descr
(
def_id
);
self
.tcx.sess
.span_err
(
span
,
&
format!
(
"{} has missing stability attribute"
,
descr
));
}
}
}
...
...
@@ -362,42 +364,42 @@ fn visit_item(&mut self, i: &'tcx Item<'tcx>) {
// optional. They inherit stability from their parents when unannotated.
hir
::
ItemKind
::
Impl
{
of_trait
:
None
,
..
}
|
hir
::
ItemKind
::
ForeignMod
(
..
)
=>
{}
_
=>
self
.check_missing_stability
(
i
.hir_id
,
i
.span
,
i
.kind
.descr
()
),
_
=>
self
.check_missing_stability
(
i
.hir_id
,
i
.span
),
}
intravisit
::
walk_item
(
self
,
i
)
}
fn
visit_trait_item
(
&
mut
self
,
ti
:
&
'tcx
hir
::
TraitItem
<
'tcx
>
)
{
self
.check_missing_stability
(
ti
.hir_id
,
ti
.span
,
"item"
);
self
.check_missing_stability
(
ti
.hir_id
,
ti
.span
);
intravisit
::
walk_trait_item
(
self
,
ti
);
}
fn
visit_impl_item
(
&
mut
self
,
ii
:
&
'tcx
hir
::
ImplItem
<
'tcx
>
)
{
let
impl_def_id
=
self
.tcx
.hir
()
.local_def_id
(
self
.tcx
.hir
()
.get_parent_item
(
ii
.hir_id
));
if
self
.tcx
.impl_trait_ref
(
impl_def_id
)
.is_none
()
{
self
.check_missing_stability
(
ii
.hir_id
,
ii
.span
,
"item"
);
self
.check_missing_stability
(
ii
.hir_id
,
ii
.span
);
}
intravisit
::
walk_impl_item
(
self
,
ii
);
}
fn
visit_variant
(
&
mut
self
,
var
:
&
'tcx
Variant
<
'tcx
>
,
g
:
&
'tcx
Generics
<
'tcx
>
,
item_id
:
HirId
)
{
self
.check_missing_stability
(
var
.id
,
var
.span
,
"variant"
);
self
.check_missing_stability
(
var
.id
,
var
.span
);
intravisit
::
walk_variant
(
self
,
var
,
g
,
item_id
);
}
fn
visit_struct_field
(
&
mut
self
,
s
:
&
'tcx
StructField
<
'tcx
>
)
{
self
.check_missing_stability
(
s
.hir_id
,
s
.span
,
"field"
);
self
.check_missing_stability
(
s
.hir_id
,
s
.span
);
intravisit
::
walk_struct_field
(
self
,
s
);
}
fn
visit_foreign_item
(
&
mut
self
,
i
:
&
'tcx
hir
::
ForeignItem
<
'tcx
>
)
{
self
.check_missing_stability
(
i
.hir_id
,
i
.span
,
i
.kind
.descriptive_variant
()
);
self
.check_missing_stability
(
i
.hir_id
,
i
.span
);
intravisit
::
walk_foreign_item
(
self
,
i
);
}
fn
visit_macro_def
(
&
mut
self
,
md
:
&
'tcx
hir
::
MacroDef
<
'tcx
>
)
{
self
.check_missing_stability
(
md
.hir_id
,
md
.span
,
"macro"
);
self
.check_missing_stability
(
md
.hir_id
,
md
.span
);
}
}
...
...
@@ -585,7 +587,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
if
tcx
.stability
()
.staged_api
[
&
LOCAL_CRATE
]
{
let
krate
=
tcx
.hir
()
.krate
();
let
mut
missing
=
MissingStabilityAnnotations
{
tcx
,
access_levels
};
missing
.check_missing_stability
(
hir
::
CRATE_HIR_ID
,
krate
.item.span
,
"crate"
);
missing
.check_missing_stability
(
hir
::
CRATE_HIR_ID
,
krate
.item.span
);
intravisit
::
walk_crate
(
&
mut
missing
,
krate
);
krate
.visit_all_item_likes
(
&
mut
missing
.as_deep_visitor
());
}
...
...
src/test/ui/associated-const/associated-const-dead-code.rs
浏览文件 @
d00f94ff
...
...
@@ -4,7 +4,7 @@
impl
MyFoo
{
const
BAR
:
u32
=
1
;
//~^ ERROR associated const is never used: `BAR`
//~^ ERROR associated const
ant
is never used: `BAR`
}
fn
main
()
{
...
...
src/test/ui/associated-const/associated-const-dead-code.stderr
浏览文件 @
d00f94ff
error: associated const is never used: `BAR`
error: associated const
ant
is never used: `BAR`
--> $DIR/associated-const-dead-code.rs:6:5
|
LL | const BAR: u32 = 1;
...
...
src/test/ui/issues/issue-17718-const-naming.rs
浏览文件 @
d00f94ff
...
...
@@ -3,6 +3,6 @@
const
foo
:
isize
=
3
;
//~^ ERROR: should have an upper case name
//~^^ ERROR: constant i
tem i
s never used
//~^^ ERROR: constant is never used
fn
main
()
{}
src/test/ui/issues/issue-17718-const-naming.stderr
浏览文件 @
d00f94ff
error: constant i
tem i
s never used: `foo`
error: constant is never used: `foo`
--> $DIR/issue-17718-const-naming.rs:4:1
|
LL | const foo: isize = 3;
...
...
src/test/ui/lint/dead-code/lint-dead-code-1.rs
浏览文件 @
d00f94ff
...
...
@@ -17,14 +17,14 @@ mod foo2 {
}
pub
static
pub_static
:
isize
=
0
;
static
priv_static
:
isize
=
0
;
//~ ERROR: static i
tem i
s never used
static
priv_static
:
isize
=
0
;
//~ ERROR: static is never used
const
used_static
:
isize
=
0
;
pub
static
used_static2
:
isize
=
used_static
;
const
USED_STATIC
:
isize
=
0
;
const
STATIC_USED_IN_ENUM_DISCRIMINANT
:
isize
=
10
;
pub
const
pub_const
:
isize
=
0
;
const
priv_const
:
isize
=
0
;
//~ ERROR: constant i
tem i
s never used
const
priv_const
:
isize
=
0
;
//~ ERROR: constant is never used
const
used_const
:
isize
=
0
;
pub
const
used_const2
:
isize
=
used_const
;
const
USED_CONST
:
isize
=
1
;
...
...
src/test/ui/lint/dead-code/lint-dead-code-1.stderr
浏览文件 @
d00f94ff
...
...
@@ -10,13 +10,13 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
error: static i
tem i
s never used: `priv_static`
error: static is never used: `priv_static`
--> $DIR/lint-dead-code-1.rs:20:1
|
LL | static priv_static: isize = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: constant i
tem i
s never used: `priv_const`
error: constant is never used: `priv_const`
--> $DIR/lint-dead-code-1.rs:27:1
|
LL | const priv_const: isize = 0;
...
...
src/test/ui/lint/dead-code/lint-dead-code-3.rs
浏览文件 @
d00f94ff
...
...
@@ -12,7 +12,7 @@
struct
Foo
;
//~ ERROR: struct is never constructed
impl
Foo
{
fn
foo
(
&
self
)
{
//~ ERROR:
method
is never used
fn
foo
(
&
self
)
{
//~ ERROR:
associated function
is never used
bar
()
}
}
...
...
@@ -58,7 +58,7 @@ pub fn baz() {
enum
c_void
{}
//~ ERROR: enum is never used
extern
{
fn
free
(
p
:
*
const
c_void
);
//~ ERROR: f
oreign f
unction is never used
fn
free
(
p
:
*
const
c_void
);
//~ ERROR: function is never used
}
// Check provided method
...
...
src/test/ui/lint/dead-code/lint-dead-code-3.stderr
浏览文件 @
d00f94ff
...
...
@@ -10,7 +10,7 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
error:
method
is never used: `foo`
error:
associated function
is never used: `foo`
--> $DIR/lint-dead-code-3.rs:15:5
|
LL | fn foo(&self) {
...
...
@@ -28,7 +28,7 @@ error: enum is never used: `c_void`
LL | enum c_void {}
| ^^^^^^
error: f
oreign f
unction is never used: `free`
error: function is never used: `free`
--> $DIR/lint-dead-code-3.rs:61:5
|
LL | fn free(p: *const c_void);
...
...
src/test/ui/stability-attribute/missing-stability-attr-at-top-level.rs
浏览文件 @
d00f94ff
#![feature(staged_api)]
//~^ ERROR
crat
e has missing stability attribute
//~^ ERROR
modul
e has missing stability attribute
fn
main
()
{}
src/test/ui/stability-attribute/missing-stability-attr-at-top-level.stderr
浏览文件 @
d00f94ff
error:
crat
e has missing stability attribute
error:
modul
e has missing stability attribute
--> $DIR/missing-stability-attr-at-top-level.rs:1:1
|
LL | / #![feature(staged_api)]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录