11
11
// FIXME: switch to something more ergonomic here, once available.
12
12
// (Currently there is no way to opt into sysroot crates without `extern crate`.)
13
13
extern crate rustc_driver;
14
- extern crate rustc_errors;
15
14
extern crate rustc_interface;
16
15
extern crate rustc_session;
17
16
extern crate rustc_span;
@@ -20,13 +19,10 @@ use rustc_interface::interface;
20
19
use rustc_session:: parse:: ParseSess ;
21
20
use rustc_span:: symbol:: Symbol ;
22
21
23
- use std:: borrow:: Cow ;
24
22
use std:: env;
25
23
use std:: ops:: Deref ;
26
- use std:: panic;
27
24
use std:: path:: Path ;
28
25
use std:: process:: exit;
29
- use std:: sync:: LazyLock ;
30
26
31
27
/// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If
32
28
/// true, then return it. The parameter is assumed to be either `--arg=value` or `--arg value`.
@@ -198,66 +194,18 @@ You can use tool lints to allow or deny lints from your code, eg.:
198
194
199
195
const BUG_REPORT_URL : & str = "https://github.com/rust-lang/rust-clippy/issues/new" ;
200
196
201
- type PanicCallback = dyn Fn ( & panic:: PanicInfo < ' _ > ) + Sync + Send + ' static ;
202
- static ICE_HOOK : LazyLock < Box < PanicCallback > > = LazyLock :: new ( || {
203
- let hook = panic:: take_hook ( ) ;
204
- panic:: set_hook ( Box :: new ( |info| report_clippy_ice ( info, BUG_REPORT_URL ) ) ) ;
205
- hook
206
- } ) ;
207
-
208
- fn report_clippy_ice ( info : & panic:: PanicInfo < ' _ > , bug_report_url : & str ) {
209
- // Invoke our ICE handler, which prints the actual panic message and optionally a backtrace
210
- ( * ICE_HOOK ) ( info) ;
211
-
212
- // Separate the output with an empty line
213
- eprintln ! ( ) ;
214
-
215
- let fallback_bundle = rustc_errors:: fallback_fluent_bundle ( rustc_driver:: DEFAULT_LOCALE_RESOURCES . to_vec ( ) , false ) ;
216
- let emitter = Box :: new ( rustc_errors:: emitter:: EmitterWriter :: stderr (
217
- rustc_errors:: ColorConfig :: Auto ,
218
- None ,
219
- None ,
220
- fallback_bundle,
221
- false ,
222
- false ,
223
- None ,
224
- false ,
225
- false ,
226
- rustc_errors:: TerminalUrl :: No ,
227
- ) ) ;
228
- let handler = rustc_errors:: Handler :: with_emitter ( true , None , emitter) ;
229
-
230
- // a .span_bug or .bug call has already printed what
231
- // it wants to print.
232
- if !info. payload ( ) . is :: < rustc_errors:: ExplicitBug > ( ) {
233
- let mut d = rustc_errors:: Diagnostic :: new ( rustc_errors:: Level :: Bug , "unexpected panic" ) ;
234
- handler. emit_diagnostic ( & mut d) ;
235
- }
236
-
237
- let version_info = rustc_tools_util:: get_version_info!( ) ;
238
-
239
- let xs: Vec < Cow < ' static , str > > = vec ! [
240
- "the compiler unexpectedly panicked. this is a bug." . into( ) ,
241
- format!( "we would appreciate a bug report: {bug_report_url}" ) . into( ) ,
242
- format!( "Clippy version: {version_info}" ) . into( ) ,
243
- ] ;
244
-
245
- for note in & xs {
246
- handler. note_without_error ( note. as_ref ( ) ) ;
247
- }
248
-
249
- // If backtraces are enabled, also print the query stack
250
- let backtrace = env:: var_os ( "RUST_BACKTRACE" ) . map_or ( false , |x| & x != "0" ) ;
251
-
252
- let num_frames = if backtrace { None } else { Some ( 2 ) } ;
253
-
254
- interface:: try_print_query_stack ( & handler, num_frames) ;
255
- }
256
-
257
197
#[ allow( clippy:: too_many_lines) ]
258
198
pub fn main ( ) {
259
199
rustc_driver:: init_rustc_env_logger ( ) ;
260
- LazyLock :: force ( & ICE_HOOK ) ;
200
+
201
+ rustc_driver:: install_ice_hook ( BUG_REPORT_URL , |handler| {
202
+ // FIXME: this macro calls unwrap internally but is called in a panicking context! It's not
203
+ // as simple as moving the call from the hook to main, because `install_ice_hook` doesn't
204
+ // accept a generic closure.
205
+ let version_info = rustc_tools_util:: get_version_info!( ) ;
206
+ handler. note_without_error ( format ! ( "Clippy version: {version_info}" ) ) ;
207
+ } ) ;
208
+
261
209
exit ( rustc_driver:: catch_with_exit_code ( move || {
262
210
let mut orig_args: Vec < String > = env:: args ( ) . collect ( ) ;
263
211
let has_sysroot_arg = arg_value ( & orig_args, "--sysroot" , |_| true ) . is_some ( ) ;
0 commit comments