Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b27ccbc7
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,发现更多精彩内容 >>
提交
b27ccbc7
编写于
9月 02, 2021
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
Auto merge of #87114 - cjgillot:abilint, r=estebank
Lint missing Abi in ast validation instead of lowering.
上级
cc9bb152
8d7d488d
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
61 addition
and
50 deletion
+61
-50
Cargo.lock
Cargo.lock
+1
-0
compiler/rustc_ast_lowering/src/item.rs
compiler/rustc_ast_lowering/src/item.rs
+13
-24
compiler/rustc_ast_lowering/src/lib.rs
compiler/rustc_ast_lowering/src/lib.rs
+2
-24
compiler/rustc_ast_passes/Cargo.toml
compiler/rustc_ast_passes/Cargo.toml
+1
-0
compiler/rustc_ast_passes/src/ast_validation.rs
compiler/rustc_ast_passes/src/ast_validation.rs
+41
-2
compiler/rustc_target/src/spec/abi.rs
compiler/rustc_target/src/spec/abi.rs
+3
-0
未找到文件。
Cargo.lock
浏览文件 @
b27ccbc7
...
...
@@ -3556,6 +3556,7 @@ dependencies = [
"rustc_parse",
"rustc_session",
"rustc_span",
"rustc_target",
"tracing",
]
...
...
compiler/rustc_ast_lowering/src/item.rs
浏览文件 @
b27ccbc7
...
...
@@ -279,7 +279,7 @@ fn lower_item_kind(
);
let
sig
=
hir
::
FnSig
{
decl
,
header
:
this
.lower_fn_header
(
header
,
fn_sig_span
,
id
),
header
:
this
.lower_fn_header
(
header
),
span
:
this
.lower_span
(
fn_sig_span
),
};
hir
::
ItemKind
::
Fn
(
sig
,
generics
,
body_id
)
...
...
@@ -291,17 +291,12 @@ fn lower_item_kind(
}
ModKind
::
Unloaded
=>
panic!
(
"`mod` items should have been loaded by now"
),
},
ItemKind
::
ForeignMod
(
ref
fm
)
=>
{
if
fm
.abi
.is_none
()
{
self
.maybe_lint_missing_abi
(
span
,
id
,
abi
::
Abi
::
C
{
unwind
:
false
});
}
hir
::
ItemKind
::
ForeignMod
{
abi
:
fm
.abi
.map_or
(
abi
::
Abi
::
C
{
unwind
:
false
},
|
abi
|
self
.lower_abi
(
abi
)),
ItemKind
::
ForeignMod
(
ref
fm
)
=>
hir
::
ItemKind
::
ForeignMod
{
abi
:
fm
.abi
.map_or
(
abi
::
Abi
::
FALLBACK
,
|
abi
|
self
.lower_abi
(
abi
)),
items
:
self
.arena
.alloc_from_iter
(
fm
.items
.iter
()
.map
(|
x
|
self
.lower_foreign_item_ref
(
x
))),
}
}
},
ItemKind
::
GlobalAsm
(
ref
asm
)
=>
{
hir
::
ItemKind
::
GlobalAsm
(
self
.lower_inline_asm
(
span
,
asm
))
}
...
...
@@ -807,7 +802,7 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem<'hir> {
AssocItemKind
::
Fn
(
box
FnKind
(
_
,
ref
sig
,
ref
generics
,
None
))
=>
{
let
names
=
self
.lower_fn_params_to_names
(
&
sig
.decl
);
let
(
generics
,
sig
)
=
self
.lower_method_sig
(
generics
,
sig
,
trait_item_def_id
,
false
,
None
,
i
.id
);
self
.lower_method_sig
(
generics
,
sig
,
trait_item_def_id
,
false
,
None
);
(
generics
,
hir
::
TraitItemKind
::
Fn
(
sig
,
hir
::
TraitFn
::
Required
(
names
)))
}
AssocItemKind
::
Fn
(
box
FnKind
(
_
,
ref
sig
,
ref
generics
,
Some
(
ref
body
)))
=>
{
...
...
@@ -820,7 +815,6 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem<'hir> {
trait_item_def_id
,
false
,
asyncness
.opt_return_id
(),
i
.id
,
);
(
generics
,
hir
::
TraitItemKind
::
Fn
(
sig
,
hir
::
TraitFn
::
Provided
(
body_id
)))
}
...
...
@@ -897,7 +891,6 @@ fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem<'hir> {
impl_item_def_id
,
impl_trait_return_allow
,
asyncness
.opt_return_id
(),
i
.id
,
);
(
generics
,
hir
::
ImplItemKind
::
Fn
(
sig
,
body_id
))
...
...
@@ -1292,9 +1285,8 @@ fn lower_method_sig(
fn_def_id
:
LocalDefId
,
impl_trait_return_allow
:
bool
,
is_async
:
Option
<
NodeId
>
,
id
:
NodeId
,
)
->
(
hir
::
Generics
<
'hir
>
,
hir
::
FnSig
<
'hir
>
)
{
let
header
=
self
.lower_fn_header
(
sig
.header
,
sig
.span
,
id
);
let
header
=
self
.lower_fn_header
(
sig
.header
);
let
(
generics
,
decl
)
=
self
.add_in_band_defs
(
generics
,
fn_def_id
,
...
...
@@ -1311,12 +1303,12 @@ fn lower_method_sig(
(
generics
,
hir
::
FnSig
{
header
,
decl
,
span
:
self
.lower_span
(
sig
.span
)
})
}
fn
lower_fn_header
(
&
mut
self
,
h
:
FnHeader
,
span
:
Span
,
id
:
NodeId
)
->
hir
::
FnHeader
{
fn
lower_fn_header
(
&
mut
self
,
h
:
FnHeader
)
->
hir
::
FnHeader
{
hir
::
FnHeader
{
unsafety
:
self
.lower_unsafety
(
h
.unsafety
),
asyncness
:
self
.lower_asyncness
(
h
.asyncness
),
constness
:
self
.lower_constness
(
h
.constness
),
abi
:
self
.lower_extern
(
h
.ext
,
span
,
id
),
abi
:
self
.lower_extern
(
h
.ext
),
}
}
...
...
@@ -1327,13 +1319,10 @@ pub(super) fn lower_abi(&mut self, abi: StrLit) -> abi::Abi {
})
}
pub
(
super
)
fn
lower_extern
(
&
mut
self
,
ext
:
Extern
,
span
:
Span
,
id
:
NodeId
)
->
abi
::
Abi
{
pub
(
super
)
fn
lower_extern
(
&
mut
self
,
ext
:
Extern
)
->
abi
::
Abi
{
match
ext
{
Extern
::
None
=>
abi
::
Abi
::
Rust
,
Extern
::
Implicit
=>
{
self
.maybe_lint_missing_abi
(
span
,
id
,
abi
::
Abi
::
C
{
unwind
:
false
});
abi
::
Abi
::
C
{
unwind
:
false
}
}
Extern
::
Implicit
=>
abi
::
Abi
::
FALLBACK
,
Extern
::
Explicit
(
abi
)
=>
self
.lower_abi
(
abi
),
}
}
...
...
compiler/rustc_ast_lowering/src/lib.rs
浏览文件 @
b27ccbc7
...
...
@@ -53,7 +53,7 @@
use
rustc_hir
::
intravisit
;
use
rustc_hir
::{
ConstArg
,
GenericArg
,
InferKind
,
ParamName
};
use
rustc_index
::
vec
::{
Idx
,
IndexVec
};
use
rustc_session
::
lint
::
builtin
::
{
BARE_TRAIT_OBJECTS
,
MISSING_ABI
}
;
use
rustc_session
::
lint
::
builtin
::
BARE_TRAIT_OBJECTS
;
use
rustc_session
::
lint
::{
BuiltinLintDiagnostics
,
LintBuffer
};
use
rustc_session
::
utils
::{
FlattenNonterminals
,
NtToTokenstream
};
use
rustc_session
::
Session
;
...
...
@@ -62,7 +62,6 @@
use
rustc_span
::
source_map
::{
respan
,
CachingSourceMapView
,
DesugaringKind
};
use
rustc_span
::
symbol
::{
kw
,
sym
,
Ident
,
Symbol
};
use
rustc_span
::{
Span
,
DUMMY_SP
};
use
rustc_target
::
spec
::
abi
::
Abi
;
use
smallvec
::
SmallVec
;
use
std
::
collections
::
BTreeMap
;
...
...
@@ -1361,7 +1360,6 @@ fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext<'_, 'hir>) ->
}
TyKind
::
BareFn
(
ref
f
)
=>
self
.with_in_scope_lifetime_defs
(
&
f
.generic_params
,
|
this
|
{
this
.with_anonymous_lifetime_mode
(
AnonymousLifetimeMode
::
PassThrough
,
|
this
|
{
let
span
=
this
.sess
.source_map
()
.next_point
(
t
.span
.shrink_to_lo
());
hir
::
TyKind
::
BareFn
(
this
.arena
.alloc
(
hir
::
BareFnTy
{
generic_params
:
this
.lower_generic_params
(
&
f
.generic_params
,
...
...
@@ -1369,7 +1367,7 @@ fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext<'_, 'hir>) ->
ImplTraitContext
::
disallowed
(),
),
unsafety
:
this
.lower_unsafety
(
f
.unsafety
),
abi
:
this
.lower_extern
(
f
.ext
,
span
,
t
.id
),
abi
:
this
.lower_extern
(
f
.ext
),
decl
:
this
.lower_fn_decl
(
&
f
.decl
,
None
,
false
,
None
),
param_names
:
this
.lower_fn_params_to_names
(
&
f
.decl
),
}))
...
...
@@ -2749,26 +2747,6 @@ fn maybe_lint_bare_trait(&mut self, span: Span, id: NodeId, is_global: bool) {
}
}
}
fn
maybe_lint_missing_abi
(
&
mut
self
,
span
:
Span
,
id
:
NodeId
,
default
:
Abi
)
{
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
// call site which do not have a macro backtrace. See #61963.
let
is_macro_callsite
=
self
.sess
.source_map
()
.span_to_snippet
(
span
)
.map
(|
snippet
|
snippet
.starts_with
(
"#["
))
.unwrap_or
(
true
);
if
!
is_macro_callsite
{
self
.resolver
.lint_buffer
()
.buffer_lint_with_diagnostic
(
MISSING_ABI
,
id
,
span
,
"extern declarations without an explicit ABI are deprecated"
,
BuiltinLintDiagnostics
::
MissingAbi
(
span
,
default
),
)
}
}
}
fn
body_ids
(
bodies
:
&
BTreeMap
<
hir
::
BodyId
,
hir
::
Body
<
'_
>>
)
->
Vec
<
hir
::
BodyId
>
{
...
...
compiler/rustc_ast_passes/Cargo.toml
浏览文件 @
b27ccbc7
...
...
@@ -14,4 +14,5 @@ rustc_feature = { path = "../rustc_feature" }
rustc_parse
=
{
path
=
"../rustc_parse"
}
rustc_session
=
{
path
=
"../rustc_session"
}
rustc_span
=
{
path
=
"../rustc_span"
}
rustc_target
=
{
path
=
"../rustc_target"
}
rustc_ast
=
{
path
=
"../rustc_ast"
}
compiler/rustc_ast_passes/src/ast_validation.rs
浏览文件 @
b27ccbc7
...
...
@@ -15,12 +15,13 @@
use
rustc_data_structures
::
fx
::
FxHashMap
;
use
rustc_errors
::{
error_code
,
pluralize
,
struct_span_err
,
Applicability
};
use
rustc_parse
::
validate_attr
;
use
rustc_session
::
lint
::
builtin
::
PATTERNS_IN_FNS_WITHOUT_BODY
;
use
rustc_session
::
lint
::
builtin
::
{
MISSING_ABI
,
PATTERNS_IN_FNS_WITHOUT_BODY
}
;
use
rustc_session
::
lint
::{
BuiltinLintDiagnostics
,
LintBuffer
};
use
rustc_session
::
Session
;
use
rustc_span
::
source_map
::
Spanned
;
use
rustc_span
::
symbol
::{
kw
,
sym
,
Ident
};
use
rustc_span
::
Span
;
use
rustc_target
::
spec
::
abi
;
use
std
::
mem
;
use
std
::
ops
::
DerefMut
;
...
...
@@ -844,6 +845,10 @@ fn visit_ty_common(&mut self, ty: &'a Ty) {
.emit
();
});
self
.check_late_bound_lifetime_defs
(
&
bfty
.generic_params
);
if
let
Extern
::
Implicit
=
bfty
.ext
{
let
sig_span
=
self
.session
.source_map
()
.next_point
(
ty
.span
.shrink_to_lo
());
self
.maybe_lint_missing_abi
(
sig_span
,
ty
.id
);
}
}
TyKind
::
TraitObject
(
ref
bounds
,
..
)
=>
{
let
mut
any_lifetime_bounds
=
false
;
...
...
@@ -894,6 +899,26 @@ fn visit_ty_common(&mut self, ty: &'a Ty) {
_
=>
{}
}
}
fn
maybe_lint_missing_abi
(
&
mut
self
,
span
:
Span
,
id
:
NodeId
)
{
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
// call site which do not have a macro backtrace. See #61963.
let
is_macro_callsite
=
self
.session
.source_map
()
.span_to_snippet
(
span
)
.map
(|
snippet
|
snippet
.starts_with
(
"#["
))
.unwrap_or
(
true
);
if
!
is_macro_callsite
{
self
.lint_buffer
.buffer_lint_with_diagnostic
(
MISSING_ABI
,
id
,
span
,
"extern declarations without an explicit ABI are deprecated"
,
BuiltinLintDiagnostics
::
MissingAbi
(
span
,
abi
::
Abi
::
FALLBACK
),
)
}
}
}
/// Checks that generic parameters are in the correct order,
...
...
@@ -1178,7 +1203,7 @@ fn visit_item(&mut self, item: &'a Item) {
walk_list!
(
self
,
visit_attribute
,
&
item
.attrs
);
return
;
// Avoid visiting again.
}
ItemKind
::
ForeignMod
(
ForeignMod
{
unsafety
,
..
})
=>
{
ItemKind
::
ForeignMod
(
ForeignMod
{
abi
,
unsafety
,
..
})
=>
{
let
old_item
=
mem
::
replace
(
&
mut
self
.extern_mod
,
Some
(
item
));
self
.invalid_visibility
(
&
item
.vis
,
...
...
@@ -1187,6 +1212,9 @@ fn visit_item(&mut self, item: &'a Item) {
if
let
Unsafe
::
Yes
(
span
)
=
unsafety
{
self
.err_handler
()
.span_err
(
span
,
"extern block cannot be declared unsafe"
);
}
if
abi
.is_none
()
{
self
.maybe_lint_missing_abi
(
item
.span
,
item
.id
);
}
visit
::
walk_item
(
self
,
item
);
self
.extern_mod
=
old_item
;
return
;
// Avoid visiting again.
...
...
@@ -1526,6 +1554,17 @@ fn visit_fn(&mut self, fk: FnKind<'a>, span: Span, id: NodeId) {
.emit
();
}
if
let
FnKind
::
Fn
(
_
,
_
,
FnSig
{
span
:
sig_span
,
header
:
FnHeader
{
ext
:
Extern
::
Implicit
,
..
},
..
},
_
,
_
,
)
=
fk
{
self
.maybe_lint_missing_abi
(
*
sig_span
,
id
);
}
// Functions without bodies cannot have patterns.
if
let
FnKind
::
Fn
(
ctxt
,
_
,
sig
,
_
,
None
)
=
fk
{
Self
::
check_decl_no_pat
(
&
sig
.decl
,
|
span
,
ident
,
mut_ident
|
{
...
...
compiler/rustc_target/src/spec/abi.rs
浏览文件 @
b27ccbc7
...
...
@@ -87,6 +87,9 @@ pub fn all_names() -> Vec<&'static str> {
}
impl
Abi
{
/// Default ABI chosen for `extern fn` declarations without an explicit ABI.
pub
const
FALLBACK
:
Abi
=
Abi
::
C
{
unwind
:
false
};
#[inline]
pub
fn
index
(
self
)
->
usize
{
// N.B., this ordering MUST match the AbiDatas array above.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录