Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
356fa2c5
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,发现更多精彩内容 >>
提交
356fa2c5
编写于
1月 14, 2017
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Warn on unused `#[macro_use]` imports.
上级
2efec3c1
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
67 addition
and
24 deletion
+67
-24
src/libproc_macro_tokens/lib.rs
src/libproc_macro_tokens/lib.rs
+1
-1
src/librustc/lib.rs
src/librustc/lib.rs
+1
-1
src/librustc_const_math/lib.rs
src/librustc_const_math/lib.rs
+2
-2
src/librustc_driver/lib.rs
src/librustc_driver/lib.rs
+0
-1
src/librustc_errors/lib.rs
src/librustc_errors/lib.rs
+0
-2
src/librustc_incremental/lib.rs
src/librustc_incremental/lib.rs
+1
-1
src/librustc_lint/lib.rs
src/librustc_lint/lib.rs
+0
-1
src/librustc_plugin/Cargo.toml
src/librustc_plugin/Cargo.toml
+0
-1
src/librustc_plugin/lib.rs
src/librustc_plugin/lib.rs
+1
-2
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+21
-2
src/librustc_resolve/check_unused.rs
src/librustc_resolve/check_unused.rs
+5
-0
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+10
-6
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+2
-0
src/libserialize/lib.rs
src/libserialize/lib.rs
+1
-1
src/test/compile-fail/imports/unused-macro-use.rs
src/test/compile-fail/imports/unused-macro-use.rs
+21
-0
src/test/compile-fail/lint-unused-extern-crate.rs
src/test/compile-fail/lint-unused-extern-crate.rs
+0
-2
src/tools/cargotest/main.rs
src/tools/cargotest/main.rs
+1
-1
未找到文件。
src/libproc_macro_tokens/lib.rs
浏览文件 @
356fa2c5
...
...
@@ -59,7 +59,7 @@
extern
crate
syntax
;
extern
crate
syntax_pos
;
#[macro_use]
extern
crate
log
;
extern
crate
log
;
pub
mod
build
;
pub
mod
parse
;
...
...
src/librustc/lib.rs
浏览文件 @
356fa2c5
...
...
@@ -57,7 +57,7 @@
extern
crate
rustc_errors
as
errors
;
#[macro_use]
extern
crate
log
;
#[macro_use]
extern
crate
syntax
;
#[macro_use]
extern
crate
syntax_pos
;
extern
crate
syntax_pos
;
#[macro_use]
#[no_link]
extern
crate
rustc_bitflags
;
extern
crate
serialize
as
rustc_serialize
;
// used by deriving
...
...
src/librustc_const_math/lib.rs
浏览文件 @
356fa2c5
...
...
@@ -28,8 +28,8 @@
#![feature(const_fn)]
#![cfg_attr(not(stage0),
feature(i128))]
#[macro_use]
extern
crate
log
;
#[macro_use]
extern
crate
syntax
;
extern
crate
log
;
extern
crate
syntax
;
// SNAP: remove use of this crate
extern
crate
rustc_i128
;
...
...
src/librustc_driver/lib.rs
浏览文件 @
356fa2c5
...
...
@@ -57,7 +57,6 @@
extern
crate
rustc_llvm
as
llvm
;
#[macro_use]
extern
crate
log
;
#[macro_use]
extern
crate
syntax
;
extern
crate
syntax_ext
;
extern
crate
syntax_pos
;
...
...
src/librustc_errors/lib.rs
浏览文件 @
356fa2c5
...
...
@@ -27,9 +27,7 @@
extern
crate
serialize
;
extern
crate
term
;
#[macro_use]
extern
crate
log
;
#[macro_use]
extern
crate
libc
;
extern
crate
std_unicode
;
extern
crate
serialize
as
rustc_serialize
;
// used by deriving
...
...
src/librustc_incremental/lib.rs
浏览文件 @
356fa2c5
...
...
@@ -30,7 +30,7 @@
extern
crate
serialize
as
rustc_serialize
;
#[macro_use]
extern
crate
log
;
#[macro_use]
extern
crate
syntax
;
extern
crate
syntax
;
extern
crate
syntax_pos
;
extern
crate
rustc_i128
;
...
...
src/librustc_lint/lib.rs
浏览文件 @
356fa2c5
...
...
@@ -37,7 +37,6 @@
#![feature(slice_patterns)]
#![feature(staged_api)]
#[macro_use]
extern
crate
syntax
;
#[macro_use]
extern
crate
rustc
;
...
...
src/librustc_plugin/Cargo.toml
浏览文件 @
356fa2c5
...
...
@@ -13,7 +13,6 @@ crate-type = ["dylib"]
log
=
{
path
=
"../liblog"
}
rustc
=
{
path
=
"../librustc"
}
rustc_back
=
{
path
=
"../librustc_back"
}
rustc_bitflags
=
{
path
=
"../librustc_bitflags"
}
rustc_metadata
=
{
path
=
"../librustc_metadata"
}
syntax
=
{
path
=
"../libsyntax"
}
syntax_pos
=
{
path
=
"../libsyntax_pos"
}
...
...
src/librustc_plugin/lib.rs
浏览文件 @
356fa2c5
...
...
@@ -63,9 +63,8 @@
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#[macro_use]
extern
crate
log
;
extern
crate
log
;
#[macro_use]
extern
crate
syntax
;
#[macro_use]
#[no_link]
extern
crate
rustc_bitflags
;
extern
crate
rustc
;
extern
crate
rustc_back
;
...
...
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
356fa2c5
...
...
@@ -552,16 +552,35 @@ fn process_legacy_macro_imports(&mut self, item: &Item, module: Module<'a>, expa
used
=
true
;
// Avoid the normal unused extern crate warning
}
let
(
graph_root
,
arenas
)
=
(
self
.graph_root
,
self
.arenas
);
let
macro_use_directive
=
|
span
|
arenas
.alloc_import_directive
(
ImportDirective
{
id
:
item
.id
,
parent
:
graph_root
,
imported_module
:
Cell
::
new
(
Some
(
module
)),
subclass
:
ImportDirectiveSubclass
::
MacroUse
,
span
:
span
,
module_path
:
Vec
::
new
(),
vis
:
Cell
::
new
(
ty
::
Visibility
::
Restricted
(
DefId
::
local
(
CRATE_DEF_INDEX
))),
expansion
:
expansion
,
used
:
Cell
::
new
(
false
),
});
if
let
Some
(
span
)
=
legacy_imports
.import_all
{
let
directive
=
macro_use_directive
(
span
);
self
.potentially_unused_imports
.push
(
directive
);
module
.for_each_child
(|
ident
,
ns
,
binding
|
if
ns
==
MacroNS
{
self
.legacy_import_macro
(
ident
.name
,
binding
,
span
,
allow_shadowing
);
let
imported_binding
=
self
.import
(
binding
,
directive
);
self
.legacy_import_macro
(
ident
.name
,
imported_binding
,
span
,
allow_shadowing
);
});
}
else
{
for
(
name
,
span
)
in
legacy_imports
.imports
{
let
ident
=
Ident
::
with_empty_ctxt
(
name
);
let
result
=
self
.resolve_ident_in_module
(
module
,
ident
,
MacroNS
,
false
,
None
);
if
let
Ok
(
binding
)
=
result
{
self
.legacy_import_macro
(
name
,
binding
,
span
,
allow_shadowing
);
let
directive
=
macro_use_directive
(
span
);
self
.potentially_unused_imports
.push
(
directive
);
let
imported_binding
=
self
.import
(
binding
,
directive
);
self
.legacy_import_macro
(
name
,
imported_binding
,
span
,
allow_shadowing
);
}
else
{
span_err!
(
self
.session
,
span
,
E0469
,
"imported macro not found"
);
}
...
...
src/librustc_resolve/check_unused.rs
浏览文件 @
356fa2c5
...
...
@@ -125,6 +125,11 @@ pub fn check_crate(resolver: &mut Resolver, krate: &ast::Crate) {
let
msg
=
"unused extern crate"
.to_string
();
resolver
.session
.add_lint
(
lint
,
directive
.id
,
directive
.span
,
msg
);
}
ImportDirectiveSubclass
::
MacroUse
=>
{
let
lint
=
lint
::
builtin
::
UNUSED_IMPORTS
;
let
msg
=
"unused `#[macro_use]` import"
.to_string
();
resolver
.session
.add_lint
(
lint
,
directive
.id
,
directive
.span
,
msg
);
}
_
=>
{}
}
}
...
...
src/librustc_resolve/macros.rs
浏览文件 @
356fa2c5
...
...
@@ -341,12 +341,15 @@ pub fn resolve_legacy_scope(&mut self,
};
}
let
binding
=
match
binding
{
Some
(
binding
)
=>
MacroBinding
::
Legacy
(
binding
),
None
=>
match
self
.builtin_macros
.get
(
&
name
)
.cloned
()
{
Some
(
binding
)
=>
MacroBinding
::
Modern
(
binding
),
None
=>
return
None
,
},
let
binding
=
if
let
Some
(
binding
)
=
binding
{
MacroBinding
::
Legacy
(
binding
)
}
else
if
let
Some
(
binding
)
=
self
.builtin_macros
.get
(
&
name
)
.cloned
()
{
if
!
self
.use_extern_macros
{
self
.record_use
(
Ident
::
with_empty_ctxt
(
name
),
MacroNS
,
binding
,
DUMMY_SP
);
}
MacroBinding
::
Modern
(
binding
)
}
else
{
return
None
;
};
if
!
self
.use_extern_macros
{
...
...
@@ -378,6 +381,7 @@ pub fn finalize_current_module_macro_resolutions(&mut self) {
let
(
legacy_resolution
,
resolution
)
=
match
(
legacy_resolution
,
resolution
)
{
(
Some
(
legacy_resolution
),
Ok
(
resolution
))
=>
(
legacy_resolution
,
resolution
),
(
Some
(
MacroBinding
::
Modern
(
binding
)),
Err
(
_
))
=>
{
self
.record_use
(
ident
,
MacroNS
,
binding
,
span
);
self
.err_if_macro_use_proc_macro
(
ident
.name
,
span
,
binding
);
continue
},
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
356fa2c5
...
...
@@ -49,6 +49,7 @@ pub enum ImportDirectiveSubclass<'a> {
// n.b. `max_vis` is only used in `finalize_import` to check for reexport errors.
},
ExternCrate
,
MacroUse
,
}
/// One import directive.
...
...
@@ -835,5 +836,6 @@ fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass) -> St
SingleImport
{
source
,
..
}
=>
source
.to_string
(),
GlobImport
{
..
}
=>
"*"
.to_string
(),
ExternCrate
=>
"<extern crate>"
.to_string
(),
MacroUse
=>
"#[macro_use]"
.to_string
(),
}
}
src/libserialize/lib.rs
浏览文件 @
356fa2c5
...
...
@@ -39,7 +39,7 @@
// test harness access
#[cfg(test)]
extern
crate
test
;
#[macro_use]
extern
crate
log
;
extern
crate
log
;
extern
crate
std_unicode
;
extern
crate
collections
;
...
...
src/test/compile-fail/imports/unused-macro-use.rs
0 → 100644
浏览文件 @
356fa2c5
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![deny(unused)]
#[macro_use]
//~ ERROR unused `#[macro_use]` import
extern
crate
core
;
#[macro_use(
panic
//~ ERROR unused `#[macro_use]` import
)]
extern
crate
core
as
core_2
;
fn
main
()
{}
src/test/compile-fail/lint-unused-extern-crate.rs
浏览文件 @
356fa2c5
...
...
@@ -26,8 +26,6 @@
extern
crate
lint_unused_extern_crate
as
other
;
// no error, the use * marks it as used
#[macro_use]
extern
crate
core
;
// no error, the `#[macro_use]` marks it as used
#[allow(unused_imports)]
use
rand
::
isaac
::
IsaacRng
;
...
...
src/tools/cargotest/main.rs
浏览文件 @
356fa2c5
...
...
@@ -25,7 +25,7 @@ struct Test {
Test
{
name
:
"cargo"
,
repo
:
"https://github.com/rust-lang/cargo"
,
sha
:
"
b7be4f2ef2cf743492edc6dfb55d087ed88f2d76
"
,
sha
:
"
2324c2bbaf7fc6ea9cbdd77c034ef1af769cb617
"
,
lock
:
None
,
},
Test
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录