Skip to content

Commit 34d128a

Browse files
Replace under-used ImplPolarity enum with a boolean
1 parent 3338bdb commit 34d128a

File tree

9 files changed

+27
-32
lines changed

9 files changed

+27
-32
lines changed

Diff for: src/librustdoc/clean/auto_trait.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
8484
new_generics
8585
});
8686

87-
let polarity;
87+
let negative_polarity;
8888
let new_generics = match result {
8989
AutoTraitResult::PositiveImpl(new_generics) => {
90-
polarity = None;
90+
negative_polarity = false;
9191
new_generics
9292
}
9393
AutoTraitResult::NegativeImpl => {
94-
polarity = Some(ImplPolarity::Negative);
94+
negative_polarity = true;
9595

9696
// For negative impls, we use the generic params, but *not* the predicates,
9797
// from the original type. Otherwise, the displayed impl appears to be a
@@ -130,7 +130,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
130130
trait_: Some(trait_ref.clean(self.cx).get_trait_type().unwrap()),
131131
for_: ty.clean(self.cx),
132132
items: Vec::new(),
133-
polarity,
133+
negative_polarity,
134134
synthetic: true,
135135
blanket_impl: None,
136136
}),

Diff for: src/librustdoc/clean/blanket_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
131131
.in_definition_order()
132132
.collect::<Vec<_>>()
133133
.clean(self.cx),
134-
polarity: None,
134+
negative_polarity: false,
135135
synthetic: false,
136136
blanket_impl: Some(trait_ref.self_ty().clean(self.cx)),
137137
}),

Diff for: src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ crate fn build_impl(
428428
trait_,
429429
for_,
430430
items: trait_items,
431-
polarity: Some(polarity.clean(cx)),
431+
negative_polarity: polarity.clean(cx),
432432
synthetic: false,
433433
blanket_impl: None,
434434
}),

Diff for: src/librustdoc/clean/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -2069,13 +2069,14 @@ impl Clean<Item> for hir::Variant<'_> {
20692069
}
20702070
}
20712071

2072-
impl Clean<ImplPolarity> for ty::ImplPolarity {
2073-
fn clean(&self, _: &DocContext<'_>) -> ImplPolarity {
2072+
impl Clean<bool> for ty::ImplPolarity {
2073+
/// Returns whether the impl has negative polarity.
2074+
fn clean(&self, _: &DocContext<'_>) -> bool {
20742075
match self {
20752076
&ty::ImplPolarity::Positive |
20762077
// FIXME: do we want to do something else here?
2077-
&ty::ImplPolarity::Reservation => ImplPolarity::Positive,
2078-
&ty::ImplPolarity::Negative => ImplPolarity::Negative,
2078+
&ty::ImplPolarity::Reservation => false,
2079+
&ty::ImplPolarity::Negative => true,
20792080
}
20802081
}
20812082
}
@@ -2116,7 +2117,7 @@ fn clean_impl(impl_: &hir::Item<'_>, cx: &DocContext<'_>) -> Vec<Item> {
21162117
trait_,
21172118
for_,
21182119
items,
2119-
polarity: Some(cx.tcx.impl_polarity(def_id).clean(cx)),
2120+
negative_polarity: cx.tcx.impl_polarity(def_id).clean(cx),
21202121
synthetic: false,
21212122
blanket_impl: None,
21222123
});

Diff for: src/librustdoc/clean/types.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,11 @@ impl Item {
175175
}
176176

177177
crate fn is_crate(&self) -> bool {
178-
matches!(*self.kind,
178+
matches!(
179+
*self.kind,
179180
StrippedItem(box ModuleItem(Module { is_crate: true, .. }))
180-
| ModuleItem(Module { is_crate: true, .. }))
181+
| ModuleItem(Module { is_crate: true, .. })
182+
)
181183
}
182184
crate fn is_mod(&self) -> bool {
183185
self.type_() == ItemType::Module
@@ -1858,12 +1860,6 @@ crate struct Constant {
18581860
crate is_literal: bool,
18591861
}
18601862

1861-
#[derive(Clone, PartialEq, Debug)]
1862-
crate enum ImplPolarity {
1863-
Positive,
1864-
Negative,
1865-
}
1866-
18671863
#[derive(Clone, Debug)]
18681864
crate struct Impl {
18691865
crate unsafety: hir::Unsafety,
@@ -1872,7 +1868,7 @@ crate struct Impl {
18721868
crate trait_: Option<Type>,
18731869
crate for_: Type,
18741870
crate items: Vec<Item>,
1875-
crate polarity: Option<ImplPolarity>,
1871+
crate negative_polarity: bool,
18761872
crate synthetic: bool,
18771873
crate blanket_impl: Option<Type>,
18781874
}

Diff for: src/librustdoc/html/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ impl clean::Impl {
870870
}
871871

872872
if let Some(ref ty) = self.trait_ {
873-
if self.polarity == Some(clean::ImplPolarity::Negative) {
873+
if self.negative_polarity {
874874
write!(f, "!")?;
875875
}
876876

Diff for: src/librustdoc/html/render/mod.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -4327,16 +4327,15 @@ fn sidebar_assoc_items(cx: &Context<'_>, it: &clean::Item) -> String {
43274327

43284328
let mut ret = impls
43294329
.iter()
4330-
.filter_map(|i| {
4331-
let is_negative_impl = is_negative_impl(i.inner_impl());
4332-
if let Some(ref i) = i.inner_impl().trait_ {
4330+
.filter_map(|it| {
4331+
if let Some(ref i) = it.inner_impl().trait_ {
43334332
let i_display = format!("{:#}", i.print());
43344333
let out = Escape(&i_display);
43354334
let encoded = small_url_encode(&format!("{:#}", i.print()));
43364335
let generated = format!(
43374336
"<a href=\"#impl-{}\">{}{}</a>",
43384337
encoded,
4339-
if is_negative_impl { "!" } else { "" },
4338+
if it.inner_impl().negative_polarity { "!" } else { "" },
43404339
out
43414340
);
43424341
if links.insert(generated.clone()) { Some(generated) } else { None }
@@ -4503,10 +4502,6 @@ fn extract_for_impl_name(item: &clean::Item) -> Option<(String, String)> {
45034502
}
45044503
}
45054504

4506-
fn is_negative_impl(i: &clean::Impl) -> bool {
4507-
i.polarity == Some(clean::ImplPolarity::Negative)
4508-
}
4509-
45104505
fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) {
45114506
let mut sidebar = String::new();
45124507

Diff for: src/librustdoc/json/conversions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl From<clean::Impl> for Impl {
422422
trait_,
423423
for_,
424424
items,
425-
polarity,
425+
negative_polarity,
426426
synthetic,
427427
blanket_impl,
428428
} = impl_;
@@ -436,7 +436,7 @@ impl From<clean::Impl> for Impl {
436436
trait_: trait_.map(Into::into),
437437
for_: for_.into(),
438438
items: ids(items),
439-
negative: polarity == Some(clean::ImplPolarity::Negative),
439+
negative: negative_polarity,
440440
synthetic,
441441
blanket_impl: blanket_impl.map(Into::into),
442442
}

Diff for: src/librustdoc/theme.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ impl Events {
7070
}
7171

7272
fn is_comment(&self) -> bool {
73-
matches!(self, Events::StartLineComment(_) | Events::StartComment(_) | Events::EndComment(_))
73+
matches!(
74+
self,
75+
Events::StartLineComment(_) | Events::StartComment(_) | Events::EndComment(_)
76+
)
7477
}
7578
}
7679

0 commit comments

Comments
 (0)