@@ -1862,6 +1862,31 @@ impl<'test> TestCx<'test> {
18621862 }
18631863 }
18641864
1865+ if self . config . optimize_tests && !is_rustdoc {
1866+ match self . config . mode {
1867+ Ui => {
1868+ // If optimize-tests is true we still only want to optimize tests that actually get
1869+ // executed and that don't specify their own optimization levels.
1870+ // Note: aux libs don't have a pass-mode, so they won't get optimized
1871+ // unless compile-flags are set in the aux file.
1872+ if self . config . optimize_tests
1873+ && self . props . pass_mode ( & self . config ) == Some ( PassMode :: Run )
1874+ && !self
1875+ . props
1876+ . compile_flags
1877+ . iter ( )
1878+ . any ( |arg| arg == "-O" || arg. contains ( "opt-level" ) )
1879+ {
1880+ rustc. arg ( "-O" ) ;
1881+ }
1882+ }
1883+ DebugInfo => { /* debuginfo tests must be unoptimized */ }
1884+ _ => {
1885+ rustc. arg ( "-O" ) ;
1886+ }
1887+ }
1888+ }
1889+
18651890 match self . config . mode {
18661891 Incremental => {
18671892 // If we are extracting and matching errors in the new
@@ -1875,18 +1900,6 @@ impl<'test> TestCx<'test> {
18751900 rustc. arg ( "-Zdeduplicate-diagnostics=no" ) ;
18761901 }
18771902 Ui => {
1878- // If optimize-tests is true we still only want to optimize tests that actually get
1879- // executed and that don't specify their own optimization levels
1880- if self . config . optimize_tests
1881- && self . props . pass_mode ( & self . config ) == Some ( PassMode :: Run )
1882- && !self
1883- . props
1884- . compile_flags
1885- . iter ( )
1886- . any ( |arg| arg == "-O" || arg. contains ( "opt-level" ) )
1887- {
1888- rustc. arg ( "-O" ) ;
1889- }
18901903 if !self . props . compile_flags . iter ( ) . any ( |s| s. starts_with ( "--error-format" ) ) {
18911904 rustc. args ( & [ "--error-format" , "json" ] ) ;
18921905 rustc. args ( & [ "--json" , "future-incompat" ] ) ;
0 commit comments