rustdoc: Use ty::ImplPolarity
instead of custom enum
This commit is contained in:
parent
543aea6c03
commit
120ef36307
8 changed files with 17 additions and 34 deletions
|
@ -79,14 +79,14 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
|||
let polarity;
|
||||
let new_generics = match result {
|
||||
AutoTraitResult::PositiveImpl(new_generics) => {
|
||||
polarity = ImplPolarity::Positive;
|
||||
polarity = ty::ImplPolarity::Positive;
|
||||
if discard_positive_impl {
|
||||
return None;
|
||||
}
|
||||
new_generics
|
||||
}
|
||||
AutoTraitResult::NegativeImpl => {
|
||||
polarity = ImplPolarity::Negative;
|
||||
polarity = ty::ImplPolarity::Negative;
|
||||
|
||||
// For negative impls, we use the generic params, but *not* the predicates,
|
||||
// from the original type. Otherwise, the displayed impl appears to be a
|
||||
|
|
|
@ -123,7 +123,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
|||
.in_definition_order()
|
||||
.collect::<Vec<_>>()
|
||||
.clean(self.cx),
|
||||
polarity: ImplPolarity::Positive,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
kind: ImplKind::Blanket(box trait_ref.self_ty().clean(self.cx)),
|
||||
}),
|
||||
cfg: None,
|
||||
|
|
|
@ -497,7 +497,7 @@ crate fn build_impl(
|
|||
trait_,
|
||||
for_,
|
||||
items: trait_items,
|
||||
polarity: polarity.clean(cx),
|
||||
polarity,
|
||||
kind: ImplKind::Normal,
|
||||
}),
|
||||
box merged_attrs,
|
||||
|
|
|
@ -1856,18 +1856,6 @@ impl Clean<Item> for hir::Variant<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Clean<ImplPolarity> for ty::ImplPolarity {
|
||||
/// Returns whether the impl has negative polarity.
|
||||
fn clean(&self, _: &mut DocContext<'_>) -> ImplPolarity {
|
||||
match self {
|
||||
ty::ImplPolarity::Positive |
|
||||
// FIXME: do we want to do something else here?
|
||||
ty::ImplPolarity::Reservation => ImplPolarity::Positive,
|
||||
ty::ImplPolarity::Negative => ImplPolarity::Negative,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_>) -> Vec<Item> {
|
||||
let tcx = cx.tcx;
|
||||
let mut ret = Vec::new();
|
||||
|
@ -1894,7 +1882,7 @@ fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_>
|
|||
trait_,
|
||||
for_,
|
||||
items,
|
||||
polarity: tcx.impl_polarity(def_id).clean(cx),
|
||||
polarity: tcx.impl_polarity(def_id),
|
||||
kind: ImplKind::Normal,
|
||||
});
|
||||
Item::from_hir_id_and_parts(hir_id, None, kind, cx)
|
||||
|
|
|
@ -2177,7 +2177,7 @@ crate struct Impl {
|
|||
crate trait_: Option<Path>,
|
||||
crate for_: Type,
|
||||
crate items: Vec<Item>,
|
||||
crate polarity: ImplPolarity,
|
||||
crate polarity: ty::ImplPolarity,
|
||||
crate kind: ImplKind,
|
||||
}
|
||||
|
||||
|
@ -2227,13 +2227,6 @@ impl ImplKind {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME: remove this and use ty::ImplPolarity instead
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
crate enum ImplPolarity {
|
||||
Positive,
|
||||
Negative,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
crate struct Import {
|
||||
crate kind: ImportKind,
|
||||
|
|
|
@ -14,6 +14,7 @@ use rustc_data_structures::captures::Captures;
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::def_id::CRATE_DEF_INDEX;
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
@ -991,8 +992,8 @@ impl clean::Impl {
|
|||
|
||||
if let Some(ref ty) = self.trait_ {
|
||||
match self.polarity {
|
||||
clean::ImplPolarity::Positive => {}
|
||||
clean::ImplPolarity::Negative => write!(f, "!")?,
|
||||
ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => {}
|
||||
ty::ImplPolarity::Negative => write!(f, "!")?,
|
||||
}
|
||||
fmt::Display::fmt(&ty.print(cx), f)?;
|
||||
write!(f, " for ")?;
|
||||
|
|
|
@ -34,8 +34,8 @@ mod span_map;
|
|||
mod templates;
|
||||
mod write_shared;
|
||||
|
||||
crate use context::*;
|
||||
crate use span_map::{collect_spans_and_sources, LinkFromSrc};
|
||||
crate use self::context::*;
|
||||
crate use self::span_map::{collect_spans_and_sources, LinkFromSrc};
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::default::Default;
|
||||
|
@ -54,6 +54,7 @@ use rustc_hir::def::CtorKind;
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::Mutability;
|
||||
use rustc_middle::middle::stability;
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::{
|
||||
symbol::{kw, sym, Symbol},
|
||||
|
@ -2034,8 +2035,8 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
|
|||
let out = Escape(&i_display);
|
||||
let encoded = small_url_encode(format!("{:#}", i.print(cx)));
|
||||
let prefix = match it.inner_impl().polarity {
|
||||
clean::ImplPolarity::Positive => "",
|
||||
clean::ImplPolarity::Negative => "!",
|
||||
ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => "",
|
||||
ty::ImplPolarity::Negative => "!",
|
||||
};
|
||||
let generated =
|
||||
format!("<a href=\"#impl-{}\">{}{}</a>", encoded, prefix, out);
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::fmt;
|
|||
|
||||
use rustc_ast::ast;
|
||||
use rustc_hir::{def::CtorKind, def_id::DefId};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_span::def_id::CRATE_DEF_INDEX;
|
||||
use rustc_span::Pos;
|
||||
|
||||
|
@ -513,8 +513,8 @@ impl FromWithTcx<clean::Impl> for Impl {
|
|||
clean::ImplKind::Blanket(ty) => (false, Some(*ty)),
|
||||
};
|
||||
let negative_polarity = match polarity {
|
||||
clean::ImplPolarity::Positive => false,
|
||||
clean::ImplPolarity::Negative => true,
|
||||
ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => false,
|
||||
ty::ImplPolarity::Negative => true,
|
||||
};
|
||||
Impl {
|
||||
is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue