Clean up code a bit:

* Remove "bool_to_options" feature
 * Update version for compiler feature
 * rustfmt
This commit is contained in:
Guillaume Gomez 2021-10-06 15:34:59 +02:00
parent 56e5f61494
commit 8fac41a530
7 changed files with 25 additions and 17 deletions

View File

@ -676,7 +676,7 @@ declare_features! (
(active, closure_track_caller, "1.57.0", Some(87417), None),
/// Allows `#[doc(cfg_hide(...))]`.
(active, doc_cfg_hide, "1.53.0", Some(43781), None),
(active, doc_cfg_hide, "1.57.0", Some(43781), None),
// -------------------------------------------------------------------------
// feature-group-end: actual feature gates

View File

@ -65,9 +65,10 @@
#![doc(
html_playground_url = "https://play.rust-lang.org/",
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
test(no_crate_inject, attr(allow(unused_variables), deny(warnings))),
test(no_crate_inject, attr(allow(unused_variables), deny(warnings)))
)]
#![cfg_attr(not(bootstrap),
#![cfg_attr(
not(bootstrap),
doc(cfg_hide(not(test), not(any(test, bootstrap)), target_has_atomic = "ptr"))
)]
#![no_std]

View File

@ -58,9 +58,10 @@
html_playground_url = "https://play.rust-lang.org/",
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
test(no_crate_inject, attr(deny(warnings))),
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))),
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
)]
#![cfg_attr(not(bootstrap),
#![cfg_attr(
not(bootstrap),
doc(cfg_hide(
not(test),
target_pointer_width = "16",

View File

@ -193,11 +193,9 @@
html_playground_url = "https://play.rust-lang.org/",
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
test(no_crate_inject, attr(deny(warnings))),
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))),
)]
#![cfg_attr(not(bootstrap),
doc(cfg_hide(not(test), not(any(test, bootstrap))))
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
)]
#![cfg_attr(not(bootstrap), doc(cfg_hide(not(test), not(any(test, bootstrap)))))]
// Don't link to std. We are std.
#![no_std]
#![warn(deprecated_in_future)]

View File

@ -786,7 +786,9 @@ impl AttributesExt for [ast::Attribute] {
fn single(self) -> Option<Self::Item> {
let mut iter = self.into_iter();
let item = iter.next()?;
iter.next().is_none().then_some(())?;
if iter.next().is_some() {
return None;
}
Some(item)
}
}
@ -802,16 +804,19 @@ impl AttributesExt for [ast::Attribute] {
if doc_cfg.peek().is_some() {
doc_cfg
.filter_map(|attr| {
Cfg::parse(&attr).map_err(|e| sess.diagnostic().span_err(e.span, e.msg)).ok()
Cfg::parse(&attr)
.map_err(|e| sess.diagnostic().span_err(e.span, e.msg))
.ok()
})
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
} else {
self
.iter()
self.iter()
.filter(|attr| attr.has_name(sym::cfg))
.filter_map(|attr| Some(attr.meta_item_list()?.single()?.meta_item()?.clone()))
.filter_map(|attr| {
Cfg::parse(&attr).map_err(|e| sess.diagnostic().span_err(e.span, e.msg)).ok()
Cfg::parse(&attr)
.map_err(|e| sess.diagnostic().span_err(e.span, e.msg))
.ok()
})
.filter(|cfg| !hidden_cfg.contains(cfg))
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)

View File

@ -5,7 +5,6 @@
#![feature(rustc_private)]
#![feature(array_methods)]
#![feature(assert_matches)]
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(control_flow_enum)]
#![feature(box_syntax)]

View File

@ -3,10 +3,10 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir as hir;
use rustc_hir::CRATE_HIR_ID;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::Node;
use rustc_hir::CRATE_HIR_ID;
use rustc_middle::middle::privacy::AccessLevel;
use rustc_middle::ty::TyCtxt;
use rustc_span;
@ -99,7 +99,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
}
}
self.cx.cache.hidden_cfg = self.cx.tcx.hir().attrs(CRATE_HIR_ID)
self.cx.cache.hidden_cfg = self
.cx
.tcx
.hir()
.attrs(CRATE_HIR_ID)
.iter()
.filter(|attr| attr.has_name(sym::doc))
.flat_map(|attr| attr.meta_item_list().into_iter().flatten())