Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
79b5ebf5
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,发现更多精彩内容 >>
提交
79b5ebf5
编写于
7月 21, 2018
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Attach deprecation lint `proc_macro_derive_resolution_fallback` to a specific node id
上级
942b384d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
17 deletion
+49
-17
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+33
-17
src/test/ui-fulldeps/proc-macro/auxiliary/generate-mod.rs
src/test/ui-fulldeps/proc-macro/auxiliary/generate-mod.rs
+13
-0
src/test/ui-fulldeps/proc-macro/generate-mod.rs
src/test/ui-fulldeps/proc-macro/generate-mod.rs
+3
-0
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
79b5ebf5
...
...
@@ -717,7 +717,7 @@ fn visit_ty(&mut self, ty: &'tcx Ty) {
}
TyKind
::
ImplicitSelf
=>
{
let
self_ty
=
keywords
::
SelfType
.ident
();
let
def
=
self
.resolve_ident_in_lexical_scope
(
self_ty
,
TypeNS
,
true
,
ty
.span
)
let
def
=
self
.resolve_ident_in_lexical_scope
(
self_ty
,
TypeNS
,
Some
(
ty
.id
)
,
ty
.span
)
.map_or
(
Def
::
Err
,
|
d
|
d
.def
());
self
.record_def
(
ty
.id
,
PathResolution
::
new
(
def
));
}
...
...
@@ -1839,9 +1839,10 @@ fn add_to_glob_map(&mut self, id: NodeId, ident: Ident) {
fn
resolve_ident_in_lexical_scope
(
&
mut
self
,
mut
ident
:
Ident
,
ns
:
Namespace
,
record_used
:
bool
,
record_used
_id
:
Option
<
NodeId
>
,
path_span
:
Span
)
->
Option
<
LexicalScopeBinding
<
'a
>>
{
let
record_used
=
record_used_id
.is_some
();
if
ns
==
TypeNS
{
ident
.span
=
if
ident
.name
==
keywords
::
SelfType
.name
()
{
// FIXME(jseyfried) improve `Self` hygiene
...
...
@@ -1890,10 +1891,11 @@ fn resolve_ident_in_lexical_scope(&mut self,
ident
.span
=
ident
.span
.modern
();
loop
{
let
(
opt_module
,
poisoned
)
=
if
record_used
{
self
.hygienic_lexical_parent_with_compatibility_fallback
(
module
,
&
mut
ident
.span
)
let
(
opt_module
,
poisoned
)
=
if
let
Some
(
node_id
)
=
record_used_id
{
self
.hygienic_lexical_parent_with_compatibility_fallback
(
module
,
&
mut
ident
.span
,
node_id
)
}
else
{
(
self
.hygienic_lexical_parent
(
module
,
&
mut
ident
.span
),
fals
e
)
(
self
.hygienic_lexical_parent
(
module
,
&
mut
ident
.span
),
Non
e
)
};
module
=
unwrap_or!
(
opt_module
,
break
);
let
orig_current_module
=
self
.current_module
;
...
...
@@ -1905,10 +1907,10 @@ fn resolve_ident_in_lexical_scope(&mut self,
match
result
{
Ok
(
binding
)
=>
{
if
poisoned
{
if
let
Some
(
node_id
)
=
poisoned
{
self
.session
.buffer_lint_with_diagnostic
(
lint
::
builtin
::
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK
,
CRATE_NODE_ID
,
ident
.span
,
node_id
,
ident
.span
,
&
format!
(
"cannot find {} `{}` in this scope"
,
ns
.descr
(),
ident
),
lint
::
builtin
::
BuiltinLintDiagnostics
::
ProcMacroDeriveResolutionFallback
(
ident
.span
),
...
...
@@ -1916,7 +1918,7 @@ fn resolve_ident_in_lexical_scope(&mut self,
}
return
Some
(
LexicalScopeBinding
::
Item
(
binding
))
}
_
if
poisoned
=>
break
,
_
if
poisoned
.is_some
()
=>
break
,
Err
(
Undetermined
)
=>
return
None
,
Err
(
Determined
)
=>
{}
}
...
...
@@ -1965,10 +1967,11 @@ fn hygienic_lexical_parent(&mut self, module: Module<'a>, span: &mut Span)
}
fn
hygienic_lexical_parent_with_compatibility_fallback
(
&
mut
self
,
module
:
Module
<
'a
>
,
span
:
&
mut
Span
)
->
(
Option
<
Module
<
'a
>>
,
/* poisoned */
bool
)
{
&
mut
self
,
module
:
Module
<
'a
>
,
span
:
&
mut
Span
,
node_id
:
NodeId
)
->
(
Option
<
Module
<
'a
>>
,
/* poisoned */
Option
<
NodeId
>
)
{
if
let
module
@
Some
(
..
)
=
self
.hygienic_lexical_parent
(
module
,
span
)
{
return
(
module
,
fals
e
);
return
(
module
,
Non
e
);
}
// We need to support the next case under a deprecation warning
...
...
@@ -1989,13 +1992,13 @@ fn hygienic_lexical_parent_with_compatibility_fallback(
// The macro is a proc macro derive
if
module
.expansion
.looks_like_proc_macro_derive
()
{
if
parent
.expansion
.is_descendant_of
(
span
.ctxt
()
.outer
())
{
return
(
module
.parent
,
true
);
return
(
module
.parent
,
Some
(
node_id
)
);
}
}
}
}
(
None
,
fals
e
)
(
None
,
Non
e
)
}
fn
resolve_ident_in_module
(
&
mut
self
,
...
...
@@ -2758,7 +2761,7 @@ fn resolve_pattern(&mut self,
// First try to resolve the identifier as some existing
// entity, then fall back to a fresh binding.
let
binding
=
self
.resolve_ident_in_lexical_scope
(
ident
,
ValueNS
,
fals
e
,
pat
.span
)
Non
e
,
pat
.span
)
.and_then
(
LexicalScopeBinding
::
item
);
let
resolution
=
binding
.map
(
NameBinding
::
def
)
.and_then
(|
def
|
{
let
is_syntactic_ambiguity
=
opt_pat
.is_none
()
&&
...
...
@@ -3189,13 +3192,13 @@ fn type_ascription_suggestion(&self,
fn
self_type_is_available
(
&
mut
self
,
span
:
Span
)
->
bool
{
let
binding
=
self
.resolve_ident_in_lexical_scope
(
keywords
::
SelfType
.ident
(),
TypeNS
,
fals
e
,
span
);
TypeNS
,
Non
e
,
span
);
if
let
Some
(
LexicalScopeBinding
::
Def
(
def
))
=
binding
{
def
!=
Def
::
Err
}
else
{
false
}
}
fn
self_value_is_available
(
&
mut
self
,
self_span
:
Span
,
path_span
:
Span
)
->
bool
{
let
ident
=
Ident
::
new
(
keywords
::
SelfValue
.name
(),
self_span
);
let
binding
=
self
.resolve_ident_in_lexical_scope
(
ident
,
ValueNS
,
fals
e
,
path_span
);
let
binding
=
self
.resolve_ident_in_lexical_scope
(
ident
,
ValueNS
,
Non
e
,
path_span
);
if
let
Some
(
LexicalScopeBinding
::
Def
(
def
))
=
binding
{
def
!=
Def
::
Err
}
else
{
false
}
}
...
...
@@ -3472,7 +3475,9 @@ fn resolve_path(
self
.resolve_lexical_macro_path_segment
(
ident
,
ns
,
record_used
,
path_span
)
.map
(
MacroBinding
::
binding
)
}
else
{
match
self
.resolve_ident_in_lexical_scope
(
ident
,
ns
,
record_used
,
path_span
)
{
let
record_used_id
=
if
record_used
{
crate_lint
.node_id
()
.or
(
Some
(
CRATE_NODE_ID
))
}
else
{
None
};
match
self
.resolve_ident_in_lexical_scope
(
ident
,
ns
,
record_used_id
,
path_span
)
{
// we found a locally-imported or available item/module
Some
(
LexicalScopeBinding
::
Item
(
binding
))
=>
Ok
(
binding
),
// we found a local variable or type param
...
...
@@ -4692,4 +4697,15 @@ enum CrateLint {
QPathTrait
{
qpath_id
:
NodeId
,
qpath_span
:
Span
},
}
impl
CrateLint
{
fn
node_id
(
&
self
)
->
Option
<
NodeId
>
{
match
*
self
{
CrateLint
::
No
=>
None
,
CrateLint
::
SimplePath
(
id
)
|
CrateLint
::
UsePath
{
root_id
:
id
,
..
}
|
CrateLint
::
QPathTrait
{
qpath_id
:
id
,
..
}
=>
Some
(
id
),
}
}
}
__
build_diagnostic_array!
{
librustc_resolve
,
DIAGNOSTICS
}
src/test/ui-fulldeps/proc-macro/auxiliary/generate-mod.rs
浏览文件 @
79b5ebf5
...
...
@@ -52,3 +52,16 @@ mod inner_derive {
}
"
.parse
()
.unwrap
()
}
#[proc_macro_derive(CheckDeriveLint)]
pub
fn
check_derive_lint
(
_
:
TokenStream
)
->
TokenStream
{
"
type AliasDeriveLint = FromOutside; // OK
struct OuterDeriveLint;
#[allow(proc_macro_derive_resolution_fallback)]
mod inner_derive_lint {
type Alias = FromOutside; // `FromOutside` shouldn't be available from here
type Inner = OuterDeriveLint; // `OuterDeriveLint` shouldn't be available from here
}
"
.parse
()
.unwrap
()
}
src/test/ui-fulldeps/proc-macro/generate-mod.rs
浏览文件 @
79b5ebf5
...
...
@@ -31,4 +31,7 @@
//~| WARN this was previously accepted
struct
Z
;
#[derive(generate_mod::CheckDeriveLint)]
// OK, lint is suppressed
struct
W
;
fn
main
()
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录