8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use std:: cell:: RefCell ;
12
11
use std:: collections:: BTreeMap ;
13
12
use std:: env;
14
13
@@ -31,12 +30,6 @@ pub use errors::*;
31
30
// Maximum width of any line in an extended error description (inclusive).
32
31
const MAX_DESCRIPTION_WIDTH : usize = 80 ;
33
32
34
- thread_local ! {
35
- static REGISTERED_DIAGNOSTICS : RefCell <ErrorMap > = {
36
- RefCell :: new( BTreeMap :: new( ) )
37
- }
38
- }
39
-
40
33
/// Error information type.
41
34
pub struct ErrorInfo {
42
35
pub description : Option < Name > ,
@@ -46,14 +39,6 @@ pub struct ErrorInfo {
46
39
/// Mapping from error codes to metadata.
47
40
pub type ErrorMap = BTreeMap < Name , ErrorInfo > ;
48
41
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
-
57
42
pub fn expand_diagnostic_used < ' cx > ( ecx : & ' cx mut ExtCtxt ,
58
43
span : Span ,
59
44
token_tree : & [ TokenTree ] )
@@ -63,7 +48,7 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
63
48
_ => unreachable ! ( )
64
49
} ;
65
50
66
- with_registered_diagnostics ( |diagnostics| {
51
+ ecx . parse_sess . registered_diagnostics . with_lock ( |diagnostics| {
67
52
match diagnostics. get_mut ( & code. name ) {
68
53
// Previously used errors.
69
54
Some ( & mut ErrorInfo { description : _, use_site : Some ( previous_span) } ) => {
@@ -132,7 +117,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
132
117
}
133
118
} ) ;
134
119
// Add the error to the map.
135
- with_registered_diagnostics ( |diagnostics| {
120
+ ecx . parse_sess . registered_diagnostics . with_lock ( |diagnostics| {
136
121
let info = ErrorInfo {
137
122
description,
138
123
use_site : None
@@ -174,7 +159,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
174
159
175
160
// Output error metadata to `tmp/extended-errors/<target arch>/<crate name>.json`
176
161
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| {
178
163
if let Err ( e) = output_metadata ( ecx,
179
164
& target_triple,
180
165
& crate_name. name . as_str ( ) ,
@@ -194,7 +179,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
194
179
195
180
// Construct the output expression.
196
181
let ( count, expr) =
197
- with_registered_diagnostics ( |diagnostics| {
182
+ ecx . parse_sess . registered_diagnostics . with_lock ( |diagnostics| {
198
183
let descriptions: Vec < P < ast:: Expr > > =
199
184
diagnostics. iter ( ) . filter_map ( |( & code, info) | {
200
185
info. description . map ( |description| {
0 commit comments