Skip to content

Commit cc32f86

Browse files
committed
Modify libsyntax/diagnostics to not be so persnickety. The scheme
doesn't work in a multi-crate context. We'll need to come up with something better.
1 parent 1e112e9 commit cc32f86

File tree

2 files changed

+160
-26
lines changed

2 files changed

+160
-26
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![allow(non_snake_case)]
12+
13+
register_diagnostic!(E0001, r##"
14+
This error suggests that the expression arm corresponding to the noted pattern
15+
will never be reached as for all possible values of the expression being matched,
16+
one of the preceeding patterns will match.
17+
18+
This means that perhaps some of the preceeding patterns are too general, this
19+
one is too specific or the ordering is incorrect.
20+
"##)
21+
22+
register_diagnostics!(
23+
E0002,
24+
E0003,
25+
E0004,
26+
E0005,
27+
E0006,
28+
E0007,
29+
E0008,
30+
E0009,
31+
E0010,
32+
E0011,
33+
E0012,
34+
E0013,
35+
E0014,
36+
E0015,
37+
E0016,
38+
E0017,
39+
E0018,
40+
E0019,
41+
E0020,
42+
E0022,
43+
E0023,
44+
E0024,
45+
E0025,
46+
E0026,
47+
E0027,
48+
E0029,
49+
E0030,
50+
E0031,
51+
E0033,
52+
E0034,
53+
E0035,
54+
E0036,
55+
E0038,
56+
E0040,
57+
E0044,
58+
E0045,
59+
E0046,
60+
E0049,
61+
E0050,
62+
E0051,
63+
E0052,
64+
E0053,
65+
E0054,
66+
E0055,
67+
E0056,
68+
E0057,
69+
E0059,
70+
E0060,
71+
E0061,
72+
E0062,
73+
E0063,
74+
E0066,
75+
E0067,
76+
E0068,
77+
E0069,
78+
E0070,
79+
E0071,
80+
E0072,
81+
E0073,
82+
E0074,
83+
E0075,
84+
E0076,
85+
E0077,
86+
E0079,
87+
E0080,
88+
E0081,
89+
E0082,
90+
E0083,
91+
E0084,
92+
E0085,
93+
E0086,
94+
E0087,
95+
E0088,
96+
E0089,
97+
E0090,
98+
E0091,
99+
E0092,
100+
E0093,
101+
E0094,
102+
E0100,
103+
E0101,
104+
E0102,
105+
E0103,
106+
E0104,
107+
E0106,
108+
E0107,
109+
E0108,
110+
E0109,
111+
E0110,
112+
E0116,
113+
E0117,
114+
E0118,
115+
E0119,
116+
E0120,
117+
E0121,
118+
E0122,
119+
E0124,
120+
E0127,
121+
E0128,
122+
E0129,
123+
E0130,
124+
E0131,
125+
E0132,
126+
E0133,
127+
E0134,
128+
E0135,
129+
E0136,
130+
E0137,
131+
E0138,
132+
E0139,
133+
E0140,
134+
E0141,
135+
E0152,
136+
E0153,
137+
E0157,
138+
E0158,
139+
E0159,
140+
E0161,
141+
E0162,
142+
E0163,
143+
E0164,
144+
E0165,
145+
E0166,
146+
E0167,
147+
E0168,
148+
E0169
149+
)

src/libsyntax/diagnostics/plugin.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
4545
[ast::TtToken(_, token::Ident(code, _))] => code,
4646
_ => unreachable!()
4747
};
48-
with_registered_diagnostics(|diagnostics| {
49-
if !diagnostics.contains_key(&code.name) {
50-
ecx.span_err(span, format!(
51-
"unknown diagnostic code {}; add to librustc/diagnostics.rs",
52-
token::get_ident(code).get()
53-
).as_slice());
54-
}
55-
()
56-
});
5748
with_used_diagnostics(|diagnostics| {
5849
match diagnostics.insert(code.name, span) {
5950
Some(previous_span) => {
@@ -106,25 +97,19 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
10697
_ => unreachable!()
10798
};
10899

109-
let (count, expr) = with_used_diagnostics(|diagnostics_in_use| {
100+
let (count, expr) =
110101
with_registered_diagnostics(|diagnostics| {
111-
let descriptions: Vec<P<ast::Expr>> = diagnostics
112-
.iter().filter_map(|(code, description)| {
113-
if !diagnostics_in_use.contains_key(code) {
114-
ecx.span_warn(span, format!(
115-
"diagnostic code {} never used", token::get_name(*code).get()
116-
).as_slice());
117-
}
118-
description.map(|description| {
119-
ecx.expr_tuple(span, vec![
120-
ecx.expr_str(span, token::get_name(*code)),
121-
ecx.expr_str(span, token::get_name(description))
122-
])
123-
})
124-
}).collect();
102+
let descriptions: Vec<P<ast::Expr>> =
103+
diagnostics.iter().filter_map(|(code, description)| {
104+
description.map(|description| {
105+
ecx.expr_tuple(span, vec![
106+
ecx.expr_str(span, token::get_name(*code)),
107+
ecx.expr_str(span, token::get_name(description))])
108+
})
109+
}).collect();
125110
(descriptions.len(), ecx.expr_vec(span, descriptions))
126-
})
127-
});
111+
});
112+
128113
MacItems::new(vec![quote_item!(ecx,
129114
pub static $name: [(&'static str, &'static str), ..$count] = $expr;
130115
).unwrap()].into_iter())

0 commit comments

Comments
 (0)