Skip to content

Commit

Permalink
Auto merge of #47528 - GuillaumeGomez:rollup, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

- Successful merges: #47250, #47313, #47398, #47468, #47471, #47520
- Failed merges:
  • Loading branch information
bors committed Jan 18, 2018
2 parents 44afd76 + 2606537 commit 3bd4af8
Show file tree
Hide file tree
Showing 45 changed files with 821 additions and 115 deletions.
7 changes: 5 additions & 2 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ impl<'a> Builder<'a> {
Kind::Test => describe!(check::Tidy, check::Bootstrap, check::DefaultCompiletest,
check::HostCompiletest, check::Crate, check::CrateLibrustc, check::Rustdoc,
check::Linkcheck, check::Cargotest, check::Cargo, check::Rls, check::Docs,
check::ErrorIndex, check::Distcheck, check::Rustfmt, check::Miri, check::Clippy),
check::ErrorIndex, check::Distcheck, check::Rustfmt, check::Miri, check::Clippy,
check::RustdocJS),

Kind::Bench => describe!(check::Crate, check::CrateLibrustc),
Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
doc::Standalone, doc::Std, doc::Test, doc::Rustc, doc::ErrorIndex, doc::Nomicon,
Expand Down Expand Up @@ -443,7 +445,8 @@ impl<'a> Builder<'a> {
let out_dir = self.stage_out(compiler, mode);
cargo.env("CARGO_TARGET_DIR", out_dir)
.arg(cmd)
.arg("--target").arg(target);
.arg("--target")
.arg(target);

// If we were invoked from `make` then that's already got a jobserver
// set up for us so no need to tell Cargo about jobs all over again.
Expand Down
37 changes: 37 additions & 0 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,43 @@ fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct RustdocJS {
pub host: Interned<String>,
pub target: Interned<String>,
}

impl Step for RustdocJS {
type Output = ();
const DEFAULT: bool = true;
const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
run.path("src/test/rustdoc-js")
}

fn make_run(run: RunConfig) {
run.builder.ensure(RustdocJS {
host: run.host,
target: run.target,
});
}

fn run(self, builder: &Builder) {
if let Some(ref nodejs) = builder.config.nodejs {
let mut command = Command::new(nodejs);
command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
builder.ensure(::doc::Std {
target: self.target,
stage: builder.top_stage,
});
builder.run(&mut command);
} else {
println!("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
}
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Tidy {
host: Interned<String>,
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ impl Step for Standalone {

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Std {
stage: u32,
target: Interned<String>,
pub stage: u32,
pub target: Interned<String>,
}

impl Step for Std {
Expand Down
8 changes: 7 additions & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}
ObligationCauseCode::ItemObligation(item_def_id) => {
let item_name = tcx.item_path_str(item_def_id);
err.note(&format!("required by `{}`", item_name));
let msg = format!("required by `{}`", item_name);
if let Some(sp) = tcx.hir.span_if_local(item_def_id) {
let sp = tcx.sess.codemap().def_span(sp);
err.span_note(sp, &msg);
} else {
err.note(&msg);
}
}
ObligationCauseCode::ObjectCastObligation(object_ty) => {
err.note(&format!("required for the cast to the object type `{}`",
Expand Down
28 changes: 25 additions & 3 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,10 +842,32 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
if let mc::NoteClosureEnv(upvar_id) = err.cmt.note {
let node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
let sp = self.tcx.hir.span(node_id);
match self.tcx.sess.codemap().span_to_snippet(sp) {
Ok(snippet) => {
let fn_closure_msg = "`Fn` closures cannot capture their enclosing \
environment for modifications";
match (self.tcx.sess.codemap().span_to_snippet(sp), &err.cmt.cat) {
(_, &Categorization::Upvar(mc::Upvar {
kind: ty::ClosureKind::Fn, ..
})) => {
db.note(fn_closure_msg);
// we should point at the cause for this closure being
// identified as `Fn` (like in signature of method this
// closure was passed into)
}
(Ok(ref snippet), ref cat) => {
let msg = &format!("consider making `{}` mutable", snippet);
db.span_suggestion(sp, msg, format!("mut {}", snippet));
let suggestion = format!("mut {}", snippet);

if let &Categorization::Deref(ref cmt, _) = cat {
if let Categorization::Upvar(mc::Upvar {
kind: ty::ClosureKind::Fn, ..
}) = cmt.cat {
db.note(fn_closure_msg);
} else {
db.span_suggestion(sp, msg, suggestion);
}
} else {
db.span_suggestion(sp, msg, suggestion);
}
}
_ => {
db.span_help(sp, "consider making this binding mutable");
Expand Down
9 changes: 9 additions & 0 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
if trait_.def_id() == tcx.lang_items().deref_trait() {
super::build_deref_target_impls(cx, &trait_items, ret);
}
if let Some(trait_did) = trait_.def_id() {
record_extern_trait(cx, trait_did);
}

let provided = trait_.def_id().map(|did| {
tcx.provided_trait_methods(did)
Expand Down Expand Up @@ -483,3 +486,9 @@ fn separate_supertrait_bounds(mut g: clean::Generics)
});
(g, ty_bounds)
}

pub fn record_extern_trait(cx: &DocContext, did: DefId) {
cx.external_traits.borrow_mut().entry(did).or_insert_with(|| {
build_external_trait(cx, did)
});
}
3 changes: 1 addition & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3163,8 +3163,7 @@ fn register_def(cx: &DocContext, def: Def) -> DefId {
if did.is_local() { return did }
inline::record_extern_fqn(cx, did, kind);
if let TypeKind::Trait = kind {
let t = inline::build_external_trait(cx, did);
cx.external_traits.borrow_mut().insert(did, t);
inline::record_extern_trait(cx, did);
}
did
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3277,8 +3277,7 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
if let Some(impls) = c.impls.get(&did) {
for i in impls {
let impl_ = i.inner_impl();
if impl_.trait_.def_id().and_then(|d| c.traits.get(&d))
.map_or(false, |t| t.is_spotlight) {
if impl_.trait_.def_id().map_or(false, |d| c.traits[&d].is_spotlight) {
if out.is_empty() {
out.push_str(
&format!("<h3 class=\"important\">Important traits for {}</h3>\
Expand Down Expand Up @@ -3444,7 +3443,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
}

let traits = &cache().traits;
let trait_ = i.trait_did().and_then(|did| traits.get(&did));
let trait_ = i.trait_did().map(|did| &traits[&did]);

if !show_def_docs {
write!(w, "<span class='docblock autohide'>")?;
Expand Down
82 changes: 39 additions & 43 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,35 +353,33 @@
* This code is an unmodified version of the code written by Marco de Wit
* and was found at http://stackoverflow.com/a/18514751/745719
*/
var levenshtein = (function() {
var row2 = [];
return function(s1, s2) {
if (s1 === s2) {
return 0;
var levenshtein_row2 = [];
function levenshtein(s1, s2) {
if (s1 === s2) {
return 0;
}
var s1_len = s1.length, s2_len = s2.length;
if (s1_len && s2_len) {
var i1 = 0, i2 = 0, a, b, c, c2, row = levenshtein_row2;
while (i1 < s1_len) {
row[i1] = ++i1;
}
var s1_len = s1.length, s2_len = s2.length;
if (s1_len && s2_len) {
var i1 = 0, i2 = 0, a, b, c, c2, row = row2;
while (i1 < s1_len) {
row[i1] = ++i1;
}
while (i2 < s2_len) {
c2 = s2.charCodeAt(i2);
a = i2;
++i2;
b = i2;
for (i1 = 0; i1 < s1_len; ++i1) {
c = a + (s1.charCodeAt(i1) !== c2 ? 1 : 0);
a = row[i1];
b = b < a ? (b < c ? b + 1 : c) : (a < c ? a + 1 : c);
row[i1] = b;
}
while (i2 < s2_len) {
c2 = s2.charCodeAt(i2);
a = i2;
++i2;
b = i2;
for (i1 = 0; i1 < s1_len; ++i1) {
c = a + (s1.charCodeAt(i1) !== c2 ? 1 : 0);
a = row[i1];
b = b < a ? (b < c ? b + 1 : c) : (a < c ? a + 1 : c);
row[i1] = b;
}
return b;
}
return s1_len + s2_len;
};
})();
return b;
}
return s1_len + s2_len;
}

function initSearch(rawSearchIndex) {
var currentResults, index, searchIndex;
Expand All @@ -400,12 +398,20 @@
/**
* Executes the query and builds an index of results
* @param {[Object]} query [The user query]
* @param {[type]} max [The maximum results returned]
* @param {[type]} searchWords [The list of search words to query
* against]
* @return {[type]} [A search index of results]
*/
function execQuery(query, max, searchWords) {
function execQuery(query, searchWords) {
function itemTypeFromName(typename) {
for (var i = 0; i < itemTypes.length; ++i) {
if (itemTypes[i] === typename) {
return i;
}
}
return -1;
}

var valLower = query.query.toLowerCase(),
val = valLower,
typeFilter = itemTypeFromName(query.type),
Expand Down Expand Up @@ -1021,9 +1027,8 @@
return true;
}

function getQuery() {
var matches, type, query, raw =
document.getElementsByClassName('search-input')[0].value;
function getQuery(raw) {
var matches, type, query;
query = raw;

matches = query.match(/^(fn|mod|struct|enum|trait|type|const|macro)\s*:\s*/i);
Expand Down Expand Up @@ -1227,7 +1232,7 @@
}

function showResults(results) {
var output, query = getQuery();
var output, query = getQuery(document.getElementsByClassName('search-input')[0].value);

currentResults = query.id;
output = '<h1>Results for ' + escape(query.query) +
Expand Down Expand Up @@ -1271,7 +1276,7 @@
resultIndex;
var params = getQueryStringParams();

query = getQuery();
query = getQuery(document.getElementsByClassName('search-input')[0].value);
if (e) {
e.preventDefault();
}
Expand All @@ -1293,19 +1298,10 @@
}
}

results = execQuery(query, 20000, index);
results = execQuery(query, index);
showResults(results);
}

function itemTypeFromName(typename) {
for (var i = 0; i < itemTypes.length; ++i) {
if (itemTypes[i] === typename) {
return i;
}
}
return -1;
}

function buildIndex(rawSearchIndex) {
searchIndex = [];
var searchWords = [];
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ pub fn opts() -> Vec<RustcOptGroup> {
or `#![doc(html_playground_url=...)]`",
"URL")
}),
unstable("enable-commonmark", |o| {
o.optflag("", "enable-commonmark", "to enable commonmark doc rendering/testing")
unstable("disable-commonmark", |o| {
o.optflag("", "disable-commonmark", "to disable commonmark doc rendering/testing")
}),
unstable("display-warnings", |o| {
o.optflag("", "display-warnings", "to print code warnings when testing doc")
Expand Down Expand Up @@ -347,10 +347,10 @@ pub fn main_args(args: &[String]) -> isize {
let css_file_extension = matches.opt_str("e").map(|s| PathBuf::from(&s));
let cfgs = matches.opt_strs("cfg");

let render_type = if matches.opt_present("enable-commonmark") {
RenderType::Pulldown
} else {
let render_type = if matches.opt_present("disable-commonmark") {
RenderType::Hoedown
} else {
RenderType::Pulldown
};

if let Some(ref p) = css_file_extension {
Expand Down
16 changes: 9 additions & 7 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ pub struct DirBuilder {
recursive: bool,
}

/// How large a buffer to pre-allocate before reading the entire file at `path`.
fn initial_buffer_size<P: AsRef<Path>>(path: P) -> usize {
/// How large a buffer to pre-allocate before reading the entire file.
fn initial_buffer_size(file: &File) -> usize {
// Allocate one extra byte so the buffer doesn't need to grow before the
// final `read` call at the end of the file. Don't worry about `usize`
// overflow because reading will fail regardless in that case.
metadata(path).map(|m| m.len() as usize + 1).unwrap_or(0)
file.metadata().map(|m| m.len() as usize + 1).unwrap_or(0)
}

/// Read the entire contents of a file into a bytes vector.
Expand Down Expand Up @@ -254,8 +254,9 @@ fn initial_buffer_size<P: AsRef<Path>>(path: P) -> usize {
/// ```
#[unstable(feature = "fs_read_write", issue = "46588")]
pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
let mut bytes = Vec::with_capacity(initial_buffer_size(&path));
File::open(path)?.read_to_end(&mut bytes)?;
let mut file = File::open(path)?;
let mut bytes = Vec::with_capacity(initial_buffer_size(&file));
file.read_to_end(&mut bytes)?;
Ok(bytes)
}

Expand Down Expand Up @@ -295,8 +296,9 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
/// ```
#[unstable(feature = "fs_read_write", issue = "46588")]
pub fn read_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
let mut string = String::with_capacity(initial_buffer_size(&path));
File::open(path)?.read_to_string(&mut string)?;
let mut file = File::open(path)?;
let mut string = String::with_capacity(initial_buffer_size(&file));
file.read_to_string(&mut string)?;
Ok(string)
}

Expand Down
Loading

0 comments on commit 3bd4af8

Please sign in to comment.