@@ -114,20 +114,26 @@ pub(super) enum Radix {
114
114
impl Radix {
115
115
/// Returns a reasonable digit group size for this radix.
116
116
#[ must_use]
117
- crate fn suggest_grouping ( & self ) -> usize {
117
+ fn suggest_grouping ( & self ) -> usize {
118
118
match * self {
119
119
Self :: Binary | Self :: Hexadecimal => 4 ,
120
120
Self :: Octal | Self :: Decimal => 3 ,
121
121
}
122
122
}
123
123
}
124
124
125
+ /// A helper method to format numeric literals with digit grouping.
126
+ /// `lit` must be a valid numeric literal without suffix.
127
+ pub fn format_numeric_literal ( lit : & str , type_suffix : Option < & str > , float : bool ) -> String {
128
+ NumericLiteral :: new ( lit, type_suffix, float) . format ( )
129
+ }
130
+
125
131
#[ derive( Debug ) ]
126
132
pub ( super ) struct NumericLiteral < ' a > {
127
133
/// Which radix the literal was represented in.
128
- crate radix : Radix ,
134
+ radix : Radix ,
129
135
/// The radix prefix, if present.
130
- crate prefix : Option < & ' a str > ,
136
+ prefix : Option < & ' a str > ,
131
137
132
138
/// The integer part of the number.
133
139
integer : & ' a str ,
@@ -137,7 +143,7 @@ pub(super) struct NumericLiteral<'a> {
137
143
exponent : Option < ( char , & ' a str ) > ,
138
144
139
145
/// The type suffix, including preceding underscore if present.
140
- crate suffix : Option < & ' a str > ,
146
+ suffix : Option < & ' a str > ,
141
147
}
142
148
143
149
impl < ' a > NumericLiteral < ' a > {
@@ -152,7 +158,7 @@ impl<'a> NumericLiteral<'a> {
152
158
}
153
159
154
160
#[ must_use]
155
- crate fn new ( lit : & ' a str , suffix : Option < & ' a str > , float : bool ) -> Self {
161
+ fn new ( lit : & ' a str , suffix : Option < & ' a str > , float : bool ) -> Self {
156
162
// Determine delimiter for radix prefix, if present, and radix.
157
163
let radix = if lit. starts_with ( "0x" ) {
158
164
Radix :: Hexadecimal
@@ -219,7 +225,7 @@ impl<'a> NumericLiteral<'a> {
219
225
}
220
226
221
227
/// Returns literal formatted in a sensible way.
222
- crate fn format ( & self ) -> String {
228
+ fn format ( & self ) -> String {
223
229
let mut output = String :: new ( ) ;
224
230
225
231
if let Some ( prefix) = self . prefix {
@@ -324,7 +330,7 @@ enum WarningType {
324
330
}
325
331
326
332
impl WarningType {
327
- crate fn display ( & self , suggested_format : String , cx : & EarlyContext < ' _ > , span : syntax_pos:: Span ) {
333
+ fn display ( & self , suggested_format : String , cx : & EarlyContext < ' _ > , span : syntax_pos:: Span ) {
328
334
match self {
329
335
Self :: MistypedLiteralSuffix => span_lint_and_sugg (
330
336
cx,
0 commit comments