@@ -137,27 +137,28 @@ where
137
137
138
138
rustc_interface:: interface:: run_compiler ( config, |compiler| {
139
139
compiler. enter ( |queries| {
140
- use rustc_interface:: interface:: Result ;
141
- let try_func = || -> Result < T > {
142
- let mut query_context = queries. global_ctxt ( ) ;
140
+ use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
141
+ let mut query_context = catch_unwind ( AssertUnwindSafe ( || queries. global_ctxt ( ) ) )
142
+ . expect ( "Test input compilation failed while parsing" ) ;
143
+ catch_unwind ( AssertUnwindSafe ( || {
143
144
query_context. enter ( |tcx| {
144
145
// Explicitly force full `analysis` stage to detect compilation
145
146
// errors that the earlier stages might miss. This helps ensure that the
146
147
// test inputs are valid Rust (even if `callback` wouldn't
147
148
// have triggered full analysis).
148
- tcx. analysis ( ( ) )
149
+ tcx. ensure ( ) . analysis ( ( ) ) ;
149
150
} ) ;
151
+ } ) )
152
+ . expect ( "Test input compilation failed while analyzing" ) ;
150
153
151
- // `analysis` might succeed even if there are some lint / warning errors.
152
- // Detecting these requires explicitly checking.
153
- if let Some ( guar ) = compiler. sess . dcx ( ) . has_errors ( ) {
154
- return Err ( guar ) ;
155
- }
154
+ // `analysis` might succeed even if there are some lint / warning errors.
155
+ // Detecting these requires explicitly checking.
156
+ if let Some ( _error_guaranteed ) = compiler. sess . dcx ( ) . has_errors ( ) {
157
+ panic ! ( "Test input compilation failed while linting" )
158
+ }
156
159
157
- // Run the provided callback.
158
- Ok ( query_context. enter ( callback) )
159
- } ;
160
- try_func ( ) . expect ( "Test inputs shouldn't cause compilation errors" )
160
+ // Run the provided callback.
161
+ query_context. enter ( callback)
161
162
} )
162
163
} )
163
164
}
@@ -189,21 +190,21 @@ mod tests {
189
190
use super :: * ;
190
191
191
192
#[ test]
192
- #[ should_panic( expected = "Test inputs shouldn't cause compilation errors " ) ]
193
+ #[ should_panic( expected = "Test input compilation failed while parsing " ) ]
193
194
fn test_run_compiler_for_testing_panic_when_test_input_contains_syntax_errors ( ) {
194
195
run_compiler_for_testing ( "syntax error here" , |_tcx| panic ! ( "This part shouldn't execute" ) )
195
196
}
196
197
197
198
#[ test]
198
- #[ should_panic( expected = "Test inputs shouldn't cause compilation errors " ) ]
199
+ #[ should_panic( expected = "Test input compilation failed while analyzing " ) ]
199
200
fn test_run_compiler_for_testing_panic_when_test_input_triggers_analysis_errors ( ) {
200
201
run_compiler_for_testing ( "#![feature(no_such_feature)]" , |_tcx| {
201
202
panic ! ( "This part shouldn't execute" )
202
203
} )
203
204
}
204
205
205
206
#[ test]
206
- #[ should_panic( expected = "Test inputs shouldn't cause compilation errors " ) ]
207
+ #[ should_panic( expected = "Test input compilation failed while linting " ) ]
207
208
fn test_run_compiler_for_testing_panic_when_test_input_triggers_warnings ( ) {
208
209
run_compiler_for_testing ( "pub fn foo(unused_parameter: i32) {}" , |_tcx| {
209
210
panic ! ( "This part shouldn't execute" )
0 commit comments