Skip to content

Commit 23fe4a0

Browse files
Wip
1 parent e5b2a4b commit 23fe4a0

File tree

1 file changed

+0
-120
lines changed

1 file changed

+0
-120
lines changed

src/librustdoc/clean/cfg.rs

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::sync::Arc;
77
use std::{fmt, mem, ops};
88

99
use itertools::Either;
10-
use rustc_ast::{LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit};
1110
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1211
use rustc_data_structures::thin_vec::{ThinVec, thin_vec};
1312
use rustc_hir as hir;
@@ -29,12 +28,6 @@ mod tests;
2928
#[cfg_attr(test, derive(PartialEq))]
3029
pub(crate) struct Cfg(CfgEntry);
3130

32-
#[derive(PartialEq, Debug)]
33-
pub(crate) struct InvalidCfgError {
34-
pub(crate) msg: &'static str,
35-
pub(crate) span: Span,
36-
}
37-
3831
/// Whether the configuration consists of just `Cfg` or `Not`.
3932
fn is_simple_cfg(cfg: &CfgEntry) -> bool {
4033
match cfg {
@@ -105,106 +98,6 @@ fn should_capitalize_first_letter(cfg: &CfgEntry) -> bool {
10598
}
10699

107100
impl Cfg {
108-
/// Parses a `MetaItemInner` into a `Cfg`.
109-
fn parse_nested(
110-
nested_cfg: &MetaItemInner,
111-
exclude: &FxHashSet<NameValueCfg>,
112-
) -> Result<Option<Cfg>, InvalidCfgError> {
113-
match nested_cfg {
114-
MetaItemInner::MetaItem(cfg) => Cfg::parse_without(cfg, exclude),
115-
MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => {
116-
Ok(Some(Cfg(CfgEntry::Bool(*b, DUMMY_SP))))
117-
}
118-
MetaItemInner::Lit(lit) => {
119-
Err(InvalidCfgError { msg: "unexpected literal", span: lit.span })
120-
}
121-
}
122-
}
123-
124-
fn parse_without(
125-
cfg: &MetaItem,
126-
exclude: &FxHashSet<NameValueCfg>,
127-
) -> Result<Option<Cfg>, InvalidCfgError> {
128-
let name = match cfg.ident() {
129-
Some(ident) => ident.name,
130-
None => {
131-
return Err(InvalidCfgError {
132-
msg: "expected a single identifier",
133-
span: cfg.span,
134-
});
135-
}
136-
};
137-
match cfg.kind {
138-
MetaItemKind::Word => {
139-
if exclude.contains(&NameValueCfg::new(name)) {
140-
Ok(None)
141-
} else {
142-
Ok(Some(Cfg(CfgEntry::NameValue { name, value: None, span: DUMMY_SP })))
143-
}
144-
}
145-
MetaItemKind::NameValue(ref lit) => match lit.kind {
146-
LitKind::Str(value, _) => {
147-
if exclude.contains(&NameValueCfg::new_value(name, value)) {
148-
Ok(None)
149-
} else {
150-
Ok(Some(Cfg(CfgEntry::NameValue {
151-
name,
152-
value: Some(value),
153-
span: DUMMY_SP,
154-
})))
155-
}
156-
}
157-
_ => Err(InvalidCfgError {
158-
// FIXME: if the main #[cfg] syntax decided to support non-string literals,
159-
// this should be changed as well.
160-
msg: "value of cfg option should be a string literal",
161-
span: lit.span,
162-
}),
163-
},
164-
MetaItemKind::List(ref items) => {
165-
let orig_len = items.len();
166-
let mut sub_cfgs =
167-
items.iter().filter_map(|i| Cfg::parse_nested(i, exclude).transpose());
168-
let ret = match name {
169-
sym::all => {
170-
sub_cfgs.try_fold(Cfg(CfgEntry::Bool(true, DUMMY_SP)), |x, y| Ok(x & y?))
171-
}
172-
sym::any => {
173-
sub_cfgs.try_fold(Cfg(CfgEntry::Bool(false, DUMMY_SP)), |x, y| Ok(x | y?))
174-
}
175-
sym::not => {
176-
if orig_len == 1 {
177-
let mut sub_cfgs = sub_cfgs.collect::<Vec<_>>();
178-
if sub_cfgs.len() == 1 {
179-
Ok(!sub_cfgs.pop().unwrap()?)
180-
} else {
181-
return Ok(None);
182-
}
183-
} else {
184-
Err(InvalidCfgError { msg: "expected 1 cfg-pattern", span: cfg.span })
185-
}
186-
}
187-
_ => Err(InvalidCfgError { msg: "invalid predicate", span: cfg.span }),
188-
};
189-
match ret {
190-
Ok(c) => Ok(Some(c)),
191-
Err(e) => Err(e),
192-
}
193-
}
194-
}
195-
}
196-
197-
/// Parses a `MetaItem` into a `Cfg`.
198-
///
199-
/// The `MetaItem` should be the content of the `#[cfg(...)]`, e.g., `unix` or
200-
/// `target_os = "redox"`.
201-
///
202-
/// If the content is not properly formatted, it will return an error indicating what and where
203-
/// the error is.
204-
pub(crate) fn parse(cfg: &MetaItemInner) -> Result<Cfg, InvalidCfgError> {
205-
Self::parse_nested(cfg, &FxHashSet::default()).map(|ret| ret.unwrap())
206-
}
207-
208101
/// Renders the configuration for human display, as a short HTML description.
209102
pub(crate) fn render_short_html(&self) -> String {
210103
let mut msg = Display(&self.0, Format::ShortHtml).to_string();
@@ -644,10 +537,6 @@ impl NameValueCfg {
644537
fn new(name: Symbol) -> Self {
645538
Self { name, value: None }
646539
}
647-
648-
fn new_value(name: Symbol, value: Symbol) -> Self {
649-
Self { name, value: Some(value) }
650-
}
651540
}
652541

653542
impl<'a> From<&'a CfgEntry> for NameValueCfg {
@@ -751,15 +640,6 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
751640
tcx: TyCtxt<'_>,
752641
cfg_info: &mut CfgInfo,
753642
) -> Option<Arc<Cfg>> {
754-
fn single<T: IntoIterator>(it: T) -> Option<T::Item> {
755-
let mut iter = it.into_iter();
756-
let item = iter.next()?;
757-
if iter.next().is_some() {
758-
return None;
759-
}
760-
Some(item)
761-
}
762-
763643
fn check_changed_auto_active_status(
764644
changed_auto_active_status: &mut Option<rustc_span::Span>,
765645
attr_span: Span,

0 commit comments

Comments
 (0)