@@ -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