Skip to content

Commit 1b92712

Browse files
committed
expand: Leave traces when expanding cfg attributes
1 parent aba76d0 commit 1b92712

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

clippy_lints/src/attrs/duplicated_attributes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ fn check_duplicated_attr(
3737
let Some(ident) = attr.ident() else { return };
3838
let name = ident.name;
3939
if name == sym::doc
40-
|| name == sym::cfg_attr
4140
|| name == sym::cfg_attr_trace
4241
|| name == sym::rustc_on_unimplemented
4342
|| name == sym::reason {
@@ -47,7 +46,7 @@ fn check_duplicated_attr(
4746
return;
4847
}
4948
if let Some(direct_parent) = parent.last()
50-
&& ["cfg", "cfg_attr"].contains(&direct_parent.as_str())
49+
&& direct_parent == sym::cfg_trace.as_str()
5150
&& [sym::all, sym::not, sym::any].contains(&name)
5251
{
5352
// FIXME: We don't correctly check `cfg`s for now, so if it's more complex than just a one

clippy_lints/src/cfg_not_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ declare_lint_pass!(CfgNotTest => [CFG_NOT_TEST]);
3232

3333
impl EarlyLintPass for CfgNotTest {
3434
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &rustc_ast::Attribute) {
35-
if attr.has_name(rustc_span::sym::cfg) && contains_not_test(attr.meta_item_list().as_deref(), false) {
35+
if attr.has_name(rustc_span::sym::cfg_trace) && contains_not_test(attr.meta_item_list().as_deref(), false) {
3636
span_lint_and_then(
3737
cx,
3838
CFG_NOT_TEST,

clippy_lints/src/methods/is_empty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &'_ Expr<'_>, receiver: &Expr<'_
4141
fn is_under_cfg(cx: &LateContext<'_>, id: HirId) -> bool {
4242
cx.tcx
4343
.hir_parent_id_iter(id)
44-
.any(|id| cx.tcx.hir_attrs(id).iter().any(|attr| attr.has_name(sym::cfg)))
44+
.any(|id| cx.tcx.hir_attrs(id).iter().any(|attr| attr.has_name(sym::cfg_trace)))
4545
}
4646

4747
/// Similar to [`clippy_utils::expr_or_init`], but does not go up the chain if the initialization

clippy_utils/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,7 +2629,7 @@ pub fn peel_ref_operators<'hir>(cx: &LateContext<'_>, mut expr: &'hir Expr<'hir>
26292629
pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
26302630
if let TyKind::Path(QPath::Resolved(_, path)) = ty.kind {
26312631
if let Res::Def(_, def_id) = path.res {
2632-
return cx.tcx.has_attr(def_id, sym::cfg) || cx.tcx.has_attr(def_id, sym::cfg_attr);
2632+
return cx.tcx.has_attr(def_id, sym::cfg_trace) || cx.tcx.has_attr(def_id, sym::cfg_attr);
26332633
}
26342634
}
26352635
false
@@ -2699,7 +2699,7 @@ pub fn is_in_test_function(tcx: TyCtxt<'_>, id: HirId) -> bool {
26992699
/// use [`is_in_cfg_test`]
27002700
pub fn is_cfg_test(tcx: TyCtxt<'_>, id: HirId) -> bool {
27012701
tcx.hir_attrs(id).iter().any(|attr| {
2702-
if attr.has_name(sym::cfg)
2702+
if attr.has_name(sym::cfg_trace)
27032703
&& let Some(items) = attr.meta_item_list()
27042704
&& let [item] = &*items
27052705
&& item.has_name(sym::test)
@@ -2723,11 +2723,11 @@ pub fn is_in_test(tcx: TyCtxt<'_>, hir_id: HirId) -> bool {
27232723

27242724
/// Checks if the item of any of its parents has `#[cfg(...)]` attribute applied.
27252725
pub fn inherits_cfg(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
2726-
tcx.has_attr(def_id, sym::cfg)
2726+
tcx.has_attr(def_id, sym::cfg_trace)
27272727
|| tcx
27282728
.hir_parent_iter(tcx.local_def_id_to_hir_id(def_id))
27292729
.flat_map(|(parent_id, _)| tcx.hir_attrs(parent_id))
2730-
.any(|attr| attr.has_name(sym::cfg))
2730+
.any(|attr| attr.has_name(sym::cfg_trace))
27312731
}
27322732

27332733
/// Walks up the HIR tree from the given expression in an attempt to find where the value is

0 commit comments

Comments
 (0)