Skip to content

Commit ab67c37

Browse files
committed
Auto merge of #148660 - fmease:cross-crate-cfg, r=GuillaumeGomez
Encode cfg trace, not its early counterpart to fix cross-crate `doc(auto_cfg)` Fixes #141301. <details><summary>Rambling about <code>target_feature</code> which I didn't touch here</summary> Regarding #141301 (comment) (`#[target_feature(enable = …)]` on inlined cross-crate re-exports), it has the same underlying cause (namely, we neither encode `target_feature` nor `AttributeKind::TargetFeature` in the crate metadata). However, I didn't make that change because I first want to experiment with querying `TyCtxt::codegen_fn_attrs` in rustdoc instead which already works cross-crate (and also use to it for reconstructing `no_mangle`, `export_name`, `link_section` to avoid encoding these attributes unnecessarily (basically reverting #144050) as suggested in #144004 (comment)). </details> r? GuillaumeGomez
2 parents 20f1c04 + 6419f9a commit ab67c37

File tree

8 files changed

+69
-29
lines changed

8 files changed

+69
-29
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,15 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
425425
List: &["predicate"],
426426
"https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute"
427427
),
428-
DuplicatesOk, EncodeCrossCrate::Yes
428+
DuplicatesOk, EncodeCrossCrate::No
429429
),
430430
ungated!(
431431
cfg_attr, Normal,
432432
template!(
433433
List: &["predicate, attr1, attr2, ..."],
434434
"https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute"
435435
),
436-
DuplicatesOk, EncodeCrossCrate::Yes
436+
DuplicatesOk, EncodeCrossCrate::No
437437
),
438438

439439
// Testing:
@@ -1115,7 +1115,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
11151115
// can only be generated by the compiler.
11161116
ungated!(
11171117
cfg_trace, Normal, template!(Word /* irrelevant */), DuplicatesOk,
1118-
EncodeCrossCrate::No
1118+
EncodeCrossCrate::Yes
11191119
),
11201120
ungated!(
11211121
cfg_attr_trace, Normal, template!(Word /* irrelevant */), DuplicatesOk,

tests/rustdoc/doc_auto_cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Test covering RFC 3631 features.
1+
// Basic tests covering RFC 3631 features.
22

33
#![crate_name = "foo"]
44
#![feature(doc_cfg)]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ compile-flags: --cfg extension
2+
3+
#[cfg(extension)]
4+
pub fn compute() {}
5+
6+
pub struct Type;
7+
8+
impl Type {
9+
#[cfg(extension)]
10+
pub fn transform(self) -> Self { self }
11+
}

tests/rustdoc/inline_cross/auxiliary/u_default_generic_args.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Test that `doc(auto_cfg)` works with inlined cross-crate re-exports.
2+
//@ compile-flags: --cfg feature="extra" --cfg feature="addon"
3+
4+
#![feature(doc_cfg)]
5+
#![crate_name = "it"]
6+
7+
//@ aux-build: doc-auto-cfg.rs
8+
extern crate doc_auto_cfg;
9+
10+
// The cfg is on the reexported item.
11+
// issue: <https://github.com/rust-lang/rust/issues/141301>
12+
pub mod pre {
13+
//@ has 'it/pre/index.html' '//*[@class="stab portability"]' 'extension'
14+
//@ has 'it/pre/fn.compute.html' '//*[@class="stab portability"]' \
15+
// 'Available on extension only.'
16+
pub use doc_auto_cfg::*;
17+
18+
// Indeed, this reexport doesn't have a cfg badge!
19+
// That's because this crate (`it`) wouldn't've compiled in the first place
20+
// if `--cfg extension` wasn't passed when compiling the auxiliary crate
21+
// contrary to the glob import above since `compute` wouldn't exist.
22+
//
23+
//@ !has 'it/pre/fn.calculate.html' '//*[@class="stab portability"]' \
24+
// 'Available on extension only.'
25+
pub use doc_auto_cfg::compute as calculate;
26+
27+
// FIXME(HtmlDocCk): Ideally I would've used the following XPath here:
28+
// `*[@class="impl-items"][*[@id="method.transform"]]//*[@class="stab portability"]`
29+
//
30+
//@ has 'it/pre/struct.Kind.html' '//*[@id="method.transform"]' ''
31+
//@ has - '//*[@class="impl-items"]//*[@class="stab portability"]' \
32+
// 'Available on extension only.'
33+
pub use doc_auto_cfg::Type as Kind;
34+
}
35+
36+
// The cfg is on the reexport.
37+
pub mod post {
38+
// issue: <https://github.com/rust-lang/rust/issues/113982>
39+
//@ has 'it/post/index.html' '//*[@class="stab portability"]' 'extra'
40+
//@ has - '//*[@class="stab portability"]' 'extra and extension'
41+
//@ has 'it/post/struct.Type.html' '//*[@class="stab portability"]' \
42+
// 'Available on crate feature extra only.'
43+
//@ has 'it/post/fn.compute.html' '//*[@class="stab portability"]' \
44+
// 'Available on crate feature extra and extension only.'
45+
#[cfg(feature = "extra")]
46+
pub use doc_auto_cfg::*;
47+
48+
//@ has 'it/post/index.html' '//*[@class="stab portability"]' 'addon'
49+
//@ has 'it/post/struct.Addon.html' '//*[@class="stab portability"]' \
50+
// 'Available on crate feature addon only.'
51+
#[cfg(feature = "addon")]
52+
pub use doc_auto_cfg::Type as Addon;
53+
}

tests/rustdoc/reexport/auxiliary/issue-113982-doc_auto_cfg-reexport-foreign.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/rustdoc/reexport/doc_auto_cfg-reexport-foreign-113982.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/rustdoc/reexport/glob-reexport-attribute-merge-doc-auto-cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This test ensures that non-glob reexports don't get their attributes merge with
1+
// This test ensures that non-glob reexports don't get their attributes merged with
22
// the reexported item whereas glob reexports do with the `doc_auto_cfg` feature.
33

44
#![crate_name = "foo"]

0 commit comments

Comments
 (0)