11use std:: borrow:: Cow ;
22use std:: fmt:: Display ;
3+ use std:: hash:: Hash ;
34
45use rustc_data_structures:: fx:: FxIndexSet ;
56use rustc_data_structures:: stable_hasher:: {
@@ -8,9 +9,10 @@ use rustc_data_structures::stable_hasher::{
89use rustc_error_messages:: { DiagArgValue , IntoDiagArg } ;
910use rustc_hir_id:: { HirId , ItemLocalId } ;
1011use rustc_macros:: { Decodable , Encodable , HashStable_Generic } ;
12+ use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder } ;
1113use rustc_span:: def_id:: DefPathHash ;
1214pub use rustc_span:: edition:: Edition ;
13- use rustc_span:: { AttrId , HashStableContext , Ident , Span , Symbol , sym} ;
15+ use rustc_span:: { HashStableContext , Ident , Span , SpanDecoder , SpanEncoder , Symbol , sym} ;
1416use serde:: { Deserialize , Serialize } ;
1517
1618pub use self :: Level :: * ;
@@ -91,7 +93,7 @@ pub enum Applicability {
9193/// instances might be loaded from cache. Lint messages can be emitted during an
9294/// `EarlyLintPass` operating on the AST and during a `LateLintPass` traversing the
9395/// HIR tree. The AST doesn't have enough information to create a stable id. The
94- /// `LintExpectationId` will instead store the [`AttrId`] defining the expectation.
96+ /// `LintExpectationId` will instead store the `target_span` defining the expectation.
9597/// These `LintExpectationId` will be updated to use the stable [`HirId`] once the
9698/// AST has been lowered. The transformation is done by the `LintLevelsBuilder`
9799///
@@ -105,12 +107,12 @@ pub enum Applicability {
105107pub enum LintExpectationId {
106108 /// Used for lints emitted during the `EarlyLintPass`. This id is not
107109 /// hash stable and should not be cached.
108- Unstable { attr_id : AttrId , lint_index : u16 } ,
110+ Unstable { target_span : Span , lint_index : u16 , attr_index : u16 } ,
109111 /// The [`HirId`] that the lint expectation is attached to. This id is
110112 /// stable and can be cached. The additional index ensures that nodes with
111113 /// several expectations can correctly match diagnostics to the individual
112114 /// expectation.
113- Stable { hir_id : HirId , attr_id : AttrId , attr_index : u16 , lint_index : u16 } ,
115+ Stable { hir_id : HirId , attr_index : u16 , lint_index : u16 , target_span : Span } ,
114116}
115117
116118impl LintExpectationId {
@@ -140,12 +142,13 @@ impl<Hcx: HashStableContext> HashStable<Hcx> for LintExpectationId {
140142 #[ inline]
141143 fn hash_stable ( & self , hcx : & mut Hcx , hasher : & mut StableHasher ) {
142144 match self {
143- LintExpectationId :: Stable { hir_id, attr_index, lint_index, .. } => {
145+ LintExpectationId :: Stable { hir_id, target_span , attr_index, lint_index, .. } => {
144146 hir_id. hash_stable ( hcx, hasher) ;
147+ target_span. hash_stable ( hcx, hasher) ;
145148 attr_index. hash_stable ( hcx, hasher) ;
146149 lint_index. hash_stable ( hcx, hasher) ;
147150 }
148- _ => {
151+ LintExpectationId :: Unstable { .. } => {
149152 unreachable ! (
150153 "HashStable should only be called for filled and stable `LintExpectationId`"
151154 )
@@ -155,16 +158,16 @@ impl<Hcx: HashStableContext> HashStable<Hcx> for LintExpectationId {
155158}
156159
157160impl < Hcx : HashStableContext > ToStableHashKey < Hcx > for LintExpectationId {
158- type KeyType = ( DefPathHash , ItemLocalId , u16 , u16 ) ;
161+ type KeyType = ( DefPathHash , ItemLocalId , Span , u16 , u16 ) ;
159162
160163 #[ inline]
161164 fn to_stable_hash_key ( & self , hcx : & mut Hcx ) -> Self :: KeyType {
162165 match self {
163- LintExpectationId :: Stable { hir_id, attr_index, lint_index, .. } => {
166+ LintExpectationId :: Stable { hir_id, attr_index, lint_index, target_span , .. } => {
164167 let ( def_path_hash, lint_idx) = hir_id. to_stable_hash_key ( hcx) ;
165- ( def_path_hash, lint_idx, * attr_index, * lint_index)
168+ ( def_path_hash, lint_idx, * target_span , * attr_index, * lint_index)
166169 }
167- _ => {
170+ LintExpectationId :: Unstable { .. } => {
168171 unreachable ! ( "HashStable should only be called for a filled `LintExpectationId`" )
169172 }
170173 }
0 commit comments