@@ -58,6 +58,7 @@ impl DocTest {
58
58
found_extern_crate,
59
59
supports_color,
60
60
has_global_allocator,
61
+ has_macro_def,
61
62
..
62
63
} ,
63
64
failed_ast,
@@ -85,6 +86,16 @@ impl DocTest {
85
86
can_be_merged : false ,
86
87
} ;
87
88
} ;
89
+ // If the AST returned an error, we don't want this doctest to be merged with the
90
+ // others. Same if it contains `#[feature]` or `#[no_std]`.
91
+ let can_be_merged = can_merge_doctests
92
+ && !failed_ast
93
+ && !has_no_std
94
+ && !has_features
95
+ && !has_global_allocator
96
+ // If this is a merged doctest and a defined macro uses `$crate`, then the path will
97
+ // not work, so better not put it into merged doctests.
98
+ && !( has_macro_def && everything_else. contains ( "$crate" ) ) ;
88
99
Self {
89
100
supports_color,
90
101
has_main_fn,
@@ -95,9 +106,7 @@ impl DocTest {
95
106
already_has_extern_crate : found_extern_crate,
96
107
test_id,
97
108
failed_ast : false ,
98
- // If the AST returned an error, we don't want this doctest to be merged with the
99
- // others. Same if it contains `#[feature]` or `#[no_std]`.
100
- can_be_merged : !failed_ast && !has_no_std && !has_features && !has_global_allocator,
109
+ can_be_merged,
101
110
}
102
111
}
103
112
@@ -309,6 +318,7 @@ fn parse_source(
309
318
}
310
319
}
311
320
ast:: ItemKind :: MacCall ( ..) => info. found_macro = true ,
321
+ ast:: ItemKind :: MacroDef ( ..) => info. has_macro_def = true ,
312
322
_ => { }
313
323
}
314
324
}
@@ -346,6 +356,7 @@ struct ParseSourceInfo {
346
356
found_macro : bool ,
347
357
supports_color : bool ,
348
358
has_global_allocator : bool ,
359
+ has_macro_def : bool ,
349
360
}
350
361
351
362
fn check_for_main_and_extern_crate (
0 commit comments