@@ -137,27 +137,28 @@ where
137137
138138 rustc_interface:: interface:: run_compiler ( config, |compiler| {
139139 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 ( || {
143144 query_context. enter ( |tcx| {
144145 // Explicitly force full `analysis` stage to detect compilation
145146 // errors that the earlier stages might miss. This helps ensure that the
146147 // test inputs are valid Rust (even if `callback` wouldn't
147148 // have triggered full analysis).
148- tcx. analysis ( ( ) )
149+ tcx. ensure ( ) . analysis ( ( ) ) ;
149150 } ) ;
151+ } ) )
152+ . expect ( "Test input compilation failed while analyzing" ) ;
150153
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+ }
156159
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)
161162 } )
162163 } )
163164}
@@ -189,21 +190,21 @@ mod tests {
189190 use super :: * ;
190191
191192 #[ test]
192- #[ should_panic( expected = "Test inputs shouldn't cause compilation errors " ) ]
193+ #[ should_panic( expected = "Test input compilation failed while parsing " ) ]
193194 fn test_run_compiler_for_testing_panic_when_test_input_contains_syntax_errors ( ) {
194195 run_compiler_for_testing ( "syntax error here" , |_tcx| panic ! ( "This part shouldn't execute" ) )
195196 }
196197
197198 #[ test]
198- #[ should_panic( expected = "Test inputs shouldn't cause compilation errors " ) ]
199+ #[ should_panic( expected = "Test input compilation failed while analyzing " ) ]
199200 fn test_run_compiler_for_testing_panic_when_test_input_triggers_analysis_errors ( ) {
200201 run_compiler_for_testing ( "#![feature(no_such_feature)]" , |_tcx| {
201202 panic ! ( "This part shouldn't execute" )
202203 } )
203204 }
204205
205206 #[ test]
206- #[ should_panic( expected = "Test inputs shouldn't cause compilation errors " ) ]
207+ #[ should_panic( expected = "Test input compilation failed while linting " ) ]
207208 fn test_run_compiler_for_testing_panic_when_test_input_triggers_warnings ( ) {
208209 run_compiler_for_testing ( "pub fn foo(unused_parameter: i32) {}" , |_tcx| {
209210 panic ! ( "This part shouldn't execute" )
0 commit comments