@@ -123,14 +123,31 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
123
123
}
124
124
}
125
125
126
+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
127
+ enum MiriBeRustcMode {
128
+ Target ,
129
+ Host ,
130
+ Rustdoc ,
131
+ }
132
+
133
+ impl MiriBeRustcMode {
134
+ fn target_crate ( self ) -> bool {
135
+ use MiriBeRustcMode :: * ;
136
+ match self {
137
+ Target | Rustdoc => true ,
138
+ Host => false ,
139
+ }
140
+ }
141
+ }
142
+
126
143
struct MiriBeRustCompilerCalls {
127
- target_crate : bool ,
144
+ mode : MiriBeRustcMode ,
128
145
}
129
146
130
147
impl rustc_driver:: Callbacks for MiriBeRustCompilerCalls {
131
148
#[ allow( rustc:: potential_query_instability) ] // rustc_codegen_ssa (where this code is copied from) also allows this lint
132
149
fn config ( & mut self , config : & mut Config ) {
133
- if config. opts . prints . is_empty ( ) && self . target_crate {
150
+ if config. opts . prints . is_empty ( ) && self . mode == MiriBeRustcMode :: Target {
134
151
// Queries overridden here affect the data stored in `rmeta` files of dependencies,
135
152
// which will be used later in non-`MIRI_BE_RUSTC` mode.
136
153
config. override_queries = Some ( |_, local_providers| {
@@ -179,6 +196,21 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
179
196
} ) ;
180
197
}
181
198
}
199
+
200
+ fn after_analysis < ' tcx > (
201
+ & mut self ,
202
+ _: & rustc_interface:: interface:: Compiler ,
203
+ queries : & ' tcx rustc_interface:: Queries < ' tcx > ,
204
+ ) -> Compilation {
205
+ queries. global_ctxt ( ) . unwrap ( ) . enter ( |tcx| {
206
+ // Make sure compile_fail tests with post-monomorphization const-eval errors work as
207
+ // intended in rustdoc mode.
208
+ if self . mode == MiriBeRustcMode :: Rustdoc {
209
+ let _ = tcx. collect_and_partition_mono_items ( ( ) ) ;
210
+ }
211
+ } ) ;
212
+ Compilation :: Continue
213
+ }
182
214
}
183
215
184
216
fn show_error ( msg : & impl std:: fmt:: Display ) -> ! {
@@ -351,19 +383,18 @@ fn main() {
351
383
rustc_driver:: install_ice_hook ( rustc_driver:: DEFAULT_BUG_REPORT_URL , |_| ( ) ) ;
352
384
rustc_driver:: init_rustc_env_logger ( & early_dcx) ;
353
385
354
- let target_crate = if crate_kind == "target" {
355
- true
356
- } else if crate_kind == "host" {
357
- false
358
- } else {
359
- panic ! ( "invalid `MIRI_BE_RUSTC` value: {crate_kind:?}" )
386
+ let mode = match crate_kind. to_str ( ) . unwrap_or_default ( ) {
387
+ "target" => MiriBeRustcMode :: Target ,
388
+ "rustdoc" => MiriBeRustcMode :: Rustdoc ,
389
+ "host" => MiriBeRustcMode :: Host ,
390
+ _ => panic ! ( "invalid `MIRI_BE_RUSTC` value: {crate_kind:?}" ) ,
360
391
} ;
361
392
362
393
// We cannot use `rustc_driver::main` as we need to adjust the CLI arguments.
363
394
run_compiler (
364
395
args,
365
- target_crate,
366
- & mut MiriBeRustCompilerCalls { target_crate } ,
396
+ mode . target_crate ( ) ,
397
+ & mut MiriBeRustCompilerCalls { mode } ,
367
398
using_internal_features,
368
399
)
369
400
}
0 commit comments