88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- use std:: cell:: RefCell ;
1211use std:: collections:: BTreeMap ;
1312use std:: env;
1413
@@ -31,12 +30,6 @@ pub use errors::*;
3130// Maximum width of any line in an extended error description (inclusive).
3231const MAX_DESCRIPTION_WIDTH : usize = 80 ;
3332
34- thread_local ! {
35- static REGISTERED_DIAGNOSTICS : RefCell <ErrorMap > = {
36- RefCell :: new( BTreeMap :: new( ) )
37- }
38- }
39-
4033/// Error information type.
4134pub struct ErrorInfo {
4235 pub description : Option < Name > ,
@@ -46,14 +39,6 @@ pub struct ErrorInfo {
4639/// Mapping from error codes to metadata.
4740pub type ErrorMap = BTreeMap < Name , ErrorInfo > ;
4841
49- fn with_registered_diagnostics < T , F > ( f : F ) -> T where
50- F : FnOnce ( & mut ErrorMap ) -> T ,
51- {
52- REGISTERED_DIAGNOSTICS . with ( move |slot| {
53- f ( & mut * slot. borrow_mut ( ) )
54- } )
55- }
56-
5742pub fn expand_diagnostic_used < ' cx > ( ecx : & ' cx mut ExtCtxt ,
5843 span : Span ,
5944 token_tree : & [ TokenTree ] )
@@ -63,7 +48,7 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
6348 _ => unreachable ! ( )
6449 } ;
6550
66- with_registered_diagnostics ( |diagnostics| {
51+ ecx . parse_sess . registered_diagnostics . with_lock ( |diagnostics| {
6752 match diagnostics. get_mut ( & code. name ) {
6853 // Previously used errors.
6954 Some ( & mut ErrorInfo { description : _, use_site : Some ( previous_span) } ) => {
@@ -132,7 +117,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
132117 }
133118 } ) ;
134119 // Add the error to the map.
135- with_registered_diagnostics ( |diagnostics| {
120+ ecx . parse_sess . registered_diagnostics . with_lock ( |diagnostics| {
136121 let info = ErrorInfo {
137122 description,
138123 use_site : None
@@ -174,7 +159,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
174159
175160 // Output error metadata to `tmp/extended-errors/<target arch>/<crate name>.json`
176161 if let Ok ( target_triple) = env:: var ( "CFG_COMPILER_HOST_TRIPLE" ) {
177- with_registered_diagnostics ( |diagnostics| {
162+ ecx . parse_sess . registered_diagnostics . with_lock ( |diagnostics| {
178163 if let Err ( e) = output_metadata ( ecx,
179164 & target_triple,
180165 & crate_name. name . as_str ( ) ,
@@ -194,7 +179,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
194179
195180 // Construct the output expression.
196181 let ( count, expr) =
197- with_registered_diagnostics ( |diagnostics| {
182+ ecx . parse_sess . registered_diagnostics . with_lock ( |diagnostics| {
198183 let descriptions: Vec < P < ast:: Expr > > =
199184 diagnostics. iter ( ) . filter_map ( |( & code, info) | {
200185 info. description . map ( |description| {
0 commit comments