Skip to content

Commit 86b9d49

Browse files
committed
rustdoc: Remove more #[doc(cfg(..))] duplicates
1 parent cd8377d commit 86b9d49

File tree

3 files changed

+120
-19
lines changed

3 files changed

+120
-19
lines changed

src/librustdoc/clean/cfg.rs

+38-16
Original file line numberDiff line numberDiff line change
@@ -202,23 +202,34 @@ impl ops::Not for Cfg {
202202

203203
impl ops::BitAndAssign for Cfg {
204204
fn bitand_assign(&mut self, other: Cfg) {
205-
if *self == other {
206-
return;
207-
}
208205
match (self, other) {
209206
(&mut Cfg::False, _) | (_, Cfg::True) => {}
210207
(s, Cfg::False) => *s = Cfg::False,
211208
(s @ &mut Cfg::True, b) => *s = b,
212-
(&mut Cfg::All(ref mut a), Cfg::All(ref mut b)) => a.append(b),
213-
(&mut Cfg::All(ref mut a), ref mut b) => a.push(mem::replace(b, Cfg::True)),
209+
(&mut Cfg::All(ref mut a), Cfg::All(ref mut b)) => {
210+
for c in b.drain(..) {
211+
if !a.contains(&c) {
212+
a.push(c);
213+
}
214+
}
215+
}
216+
(&mut Cfg::All(ref mut a), ref mut b) => {
217+
if !a.contains(b) {
218+
a.push(mem::replace(b, Cfg::True));
219+
}
220+
}
214221
(s, Cfg::All(mut a)) => {
215222
let b = mem::replace(s, Cfg::True);
216-
a.push(b);
223+
if !a.contains(&b) {
224+
a.push(b);
225+
}
217226
*s = Cfg::All(a);
218227
}
219228
(s, b) => {
220-
let a = mem::replace(s, Cfg::True);
221-
*s = Cfg::All(vec![a, b]);
229+
if *s != b {
230+
let a = mem::replace(s, Cfg::True);
231+
*s = Cfg::All(vec![a, b]);
232+
}
222233
}
223234
}
224235
}
@@ -234,23 +245,34 @@ impl ops::BitAnd for Cfg {
234245

235246
impl ops::BitOrAssign for Cfg {
236247
fn bitor_assign(&mut self, other: Cfg) {
237-
if *self == other {
238-
return;
239-
}
240248
match (self, other) {
241249
(&mut Cfg::True, _) | (_, Cfg::False) => {}
242250
(s, Cfg::True) => *s = Cfg::True,
243251
(s @ &mut Cfg::False, b) => *s = b,
244-
(&mut Cfg::Any(ref mut a), Cfg::Any(ref mut b)) => a.append(b),
245-
(&mut Cfg::Any(ref mut a), ref mut b) => a.push(mem::replace(b, Cfg::True)),
252+
(&mut Cfg::Any(ref mut a), Cfg::Any(ref mut b)) => {
253+
for c in b.drain(..) {
254+
if !a.contains(&c) {
255+
a.push(c);
256+
}
257+
}
258+
}
259+
(&mut Cfg::Any(ref mut a), ref mut b) => {
260+
if !a.contains(b) {
261+
a.push(mem::replace(b, Cfg::True));
262+
}
263+
}
246264
(s, Cfg::Any(mut a)) => {
247265
let b = mem::replace(s, Cfg::True);
248-
a.push(b);
266+
if !a.contains(&b) {
267+
a.push(b);
268+
}
249269
*s = Cfg::Any(a);
250270
}
251271
(s, b) => {
252-
let a = mem::replace(s, Cfg::True);
253-
*s = Cfg::Any(vec![a, b]);
272+
if *s != b {
273+
let a = mem::replace(s, Cfg::True);
274+
*s = Cfg::Any(vec![a, b]);
275+
}
254276
}
255277
}
256278
}

src/librustdoc/clean/cfg/tests.rs

+52
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ fn test_cfg_and() {
8787
x &= word_cfg("test3");
8888
assert_eq!(x, word_cfg("test3"));
8989

90+
x &= word_cfg("test3");
91+
assert_eq!(x, word_cfg("test3"));
92+
93+
x &= word_cfg("test4");
94+
assert_eq!(x, Cfg::All(vec![word_cfg("test3"), word_cfg("test4")]));
95+
9096
x &= word_cfg("test4");
9197
assert_eq!(x, Cfg::All(vec![word_cfg("test3"), word_cfg("test4")]));
9298

@@ -105,6 +111,18 @@ fn test_cfg_and() {
105111
])
106112
);
107113

114+
x &= Cfg::All(vec![word_cfg("test6"), word_cfg("test7")]);
115+
assert_eq!(
116+
x,
117+
Cfg::All(vec![
118+
word_cfg("test3"),
119+
word_cfg("test4"),
120+
word_cfg("test5"),
121+
word_cfg("test6"),
122+
word_cfg("test7"),
123+
])
124+
);
125+
108126
let mut y = Cfg::Any(vec![word_cfg("a"), word_cfg("b")]);
109127
y &= x;
110128
assert_eq!(
@@ -119,6 +137,14 @@ fn test_cfg_and() {
119137
])
120138
);
121139

140+
let mut z = word_cfg("test8");
141+
z &= Cfg::All(vec![word_cfg("test9"), word_cfg("test10")]);
142+
assert_eq!(z, Cfg::All(vec![word_cfg("test9"), word_cfg("test10"), word_cfg("test8")]));
143+
144+
let mut z = word_cfg("test11");
145+
z &= Cfg::All(vec![word_cfg("test11"), word_cfg("test12")]);
146+
assert_eq!(z, Cfg::All(vec![word_cfg("test11"), word_cfg("test12")]));
147+
122148
assert_eq!(
123149
word_cfg("a") & word_cfg("b") & word_cfg("c"),
124150
Cfg::All(vec![word_cfg("a"), word_cfg("b"), word_cfg("c")])
@@ -145,6 +171,12 @@ fn test_cfg_or() {
145171
x |= word_cfg("test3");
146172
assert_eq!(x, word_cfg("test3"));
147173

174+
x |= word_cfg("test3");
175+
assert_eq!(x, word_cfg("test3"));
176+
177+
x |= word_cfg("test4");
178+
assert_eq!(x, Cfg::Any(vec![word_cfg("test3"), word_cfg("test4")]));
179+
148180
x |= word_cfg("test4");
149181
assert_eq!(x, Cfg::Any(vec![word_cfg("test3"), word_cfg("test4")]));
150182

@@ -163,6 +195,18 @@ fn test_cfg_or() {
163195
])
164196
);
165197

198+
x |= Cfg::Any(vec![word_cfg("test6"), word_cfg("test7")]);
199+
assert_eq!(
200+
x,
201+
Cfg::Any(vec![
202+
word_cfg("test3"),
203+
word_cfg("test4"),
204+
word_cfg("test5"),
205+
word_cfg("test6"),
206+
word_cfg("test7"),
207+
])
208+
);
209+
166210
let mut y = Cfg::All(vec![word_cfg("a"), word_cfg("b")]);
167211
y |= x;
168212
assert_eq!(
@@ -177,6 +221,14 @@ fn test_cfg_or() {
177221
])
178222
);
179223

224+
let mut z = word_cfg("test8");
225+
z |= Cfg::Any(vec![word_cfg("test9"), word_cfg("test10")]);
226+
assert_eq!(z, Cfg::Any(vec![word_cfg("test9"), word_cfg("test10"), word_cfg("test8")]));
227+
228+
let mut z = word_cfg("test11");
229+
z |= Cfg::Any(vec![word_cfg("test11"), word_cfg("test12")]);
230+
assert_eq!(z, Cfg::Any(vec![word_cfg("test11"), word_cfg("test12")]));
231+
180232
assert_eq!(
181233
word_cfg("a") | word_cfg("b") | word_cfg("c"),
182234
Cfg::Any(vec![word_cfg("a"), word_cfg("b"), word_cfg("c")])

src/test/rustdoc/duplicate-cfg.rs

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
1+
// ignore-tidy-linelength
2+
13
#![crate_name = "foo"]
24
#![feature(doc_cfg)]
35

4-
// @has 'foo/index.html'
5-
// @!has '-' '//*[@class="stab portability"]' 'feature="sync" and'
6-
// @has '-' '//*[@class="stab portability"]' 'feature="sync"'
6+
// @has 'foo/struct.Foo.html'
7+
// @has '-' '//*[@class="stab portability"]' 'This is supported on feature="sync" only.'
78
#[doc(cfg(feature = "sync"))]
89
#[doc(cfg(feature = "sync"))]
910
pub struct Foo;
1011

12+
// @has 'foo/bar/struct.Bar.html'
13+
// @has '-' '//*[@class="stab portability"]' 'This is supported on feature="sync" only.'
1114
#[doc(cfg(feature = "sync"))]
1215
pub mod bar {
1316
#[doc(cfg(feature = "sync"))]
1417
pub struct Bar;
1518
}
19+
20+
// @has 'foo/baz/struct.Baz.html'
21+
// @has '-' '//*[@class="stab portability"]' 'This is supported on feature="sync" and feature="send" only.'
22+
#[doc(cfg(all(feature = "sync", feature = "send")))]
23+
pub mod baz {
24+
#[doc(cfg(feature = "sync"))]
25+
pub struct Baz;
26+
}
27+
28+
// @has 'foo/qux/struct.Qux.html'
29+
// @has '-' '//*[@class="stab portability"]' 'This is supported on feature="sync" and feature="send" only.'
30+
#[doc(cfg(feature = "sync"))]
31+
pub mod qux {
32+
#[doc(cfg(all(feature = "sync", feature = "send")))]
33+
pub struct Qux;
34+
}
35+
36+
// @has 'foo/quux/struct.Quux.html'
37+
// @has '-' '//*[@class="stab portability"]' 'This is supported on feature="sync" and feature="send" and foo and bar only.'
38+
#[doc(cfg(all(feature = "sync", feature = "send", foo)))]
39+
pub mod quux {
40+
#[doc(cfg(all(feature = "send", feature = "sync", bar)))]
41+
pub struct Quux;
42+
}

0 commit comments

Comments
 (0)