Skip to content

Commit 3bd4af8

Browse files
committed
Auto merge of #47528 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 6 pull requests - Successful merges: #47250, #47313, #47398, #47468, #47471, #47520 - Failed merges:
2 parents 44afd76 + 2606537 commit 3bd4af8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+821
-115
lines changed

src/bootstrap/builder.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ impl<'a> Builder<'a> {
254254
Kind::Test => describe!(check::Tidy, check::Bootstrap, check::DefaultCompiletest,
255255
check::HostCompiletest, check::Crate, check::CrateLibrustc, check::Rustdoc,
256256
check::Linkcheck, check::Cargotest, check::Cargo, check::Rls, check::Docs,
257-
check::ErrorIndex, check::Distcheck, check::Rustfmt, check::Miri, check::Clippy),
257+
check::ErrorIndex, check::Distcheck, check::Rustfmt, check::Miri, check::Clippy,
258+
check::RustdocJS),
259+
258260
Kind::Bench => describe!(check::Crate, check::CrateLibrustc),
259261
Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
260262
doc::Standalone, doc::Std, doc::Test, doc::Rustc, doc::ErrorIndex, doc::Nomicon,
@@ -443,7 +445,8 @@ impl<'a> Builder<'a> {
443445
let out_dir = self.stage_out(compiler, mode);
444446
cargo.env("CARGO_TARGET_DIR", out_dir)
445447
.arg(cmd)
446-
.arg("--target").arg(target);
448+
.arg("--target")
449+
.arg(target);
447450

448451
// If we were invoked from `make` then that's already got a jobserver
449452
// set up for us so no need to tell Cargo about jobs all over again.

src/bootstrap/check.rs

+37
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,43 @@ fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
424424
env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
425425
}
426426

