@@ -921,19 +921,24 @@ impl UnitFor {
921921 /// whether `panic=abort` is supported for tests. Historical versions of
922922 /// rustc did not support this, but newer versions do with an unstable
923923 /// compiler flag.
924- pub fn new_test ( config : & Config , root_compile_kind : CompileKind ) -> UnitFor {
924+ ///
925+ /// Moreover, `target` is taken here for determining whether the test is
926+ /// driven by libtest harness. Cargo relaxes the panic behaviour if it is
927+ /// a custom harness, which is not required to be always unwound.
928+ pub fn new_test ( config : & Config , target : & Target , root_compile_kind : CompileKind ) -> UnitFor {
929+ // We're testing out an unstable feature (`-Zpanic-abort-tests`)
930+ // which inherits the panic setting from the dev/release profile
931+ // (basically avoid recompiles) but historical defaults required
932+ // that we always unwound.
933+ let panic_setting = if config. cli_unstable ( ) . panic_abort_tests || !target. harness ( ) {
934+ PanicSetting :: ReadProfile
935+ } else {
936+ PanicSetting :: AlwaysUnwind
937+ } ;
925938 UnitFor {
926939 host : false ,
927940 host_features : false ,
928- // We're testing out an unstable feature (`-Zpanic-abort-tests`)
929- // which inherits the panic setting from the dev/release profile
930- // (basically avoid recompiles) but historical defaults required
931- // that we always unwound.
932- panic_setting : if config. cli_unstable ( ) . panic_abort_tests {
933- PanicSetting :: ReadProfile
934- } else {
935- PanicSetting :: AlwaysUnwind
936- } ,
941+ panic_setting,
937942 root_compile_kind,
938943 artifact_target_for_features : None ,
939944 }
@@ -942,8 +947,14 @@ impl UnitFor {
942947 /// This is a special case for unit tests of a proc-macro.
943948 ///
944949 /// Proc-macro unit tests are forced to be run on the host.
945- pub fn new_host_test ( config : & Config , root_compile_kind : CompileKind ) -> UnitFor {
946- let mut unit_for = UnitFor :: new_test ( config, root_compile_kind) ;
950+ ///
951+ /// See [`UnitFor::new_test`] for more.
952+ pub fn new_host_test (
953+ config : & Config ,
954+ target : & Target ,
955+ root_compile_kind : CompileKind ,
956+ ) -> UnitFor {
957+ let mut unit_for = UnitFor :: new_test ( config, target, root_compile_kind) ;
947958 unit_for. host = true ;
948959 unit_for. host_features = true ;
949960 unit_for
0 commit comments