Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 211fde6

Browse files
If there are crate attributes, we prevent doctest to be merged with others
1 parent d276920 commit 211fde6

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

src/librustdoc/doctest/make.rs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,8 @@ impl DocTestBuilder {
4343
// If `test_id` is `None`, it means we're generating code for a code example "run" link.
4444
test_id: Option<String>,
4545
) -> Self {
46-
let SourceInfo {
47-
crate_attrs,
48-
maybe_crate_attrs,
49-
crates,
50-
everything_else,
51-
has_features,
52-
has_no_std,
53-
} = partition_source(source, edition);
46+
let SourceInfo { crate_attrs, maybe_crate_attrs, crates, everything_else } =
47+
partition_source(source, edition);
5448

5549
// Uses librustc_ast to parse the doctest and find if there's a main fn and the extern
5650
// crate already is included.
@@ -92,9 +86,8 @@ impl DocTestBuilder {
9286
// others. Same if it contains `#[feature]` or `#[no_std]`.
9387
let can_be_merged = can_merge_doctests
9488
&& !failed_ast
95-
&& !has_no_std
96-
&& !has_features
9789
&& !has_global_allocator
90+
&& crate_attrs.is_empty()
9891
// If this is a merged doctest and a defined macro uses `$crate`, then the path will
9992
// not work, so better not put it into merged doctests.
10093
&& !(has_macro_def && everything_else.contains("$crate"));
@@ -427,8 +420,6 @@ fn check_for_main_and_extern_crate(
427420
enum AttrKind {
428421
CrateAttr,
429422
Attr,
430-
Feature,
431-
NoStd,
432423
}
433424

434425
/// Returns `Some` if the attribute is complete and `Some(true)` if it is an attribute that can be
@@ -473,11 +464,7 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> Option<AttrKind>
473464
Ok(attr) => {
474465
let attr_name = attr.name_or_empty();
475466

476-
if attr_name == sym::feature {
477-
Some(AttrKind::Feature)
478-
} else if attr_name == sym::no_std {
479-
Some(AttrKind::NoStd)
480-
} else if not_crate_attrs.contains(&attr_name) {
467+
if not_crate_attrs.contains(&attr_name) {
481468
// There is one exception to these attributes:
482469
// `#![allow(internal_features)]`. If this attribute is used, we need to
483470
// consider it only as a crate-level attribute.
@@ -511,14 +498,6 @@ fn handle_attr(mod_attr_pending: &mut String, source_info: &mut SourceInfo, edit
511498
let push_to = match attr_kind {
512499
AttrKind::CrateAttr => &mut source_info.crate_attrs,
513500
AttrKind::Attr => &mut source_info.maybe_crate_attrs,
514-
AttrKind::Feature => {
515-
source_info.has_features = true;
516-
&mut source_info.crate_attrs
517-
}
518-
AttrKind::NoStd => {
519-
source_info.has_no_std = true;
520-
&mut source_info.crate_attrs
521-
}
522501
};
523502
push_to.push_str(mod_attr_pending);
524503
push_to.push('\n');
@@ -535,8 +514,6 @@ struct SourceInfo {
535514
maybe_crate_attrs: String,
536515
crates: String,
537516
everything_else: String,
538-
has_features: bool,
539-
has_no_std: bool,
540517
}
541518

542519
fn partition_source(s: &str, edition: Edition) -> SourceInfo {

0 commit comments

Comments
 (0)