Skip to content

Remove under-used ImplPolarity enum #80825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand Down
11 changes: 6 additions & 5 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down Expand Up @@ -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,
});
Expand Down
15 changes: 6 additions & 9 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1226,6 +1228,7 @@ crate enum Type {
BareFunction(Box<BareFunctionDecl>),
Tuple(Vec<Type>),
Slice(Box<Type>),
/// The `String` field is about the size or the constant representing the array's length.
Array(Box<Type>, String),
Never,
RawPointer(Mutability, Box<Type>),
Expand Down Expand Up @@ -1857,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,
Expand All @@ -1871,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>,
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "!")?;
}

Expand Down
11 changes: 3 additions & 8 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl From<clean::Impl> for Impl {
trait_,
for_,
items,
polarity,
negative_polarity,
synthetic,
blanket_impl,
} = impl_;
Expand All @@ -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),
}
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)
)
}
}

Expand Down