Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
bf1e70cd
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,发现更多精彩内容 >>
提交
bf1e70cd
编写于
12月 12, 2018
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve: Prohibit use of imported non-macro attributes
上级
e1d1487f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
42 addition
and
6 deletion
+42
-6
src/librustc/hir/def.rs
src/librustc/hir/def.rs
+1
-1
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+18
-1
src/test/ui/rust-2018/uniform-paths/prelude-fail-2.rs
src/test/ui/rust-2018/uniform-paths/prelude-fail-2.rs
+9
-0
src/test/ui/rust-2018/uniform-paths/prelude-fail-2.stderr
src/test/ui/rust-2018/uniform-paths/prelude-fail-2.stderr
+14
-0
src/test/ui/rust-2018/uniform-paths/prelude.rs
src/test/ui/rust-2018/uniform-paths/prelude.rs
+0
-4
未找到文件。
src/librustc/hir/def.rs
浏览文件 @
bf1e70cd
...
...
@@ -240,7 +240,7 @@ pub fn from_hir(vdata: &hir::VariantData) -> CtorKind {
}
impl
NonMacroAttrKind
{
fn
descr
(
self
)
->
&
'static
str
{
pub
fn
descr
(
self
)
->
&
'static
str
{
match
self
{
NonMacroAttrKind
::
Builtin
=>
"built-in attribute"
,
NonMacroAttrKind
::
Tool
=>
"tool attribute"
,
...
...
src/librustc_resolve/macros.rs
浏览文件 @
bf1e70cd
...
...
@@ -376,6 +376,7 @@ pub fn resolve_macro_to_def_inner(
.push
((
path
,
path_span
,
kind
,
parent_scope
.clone
(),
def
.ok
()));
}
self
.prohibit_imported_non_macro_attrs
(
None
,
def
.ok
(),
path_span
);
def
}
else
{
let
binding
=
self
.early_resolve_ident_in_lexical_scope
(
...
...
@@ -390,7 +391,9 @@ pub fn resolve_macro_to_def_inner(
.push
((
path
[
0
]
.ident
,
kind
,
parent_scope
.clone
(),
binding
.ok
()));
}
binding
.map
(|
binding
|
binding
.def
())
let
def
=
binding
.map
(|
binding
|
binding
.def
());
self
.prohibit_imported_non_macro_attrs
(
binding
.ok
(),
def
.ok
(),
path_span
);
def
}
}
...
...
@@ -982,6 +985,20 @@ pub fn finalize_current_module_macro_resolutions(&mut self) {
}
}
fn
prohibit_imported_non_macro_attrs
(
&
self
,
binding
:
Option
<&
'a
NameBinding
<
'a
>>
,
def
:
Option
<
Def
>
,
span
:
Span
)
{
if
let
Some
(
Def
::
NonMacroAttr
(
kind
))
=
def
{
if
kind
!=
NonMacroAttrKind
::
Tool
&&
binding
.map_or
(
true
,
|
b
|
b
.is_import
())
{
let
msg
=
format!
(
"cannot use a {} through an import"
,
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
()));
}
err
.emit
();
}
}
}
fn
suggest_macro_name
(
&
mut
self
,
name
:
&
str
,
kind
:
MacroKind
,
err
:
&
mut
DiagnosticBuilder
<
'a
>
,
span
:
Span
)
{
// First check if this is a locally-defined bang macro.
...
...
src/test/ui/rust-2018/uniform-paths/prelude-fail-2.rs
0 → 100644
浏览文件 @
bf1e70cd
// edition:2018
#![feature(uniform_paths)]
// Built-in attribute
use
inline
as
imported_inline
;
#[imported_inline]
//~ ERROR cannot use a built-in attribute through an import
fn
main
()
{}
src/test/ui/rust-2018/uniform-paths/prelude-fail-2.stderr
0 → 100644
浏览文件 @
bf1e70cd
error: cannot use a built-in attribute through an import
--> $DIR/prelude-fail-2.rs:8:3
|
LL | #[imported_inline] //~ ERROR cannot use a built-in attribute through an import
| ^^^^^^^^^^^^^^^
|
note: the built-in attribute imported here
--> $DIR/prelude-fail-2.rs:6:5
|
LL | use inline as imported_inline;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
src/test/ui/rust-2018/uniform-paths/prelude.rs
浏览文件 @
bf1e70cd
...
...
@@ -6,9 +6,6 @@
// Macro imported with `#[macro_use] extern crate`
use
vec
as
imported_vec
;
// Built-in attribute
use
inline
as
imported_inline
;
// Tool module
use
rustfmt
as
imported_rustfmt
;
...
...
@@ -20,7 +17,6 @@
type
A
=
imported_u8
;
#[imported_inline]
#[imported_rustfmt::skip]
fn
main
()
{
imported_vec!
[
0
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录