Cleanup formatting

This commit is contained in:
Aaron Hill 2018-02-10 14:34:46 -05:00
parent 9d7165fcb1
commit 1531fbe9be
No known key found for this signature in database
GPG Key ID: B4087E510E98B164
7 changed files with 37 additions and 79 deletions

View File

@ -429,7 +429,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
intercrate: None,
inferred_obligations: SnapshotVec::new(),
intercrate_ambiguity_causes: None,
allow_negative_impls: false
allow_negative_impls: false,
}
}
@ -442,7 +442,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
intercrate: Some(mode),
inferred_obligations: SnapshotVec::new(),
intercrate_ambiguity_causes: None,
allow_negative_impls: false
allow_negative_impls: false,
}
}
@ -455,7 +455,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
intercrate: None,
inferred_obligations: SnapshotVec::new(),
intercrate_ambiguity_causes: None,
allow_negative_impls
allow_negative_impls,
}
}

View File

@ -315,7 +315,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
// Due to the way projections are handled by SelectionContext, we need to run
// evaluate_predicates twice: once on the original param env, and once on the result of
// the first evaluate_predicates call
// the first evaluate_predicates call.
//
// The problem is this: most of rustc, including SelectionContext and traits::project,
// are designed to work with a concrete usage of a type (e.g. Vec<u8>
@ -338,7 +338,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
// We fix the first assumption by manually clearing out all of the InferCtxt's caches
// in between calls to SelectionContext.select. This allows us to keep all of the
// intermediate types we create bound to the 'tcx lifetime, rather than needing to lift
// them between calls
// them between calls.
//
// We fix the second assumption by reprocessing the result of our first call to
// evaluate_predicates. Using the example of '<T as SomeTrait>::SomeItem = K', our first
@ -457,13 +457,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
infcx.freshen(p)
}
fn evaluate_nested_obligations<
'b,
'c,
'd,
'cx,
T: Iterator<Item = Obligation<'cx, ty::Predicate<'cx>>>,
>(
fn evaluate_nested_obligations<'b, 'c, 'd, 'cx,
T: Iterator<Item = Obligation<'cx, ty::Predicate<'cx>>>>(
&self,
ty: ty::Ty,
nested: T,
@ -732,8 +727,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
}
}
// This is very simiiar to handle_lifetimes. Instead of matching ty::Region's to ty::Region's,
// however, we match ty::RegionVid's to ty::Region's
// This is very similar to handle_lifetimes. However, instead of matching ty::Region's
// to each other, we match ty::RegionVid's to ty::Region's
fn map_vid_to_region<'cx>(
&self,
regions: &RegionConstraintData<'cx>,
@ -843,7 +838,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
// with determining if a given set up constraints/predicates *are* met, given some
// starting conditions (e.g. user-provided code). For this reason, it's easier
// to perform the calculations we need on our own, rather than trying to make
// existing inference/solver code do what we want
// existing inference/solver code do what we want.
fn handle_lifetimes<'cx>(
&self,
regions: &RegionConstraintData<'cx>,
@ -852,8 +847,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
// Our goal is to 'flatten' the list of constraints by eliminating
// all intermediate RegionVids. At the end, all constraints should
// be between Regions (aka region variables). This gives us the information
// we need to create the Generics
//
// we need to create the Generics.
let mut finished = FxHashMap();
let mut vid_map: FxHashMap<RegionTarget, RegionDeps> = FxHashMap();
@ -1021,7 +1015,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)>,
lifetime_to_bounds: FxHashMap<Lifetime, FxHashSet<Lifetime>>,
) -> Vec<WherePredicate> {
let final_predicates = ty_to_bounds
ty_to_bounds
.into_iter()
.flat_map(|(ty, mut bounds)| {
if let Some(data) = ty_to_fn.get(&ty) {
@ -1096,9 +1090,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
bounds: bounds.into_iter().collect(),
}),
)
.collect();
final_predicates
.collect()
}
// Converts the calculated ParamEnv and lifetime information to a clean::Generics, suitable for
@ -1380,7 +1372,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
}
// This is an ugly hack, but it's the simplest way to handle synthetic impls without greatly
// refactorying either librustdoc or librustc. In particular, allowing new DefIds to be
// refactoring either librustdoc or librustc. In particular, allowing new DefIds to be
// registered after the AST is constructed would require storing the defid mapping in a
// RefCell, decreasing the performance for normal compilation for very little gain.
//

View File

