Skip to content

Commit bb6de3c

Browse files
add feature gate doc_masked and tests
1 parent c491e19 commit bb6de3c

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# `doc_masked`
2+
3+
The tracking issue for this feature is: [TODO](TODO)
4+
5+
-----
6+
7+
The `doc_masked` feature allows a crate to exclude types from a given crate from appearing in lists
8+
of trait implementations. The specifics of the feature are as follows:
9+
10+
1. When rustdoc encounters an `extern crate` statement annotated with a `#[doc(masked)]` attribute,
11+
it marks the crate as being masked.
12+
13+
2. When listing traits a given type implements, rustdoc ensures that traits from masked crates are
14+
not emitted into the documentation.
15+
16+
3. When listing types that implement a given trait, rustdoc ensures that types from masked crates
17+
are not emitted into the documentation.
18+
19+
This feature was introduced in PR [TODO](TODO) to ensure that compiler-internal and
20+
implementation-specific types and traits were not included in the standard library's documentation.
21+
Such types would introduce broken links into the documentation.
22+
23+
```rust
24+
#![feature(doc_masked)]
25+
26+
// Since std is automatically imported, we need to import it into a separate name to apply the
27+
// attribute. This is used as a simple demonstration, but any extern crate statement will suffice.
28+
#[doc(masked)]
29+
extern crate std as realstd;
30+
31+
/// A sample marker trait that exists on floating-point numbers, even though this page won't list
32+
/// them!
33+
pub trait MyMarker { }
34+
35+
impl MyMarker for f32 { }
36+
impl MyMarker for f64 { }
37+
```

src/libstd/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313
#![feature(unwind_attributes)]
314314
#![feature(vec_push_all)]
315315
#![feature(doc_cfg)]
316+
#![feature(doc_masked)]
316317
#![cfg_attr(test, feature(update_panic_count))]
317318

318319
#![default_lib_allocator]

src/libsyntax/feature_gate.rs

+6
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ declare_features! (
376376

377377
// #[doc(cfg(...))]
378378
(active, doc_cfg, "1.21.0", Some(43781)),
379+
// #[doc(masked)]
380+
(active, doc_masked, "1.21.0", None),
379381

380382
// allow `#[must_use]` on functions (RFC 1940)
381383
(active, fn_must_use, "1.21.0", Some(43302)),
@@ -1229,6 +1231,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
12291231
gate_feature_post!(&self, doc_cfg, attr.span,
12301232
"#[doc(cfg(...))] is experimental"
12311233
);
1234+
} else if content.iter().any(|c| c.check_name("masked")) {
1235+
gate_feature_post!(&self, doc_masked, attr.span,
1236+
"#[doc(masked)] is experimental"
1237+
);
12321238
}
12331239
}
12341240
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[doc(masked)] //~ ERROR: #[doc(masked)] is experimental
12+
extern crate std as realstd;
13+
14+
fn main() {}

src/test/rustdoc/doc-masked.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(doc_masked)]
12+
13+
#![doc(masked)]
14+
extern crate std as realstd;
15+
16+
// @has doc_masked/struct.LocalStruct.html
17+
// @has - '//*[@class="impl"]//code' 'impl LocalTrait for LocalStruct'
18+
// @!has - '//*[@class="impl"]//code' 'impl Copy for LocalStruct'
19+
#[derive(Copy, Clone)]
20+
pub struct LocalStruct;
21+
22+
// @has doc_masked/trait.LocalTrait.html
23+
// @has - '//*[@id="implementors-list"]//code' 'impl LocalTrait for LocalStruct'
24+
// @!has - '//*[@id="implementors-list"]//code' 'impl LocalTrait for usize'
25+
pub trait LocalTrait { }
26+
27+
impl LocalTrait for LocalStruct { }
28+
29+
impl LocalTrait for usize { }

0 commit comments

Comments
 (0)