Skip to content

Commit b2cb8e1

Browse files
authored
Unrolled build for rust-lang#121230
Rollup merge of rust-lang#121230 - GuillaumeGomez:extend-level-api, r=Nadrieril Extend Level API I need this API for rust-lang/rust-clippy#12303: I have a nested `cfg` attribute (so a `MetaItem`) and I'd like to still be able to match against all possible kind of `Level`s.
2 parents 43d3470 + c17539c commit b2cb8e1

File tree

1 file changed

+17
-13
lines changed
  • compiler/rustc_lint_defs/src

1 file changed

+17
-13
lines changed

compiler/rustc_lint_defs/src/lib.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ impl Level {
227227
}
228228

229229
/// Converts a lower-case string to a level. This will never construct the expect
230-
/// level as that would require a [`LintExpectationId`]
231-
pub fn from_str(x: &str) -> Option<Level> {
230+
/// level as that would require a [`LintExpectationId`].
231+
pub fn from_str(x: &str) -> Option<Self> {
232232
match x {
233233
"allow" => Some(Level::Allow),
234234
"warn" => Some(Level::Warn),
@@ -238,17 +238,21 @@ impl Level {
238238
}
239239
}
240240

241-
/// Converts a symbol to a level.
242-
pub fn from_attr(attr: &Attribute) -> Option<Level> {
243-
match attr.name_or_empty() {
244-
sym::allow => Some(Level::Allow),
245-
sym::expect => Some(Level::Expect(LintExpectationId::Unstable {
246-
attr_id: attr.id,
247-
lint_index: None,
248-
})),
249-
sym::warn => Some(Level::Warn),
250-
sym::deny => Some(Level::Deny),
251-
sym::forbid => Some(Level::Forbid),
241+
/// Converts an `Attribute` to a level.
242+
pub fn from_attr(attr: &Attribute) -> Option<Self> {
243+
Self::from_symbol(attr.name_or_empty(), Some(attr.id))
244+
}
245+
246+
/// Converts a `Symbol` to a level.
247+
pub fn from_symbol(s: Symbol, id: Option<AttrId>) -> Option<Self> {
248+
match (s, id) {
249+
(sym::allow, _) => Some(Level::Allow),
250+
(sym::expect, Some(attr_id)) => {
251+
Some(Level::Expect(LintExpectationId::Unstable { attr_id, lint_index: None }))
252+
}
253+
(sym::warn, _) => Some(Level::Warn),
254+
(sym::deny, _) => Some(Level::Deny),
255+
(sym::forbid, _) => Some(Level::Forbid),
252256
_ => None,
253257
}
254258
}

0 commit comments

Comments
 (0)