Skip to content

Commit 120ef36

Browse files
committed
rustdoc: Use ty::ImplPolarity instead of custom enum
1 parent 543aea6 commit 120ef36

File tree

8 files changed

+17
-34
lines changed

8 files changed

+17
-34
lines changed

src/librustdoc/clean/auto_trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
7979
let polarity;
8080
let new_generics = match result {
8181
AutoTraitResult::PositiveImpl(new_generics) => {
82-
polarity = ImplPolarity::Positive;
82+
polarity = ty::ImplPolarity::Positive;
8383
if discard_positive_impl {
8484
return None;
8585
}
8686
new_generics
8787
}
8888
AutoTraitResult::NegativeImpl => {
89-
polarity = ImplPolarity::Negative;
89+
polarity = ty::ImplPolarity::Negative;
9090

9191
// For negative impls, we use the generic params, but *not* the predicates,
9292
// from the original type. Otherwise, the displayed impl appears to be a

src/librustdoc/clean/blanket_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
123123
.in_definition_order()
124124
.collect::<Vec<_>>()
125125
.clean(self.cx),
126-
polarity: ImplPolarity::Positive,
126+
polarity: ty::ImplPolarity::Positive,
127127
kind: ImplKind::Blanket(box trait_ref.self_ty().clean(self.cx)),
128128
}),
129129
cfg: None,

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ crate fn build_impl(
497497
trait_,
498498
for_,
499499
items: trait_items,
500-
polarity: polarity.clean(cx),
500+
polarity,
501501
kind: ImplKind::Normal,
502502
}),
503503
box merged_attrs,

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,18 +1856,6 @@ impl Clean<Item> for hir::Variant<'_> {
18561856
}
18571857
}
18581858

1859-
impl Clean<ImplPolarity> for ty::ImplPolarity {
1860-
/// Returns whether the impl has negative polarity.
1861-
fn clean(&self, _: &mut DocContext<'_>) -> ImplPolarity {
1862-
match self {
1863-
ty::ImplPolarity::Positive |
1864-
// FIXME: do we want to do something else here?
1865-
ty::ImplPolarity::Reservation => ImplPolarity::Positive,
1866-
ty::ImplPolarity::Negative => ImplPolarity::Negative,
1867-
}
1868-
}
1869-
}
1870-
18711859
fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_>) -> Vec<Item> {
18721860
let tcx = cx.tcx;
18731861
let mut ret = Vec::new();
@@ -1894,7 +1882,7 @@ fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_>
18941882
trait_,
18951883
for_,
18961884
items,
1897-
polarity: tcx.impl_polarity(def_id).clean(cx),
1885+
polarity: tcx.impl_polarity(def_id),
18981886
kind: ImplKind::Normal,
18991887
});
19001888
Item::from_hir_id_and_parts(hir_id, None, kind, cx)

src/librustdoc/clean/types.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,7 @@ crate struct Impl {
21772177
crate trait_: Option<Path>,
21782178
crate for_: Type,
21792179
crate items: Vec<Item>,
2180-
crate polarity: ImplPolarity,
2180+
crate polarity: ty::ImplPolarity,
21812181
crate kind: ImplKind,
21822182
}
21832183

@@ -2227,13 +2227,6 @@ impl ImplKind {
22272227
}
22282228
}
22292229

2230-
// FIXME: remove this and use ty::ImplPolarity instead
2231-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
2232-
crate enum ImplPolarity {
2233-
Positive,
2234-
Negative,
2235-
}
2236-
22372230
#[derive(Clone, Debug)]
22382231
crate struct Import {
22392232
crate kind: ImportKind,

src/librustdoc/html/format.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_data_structures::captures::Captures;
1414
use rustc_data_structures::fx::FxHashSet;
1515
use rustc_hir as hir;
1616
use rustc_hir::def_id::DefId;
17+
use rustc_middle::ty;
1718
use rustc_middle::ty::TyCtxt;
1819
use rustc_span::def_id::CRATE_DEF_INDEX;
1920
use rustc_target::spec::abi::Abi;
@@ -991,8 +992,8 @@ impl clean::Impl {
991992

992993
if let Some(ref ty) = self.trait_ {
993994
match self.polarity {
994-
clean::ImplPolarity::Positive => {}
995-
clean::ImplPolarity::Negative => write!(f, "!")?,
995+
ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => {}
996+
ty::ImplPolarity::Negative => write!(f, "!")?,
996997
}
997998
fmt::Display::fmt(&ty.print(cx), f)?;
998999
write!(f, " for ")?;

src/librustdoc/html/render/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ mod span_map;
3434
mod templates;
3535
mod write_shared;
3636

37-
crate use context::*;
38-
crate use span_map::{collect_spans_and_sources, LinkFromSrc};
37+
crate use self::context::*;
38+
crate use self::span_map::{collect_spans_and_sources, LinkFromSrc};
3939

4040
use std::collections::VecDeque;
4141
use std::default::Default;
@@ -54,6 +54,7 @@ use rustc_hir::def::CtorKind;
5454
use rustc_hir::def_id::DefId;
5555
use rustc_hir::Mutability;
5656
use rustc_middle::middle::stability;
57+
use rustc_middle::ty;
5758
use rustc_middle::ty::TyCtxt;
5859
use rustc_span::{
5960
symbol::{kw, sym, Symbol},
@@ -2034,8 +2035,8 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
20342035
let out = Escape(&i_display);
20352036
let encoded = small_url_encode(format!("{:#}", i.print(cx)));
20362037
let prefix = match it.inner_impl().polarity {
2037-
clean::ImplPolarity::Positive => "",
2038-
clean::ImplPolarity::Negative => "!",
2038+
ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => "",
2039+
ty::ImplPolarity::Negative => "!",
20392040
};
20402041
let generated =
20412042
format!("<a href=\"#impl-{}\">{}{}</a>", encoded, prefix, out);

src/librustdoc/json/conversions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::fmt;
99

1010
use rustc_ast::ast;
1111
use rustc_hir::{def::CtorKind, def_id::DefId};
12-
use rustc_middle::ty::TyCtxt;
12+
use rustc_middle::ty::{self, TyCtxt};
1313
use rustc_span::def_id::CRATE_DEF_INDEX;
1414
use rustc_span::Pos;
1515

@@ -513,8 +513,8 @@ impl FromWithTcx<clean::Impl> for Impl {
513513
clean::ImplKind::Blanket(ty) => (false, Some(*ty)),
514514
};
515515
let negative_polarity = match polarity {
516-
clean::ImplPolarity::Positive => false,
517-
clean::ImplPolarity::Negative => true,
516+
ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => false,
517+
ty::ImplPolarity::Negative => true,
518518
};
519519
Impl {
520520
is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,

0 commit comments

Comments
 (0)