@@ -11,7 +11,6 @@ extern crate rustc_middle;
1111extern crate rustc_session;
1212extern crate rustc_span;
1313
14- use once_cell:: sync:: Lazy ;
1514use rustc_driver:: Callbacks ;
1615use rustc_interface:: interface;
1716use rustc_session:: config:: ErrorOutputType ;
@@ -24,8 +23,6 @@ use std::path::Path;
2423const PLRUSTC_USER_CRATE_NAME : & str = "PLRUSTC_USER_CRATE_NAME" ;
2524const PLRUSTC_USER_CRATE_ALLOWED_SOURCE_PATHS : & str = "PLRUSTC_USER_CRATE_ALLOWED_SOURCE_PATHS" ;
2625
27- const PLRUSTC_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
28-
2926mod lints;
3027
3128struct PlrustcCallbacks {
@@ -51,62 +48,8 @@ impl Callbacks for PlrustcCallbacks {
5148 }
5249}
5350
54- // TODO: eventually we can replace this with:
55- // rustc_driver::install_ice_hook("https://github.com/tcdi/plrust/issues/new", |_| ());
56- fn install_ice_hook ( ) {
57- fn report_plrustc_ice ( info : & std:: panic:: PanicInfo < ' _ > , bug_report_url : & str ) {
58- // Invoke the default panic handler to print the message and (possibly) a back trace
59- ( * PANIC_HOOK ) ( info) ;
60- // Separate output with an empty line
61- eprintln ! ( ) ;
62-
63- let fallback_bundle = rustc_errors:: fallback_fluent_bundle (
64- rustc_driver:: DEFAULT_LOCALE_RESOURCES . into ( ) ,
65- false ,
66- ) ;
67- let emitter = Box :: new ( rustc_errors:: emitter:: EmitterWriter :: stderr (
68- rustc_errors:: ColorConfig :: Auto ,
69- None ,
70- None ,
71- fallback_bundle,
72- false ,
73- false ,
74- None ,
75- false ,
76- false ,
77- rustc_errors:: TerminalUrl :: No ,
78- ) ) ;
79- let handler = rustc_errors:: Handler :: with_emitter ( true , None , emitter) ;
80-
81- // Don't need to print anything extra for ExplicitBug
82- if !info. payload ( ) . is :: < rustc_errors:: ExplicitBug > ( ) {
83- let mut d = rustc_errors:: Diagnostic :: new ( rustc_errors:: Level :: Bug , "unexpected panic" ) ;
84- handler. emit_diagnostic ( & mut d) ;
85- }
86- handler. note_without_error ( "`plrustc` unexpectedly panicked. This is probably a bug." ) ;
87- handler. note_without_error ( & format ! ( "Please file a bug report at <{bug_report_url}>" ) ) ;
88- handler. note_without_error ( & format ! ( "plrustc version: {PLRUSTC_VERSION}" ) ) ;
89-
90- // If backtraces are enabled, also print the query stack
91- let backtrace = std:: env:: var_os ( "RUST_BACKTRACE" ) . map_or ( false , |x| & x != "0" ) ;
92-
93- let num_frames = if backtrace { None } else { Some ( 2 ) } ;
94-
95- interface:: try_print_query_stack ( & handler, num_frames) ;
96- }
97-
98- type PanicCallback = Box < dyn Fn ( & std:: panic:: PanicInfo < ' _ > ) + Sync + Send + ' static > ;
99- static PANIC_HOOK : Lazy < PanicCallback > = Lazy :: new ( || {
100- let hook = std:: panic:: take_hook ( ) ;
101- let bug_report_url = "https://github.com/tcdi/plrust/issues/new" ;
102- std:: panic:: set_hook ( Box :: new ( |info| report_plrustc_ice ( info, bug_report_url) ) ) ;
103- hook
104- } ) ;
105- Lazy :: force ( & PANIC_HOOK ) ;
106- }
107-
10851fn main ( ) {
109- install_ice_hook ( ) ;
52+ rustc_driver :: install_ice_hook ( "https://github.com/tcdi/plrust/issues/new" , |_| ( ) ) ;
11053 rustc_driver:: init_rustc_env_logger ( ) ;
11154 std:: process:: exit ( rustc_driver:: catch_with_exit_code ( move || {
11255 let args = rustc_driver:: args:: arg_expand_all ( & std:: env:: args ( ) . collect :: < Vec < _ > > ( ) ) ;
@@ -177,7 +120,7 @@ impl PlrustcConfig {
177120 let Some ( allowed) = self . plrust_user_crate_allowed_source_paths . as_deref ( ) else {
178121 early_error (
179122 ErrorOutputType :: default ( ) ,
180- & format ! (
123+ format ! (
181124 "if `{PLRUSTC_USER_CRATE_NAME}` is provided, \
182125 then `{PLRUSTC_USER_CRATE_ALLOWED_SOURCE_PATHS}` should also be provided",
183126 ) ,
@@ -189,22 +132,22 @@ impl PlrustcConfig {
189132 if !path. is_absolute ( ) {
190133 early_error (
191134 ErrorOutputType :: default ( ) ,
192- & format ! ( "`{PLRUSTC_USER_CRATE_ALLOWED_SOURCE_PATHS}` contains relative path: {allowed:?}" ) ,
135+ format ! ( "`{PLRUSTC_USER_CRATE_ALLOWED_SOURCE_PATHS}` contains relative path: {allowed:?}" ) ,
193136 ) ;
194137 }
195138 let path = path. canonicalize ( ) . ok ( ) ?;
196139 let Some ( pathstr) = path. to_str ( ) else {
197140 early_error (
198141 ErrorOutputType :: default ( ) ,
199- & format ! ( "`{PLRUSTC_USER_CRATE_ALLOWED_SOURCE_PATHS}` contains non-UTF-8 path: {allowed:?}" ) ,
142+ format ! ( "`{PLRUSTC_USER_CRATE_ALLOWED_SOURCE_PATHS}` contains non-UTF-8 path: {allowed:?}" ) ,
200143 ) ;
201144 } ;
202145 Some ( pathstr. to_owned ( ) )
203146 } ) . collect :: < Vec < String > > ( ) ;
204147 if allowed_source_dirs. is_empty ( ) {
205148 early_error (
206149 ErrorOutputType :: default ( ) ,
207- & format ! (
150+ format ! (
208151 "`{PLRUSTC_USER_CRATE_ALLOWED_SOURCE_PATHS}` was provided but contained no paths \
209152 which exist: {allowed:?}",
210153 ) ,
0 commit comments