Replace under-used ImplPolarity enum with a boolean

This commit is contained in:
Guillaume Gomez 2021-01-08 22:54:35 +01:00
parent 3338bdb23d
commit 34d128a263
9 changed files with 27 additions and 32 deletions

View File

@ -84,14 +84,14 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
new_generics
});
let polarity;
let negative_polarity;
let new_generics = match result {
AutoTraitResult::PositiveImpl(new_generics) => {
polarity = None;
negative_polarity = false;
new_generics
}
AutoTraitResult::NegativeImpl => {
polarity = Some(ImplPolarity::Negative);
negative_polarity = true;
// For negative impls, we use the generic params, but *not* the predicates,
// from the original type. Otherwise, the displayed impl appears to be a
@ -130,7 +130,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
trait_: Some(trait_ref.clean(self.cx).get_trait_type().unwrap()),
for_: ty.clean(self.cx),
items: Vec::new(),
polarity,
negative_polarity,
synthetic: true,
blanket_impl: None,
}),

View File

@ -131,7 +131,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
.in_definition_order()
.collect::<Vec<_>>()
.clean(self.cx),
polarity: None,
negative_polarity: false,
synthetic: false,
blanket_impl: Some(trait_ref.self_ty().clean(self.cx)),
}),

View File

@ -428,7 +428,7 @@ crate fn build_impl(
trait_,
for_,
items: trait_items,
polarity: Some(polarity.clean(cx)),
negative_polarity: polarity.clean(cx),
synthetic: false,
blanket_impl: None,
}),

View File

@ -2069,13 +2069,14 @@ impl Clean<Item> for hir::Variant<'_> {
}
}
impl Clean<ImplPolarity> for ty::ImplPolarity {
fn clean(&self, _: &DocContext<'_>) -> ImplPolarity {
impl Clean<bool> for ty::ImplPolarity {
/// Returns whether the impl has negative polarity.
fn clean(&self, _: &DocContext<'_>) -> bool {
match self {
&ty::ImplPolarity::Positive |
// FIXME: do we want to do something else here?
&ty::ImplPolarity::Reservation => ImplPolarity::Positive,
&ty::ImplPolarity::Negative => ImplPolarity::Negative,
&ty::ImplPolarity::Reservation => false,
&ty::ImplPolarity::Negative => true,
}
}
}
@ -2116,7 +2117,7 @@ fn clean_impl(impl_: &hir::Item<'_>, cx: &DocContext<'_>) -> Vec<Item> {
trait_,
for_,
items,
polarity: Some(cx.tcx.impl_polarity(def_id).clean(cx)),
negative_polarity: cx.tcx.impl_polarity(def_id).clean(cx),
synthetic: false,
blanket_impl: None,
});

View File

@ -175,9 +175,11 @@ impl Item {
}
crate fn is_crate(&self) -> bool {
matches!(*self.kind,
matches!(
*self.kind,
StrippedItem(box ModuleItem(Module { is_crate: true, .. }))
| ModuleItem(Module { is_crate: true, .. }))
| ModuleItem(Module { is_crate: true, .. })
)
}
crate fn is_mod(&self) -> bool {
self.type_() == ItemType::Module
@ -1858,12 +1860,6 @@ crate struct Constant {
crate is_literal: bool,
}
#[derive(Clone, PartialEq, Debug)]
crate enum ImplPolarity {
Positive,
Negative,
}
#[derive(Clone, Debug)]
crate struct Impl {
crate unsafety: hir::Unsafety,
@ -1872,7 +1868,7 @@ crate struct Impl {
crate trait_: Option<Type>,
crate for_: Type,
crate items: Vec<Item>,
crate polarity: Option<ImplPolarity>,
crate negative_polarity: bool,
crate synthetic: bool,
crate blanket_impl: Option<Type>,
}

View File

@ -870,7 +870,7 @@ impl clean::Impl {
}
if let Some(ref ty) = self.trait_ {
if self.polarity == Some(clean::ImplPolarity::Negative) {
if self.negative_polarity {
write!(f, "!")?;
}

View File

@ -4327,16 +4327,15 @@ fn sidebar_assoc_items(cx: &Context<'_>, it: &clean::Item) -> String {
let mut ret = impls
.iter()
.filter_map(|i| {
let is_negative_impl = is_negative_impl(i.inner_impl());
if let Some(ref i) = i.inner_impl().trait_ {
.filter_map(|it| {
if let Some(ref i) = it.inner_impl().trait_ {
let i_display = format!("{:#}", i.print());
let out = Escape(&i_display);
let encoded = small_url_encode(&format!("{:#}", i.print()));
let generated = format!(
"<a href=\"#impl-{}\">{}{}</a>",
encoded,
if is_negative_impl { "!" } else { "" },
if it.inner_impl().negative_polarity { "!" } else { "" },
out
);
if links.insert(generated.clone()) { Some(generated) } else { None }
@ -4503,10 +4502,6 @@ fn extract_for_impl_name(item: &clean::Item) -> Option<(String, String)> {
}
}
fn is_negative_impl(i: &clean::Impl) -> bool {
i.polarity == Some(clean::ImplPolarity::Negative)
}
fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) {
let mut sidebar = String::new();

View File

@ -422,7 +422,7 @@ impl From<clean::Impl> for Impl {
trait_,
for_,
items,
polarity,
negative_polarity,
synthetic,
blanket_impl,
} = impl_;
@ -436,7 +436,7 @@ impl From<clean::Impl> for Impl {
trait_: trait_.map(Into::into),
for_: for_.into(),
items: ids(items),
negative: polarity == Some(clean::ImplPolarity::Negative),
negative: negative_polarity,
synthetic,
blanket_impl: blanket_impl.map(Into::into),
}

View File

@ -70,7 +70,10 @@ impl Events {
}
fn is_comment(&self) -> bool {
matches!(self, Events::StartLineComment(_) | Events::StartComment(_) | Events::EndComment(_))
matches!(
self,
Events::StartLineComment(_) | Events::StartComment(_) | Events::EndComment(_)
)
}
}