Skip to content

Commit 0f6e739

Browse files
committed
fix: before parser was preventing check_target, but now tht I used a closure it considers other checks also
1 parent 82ff754 commit 0f6e739

1 file changed

Lines changed: 23 additions & 25 deletions

File tree

  • compiler/rustc_attr_parsing/src/attributes

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ impl AttributeParser for InlineParser {
5959
}
6060
};
6161

62+
cx.check_target(
63+
&attr_args,
64+
&AllowedTargets::AllowList(&[
65+
Allow(Target::Fn),
66+
Allow(Target::Method(MethodKind::Inherent)),
67+
Allow(Target::Method(MethodKind::Trait { body: true })),
68+
Allow(Target::Method(MethodKind::TraitImpl)),
69+
Allow(Target::Closure),
70+
Allow(Target::Delegation { mac: false }),
71+
Warn(Target::Method(MethodKind::Trait { body: false })),
72+
Warn(Target::ForeignFn),
73+
Warn(Target::Field),
74+
Warn(Target::MacroDef),
75+
Warn(Target::Arm),
76+
Warn(Target::AssocConst),
77+
Warn(Target::MacroCall),
78+
]),
79+
);
80+
6281
let parse_attr = |cx: &mut AcceptContext<'_, '_>| match args {
6382
ArgParser::NoArgs => Some(InlineAttr::Hint),
6483

@@ -69,19 +88,17 @@ impl AttributeParser for InlineParser {
6988
};
7089

7190
if let Err(args_span) = item.args().as_no_args() {
72-
cx.adcx()
73-
.expected_specific_argument(args_span, &[sym::always, sym::never]);
91+
cx.adcx().expected_no_args(args_span);
7492
return None;
7593
}
7694

7795
match item.path().word_sym() {
7896
Some(sym::always) => Some(InlineAttr::Always),
7997
Some(sym::never) => Some(InlineAttr::Never),
8098
_ => {
81-
cx.adcx().expected_specific_argument(
82-
item.span(),
83-
&[sym::always, sym::never],
84-
);
99+
let span = item.args().span().unwrap();
100+
cx.adcx()
101+
.expected_specific_argument(span, &[sym::always, sym::never]);
85102
return None;
86103
}
87104
}
@@ -93,25 +110,6 @@ impl AttributeParser for InlineParser {
93110
}
94111
};
95112

96-
cx.check_target(
97-
&attr_args,
98-
&AllowedTargets::AllowList(&[
99-
Allow(Target::Fn),
100-
Allow(Target::Method(MethodKind::Inherent)),
101-
Allow(Target::Method(MethodKind::Trait { body: true })),
102-
Allow(Target::Method(MethodKind::TraitImpl)),
103-
Allow(Target::Closure),
104-
Allow(Target::Delegation { mac: false }),
105-
Warn(Target::Method(MethodKind::Trait { body: false })),
106-
Warn(Target::ForeignFn),
107-
Warn(Target::Field),
108-
Warn(Target::MacroDef),
109-
Warn(Target::Arm),
110-
Warn(Target::AssocConst),
111-
Warn(Target::MacroCall),
112-
]),
113-
);
114-
115113
if let Some(prev) = &group.inline {
116114
cx.warn_unused_duplicate(prev.span, span);
117115
return;

0 commit comments

Comments
 (0)