Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
83f553c9
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,发现更多精彩内容 >>
提交
83f553c9
编写于
11月 04, 2019
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Address review comments
上级
09fff506
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
140 addition
and
10 deletion
+140
-10
src/librustc/hir/def.rs
src/librustc/hir/def.rs
+17
-0
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+1
-2
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+1
-1
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+3
-1
src/libsyntax/feature_gate/active.rs
src/libsyntax/feature_gate/active.rs
+2
-2
src/libsyntax/feature_gate/builtin_attrs.rs
src/libsyntax/feature_gate/builtin_attrs.rs
+2
-2
src/test/ui/attributes/register-attr-tool-import.rs
src/test/ui/attributes/register-attr-tool-import.rs
+14
-0
src/test/ui/attributes/register-attr-tool-import.stderr
src/test/ui/attributes/register-attr-tool-import.stderr
+26
-0
src/test/ui/attributes/register-attr-tool-prelude.rs
src/test/ui/attributes/register-attr-tool-prelude.rs
+14
-0
src/test/ui/attributes/register-attr-tool-prelude.stderr
src/test/ui/attributes/register-attr-tool-prelude.stderr
+15
-0
src/test/ui/attributes/register-attr-tool-unused.rs
src/test/ui/attributes/register-attr-tool-unused.rs
+10
-0
src/test/ui/attributes/register-attr-tool-unused.stderr
src/test/ui/attributes/register-attr-tool-unused.stderr
+33
-0
src/test/ui/feature-gates/feature-gate-register_attr.stderr
src/test/ui/feature-gates/feature-gate-register_attr.stderr
+1
-1
src/test/ui/feature-gates/feature-gate-register_tool.stderr
src/test/ui/feature-gates/feature-gate-register_tool.stderr
+1
-1
未找到文件。
src/librustc/hir/def.rs
浏览文件 @
83f553c9
...
...
@@ -333,6 +333,22 @@ pub fn descr(self) -> &'static str {
NonMacroAttrKind
::
LegacyPluginHelper
=>
"legacy plugin helper attribute"
,
}
}
pub
fn
article
(
self
)
->
&
'static
str
{
match
self
{
NonMacroAttrKind
::
Registered
=>
"an"
,
_
=>
"a"
,
}
}
/// Users of some attributes cannot mark them as used, so they are considered always used.
pub
fn
is_used
(
self
)
->
bool
{
match
self
{
NonMacroAttrKind
::
Tool
|
NonMacroAttrKind
::
DeriveHelper
=>
true
,
NonMacroAttrKind
::
Builtin
|
NonMacroAttrKind
::
Registered
|
NonMacroAttrKind
::
LegacyPluginHelper
=>
false
,
}
}
}
impl
<
Id
>
Res
<
Id
>
{
...
...
@@ -389,6 +405,7 @@ pub fn descr(&self) -> &'static str {
pub
fn
article
(
&
self
)
->
&
'static
str
{
match
*
self
{
Res
::
Def
(
kind
,
_
)
=>
kind
.article
(),
Res
::
NonMacroAttr
(
kind
)
=>
kind
.article
(),
Res
::
Err
=>
"an"
,
_
=>
"a"
,
}
...
...
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
83f553c9
...
...
@@ -141,8 +141,7 @@ impl<'a> Resolver<'a> {
crate
fn
get_macro
(
&
mut
self
,
res
:
Res
)
->
Option
<
Lrc
<
SyntaxExtension
>>
{
match
res
{
Res
::
Def
(
DefKind
::
Macro
(
..
),
def_id
)
=>
self
.get_macro_by_def_id
(
def_id
),
Res
::
NonMacroAttr
(
attr_kind
)
=>
Some
(
self
.non_macro_attr
(
attr_kind
==
NonMacroAttrKind
::
Tool
)),
Res
::
NonMacroAttr
(
attr_kind
)
=>
Some
(
self
.non_macro_attr
(
attr_kind
.is_used
())),
_
=>
None
,
}
}
...
...
src/librustc_resolve/lib.rs
浏览文件 @
83f553c9
...
...
@@ -1472,7 +1472,7 @@ fn visit_scopes<T>(
Scope
::
MacroRules
(
..
)
=>
true
,
Scope
::
CrateRoot
=>
true
,
Scope
::
Module
(
..
)
=>
true
,
Scope
::
RegisteredAttrs
=>
tru
e
,
Scope
::
RegisteredAttrs
=>
use_prelud
e
,
Scope
::
MacroUsePrelude
=>
use_prelude
||
rust_2015
,
Scope
::
BuiltinAttrs
=>
true
,
Scope
::
LegacyPluginHelpers
=>
use_prelude
||
rust_2015
,
...
...
src/librustc_resolve/macros.rs
浏览文件 @
83f553c9
...
...
@@ -94,6 +94,7 @@ fn fast_print_path(path: &ast::Path) -> Symbol {
}
}
/// The code common between processing `#![register_tool]` and `#![register_attr]`.
fn
registered_idents
(
sess
:
&
Session
,
attrs
:
&
[
ast
::
Attribute
],
...
...
@@ -832,7 +833,8 @@ fn prohibit_imported_non_macro_attrs(&self, binding: Option<&'a NameBinding<'a>>
res
:
Option
<
Res
>
,
span
:
Span
)
{
if
let
Some
(
Res
::
NonMacroAttr
(
kind
))
=
res
{
if
kind
!=
NonMacroAttrKind
::
Tool
&&
binding
.map_or
(
true
,
|
b
|
b
.is_import
())
{
let
msg
=
format!
(
"cannot use a {} through an import"
,
kind
.descr
());
let
msg
=
format!
(
"cannot use {} {} through an import"
,
kind
.article
(),
kind
.descr
());
let
mut
err
=
self
.session
.struct_span_err
(
span
,
&
msg
);
if
let
Some
(
binding
)
=
binding
{
err
.span_note
(
binding
.span
,
&
format!
(
"the {} imported here"
,
kind
.descr
()));
...
...
src/libsyntax/feature_gate/active.rs
浏览文件 @
83f553c9
...
...
@@ -524,10 +524,10 @@ pub fn set(&self, features: &mut Features, span: Span) {
(
active
,
abi_efiapi
,
"1.40.0"
,
Some
(
65815
),
None
),
/// Allows using the `#[register_attr]` attribute.
(
active
,
register_attr
,
"1.41.0"
,
Some
(
29642
),
None
),
(
active
,
register_attr
,
"1.41.0"
,
Some
(
66080
),
None
),
/// Allows using the `#[register_attr]` attribute.
(
active
,
register_tool
,
"1.41.0"
,
Some
(
44690
),
None
),
(
active
,
register_tool
,
"1.41.0"
,
Some
(
66079
),
None
),
// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
...
...
src/libsyntax/feature_gate/builtin_attrs.rs
浏览文件 @
83f553c9
...
...
@@ -330,11 +330,11 @@ fn is_deprecated(&self) -> bool {
gated!
(
ffi_returns_twice
,
Whitelisted
,
template!
(
Word
),
experimental!
(
ffi_returns_twice
)),
gated!
(
track_caller
,
Whitelisted
,
template!
(
Word
),
experimental!
(
track_caller
)),
gated!
(
register_attr
,
Whitelisted
,
template!
(
List
:
"attr1, attr2, ..."
),
register_attr
,
CrateLevel
,
template!
(
List
:
"attr1, attr2, ..."
),
experimental!
(
register_attr
),
),
gated!
(
register_tool
,
Whitelisted
,
template!
(
List
:
"tool1, tool2, ..."
),
register_tool
,
CrateLevel
,
template!
(
List
:
"tool1, tool2, ..."
),
experimental!
(
register_tool
),
),
...
...
src/test/ui/attributes/register-attr-tool-import.rs
0 → 100644
浏览文件 @
83f553c9
// edition:2018
#![feature(register_attr)]
#![feature(register_tool)]
#![register_attr(attr)]
#![register_tool(tool)]
use
attr
as
renamed_attr
;
// OK
use
tool
as
renamed_tool
;
// OK
#[renamed_attr]
//~ ERROR cannot use an explicitly registered attribute through an import
#[renamed_tool::attr]
//~ ERROR cannot use a tool module through an import
fn
main
()
{}
src/test/ui/attributes/register-attr-tool-import.stderr
0 → 100644
浏览文件 @
83f553c9
error: cannot use an explicitly registered attribute through an import
--> $DIR/register-attr-tool-import.rs:12:3
|
LL | #[renamed_attr]
| ^^^^^^^^^^^^
|
note: the explicitly registered attribute imported here
--> $DIR/register-attr-tool-import.rs:9:5
|
LL | use attr as renamed_attr; // OK
| ^^^^^^^^^^^^^^^^^^^^
error: cannot use a tool module through an import
--> $DIR/register-attr-tool-import.rs:13:3
|
LL | #[renamed_tool::attr]
| ^^^^^^^^^^^^
|
note: the tool module imported here
--> $DIR/register-attr-tool-import.rs:10:5
|
LL | use tool as renamed_tool; // OK
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
src/test/ui/attributes/register-attr-tool-prelude.rs
0 → 100644
浏览文件 @
83f553c9
#![feature(register_attr)]
#![feature(register_tool)]
#![register_attr(attr)]
#![register_tool(tool)]
#[no_implicit_prelude]
mod
m
{
#[attr]
//~ ERROR cannot find attribute `attr` in this scope
#[tool::attr]
//~ ERROR failed to resolve: use of undeclared type or module `tool`
fn
check
()
{}
}
fn
main
()
{}
src/test/ui/attributes/register-attr-tool-prelude.stderr
0 → 100644
浏览文件 @
83f553c9
error[E0433]: failed to resolve: use of undeclared type or module `tool`
--> $DIR/register-attr-tool-prelude.rs:10:7
|
LL | #[tool::attr]
| ^^^^ use of undeclared type or module `tool`
error: cannot find attribute `attr` in this scope
--> $DIR/register-attr-tool-prelude.rs:9:7
|
LL | #[attr]
| ^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0433`.
src/test/ui/attributes/register-attr-tool-unused.rs
0 → 100644
浏览文件 @
83f553c9
#![deny(unused)]
#![feature(register_attr)]
#![feature(register_tool)]
#[register_attr(attr)]
//~ ERROR crate-level attribute should be an inner attribute
//~| ERROR unused attribute
#[register_tool(tool)]
//~ ERROR crate-level attribute should be an inner attribute
//~| ERROR unused attribute
fn
main
()
{}
src/test/ui/attributes/register-attr-tool-unused.stderr
0 → 100644
浏览文件 @
83f553c9
error: unused attribute
--> $DIR/register-attr-tool-unused.rs:6:1
|
LL | #[register_attr(attr)]
| ^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/register-attr-tool-unused.rs:1:9
|
LL | #![deny(unused)]
| ^^^^^^
= note: `#[deny(unused_attributes)]` implied by `#[deny(unused)]`
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
--> $DIR/register-attr-tool-unused.rs:6:1
|
LL | #[register_attr(attr)]
| ^^^^^^^^^^^^^^^^^^^^^^
error: unused attribute
--> $DIR/register-attr-tool-unused.rs:8:1
|
LL | #[register_tool(tool)]
| ^^^^^^^^^^^^^^^^^^^^^^
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
--> $DIR/register-attr-tool-unused.rs:8:1
|
LL | #[register_tool(tool)]
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors
src/test/ui/feature-gates/feature-gate-register_attr.stderr
浏览文件 @
83f553c9
...
...
@@ -4,7 +4,7 @@ error[E0658]: the `#[register_attr]` attribute is an experimental feature
LL | #![register_attr(attr)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/
29642
= note: for more information, see https://github.com/rust-lang/rust/issues/
66080
= help: add `#![feature(register_attr)]` to the crate attributes to enable
error: aborting due to previous error
...
...
src/test/ui/feature-gates/feature-gate-register_tool.stderr
浏览文件 @
83f553c9
...
...
@@ -4,7 +4,7 @@ error[E0658]: the `#[register_tool]` attribute is an experimental feature
LL | #![register_tool(tool)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/
44690
= note: for more information, see https://github.com/rust-lang/rust/issues/
66079
= help: add `#![feature(register_tool)]` to the crate attributes to enable
error: aborting due to previous error
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录