@@ -3,21 +3,15 @@ use crate::{
3
3
CodeSuggestion , DiagnosticBuilder , DiagnosticMessage , EmissionGuarantee , Level , MultiSpan ,
4
4
SubdiagnosticMessage , Substitution , SubstitutionPart , SuggestionStyle ,
5
5
} ;
6
- use rustc_ast as ast;
7
- use rustc_ast_pretty:: pprust;
8
6
use rustc_data_structures:: fx:: FxHashMap ;
9
7
use rustc_error_messages:: FluentValue ;
10
- use rustc_hir as hir;
11
8
use rustc_lint_defs:: { Applicability , LintExpectationId } ;
12
9
use rustc_span:: edition:: LATEST_STABLE_EDITION ;
13
- use rustc_span:: symbol:: { Ident , MacroRulesNormalizedIdent , Symbol } ;
14
- use rustc_span:: { edition:: Edition , Span , DUMMY_SP } ;
15
- use rustc_target:: spec:: { PanicStrategy , SplitDebuginfo , StackProtector , TargetTriple } ;
10
+ use rustc_span:: symbol:: Symbol ;
11
+ use rustc_span:: { Span , DUMMY_SP } ;
16
12
use std:: borrow:: Cow ;
17
13
use std:: fmt;
18
14
use std:: hash:: { Hash , Hasher } ;
19
- use std:: num:: ParseIntError ;
20
- use std:: path:: { Path , PathBuf } ;
21
15
22
16
/// Error type for `Diagnostic`'s `suggestions` field, indicating that
23
17
/// `.disable_suggestions()` was called on the `Diagnostic`.
@@ -49,119 +43,6 @@ pub trait IntoDiagnosticArg {
49
43
fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > ;
50
44
}
51
45
52
- pub struct DiagnosticArgFromDisplay < ' a > ( pub & ' a dyn fmt:: Display ) ;
53
-
54
- impl IntoDiagnosticArg for DiagnosticArgFromDisplay < ' _ > {
55
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
56
- self . 0 . to_string ( ) . into_diagnostic_arg ( )
57
- }
58
- }
59
-
60
- impl < ' a > From < & ' a dyn fmt:: Display > for DiagnosticArgFromDisplay < ' a > {
61
- fn from ( t : & ' a dyn fmt:: Display ) -> Self {
62
- DiagnosticArgFromDisplay ( t)
63
- }
64
- }
65
-
66
- impl < ' a , T : fmt:: Display > From < & ' a T > for DiagnosticArgFromDisplay < ' a > {
67
- fn from ( t : & ' a T ) -> Self {
68
- DiagnosticArgFromDisplay ( t)
69
- }
70
- }
71
-
72
- macro_rules! into_diagnostic_arg_using_display {
73
- ( $( $ty: ty ) ,+ $( , ) ?) => {
74
- $(
75
- impl IntoDiagnosticArg for $ty {
76
- fn into_diagnostic_arg( self ) -> DiagnosticArgValue <' static > {
77
- self . to_string( ) . into_diagnostic_arg( )
78
- }
79
- }
80
- ) +
81
- }
82
- }
83
-
84
- into_diagnostic_arg_using_display ! (
85
- i8 ,
86
- u8 ,
87
- i16 ,
88
- u16 ,
89
- i32 ,
90
- u32 ,
91
- i64 ,
92
- u64 ,
93
- i128 ,
94
- u128 ,
95
- std:: io:: Error ,
96
- std:: num:: NonZeroU32 ,
97
- hir:: Target ,
98
- Edition ,
99
- Ident ,
100
- MacroRulesNormalizedIdent ,
101
- ParseIntError ,
102
- StackProtector ,
103
- & TargetTriple ,
104
- SplitDebuginfo
105
- ) ;
106
-
107
- impl IntoDiagnosticArg for bool {
108
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
109
- if self {
110
- DiagnosticArgValue :: Str ( Cow :: Borrowed ( "true" ) )
111
- } else {
112
- DiagnosticArgValue :: Str ( Cow :: Borrowed ( "false" ) )
113
- }
114
- }
115
- }
116
-
117
- impl IntoDiagnosticArg for char {
118
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
119
- DiagnosticArgValue :: Str ( Cow :: Owned ( format ! ( "{:?}" , self ) ) )
120
- }
121
- }
122
-
123
- impl IntoDiagnosticArg for Symbol {
124
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
125
- self . to_ident_string ( ) . into_diagnostic_arg ( )
126
- }
127
- }
128
-
129
- impl < ' a > IntoDiagnosticArg for & ' a str {
130
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
131
- self . to_string ( ) . into_diagnostic_arg ( )
132
- }
133
- }
134
-
135
- impl IntoDiagnosticArg for String {
136
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
137
- DiagnosticArgValue :: Str ( Cow :: Owned ( self ) )
138
- }
139
- }
140
-
141
- impl < ' a > IntoDiagnosticArg for & ' a Path {
142
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
143
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . display ( ) . to_string ( ) ) )
144
- }
145
- }
146
-
147
- impl IntoDiagnosticArg for PathBuf {
148
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
149
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . display ( ) . to_string ( ) ) )
150
- }
151
- }
152
-
153
- impl IntoDiagnosticArg for usize {
154
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
155
- DiagnosticArgValue :: Number ( self )
156
- }
157
- }
158
-
159
- impl IntoDiagnosticArg for PanicStrategy {
160
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
161
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . desc ( ) . to_string ( ) ) )
162
- }
163
- }
164
-
165
46
impl < ' source > Into < FluentValue < ' source > > for DiagnosticArgValue < ' source > {
166
47
fn into ( self ) -> FluentValue < ' source > {
167
48
match self {
@@ -171,34 +52,6 @@ impl<'source> Into<FluentValue<'source>> for DiagnosticArgValue<'source> {
171
52
}
172
53
}
173
54
174
- impl IntoDiagnosticArg for hir:: ConstContext {
175
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
176
- DiagnosticArgValue :: Str ( Cow :: Borrowed ( match self {
177
- hir:: ConstContext :: ConstFn => "constant function" ,
178
- hir:: ConstContext :: Static ( _) => "static" ,
179
- hir:: ConstContext :: Const => "constant" ,
180
- } ) )
181
- }
182
- }
183
-
184
- impl IntoDiagnosticArg for ast:: Path {
185
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
186
- DiagnosticArgValue :: Str ( Cow :: Owned ( pprust:: path_to_string ( & self ) ) )
187
- }
188
- }
189
-
190
- impl IntoDiagnosticArg for ast:: token:: Token {
191
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
192
- DiagnosticArgValue :: Str ( pprust:: token_to_string ( & self ) )
193
- }
194
- }
195
-
196
- impl IntoDiagnosticArg for ast:: token:: TokenKind {
197
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
198
- DiagnosticArgValue :: Str ( pprust:: token_kind_to_string ( & self ) )
199
- }
200
- }
201
-
202
55
/// Trait implemented by error types. This should not be implemented manually. Instead, use
203
56
/// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic].
204
57
#[ cfg_attr( bootstrap, rustc_diagnostic_item = "AddSubdiagnostic" ) ]
0 commit comments