Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Cleanup formatting
  • Loading branch information
Aaron1011 committed Feb 18, 2018
commit 1531fbe9becc9b5d84a9360fb75440efc41b7db7
6 changes: 3 additions & 3 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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,
}
}

Expand All @@ -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,
}
}

Expand Down
30 changes: 11 additions & 19 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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>,
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
//
Expand Down
4 changes: 1 addition & 3 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
37 changes: 14 additions & 23 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3077,7 +3077,7 @@ impl Path {
params: PathParameters::AngleBracketed {
lifetimes: Vec::new(),
types: Vec::new(),
bindings: Vec::new()
bindings: Vec::new(),
}
}]
}
Expand Down Expand Up @@ -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
}
}
Expand All @@ -3180,15 +3180,15 @@ fn strip_path(path: &Path) -> Path {
params: PathParameters::AngleBracketed {
lifetimes: Vec::new(),
types: Vec::new(),
bindings: Vec::new()
bindings: Vec::new(),
}
}
}).collect();

Path {
global: path.global,
def: path.def.clone(),
segments
segments,
}
}

Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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| {
Expand All @@ -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> {
Expand Down Expand Up @@ -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]);
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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())
}
}
Expand Down Expand Up @@ -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),
Expand All @@ -4001,7 +3992,7 @@ impl From<TyParamBound> for SimpleBound {
t.generic_params,
mod_)
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the comma at the end of the line.

_ => panic!("Unexpected bound {:?}", bound)
_ => panic!("Unexpected bound {:?}", bound),
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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());

Expand Down
18 changes: 0 additions & 18 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ pub enum ExternalLocation {
Unknown,
}


/// Metadata about implementations for a type or trait.
#[derive(Clone)]
pub struct Impl {
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -2512,22 +2510,6 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
}
write!(w, "</ul>")?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what do you close in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This time, <ul class='item-list' id='synthetic-implementors-list'> is closed

}

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
Expand Down
9 changes: 3 additions & 6 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down