427+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
428+
pub struct RustdocJS {
429+
pub host: Interned<String>,
430+
pub target: Interned<String>,
431+
}
432+
433+
impl Step for RustdocJS {
434+
type Output = ();
435+
const DEFAULT: bool = true;
436+
const ONLY_HOSTS: bool = true;
437+
438+
fn should_run(run: ShouldRun) -> ShouldRun {
439+
run.path("src/test/rustdoc-js")
440+
}
441+
442+
fn make_run(run: RunConfig) {
443+
run.builder.ensure(RustdocJS {
444+
host: run.host,
445+
target: run.target,
446+
});
447+
}
448+
449+
fn run(self, builder: &Builder) {
450+
if let Some(ref nodejs) = builder.config.nodejs {
451+
let mut command = Command::new(nodejs);
452+
command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
453+
builder.ensure(::doc::Std {
454+
target: self.target,
455+
stage: builder.top_stage,
456+
});
457+
builder.run(&mut command);
458+
} else {
459+
println!("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
460+
}
461+
}
462+
}
463+
427464
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
428465
pub struct Tidy {
429466
host: Interned<String>,

src/bootstrap/doc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@ impl Step for Standalone {
419419

420420
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
421421
pub struct Std {
422-
stage: u32,
423-
target: Interned<String>,
422+
pub stage: u32,
423+
pub target: Interned<String>,
424424
}
425425

426426
impl Step for Std {

src/librustc/traits/error_reporting.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12411241
}
12421242
ObligationCauseCode::ItemObligation(item_def_id) => {
12431243
let item_name = tcx.item_path_str(item_def_id);
1244-
err.note(&format!("required by `{}`", item_name));
1244+
let msg = format!("required by `{}`", item_name);
1245+
if let Some(sp) = tcx.hir.span_if_local(item_def_id) {
1246+
let sp = tcx.sess.codemap().def_span(sp);
1247+
err.span_note(sp, &msg);
1248+
} else {
1249+
err.note(&msg);
1250+
}
12451251
}
12461252
ObligationCauseCode::ObjectCastObligation(object_ty) => {
12471253
err.note(&format!("required for the cast to the object type `{}`",

src/librustc_borrowck/borrowck/mod.rs

+25-3
Original file line numberDiff line numberDiff line change
@@ -842,10 +842,32 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
842842
if let mc::NoteClosureEnv(upvar_id) = err.cmt.note {
843843
let node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
844844
let sp = self.tcx.hir.span(node_id);
845-
match self.tcx.sess.codemap().span_to_snippet(sp) {
846-
Ok(snippet) => {
845+
let fn_closure_msg = "`Fn` closures cannot capture their enclosing \
846+
environment for modifications";
847+
match (self.tcx.sess.codemap().span_to_snippet(sp), &err.cmt.cat) {
848+
(_, &Categorization::Upvar(mc::Upvar {
849+
kind: ty::ClosureKind::Fn, ..
850+
})) => {
851+
db.note(fn_closure_msg);
852+
// we should point at the cause for this closure being
853+
// identified as `Fn` (like in signature of method this
854+
// closure was passed into)
855+
}
856+
(Ok(ref snippet), ref cat) => {
847857
let msg = &format!("consider making `{}` mutable", snippet);
848-
db.span_suggestion(sp, msg, format!("mut {}", snippet));
858+
let suggestion = format!("mut {}", snippet);
859+
860+
if let &Categorization::Deref(ref cmt, _) = cat {
861+
if let Categorization::Upvar(mc::Upvar {
862+
kind: ty::ClosureKind::Fn, ..
863+
}) = cmt.cat {
864+
db.note(fn_closure_msg);
865+
} else {
866+
db.span_suggestion(sp, msg, suggestion);
867+
}
868+
} else {
869+
db.span_suggestion(sp, msg, suggestion);
870+
}
849871
}
850872
_ => {
851873
db.span_help(sp, "consider making this binding mutable");

src/librustdoc/clean/inline.rs

+9
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
328328
if trait_.def_id() == tcx.lang_items().deref_trait() {
329329
super::build_deref_target_impls(cx, &trait_items, ret);
330330
}
331+
if let Some(trait_did) = trait_.def_id() {
332+
record_extern_trait(cx, trait_did);
333+
}
331334

332335
let provided = trait_.def_id().map(|did| {
333336
tcx.provided_trait_methods(did)
@@ -483,3 +486,9 @@ fn separate_supertrait_bounds(mut g: clean::Generics)
483486
});
484487
(g, ty_bounds)
485488
}
489+
490+
pub fn record_extern_trait(cx: &DocContext, did: DefId) {
491+
cx.external_traits.borrow_mut().entry(did).or_insert_with(|| {
492+
build_external_trait(cx, did)
493+
});
494+
}

src/librustdoc/clean/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3163,8 +3163,7 @@ fn register_def(cx: &DocContext, def: Def) -> DefId {
31633163
if did.is_local() { return did }
31643164
inline::record_extern_fqn(cx, did, kind);
31653165
if let TypeKind::Trait = kind {
3166-
let t = inline::build_external_trait(cx, did);
3167-
cx.external_traits.borrow_mut().insert(did, t);
3166+
inline::record_extern_trait(cx, did);
31683167
}
31693168
did
31703169
}

src/librustdoc/html/render.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3277,8 +3277,7 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
32773277
if let Some(impls) = c.impls.get(&did) {
32783278
for i in impls {
32793279
let impl_ = i.inner_impl();
3280-
if impl_.trait_.def_id().and_then(|d| c.traits.get(&d))
3281-
.map_or(false, |t| t.is_spotlight) {
3280+
if impl_.trait_.def_id().map_or(false, |d| c.traits[&d].is_spotlight) {
32823281
if out.is_empty() {
32833282
out.push_str(
32843283
&format!("<h3 class=\"important\">Important traits for {}</h3>\
@@ -3444,7 +3443,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
34443443
}
34453444

34463445
let traits = &cache().traits;
3447-
let trait_ = i.trait_did().and_then(|did| traits.get(&did));
3446+
let trait_ = i.trait_did().map(|did| &traits[&did]);
34483447

34493448
if !show_def_docs {
34503449
write!(w, "<span class='docblock autohide'>")?;

src/librustdoc/html/static/main.js

+39-43
Original file line numberDiff line numberDiff line change
@@ -353,35 +353,33 @@
353353
* This code is an unmodified version of the code written by Marco de Wit
354354
* and was found at http://stackoverflow.com/a/18514751/745719
355355
*/
356-
var levenshtein = (function() {
357-
var row2 = [];
358-
return function(s1, s2) {
359-
if (s1 === s2) {
360-
return 0;
356+
var levenshtein_row2 = [];
357+
function levenshtein(s1, s2) {
358+
if (s1 === s2) {
359+
return 0;
360+
}
361+
var s1_len = s1.length, s2_len = s2.length;
362+
if (s1_len && s2_len) {
363+
var i1 = 0, i2 = 0, a, b, c, c2, row = levenshtein_row2;
364+
while (i1 < s1_len) {
365+
row[i1] = ++i1;
361366
}
362-
var s1_len = s1.length, s2_len = s2.length;
363-
if (s1_len && s2_len) {
364-
var i1 = 0, i2 = 0, a, b, c, c2, row = row2;
365-
while (i1 < s1_len) {
366-
row[i1] = ++i1;
367-
}
368-
while (i2 < s2_len) {
369-
c2 = s2.charCodeAt(i2);
370-
a = i2;
371-
++i2;
372-
b = i2;
373-
for (i1 = 0; i1 < s1_len; ++i1) {
374-
c = a + (s1.charCodeAt(i1) !== c2 ? 1 : 0);
375-
a = row[i1];
376-
b = b < a ? (b < c ? b + 1 : c) : (a < c ? a + 1 : c);
377-
row[i1] = b;
378-
}
367+
while (i2 < s2_len) {
368+
c2 = s2.charCodeAt(i2);
369+
a = i2;
370+
++i2;
371+
b = i2;
372+
for (i1 = 0; i1 < s1_len; ++i1) {
373+
c = a + (s1.charCodeAt(i1) !== c2 ? 1 : 0);
374+
a = row[i1];
375+
b = b < a ? (b < c ? b + 1 : c) : (a < c ? a + 1 : c);
376+
row[i1] = b;
379377
}
380-
return b;
381378
}
382-
return s1_len + s2_len;
383-
};
384-
})();
379+
return b;
380+
}
381+
return s1_len + s2_len;
382+
}
385383

386384
function initSearch(rawSearchIndex) {
387385
var currentResults, index, searchIndex;
@@ -400,12 +398,20 @@
400398
/**
401399
* Executes the query and builds an index of results
402400
* @param {[Object]} query [The user query]
403-
* @param {[type]} max [The maximum results returned]
404401
* @param {[type]} searchWords [The list of search words to query
405402
* against]
406403
* @return {[type]} [A search index of results]
407404
*/
408-
function execQuery(query, max, searchWords) {
405+
function execQuery(query, searchWords) {
406+
function itemTypeFromName(typename) {
407+
for (var i = 0; i < itemTypes.length; ++i) {
408+
if (itemTypes[i] === typename) {
409+
return i;
410+
}
411+
}
412+
return -1;
413+
}
414+
409415
var valLower = query.query.toLowerCase(),
410416
val = valLower,
411417
typeFilter = itemTypeFromName(query.type),
@@ -1021,9 +1027,8 @@
10211027
return true;
10221028
}
10231029

1024-
function getQuery() {
1025-
var matches, type, query, raw =
1026-
document.getElementsByClassName('search-input')[0].value;
1030+
function getQuery(raw) {
1031+
var matches, type, query;
10271032
query = raw;
10281033

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

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

12321237
currentResults = query.id;
12331238
output = '<h1>Results for ' + escape(query.query) +
@@ -1271,7 +1276,7 @@
12711276
resultIndex;
12721277
var params = getQueryStringParams();
12731278

1274-
query = getQuery();
1279+
query = getQuery(document.getElementsByClassName('search-input')[0].value);
12751280
if (e) {
12761281
e.preventDefault();
12771282
}
@@ -1293,19 +1298,10 @@
12931298
}
12941299
}
12951300

1296-
results = execQuery(query, 20000, index);
1301+
results = execQuery(query, index);
12971302
showResults(results);
12981303
}
12991304

1300-
function itemTypeFromName(typename) {
1301-
for (var i = 0; i < itemTypes.length; ++i) {
1302-
if (itemTypes[i] === typename) {
1303-
return i;
1304-
}
1305-
}
1306-
return -1;
1307-
}
1308-
13091305
function buildIndex(rawSearchIndex) {
13101306
searchIndex = [];
13111307
var searchWords = [];

src/librustdoc/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ pub fn opts() -> Vec<RustcOptGroup> {
242242
or `#![doc(html_playground_url=...)]`",
243243
"URL")
244244
}),
245-
unstable("enable-commonmark", |o| {
246-
o.optflag("", "enable-commonmark", "to enable commonmark doc rendering/testing")
245+
unstable("disable-commonmark", |o| {
246+
o.optflag("", "disable-commonmark", "to disable commonmark doc rendering/testing")
247247
}),
248248
unstable("display-warnings", |o| {
249249
o.optflag("", "display-warnings", "to print code warnings when testing doc")
@@ -347,10 +347,10 @@ pub fn main_args(args: &[String]) -> isize {
347347
let css_file_extension = matches.opt_str("e").map(|s| PathBuf::from(&s));
348348
let cfgs = matches.opt_strs("cfg");
349349

350-
let render_type = if matches.opt_present("enable-commonmark") {
351-
RenderType::Pulldown
352-
} else {
350+
let render_type = if matches.opt_present("disable-commonmark") {
353351
RenderType::Hoedown
352+
} else {
353+
RenderType::Pulldown
354354
};
355355

356356
if let Some(ref p) = css_file_extension {

src/libstd/fs.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ pub struct DirBuilder {
211211
recursive: bool,
212212
}
213213

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

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

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

0 commit comments

Comments
 (0)