@ -120,7 +120,6 @@ pub fn load_attrs(cx: &DocContext, did: DefId) -> clean::Attributes {
cx.tcx.get_attrs(did).clean(cx)
}
/// Record an external fully qualified name in the external_paths cache.
///
/// These names are used later on by HTML rendering to generate things like
@ -267,7 +266,6 @@ pub fn build_impls(cx: &DocContext, did: DefId, auto_traits: bool) -> Vec<clean:
cx.populated_all_crate_impls.set(true);
for &cnum in tcx.crates().iter() {
for did in tcx.all_trait_implementations(cnum).iter() {
build_impl(cx, *did, &mut impls);
@ -373,7 +371,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
for_,
items: trait_items,
polarity: Some(polarity.clean(cx)),
synthetic: false
synthetic: false,
}),
source: tcx.def_span(did).clean(cx),
name: None,

View File

@ -3077,7 +3077,7 @@ impl Path {
params: PathParameters::AngleBracketed {
lifetimes: Vec::new(),
types: Vec::new(),
bindings: Vec::new()
bindings: Vec::new(),
}
}]
}
@ -3152,23 +3152,23 @@ fn strip_type(ty: Type) -> Type {
match ty {
Type::ResolvedPath { path, typarams, did, is_generic } => {
Type::ResolvedPath { path: strip_path(&path), typarams, did, is_generic }
},
}
Type::Tuple(inner_tys) => {
Type::Tuple(inner_tys.iter().map(|t| strip_type(t.clone())).collect())
},
}
Type::Slice(inner_ty) => Type::Slice(Box::new(strip_type(*inner_ty))),
Type::Array(inner_ty, s) => Type::Array(Box::new(strip_type(*inner_ty)), s),
Type::Unique(inner_ty) => Type::Unique(Box::new(strip_type(*inner_ty))),
Type::RawPointer(m, inner_ty) => Type::RawPointer(m, Box::new(strip_type(*inner_ty))),
Type::BorrowedRef { lifetime, mutability, type_ } => {
Type::BorrowedRef { lifetime, mutability, type_: Box::new(strip_type(*type_)) }
},
}
Type::QPath { name, self_type, trait_ } => {
Type::QPath {
name,
self_type: Box::new(strip_type(*self_type)), trait_: Box::new(strip_type(*trait_))
}
},
}
_ => ty
}
}
@ -3180,7 +3180,7 @@ fn strip_path(path: &Path) -> Path {
params: PathParameters::AngleBracketed {
lifetimes: Vec::new(),
types: Vec::new(),
bindings: Vec::new()
bindings: Vec::new(),
}
}
}).collect();
@ -3188,7 +3188,7 @@ fn strip_path(path: &Path) -> Path {
Path {
global: path.global,
def: path.def.clone(),
segments
segments,
}
}
@ -3361,7 +3361,6 @@ pub fn get_auto_traits_with_node_id(cx: &DocContext, id: ast::NodeId, name: Stri
}
pub fn get_auto_traits_with_def_id(cx: &DocContext, id: DefId) -> Vec<Item> {
let finder = AutoTraitFinder {
cx,
};
@ -3404,7 +3403,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
for_: self.for_.clean(cx),
items,
polarity: Some(self.polarity.clean(cx)),
synthetic: false
synthetic: false,
})
});
ret
@ -3819,8 +3818,6 @@ impl Clean<TypeBinding> for hir::TypeBinding {
}
}
pub fn def_id_to_path(cx: &DocContext, did: DefId, name: Option<String>) -> Vec<String> {
let crate_name = name.unwrap_or_else(|| cx.tcx.crate_name(did.krate).to_string());
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
@ -3835,15 +3832,14 @@ pub fn def_id_to_path(cx: &DocContext, did: DefId, name: Option<String>) -> Vec<
once(crate_name).chain(relative).collect()
}
// Start of code copied from rust-clippy
pub fn get_trait_def_id(tcx: &TyCtxt, path: &[&str], use_local: bool) -> Option<DefId> {
return if use_local {
if use_local {
path_to_def_local(tcx, path)
} else {
path_to_def(tcx, path)
};
}
}
pub fn path_to_def_local(tcx: &TyCtxt, path: &[&str]) -> Option<DefId> {
@ -3878,7 +3874,6 @@ pub fn path_to_def_local(tcx: &TyCtxt, path: &[&str]) -> Option<DefId> {
pub fn path_to_def(tcx: &TyCtxt, path: &[&str]) -> Option<DefId> {
let crates = tcx.crates();
let krate = crates
.iter()
.find(|&&krate| tcx.crate_name(krate) == path[0]);
@ -3902,7 +3897,7 @@ pub fn path_to_def(tcx: &TyCtxt, path: &[&str]) -> Option<DefId> {
if path_it.peek().is_none() {
return match item.def {
def::Def::Trait(did) => Some(did),
_ => None
_ => None,
}
}
@ -3942,7 +3937,7 @@ fn get_path_for_type(tcx: TyCtxt, def_id: DefId, def_ctor: fn(DefId) -> Def) ->
segments: hir::HirVec::from_vec(apb.names.iter().map(|s| hir::PathSegment {
name: ast::Name::intern(&s),
parameters: None,
infer_types: false
infer_types: false,
}).collect())
}
}
@ -3970,24 +3965,20 @@ enum SimpleBound {
enum AutoTraitResult {
ExplicitImpl,
PositiveImpl(Generics),
NegativeImpl,
}
impl AutoTraitResult {
fn is_auto(&self) -> bool {
match *self {
AutoTraitResult::PositiveImpl(_) | AutoTraitResult::NegativeImpl => true,
_ => false
_ => false,
}
}
}
impl From<TyParamBound> for SimpleBound {
fn from(bound: TyParamBound) -> Self {
match bound.clone() {
TyParamBound::RegionBound(l) => SimpleBound::RegionBound(l),
@ -4001,7 +3992,7 @@ impl From<TyParamBound> for SimpleBound {
t.generic_params,
mod_)
},
_ => panic!("Unexpected bound {:?}", bound)
_ => panic!("Unexpected bound {:?}", bound),
}
}
}

View File

@ -239,13 +239,11 @@ pub fn run_core(search_paths: SearchPaths,
.collect()
};
let send_trait;
if crate_name == Some("core".to_string()) {
send_trait = clean::get_trait_def_id(&tcx, &["marker", "Send"], true);
let send_trait = if crate_name == Some("core".to_string()) {
clean::get_trait_def_id(&tcx, &["marker", "Send"], true)
} else {
send_trait = clean::get_trait_def_id(&tcx, &["core", "marker", "Send"], false)
}
clean::get_trait_def_id(&tcx, &["core", "marker", "Send"], false)
};
let ctxt = DocContext {
tcx,
@ -262,7 +260,7 @@ pub fn run_core(search_paths: SearchPaths,
send_trait: send_trait,
fake_def_ids: RefCell::new(FxHashMap()),
all_fake_def_ids: RefCell::new(FxHashSet()),
generated_synthetics: RefCell::new(FxHashSet())
generated_synthetics: RefCell::new(FxHashSet()),
};
debug!("crate: {:?}", tcx.hir.krate());

View File

@ -169,7 +169,6 @@ pub enum ExternalLocation {
Unknown,
}
/// Metadata about implementations for a type or trait.
#[derive(Clone)]
pub struct Impl {
@ -523,7 +522,6 @@ pub fn run(mut krate: clean::Crate,
themes,
};
// If user passed in `--playground-url` arg, we fill in crate name here
if let Some(url) = playground_url {
markdown::PLAYGROUND.with(|slot| {
@ -2512,22 +2510,6 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
}
write!(w, "</ul>")?;
}
write!(w, r#"<script type="text/javascript">
window.inlined_types=new Set();"#)?;
write!(w, r#"<script type="text/javascript" async
src="{root_path}/implementors/{path}/{ty}.{name}.js">
</script>"#,
root_path = vec![".."; cx.current.len()].join("/"),
path = if it.def_id.is_local() {
cx.current.join("/")
} else {
let (ref path, _) = cache.external_paths[&it.def_id];
path[..path.len() - 1].join("/")
},
ty = it.type_().css_class(),
name = *it.name.as_ref().unwrap())?;
} else {
// even without any implementations to write in, we still want the heading and list, so the
// implementors javascript file pulled in below has somewhere to write the impls into

View File

@ -1569,20 +1569,17 @@
for (var i = 0; i < libs.length; ++i) {
if (libs[i] === currentCrate) { continue; }
var structs = imp[libs[i]];
struct_loop:
for (var j = 0; j < structs.length; ++j) {
var struct = structs[j];
var list = struct.synthetic ? synthetic_implementors : implementors;
var bail = false;
for (var k = 0; k < struct.types.length; k++) {
if (window.inlined_types.has(struct.types[k])) {
bail = true;
break;
continue struct_loop;
}
}
if (bail) {
continue;
}
var code = document.createElement('code');
code.innerHTML = struct.text;