@@ -156,21 +156,22 @@ impl<'a> BuildDocTestBuilder<'a> {
156156
157157 // Up until now, we've been dealing with settings for the whole crate.
158158 // Now, infer settings for this particular test.
159+ //
160+ // Avoid tests with incompatible attributes.
161+ let opt_out = lang_str. is_some_and ( |lang_str| {
162+ lang_str. compile_fail || lang_str. test_harness || lang_str. standalone_crate
163+ } ) ;
159164 let can_be_merged = if can_merge_doctests == MergeDoctests :: Auto {
160- let mut can_merge = false ;
161- // Avoid tests with incompatible attributes.
162- can_merge |= lang_str. is_some_and ( |lang_str| {
163- !lang_str. compile_fail && !lang_str. test_harness && !lang_str. standalone_crate
164- } ) ;
165- // If it contains `#[feature]` or `#[no_std]`, we don't want it to be merged either.
166- can_merge &= !has_global_allocator
167- && crate_attrs. is_empty ( )
165+ // We try to look at the contents of the test to detect whether it should be merged.
166+ // This is not a complete list of possible failures, but it catches many cases.
167+ let will_probably_fail = has_global_allocator
168+ || !crate_attrs. is_empty ( )
168169 // If this is a merged doctest and a defined macro uses `$crate`, then the path will
169170 // not work, so better not put it into merged doctests.
170- && ! ( has_macro_def && everything_else. contains ( "$crate" ) ) ;
171- can_merge
171+ || ( has_macro_def && everything_else. contains ( "$crate" ) ) ;
172+ !opt_out && !will_probably_fail
172173 } else {
173- can_merge_doctests != MergeDoctests :: Never
174+ can_merge_doctests != MergeDoctests :: Never && !opt_out
174175 } ;
175176 DocTestBuilder {
176177 supports_color,
0 commit comments