1+ #![ feature( min_specialization) ]
2+
13#[ macro_use]
24extern crate rustc_macros;
35
@@ -46,13 +48,60 @@ pub enum Applicability {
4648 Unspecified ,
4749}
4850
51+ rustc_index:: newtype_index! {
52+ /// FIXME: The lint expectation ID is currently a simple copy of the `AttrId`
53+ /// that the expectation originated from. In the future it should be generated
54+ /// by other means. This is for one to keep the IDs independent of each other
55+ /// and also to ensure that it is actually stable between compilation sessions.
56+ /// (The `AttrId` for instance, is not stable).
57+ ///
58+ /// Additionally, it would be nice if this generation could be moved into
59+ /// [`Level::from_symbol`] to have it all contained in one module and to
60+ /// make it simpler to use.
61+ pub struct LintExpectationId {
62+ DEBUG_FORMAT = "LintExpectationId({})"
63+ }
64+ }
65+
66+ rustc_data_structures:: impl_stable_hash_via_hash!( LintExpectationId ) ;
67+
68+ impl < HCX > ToStableHashKey < HCX > for LintExpectationId {
69+ type KeyType = u32 ;
70+
71+ #[ inline]
72+ fn to_stable_hash_key ( & self , _: & HCX ) -> Self :: KeyType {
73+ self . as_u32 ( )
74+ }
75+ }
76+
4977/// Setting for how to handle a lint.
78+ ///
79+ /// See: https://doc.rust-lang.org/rustc/lints/levels.html
5080#[ derive( Clone , Copy , PartialEq , PartialOrd , Eq , Ord , Debug , Hash ) ]
5181pub enum Level {
82+ /// The `allow` level will not issue any message.
5283 Allow ,
84+ /// The `expect` level will suppress the lint message but intern produce a message
85+ /// if the lint wasn't issued in the expected scope. `Expect` should not be used as
86+ /// an initial level for a lint.
87+ ///
88+ /// Note that this still means that the lint is enabled in this position and should
89+ /// be emitted, this will intern fulfill the expectation and suppress the lint.
90+ ///
91+ /// See RFC 2383.
92+ ///
93+ /// The `LintExpectationId` is used to later link a lint emission to the actual
94+ /// expectation. It can be ignored in most cases.
95+ Expect ( LintExpectationId ) ,
96+ /// The `warn` level will produce a warning if the lint was violated, however the
97+ /// compiler will continue with its execution.
5398 Warn ,
5499 ForceWarn ,
100+ /// The `deny` level will produce an error and stop further execution after the lint
101+ /// pass is complete.
55102 Deny ,
103+ /// `Forbid` is equivalent to the `deny` level but can't be overwritten like the previous
104+ /// levels.
56105 Forbid ,
57106}
58107
@@ -63,28 +112,31 @@ impl Level {
63112 pub fn as_str ( self ) -> & ' static str {
64113 match self {
65114 Level :: Allow => "allow" ,
115+ Level :: Expect ( _) => "expect" ,
66116 Level :: Warn => "warn" ,
67117 Level :: ForceWarn => "force-warn" ,
68118 Level :: Deny => "deny" ,
69119 Level :: Forbid => "forbid" ,
70120 }
71121 }
72122
73- /// Converts a lower-case string to a level.
123+ /// Converts a lower-case string to a level. This will never construct the expect
124+ /// level as that would require a [`LintExpectationId`]
74125 pub fn from_str ( x : & str ) -> Option < Level > {
75126 match x {
76127 "allow" => Some ( Level :: Allow ) ,
77128 "warn" => Some ( Level :: Warn ) ,
78129 "deny" => Some ( Level :: Deny ) ,
79130 "forbid" => Some ( Level :: Forbid ) ,
80- _ => None ,
131+ "expect" | _ => None ,
81132 }
82133 }
83134
84135 /// Converts a symbol to a level.
85136 pub fn from_symbol ( x : Symbol ) -> Option < Level > {
86137 match x {
87138 sym:: allow => Some ( Level :: Allow ) ,
139+ sym:: expect => Some ( Level :: Expect ( LintExpectationId :: from ( 0u32 ) ) ) ,
88140 sym:: warn => Some ( Level :: Warn ) ,
89141 sym:: deny => Some ( Level :: Deny ) ,
90142 sym:: forbid => Some ( Level :: Forbid ) ,
0 commit comments