Skip to content

Commit 33d0327

Browse files
Keep a list of CfgEntry instead of just one
1 parent a5e8db9 commit 33d0327

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl DocParser {
225225
args: &ArgParser<'_>,
226226
) {
227227
if let Some(cfg_entry) = super::cfg::parse_cfg(cx, args) {
228-
self.attribute.cfg = Some(cfg_entry);
228+
self.attribute.cfg.push(cfg_entry);
229229
}
230230
}
231231

@@ -524,6 +524,9 @@ impl<S: Stage> AttributeParser<S> for DocParser {
524524

525525
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
526526
if self.nb_doc_attrs != 0 {
527+
if std::env::var("LOL").is_ok() {
528+
eprintln!("+++++> {:#?}", self.attribute);
529+
}
527530
Some(AttributeKind::Doc(Box::new(self.attribute)))
528531
} else {
529532
None

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ pub struct DocAttribute {
479479
pub inline: Option<(DocInline, Span)>,
480480

481481
// unstable
482-
pub cfg: Option<CfgEntry>,
482+
pub cfg: ThinVec<CfgEntry>,
483483
pub auto_cfg: ThinVec<CfgHideShow>,
484484
/// This is for `#[doc(auto_cfg = false|true)]`.
485485
pub auto_cfg_change: Option<(bool, Span)>,
@@ -512,7 +512,7 @@ impl Default for DocAttribute {
512512
aliases: FxIndexMap::default(),
513513
hidden: None,
514514
inline: None,
515-
cfg: None,
515+
cfg: ThinVec::new(),
516516
auto_cfg: ThinVec::new(),
517517
auto_cfg_change: None,
518518
fake_variadic: None,

src/librustdoc/clean/cfg.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::html::escape::Escape;
2424
#[cfg(test)]
2525
mod tests;
2626

27-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
27+
#[derive(Clone, Debug, Hash)]
2828
pub(crate) struct Cfg(CfgEntry);
2929

3030
#[derive(PartialEq, Debug)]
@@ -299,13 +299,13 @@ impl Cfg {
299299
///
300300
/// See `tests::test_simplify_with` for examples.
301301
pub(crate) fn simplify_with(&self, assume: &Self) -> Option<Self> {
302-
if self == assume {
302+
if self.0.is_equivalent_to(&assume.0) {
303303
None
304304
} else if let CfgEntry::All(a, _) = &self.0 {
305305
let mut sub_cfgs: ThinVec<CfgEntry> = if let CfgEntry::All(b, _) = &assume.0 {
306-
a.iter().filter(|a| !b.contains(a)).cloned().collect()
306+
a.iter().filter(|a| !b.iter().any(|b| a.is_equivalent_to(b))).cloned().collect()
307307
} else {
308-
a.iter().filter(|&a| *a != assume.0).cloned().collect()
308+
a.iter().filter(|&a| !a.is_equivalent_to(&assume.0)).cloned().collect()
309309
};
310310
let len = sub_cfgs.len();
311311
match len {
@@ -314,7 +314,7 @@ impl Cfg {
314314
_ => Some(Cfg(CfgEntry::All(sub_cfgs, DUMMY_SP))),
315315
}
316316
} else if let CfgEntry::All(b, _) = &assume.0
317-
&& b.contains(&self.0)
317+
&& b.iter().any(|b| b.is_equivalent_to(&self.0))
318318
{
319319
None
320320
} else {
@@ -838,7 +838,7 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
838838
cfg_info.parent_is_doc_cfg = true;
839839
}
840840
for attr in doc_cfg {
841-
if let Some(new_cfg) = attr.cfg.clone() {
841+
for new_cfg in attr.cfg.clone() {
842842
cfg_info.current_cfg &= Cfg(new_cfg);
843843
}
844844
}

src/librustdoc/passes/collect_trait_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
6767
let mut parent = Some(tcx.parent(impl_def_id));
6868
while let Some(did) = parent {
6969
attr_buf.extend(tcx.get_all_attrs(did).iter().filter_map(|attr| match attr {
70-
Attribute::Parsed(AttributeKind::Doc(d)) if d.cfg.is_some() => {
70+
Attribute::Parsed(AttributeKind::Doc(d)) if !d.cfg.is_empty() => {
7171
let mut new_attr = DocAttribute::default();
7272
new_attr.cfg = d.cfg.clone();
7373
Some(Attribute::Parsed(AttributeKind::Doc(Box::new(new_attr))))

src/librustdoc/passes/propagate_doc_cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct CfgPropagator<'a, 'tcx> {
3434
fn add_only_cfg_attributes(attrs: &mut Vec<Attribute>, new_attrs: &[Attribute]) {
3535
for attr in new_attrs {
3636
if let Attribute::Parsed(AttributeKind::Doc(d)) = attr
37-
&& d.cfg.is_some()
37+
&& !d.cfg.is_empty()
3838
{
3939
let mut new_attr = DocAttribute::default();
4040
new_attr.cfg = d.cfg.clone();

0 commit comments

Comments
 (0)