Skip to content

Commit 3ea9462

Browse files
Remove Cfg::matches and use eval_config_entry instead
1 parent 64aaeac commit 3ea9462

File tree

3 files changed

+7
-26
lines changed

3 files changed

+7
-26
lines changed

src/librustdoc/clean/cfg.rs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_hir as hir;
1414
use rustc_hir::Attribute;
1515
use rustc_hir::attrs::{self, AttributeKind, CfgEntry, CfgHideShow, HideOrShow};
1616
use rustc_middle::ty::TyCtxt;
17-
use rustc_session::parse::ParseSess;
1817
use rustc_span::symbol::{Symbol, sym};
1918
use rustc_span::{DUMMY_SP, Span};
2019

@@ -206,30 +205,6 @@ impl Cfg {
206205
Self::parse_nested(cfg, &FxHashSet::default()).map(|ret| ret.unwrap())
207206
}
208207

209-
/// Checks whether the given configuration can be matched in the current session.
210-
///
211-
/// Equivalent to `attr::cfg_matches`.
212-
pub(crate) fn matches(&self, psess: &ParseSess) -> bool {
213-
fn cfg_matches(cfg: &CfgEntry, psess: &ParseSess) -> bool {
214-
match cfg {
215-
CfgEntry::Bool(v, _) => *v,
216-
CfgEntry::Not(child, _) => !cfg_matches(child, psess),
217-
CfgEntry::All(sub_cfgs, _) => {
218-
sub_cfgs.iter().all(|sub_cfg| cfg_matches(sub_cfg, psess))
219-
}
220-
CfgEntry::Any(sub_cfgs, _) => {
221-
sub_cfgs.iter().any(|sub_cfg| cfg_matches(sub_cfg, psess))
222-
}
223-
CfgEntry::NameValue { name, value, .. } => psess.config.contains(&(*name, *value)),
224-
CfgEntry::Version(..) => {
225-
// FIXME: should be handled.
226-
false
227-
}
228-
}
229-
}
230-
cfg_matches(&self.0, psess)
231-
}
232-
233208
/// Renders the configuration for human display, as a short HTML description.
234209
pub(crate) fn render_short_html(&self) -> String {
235210
let mut msg = Display(&self.0, Format::ShortHtml).to_string();
@@ -320,6 +295,10 @@ impl Cfg {
320295
fn omit_preposition(&self) -> bool {
321296
matches!(self.0, CfgEntry::Bool(..))
322297
}
298+
299+
pub(crate) fn inner(&self) -> &CfgEntry {
300+
&self.0
301+
}
323302
}
324303

325304
impl ops::Not for Cfg {

src/librustdoc/doctest/rust.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::str::FromStr;
66
use std::sync::Arc;
77

88
use proc_macro2::{TokenStream, TokenTree};
9+
use rustc_attr_parsing::eval_config_entry;
910
use rustc_hir::attrs::AttributeKind;
1011
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
1112
use rustc_hir::{self as hir, Attribute, CRATE_HIR_ID, intravisit};
@@ -123,7 +124,7 @@ impl HirCollector<'_> {
123124
let ast_attrs = self.tcx.hir_attrs(self.tcx.local_def_id_to_hir_id(def_id));
124125
if let Some(ref cfg) =
125126
extract_cfg_from_attrs(ast_attrs.iter(), self.tcx, &mut CfgInfo::default())
126-
&& !cfg.matches(&self.tcx.sess.psess)
127+
&& !eval_config_entry(&self.tcx.sess, cfg.inner()).as_bool()
127128
{
128129
return;
129130
}

src/librustdoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
extern crate rustc_abi;
3333
extern crate rustc_ast;
3434
extern crate rustc_ast_pretty;
35+
extern crate rustc_attr_parsing;
3536
extern crate rustc_data_structures;
3637
extern crate rustc_driver;
3738
extern crate rustc_errors;

0 commit comments

Comments
 (0)