Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6c869d3

Browse files
committedJan 16, 2021
Auto merge of #81057 - GuillaumeGomez:rollup-yl2kqst, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - #77693 (Add test for #59352) - #80515 (Improve JS performance by storing length before comparing to it in loops) - #81030 (Update mdbook) - #81033 (Remove useless `clean::Variant` struct) - #81049 (inline: Round word-size cost estimates up) - #81054 (Drop a few unneeded borrows) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents fcbd305 + f8b1baa commit 6c869d3

File tree

15 files changed

+231
-112
lines changed

15 files changed

+231
-112
lines changed
 

‎Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,9 +1973,9 @@ dependencies = [
19731973

19741974
[[package]]
19751975
name = "mdbook"
1976-
version = "0.4.5"
1976+
version = "0.4.6"
19771977
source = "registry+https://github.com/rust-lang/crates.io-index"
1978-
checksum = "21251d3eb9ca5e8ac5b73384ddaa483a9bbc7d7dcd656b1fa8f266634810334a"
1978+
checksum = "b3d948b64449003363127ed6c6139f03273982c3fe97da4cb3dee933e38ce38f"
19791979
dependencies = [
19801980
"ammonia",
19811981
"anyhow",

‎compiler/rustc_mir/src/transform/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl Inliner<'tcx> {
382382
// Cost of the var is the size in machine-words, if we know
383383
// it.
384384
if let Some(size) = type_size_of(tcx, self.param_env, ty) {
385-
cost += (size / ptr_size) as usize;
385+
cost += ((size + ptr_size - 1) / ptr_size) as usize;
386386
} else {
387387
cost += UNKNOWN_SIZE_COST;
388388
}

‎compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -813,25 +813,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
813813
if ty.is_never() {
814814
None
815815
} else {
816-
Some(match &elem.kind {
816+
Some(match elem.kind {
817817
// Point at the tail expression when possible.
818818
hir::ExprKind::Block(block, _) => {
819-
block.expr.as_ref().map_or(block.span, |e| e.span)
819+
block.expr.map_or(block.span, |e| e.span)
820820
}
821821
_ => elem.span,
822822
})
823823
}
824824
})
825825
};
826826

827-
if let hir::ExprKind::If(_, _, Some(el)) = &expr.kind {
827+
if let hir::ExprKind::If(_, _, Some(el)) = expr.kind {
828828
if let Some(rslt) = check_in_progress(el) {
829829
return rslt;
830830
}
831831
}
832832

833-
if let hir::ExprKind::Match(_, arms, _) = &expr.kind {
834-
let mut iter = arms.iter().filter_map(|arm| check_in_progress(&arm.body));
833+
if let hir::ExprKind::Match(_, arms, _) = expr.kind {
834+
let mut iter = arms.iter().filter_map(|arm| check_in_progress(arm.body));
835835
if let Some(span) = iter.next() {
836836
if iter.next().is_none() {
837837
return span;

‎src/librustdoc/clean/mod.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,11 +1840,11 @@ impl Clean<VariantStruct> for rustc_hir::VariantData<'_> {
18401840
impl Clean<Item> for ty::VariantDef {
18411841
fn clean(&self, cx: &DocContext<'_>) -> Item {
18421842
let kind = match self.ctor_kind {
1843-
CtorKind::Const => VariantKind::CLike,
1844-
CtorKind::Fn => VariantKind::Tuple(
1843+
CtorKind::Const => Variant::CLike,
1844+
CtorKind::Fn => Variant::Tuple(
18451845
self.fields.iter().map(|f| cx.tcx.type_of(f.did).clean(cx)).collect(),
18461846
),
1847-
CtorKind::Fictive => VariantKind::Struct(VariantStruct {
1847+
CtorKind::Fictive => Variant::Struct(VariantStruct {
18481848
struct_type: doctree::Plain,
18491849
fields_stripped: false,
18501850
fields: self
@@ -1861,25 +1861,21 @@ impl Clean<Item> for ty::VariantDef {
18611861
.collect(),
18621862
}),
18631863
};
1864-
let what_rustc_thinks = Item::from_def_id_and_parts(
1865-
self.def_id,
1866-
Some(self.ident.name),
1867-
VariantItem(Variant { kind }),
1868-
cx,
1869-
);
1864+
let what_rustc_thinks =
1865+
Item::from_def_id_and_parts(self.def_id, Some(self.ident.name), VariantItem(kind), cx);
18701866
// don't show `pub` for fields, which are always public
18711867
Item { visibility: Inherited, ..what_rustc_thinks }
18721868
}
18731869
}
18741870

1875-
impl Clean<VariantKind> for hir::VariantData<'_> {
1876-
fn clean(&self, cx: &DocContext<'_>) -> VariantKind {
1871+
impl Clean<Variant> for hir::VariantData<'_> {
1872+
fn clean(&self, cx: &DocContext<'_>) -> Variant {
18771873
match self {
1878-
hir::VariantData::Struct(..) => VariantKind::Struct(self.clean(cx)),
1874+
hir::VariantData::Struct(..) => Variant::Struct(self.clean(cx)),
18791875
hir::VariantData::Tuple(..) => {
1880-
VariantKind::Tuple(self.fields().iter().map(|x| x.ty.clean(cx)).collect())
1876+
Variant::Tuple(self.fields().iter().map(|x| x.ty.clean(cx)).collect())
18811877
}
1882-
hir::VariantData::Unit(..) => VariantKind::CLike,
1878+
hir::VariantData::Unit(..) => Variant::CLike,
18831879
}
18841880
}
18851881
}
@@ -2048,7 +2044,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
20482044

20492045
impl Clean<Item> for hir::Variant<'_> {
20502046
fn clean(&self, cx: &DocContext<'_>) -> Item {
2051-
let kind = VariantItem(Variant { kind: self.data.clean(cx) });
2047+
let kind = VariantItem(self.data.clean(cx));
20522048
let what_rustc_thinks =
20532049
Item::from_hir_id_and_parts(self.id, Some(self.ident.name), kind, cx);
20542050
// don't show `pub` for variants, which are always public

‎src/librustdoc/clean/types.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ impl Item {
237237
match *self.kind {
238238
StructItem(ref _struct) => Some(_struct.fields_stripped),
239239
UnionItem(ref union) => Some(union.fields_stripped),
240-
VariantItem(Variant { kind: VariantKind::Struct(ref vstruct) }) => {
241-
Some(vstruct.fields_stripped)
242-
}
240+
VariantItem(Variant::Struct(ref vstruct)) => Some(vstruct.fields_stripped),
243241
_ => None,
244242
}
245243
}
@@ -353,7 +351,7 @@ impl ItemKind {
353351
match self {
354352
StructItem(s) => s.fields.iter(),
355353
UnionItem(u) => u.fields.iter(),
356-
VariantItem(Variant { kind: VariantKind::Struct(v) }) => v.fields.iter(),
354+
VariantItem(Variant::Struct(v)) => v.fields.iter(),
357355
EnumItem(e) => e.variants.iter(),
358356
TraitItem(t) => t.items.iter(),
359357
ImplItem(i) => i.items.iter(),
@@ -1719,12 +1717,7 @@ crate struct Enum {
17191717
}
17201718

17211719
#[derive(Clone, Debug)]
1722-
crate struct Variant {
1723-
crate kind: VariantKind,
1724-
}
1725-
1726-
#[derive(Clone, Debug)]
1727-
crate enum VariantKind {
1720+
crate enum Variant {
17281721
CLike,
17291722
Tuple(Vec<Type>),
17301723
Struct(VariantStruct),

‎src/librustdoc/fold.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ crate trait DocFolder: Sized {
5555
}
5656
VariantItem(i) => {
5757
let i2 = i.clone(); // this clone is small
58-
match i.kind {
59-
VariantKind::Struct(mut j) => {
58+
match i {
59+
Variant::Struct(mut j) => {
6060
let num_fields = j.fields.len();
6161
j.fields = j.fields.into_iter().filter_map(|x| self.fold_item(x)).collect();
6262
j.fields_stripped |= num_fields != j.fields.len()
6363
|| j.fields.iter().any(|f| f.is_stripped());
64-
VariantItem(Variant { kind: VariantKind::Struct(j) })
64+
VariantItem(Variant::Struct(j))
6565
}
6666
_ => VariantItem(i2),
6767
}

‎src/librustdoc/html/render/mod.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,9 +3200,9 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
32003200
write!(w, " ");
32013201
let name = v.name.as_ref().unwrap();
32023202
match *v.kind {
3203-
clean::VariantItem(ref var) => match var.kind {
3204-
clean::VariantKind::CLike => write!(w, "{}", name),
3205-
clean::VariantKind::Tuple(ref tys) => {
3203+
clean::VariantItem(ref var) => match var {
3204+
clean::Variant::CLike => write!(w, "{}", name),
3205+
clean::Variant::Tuple(ref tys) => {
32063206
write!(w, "{}(", name);
32073207
for (i, ty) in tys.iter().enumerate() {
32083208
if i > 0 {
@@ -3212,7 +3212,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
32123212
}
32133213
write!(w, ")");
32143214
}
3215-
clean::VariantKind::Struct(ref s) => {
3215+
clean::Variant::Struct(ref s) => {
32163216
render_struct(w, v, None, s.struct_type, &s.fields, " ", false, cx);
32173217
}
32183218
},
@@ -3249,25 +3249,22 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
32493249
id = id,
32503250
name = variant.name.as_ref().unwrap()
32513251
);
3252-
if let clean::VariantItem(ref var) = *variant.kind {
3253-
if let clean::VariantKind::Tuple(ref tys) = var.kind {
3254-
write!(w, "(");
3255-
for (i, ty) in tys.iter().enumerate() {
3256-
if i > 0 {
3257-
write!(w, ",&nbsp;");
3258-
}
3259-
write!(w, "{}", ty.print());
3252+
if let clean::VariantItem(clean::Variant::Tuple(ref tys)) = *variant.kind {
3253+
write!(w, "(");
3254+
for (i, ty) in tys.iter().enumerate() {
3255+
if i > 0 {
3256+
write!(w, ",&nbsp;");
32603257
}
3261-
write!(w, ")");
3258+
write!(w, "{}", ty.print());
32623259
}
3260+
write!(w, ")");
32633261
}
32643262
write!(w, "</code></div>");
32653263
document(w, cx, variant, Some(it));
32663264
document_non_exhaustive(w, variant);
32673265

3268-
use crate::clean::{Variant, VariantKind};
3269-
if let clean::VariantItem(Variant { kind: VariantKind::Struct(ref s) }) = *variant.kind
3270-
{
3266+
use crate::clean::Variant;
3267+
if let clean::VariantItem(Variant::Struct(ref s)) = *variant.kind {
32713268
let variant_id = cx.derive_id(format!(
32723269
"{}.{}.fields",
32733270
ItemType::Variant,

‎src/librustdoc/html/static/main.js

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,7 @@ function defocusSearchBar() {
648648
*/
649649
function execQuery(query, searchWords, filterCrates) {
650650
function itemTypeFromName(typename) {
651-
var length = itemTypes.length;
652-
for (var i = 0; i < length; ++i) {
651+
for (var i = 0, len = itemTypes.length; i < len; ++i) {
653652
if (itemTypes[i] === typename) {
654653
return i;
655654
}
@@ -667,8 +666,7 @@ function defocusSearchBar() {
667666

668667
function transformResults(results, isType) {
669668
var out = [];
670-
var length = results.length;
671-
for (var i = 0; i < length; ++i) {
669+
for (var i = 0, len = results.length; i < len; ++i) {
672670
if (results[i].id > -1) {
673671
var obj = searchIndex[results[i].id];
674672
obj.lev = results[i].lev;
@@ -697,11 +695,11 @@ function defocusSearchBar() {
697695
}
698696
}
699697
results = ar;
700-
var i;
701-
var nresults = results.length;
702-
for (i = 0; i < nresults; ++i) {
703-
results[i].word = searchWords[results[i].id];
704-
results[i].item = searchIndex[results[i].id] || {};
698+
var i, len, result;
699+
for (i = 0, len = results.length; i < len; ++i) {
700+
result = results[i];
701+
result.word = searchWords[result.id];
702+
result.item = searchIndex[result.id] || {};
705703
}
706704
// if there are no results then return to default and fail
707705
if (results.length === 0) {
@@ -775,8 +773,7 @@ function defocusSearchBar() {
775773
return 0;
776774
});
777775

778-
var length = results.length;
779-
for (i = 0; i < length; ++i) {
776+
for (i = 0, len = results.length; i < len; ++i) {
780777
var result = results[i];
781778

782779
// this validation does not make sense when searching by types
@@ -833,11 +830,10 @@ function defocusSearchBar() {
833830
var vlength = val.generics.length;
834831
for (var y = 0; y < vlength; ++y) {
835832
var lev = { pos: -1, lev: MAX_LEV_DISTANCE + 1};
836-
var elength = elems.length;
837833
var firstGeneric = getObjectFromId(val.generics[y]).name;
838-
for (var x = 0; x < elength; ++x) {
834+
for (var x = 0, elength = elems.length; x < elength; ++x) {
839835
var tmp_lev = levenshtein(getObjectFromId(elems[x]).name,
840-
firstGeneric);
836+
firstGeneric);
841837
if (tmp_lev < lev.lev) {
842838
lev.lev = tmp_lev;
843839
lev.pos = x;
@@ -861,7 +857,7 @@ function defocusSearchBar() {
861857
// Check for type name and type generics (if any).
862858
function checkType(obj, val, literalSearch) {
863859
var lev_distance = MAX_LEV_DISTANCE + 1;
864-
var x;
860+
var len, x, y, e_len, firstGeneric;
865861
if (obj[NAME] === val.name) {
866862
if (literalSearch === true) {
867863
if (val.generics && val.generics.length !== 0) {
@@ -870,10 +866,12 @@ function defocusSearchBar() {
870866
var elems = obj[GENERICS_DATA].slice(0);
871867
var allFound = true;
872868

873-
for (var y = 0; allFound === true && y < val.generics.length; ++y) {
869+
len = val.generics.length;
870+
for (y = 0; allFound === true && y < len; ++y) {
874871
allFound = false;
875-
var firstGeneric = getObjectFromId(val.generics[y]).name;
876-
for (x = 0; allFound === false && x < elems.length; ++x) {
872+
firstGeneric = getObjectFromId(val.generics[y]).name;
873+
e_len = elems.length;
874+
for (x = 0; allFound === false && x < e_len; ++x) {
877875
allFound = getObjectFromId(elems[x]).name === firstGeneric;
878876
}
879877
if (allFound === true) {
@@ -903,12 +901,10 @@ function defocusSearchBar() {
903901
// Names didn't match so let's check if one of the generic types could.
904902
if (literalSearch === true) {
905903
if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) {
906-
var length = obj[GENERICS_DATA].length;
907-
for (x = 0; x < length; ++x) {
908-
if (obj[GENERICS_DATA][x] === val.name) {
909-
return true;
910-
}
911-
}
904+
return obj[GENERICS_DATA].some(
905+
function(name) {
906+
return name === val.name;
907+
});
912908
}
913909
return false;
914910
}
@@ -965,7 +961,7 @@ function defocusSearchBar() {
965961
if (typeof ret[0] === "string") {
966962
ret = [ret];
967963
}
968-
for (var x = 0; x < ret.length; ++x) {
964+
for (var x = 0, len = ret.length; x < len; ++x) {
969965
var tmp = ret[x];
970966
if (typePassesFilter(typeFilter, tmp[1]) === false) {
971967
continue;
@@ -1072,23 +1068,22 @@ function defocusSearchBar() {
10721068
// aliases to be before the others in the displayed results.
10731069
var aliases = [];
10741070
var crateAliases = [];
1075-
var i;
10761071
if (filterCrates !== undefined) {
10771072
if (ALIASES[filterCrates] && ALIASES[filterCrates][query.search]) {
1078-
for (i = 0; i < ALIASES[filterCrates][query.search].length; ++i) {
1079-
aliases.push(
1080-
createAliasFromItem(
1081-
searchIndex[ALIASES[filterCrates][query.search][i]]));
1073+
var query_aliases = ALIASES[filterCrates][query.search];
1074+
var len = query_aliases.length;
1075+
for (var i = 0; i < len; ++i) {
1076+
aliases.push(createAliasFromItem(searchIndex[query_aliases[i]]));
10821077
}
10831078
}
10841079
} else {
10851080
Object.keys(ALIASES).forEach(function(crate) {
10861081
if (ALIASES[crate][query.search]) {
10871082
var pushTo = crate === window.currentCrate ? crateAliases : aliases;
1088-
for (i = 0; i < ALIASES[crate][query.search].length; ++i) {
1089-
pushTo.push(
1090-
createAliasFromItem(
1091-
searchIndex[ALIASES[crate][query.search][i]]));
1083+
var query_aliases = ALIASES[crate][query.search];
1084+
var len = query_aliases.length;
1085+
for (var i = 0; i < len; ++i) {
1086+
pushTo.push(createAliasFromItem(searchIndex[query_aliases[i]]));
10921087
}
10931088
}
10941089
});
@@ -1123,11 +1118,12 @@ function defocusSearchBar() {
11231118

11241119
// quoted values mean literal search
11251120
var nSearchWords = searchWords.length;
1126-
var i;
1121+
var i, it;
11271122
var ty;
11281123
var fullId;
11291124
var returned;
11301125
var in_args;
1126+
var len;
11311127
if ((val.charAt(0) === "\"" || val.charAt(0) === "'") &&
11321128
val.charAt(val.length - 1) === val.charAt(0))
11331129
{
@@ -1175,7 +1171,7 @@ function defocusSearchBar() {
11751171
var input = parts[0];
11761172
// sort inputs so that order does not matter
11771173
var inputs = input.split(",").map(trimmer).sort();
1178-
for (i = 0; i < inputs.length; ++i) {
1174+
for (i = 0, len = inputs.length; i < len; ++i) {
11791175
inputs[i] = extractGenerics(inputs[i]);
11801176
}
11811177
var output = extractGenerics(parts[1]);
@@ -1200,7 +1196,7 @@ function defocusSearchBar() {
12001196
is_module = true;
12011197
} else {
12021198
var allFound = true;
1203-
for (var it = 0; allFound === true && it < inputs.length; it++) {
1199+
for (it = 0, len = inputs.length; allFound === true && it < len; it++) {
12041200
allFound = checkType(type, inputs[it], true);
12051201
}
12061202
in_args = allFound;
@@ -1243,7 +1239,7 @@ function defocusSearchBar() {
12431239

12441240
var paths = valLower.split("::");
12451241
var j;
1246-
for (j = 0; j < paths.length; ++j) {
1242+
for (j = 0, len = paths.length; j < len; ++j) {
12471243
if (paths[j] === "") {
12481244
paths.splice(j, 1);
12491245
j -= 1;
@@ -1365,7 +1361,7 @@ function defocusSearchBar() {
13651361
* @return {[boolean]} [Whether the result is valid or not]
13661362
*/
13671363
function validateResult(name, path, keys, parent) {
1368-
for (var i = 0; i < keys.length; ++i) {
1364+
for (var i = 0, len = keys.length; i < len; ++i) {
13691365
// each check is for validation so we negate the conditions and invalidate
13701366
if (!(
13711367
// check for an exact name match
@@ -1686,7 +1682,7 @@ function defocusSearchBar() {
16861682
function getSmallest(arrays, positions, notDuplicates) {
16871683
var start = null;
16881684

1689-
for (var it = 0; it < positions.length; ++it) {
1685+
for (var it = 0, len = positions.length; it < len; ++it) {
16901686
if (arrays[it].length > positions[it] &&
16911687
(start === null || start > arrays[it][positions[it]].lev) &&
16921688
!notDuplicates[arrays[it][positions[it]].fullPath]) {
@@ -1701,7 +1697,7 @@ function defocusSearchBar() {
17011697
var positions = [];
17021698
var notDuplicates = {};
17031699

1704-
for (var x = 0; x < arrays.length; ++x) {
1700+
for (var x = 0, arrays_len = arrays.length; x < arrays_len; ++x) {
17051701
positions.push(0);
17061702
}
17071703
while (ret.length < MAX_RESULTS) {
@@ -1710,7 +1706,7 @@ function defocusSearchBar() {
17101706
if (smallest === null) {
17111707
break;
17121708
}
1713-
for (x = 0; x < arrays.length && ret.length < MAX_RESULTS; ++x) {
1709+
for (x = 0; x < arrays_len && ret.length < MAX_RESULTS; ++x) {
17141710
if (arrays[x].length > positions[x] &&
17151711
arrays[x][positions[x]].lev === smallest &&
17161712
!notDuplicates[arrays[x][positions[x]].fullPath]) {
@@ -1730,7 +1726,7 @@ function defocusSearchBar() {
17301726
"others": [],
17311727
};
17321728

1733-
for (var i = 0; i < queries.length; ++i) {
1729+
for (var i = 0, len = queries.length; i < len; ++i) {
17341730
query = queries[i].trim();
17351731
if (query.length !== 0) {
17361732
var tmp = execQuery(getQuery(query), searchWords, filterCrates);
@@ -1884,7 +1880,7 @@ function defocusSearchBar() {
18841880
ALIASES[crate][alias_name] = [];
18851881
}
18861882
local_aliases = aliases[alias_name];
1887-
for (j = 0; j < local_aliases.length; ++j) {
1883+
for (j = 0, len = local_aliases.length; j < len; ++j) {
18881884
ALIASES[crate][alias_name].push(local_aliases[j] + currentIndex);
18891885
}
18901886
}
@@ -2052,8 +2048,7 @@ function defocusSearchBar() {
20522048
div.appendChild(h3);
20532049
var ul = document.createElement("ul");
20542050

2055-
var length = filtered.length;
2056-
for (var i = 0; i < length; ++i) {
2051+
for (var i = 0, len = filtered.length; i < len; ++i) {
20572052
var item = filtered[i];
20582053
var name = item[0];
20592054
var desc = item[1]; // can be null
@@ -2122,21 +2117,18 @@ function defocusSearchBar() {
21222117
}
21232118

21242119
var libs = Object.getOwnPropertyNames(imp);
2125-
var llength = libs.length;
2126-
for (var i = 0; i < llength; ++i) {
2120+
for (var i = 0, llength = libs.length; i < llength; ++i) {
21272121
if (libs[i] === currentCrate) { continue; }
21282122
var structs = imp[libs[i]];
21292123

2130-
var slength = structs.length;
21312124
struct_loop:
2132-
for (var j = 0; j < slength; ++j) {
2125+
for (var j = 0, slength = structs.length; j < slength; ++j) {
21332126
var struct = structs[j];
21342127

21352128
var list = struct.synthetic ? synthetic_implementors : implementors;
21362129

21372130
if (struct.synthetic) {
2138-
var stlength = struct.types.length;
2139-
for (var k = 0; k < stlength; k++) {
2131+
for (var k = 0, stlength = struct.types.length; k < stlength; k++) {
21402132
if (inlined_types.has(struct.types[k])) {
21412133
continue struct_loop;
21422134
}
@@ -2853,7 +2845,7 @@ function defocusSearchBar() {
28532845
return 0;
28542846
});
28552847
var savedCrate = getSettingValue("saved-filter-crate");
2856-
for (var i = 0; i < crates_text.length; ++i) {
2848+
for (var i = 0, len = crates_text.length; i < len; ++i) {
28572849
var option = document.createElement("option");
28582850
option.value = crates_text[i];
28592851
option.innerText = crates_text[i];

‎src/librustdoc/html/static/source-script.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function getCurrentFilePath() {
88
var parts = window.location.pathname.split("/");
99
var rootPathParts = window.rootPath.split("/");
1010

11-
for (var i = 0; i < rootPathParts.length; ++i) {
11+
for (var i = 0, len = rootPathParts.length; i < len; ++i) {
1212
if (rootPathParts[i] === "..") {
1313
parts.pop();
1414
}
@@ -35,12 +35,14 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) {
3535
};
3636
name.innerText = elem["name"];
3737

38+
var i, len;
39+
3840
var children = document.createElement("div");
3941
children.className = "children";
4042
var folders = document.createElement("div");
4143
folders.className = "folders";
4244
if (elem.dirs) {
43-
for (var i = 0; i < elem.dirs.length; ++i) {
45+
for (i = 0, len = elem.dirs.length; i < len; ++i) {
4446
if (createDirEntry(elem.dirs[i], folders, fullPath, currentFile,
4547
hasFoundFile) === true) {
4648
addClass(name, "expand");
@@ -53,7 +55,7 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) {
5355
var files = document.createElement("div");
5456
files.className = "files";
5557
if (elem.files) {
56-
for (i = 0; i < elem.files.length; ++i) {
58+
for (i = 0, len = elem.files.length; i < len; ++i) {
5759
var file = document.createElement("a");
5860
file.innerText = elem.files[i];
5961
file.href = window.rootPath + "src/" + fullPath + elem.files[i] + ".html";

‎src/librustdoc/json/conversions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ impl From<clean::VariantStruct> for Struct {
482482

483483
impl From<clean::Variant> for Variant {
484484
fn from(variant: clean::Variant) -> Self {
485-
use clean::VariantKind::*;
486-
match variant.kind {
485+
use clean::Variant::*;
486+
match variant {
487487
CLike => Variant::Plain,
488488
Tuple(t) => Variant::Tuple(t.into_iter().map(Into::into).collect()),
489489
Struct(s) => Variant::Struct(ids(s.fields)),

‎src/librustdoc/passes/stripper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'a> DocFolder for Stripper<'a> {
9494
// implementations of traits are always public.
9595
clean::ImplItem(ref imp) if imp.trait_.is_some() => true,
9696
// Struct variant fields have inherited visibility
97-
clean::VariantItem(clean::Variant { kind: clean::VariantKind::Struct(..) }) => true,
97+
clean::VariantItem(clean::Variant::Struct(..)) => true,
9898
_ => false,
9999
};
100100

‎src/test/codegen/issue-59352.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This test is a mirror of mir-opt/issues/issue-59352.rs. The LLVM inliner doesn't inline
2+
// `char::method::is_digit()` and `char::method::to_digit()`, probably because of their size.
3+
//
4+
// Currently, the MIR optimizer isn't capable of removing the unreachable panic in this test case.
5+
// Once the optimizer can do that, mir-opt/issues/issue-59352.rs will need to be updated and this
6+
// test case should be removed as it will become redundant.
7+
8+
// mir-opt-level=2 enables inlining and enables LLVM to optimize away the unreachable panic call.
9+
// compile-flags: -O -Z mir-opt-level=2
10+
11+
#![crate_type = "rlib"]
12+
13+
// CHECK-LABEL: @num_to_digit
14+
#[no_mangle]
15+
pub fn num_to_digit(num: char) -> u32 {
16+
// CHECK-NOT: panic
17+
if num.is_digit(8) { num.to_digit(8).unwrap() } else { 0 }
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This test is a mirror of codegen/issue-59352.rs.
2+
// The LLVM inliner doesn't inline `char::method::is_digit()` and so it doesn't recognize this case
3+
// as effectively `if x.is_some() { x.unwrap() } else { 0 }`.
4+
//
5+
// Currently, the MIR optimizer isn't capable of removing the unreachable panic in this test case.
6+
// Once the optimizer can do that, this test case will need to be updated and codegen/issue-59352.rs
7+
// removed.
8+
9+
// EMIT_MIR issue_59352.num_to_digit.PreCodegen.after.mir
10+
// compile-flags: -Z mir-opt-level=2 -Z span_free_formats
11+
12+
pub fn num_to_digit(num: char) -> u32 {
13+
// CHECK-NOT: panic
14+
if num.is_digit(8) { num.to_digit(8).unwrap() } else { 0 }
15+
}
16+
17+
pub fn main() {
18+
num_to_digit('2');
19+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// MIR for `num_to_digit` after PreCodegen
2+
3+
fn num_to_digit(_1: char) -> u32 {
4+
debug num => _1; // in scope 0 at $DIR/issue-59352.rs:12:21: 12:24
5+
let mut _0: u32; // return place in scope 0 at $DIR/issue-59352.rs:12:35: 12:38
6+
let mut _2: bool; // in scope 0 at $DIR/issue-59352.rs:14:8: 14:23
7+
let mut _3: std::option::Option<u32>; // in scope 0 at $DIR/issue-59352.rs:14:26: 14:41
8+
let mut _4: char; // in scope 0 at $DIR/issue-59352.rs:14:26: 14:29
9+
let mut _5: u32; // in scope 0 at $DIR/issue-59352.rs:14:8: 14:23
10+
let mut _10: isize; // in scope 0 at $DIR/issue-59352.rs:14:8: 14:23
11+
scope 1 (inlined char::methods::<impl char>::is_digit) { // at $DIR/issue-59352.rs:14:8: 14:23
12+
debug self => _8; // in scope 1 at $DIR/issue-59352.rs:14:8: 14:23
13+
debug radix => _5; // in scope 1 at $DIR/issue-59352.rs:14:8: 14:23
14+
let mut _6: &std::option::Option<u32>; // in scope 1 at $DIR/issue-59352.rs:14:8: 14:23
15+
let _7: std::option::Option<u32>; // in scope 1 at $DIR/issue-59352.rs:14:8: 14:23
16+
let mut _8: char; // in scope 1 at $DIR/issue-59352.rs:14:8: 14:23
17+
scope 2 (inlined Option::<u32>::is_some) { // at $DIR/issue-59352.rs:14:8: 14:23
18+
debug self => _6; // in scope 2 at $DIR/issue-59352.rs:14:8: 14:23
19+
}
20+
}
21+
scope 3 (inlined #[track_caller] Option::<u32>::unwrap) { // at $DIR/issue-59352.rs:14:26: 14:50
22+
debug self => _3; // in scope 3 at $DIR/issue-59352.rs:14:26: 14:50
23+
let mut _9: isize; // in scope 3 at $DIR/issue-59352.rs:14:26: 14:50
24+
scope 4 {
25+
debug val => _0; // in scope 4 at $DIR/issue-59352.rs:14:26: 14:50
26+
}
27+
}
28+
29+
bb0: {
30+
StorageLive(_2); // scope 0 at $DIR/issue-59352.rs:14:8: 14:23
31+
_8 = _1; // scope 0 at $DIR/issue-59352.rs:14:8: 14:11
32+
StorageLive(_5); // scope 0 at $DIR/issue-59352.rs:14:8: 14:23
33+
_5 = const 8_u32; // scope 0 at $DIR/issue-59352.rs:14:8: 14:23
34+
StorageLive(_6); // scope 1 at $DIR/issue-59352.rs:14:8: 14:23
35+
StorageLive(_7); // scope 1 at $DIR/issue-59352.rs:14:8: 14:23
36+
_7 = char::methods::<impl char>::to_digit(move _8, const 8_u32) -> bb5; // scope 1 at $DIR/issue-59352.rs:14:8: 14:23
37+
// mir::Constant
38+
// + span: $DIR/issue-59352.rs:14:8: 14:23
39+
// + literal: Const { ty: fn(char, u32) -> std::option::Option<u32> {std::char::methods::<impl char>::to_digit}, val: Value(Scalar(<ZST>)) }
40+
}
41+
42+
bb1: {
43+
StorageLive(_3); // scope 0 at $DIR/issue-59352.rs:14:26: 14:41
44+
StorageLive(_4); // scope 0 at $DIR/issue-59352.rs:14:26: 14:29
45+
_4 = _1; // scope 0 at $DIR/issue-59352.rs:14:26: 14:29
46+
_3 = char::methods::<impl char>::to_digit(move _4, const 8_u32) -> bb3; // scope 0 at $DIR/issue-59352.rs:14:26: 14:41
47+
// mir::Constant
48+
// + span: $DIR/issue-59352.rs:14:30: 14:38
49+
// + literal: Const { ty: fn(char, u32) -> std::option::Option<u32> {std::char::methods::<impl char>::to_digit}, val: Value(Scalar(<ZST>)) }
50+
}
51+
52+
bb2: {
53+
_0 = const 0_u32; // scope 0 at $DIR/issue-59352.rs:14:60: 14:61
54+
goto -> bb4; // scope 0 at $DIR/issue-59352.rs:14:5: 14:63
55+
}
56+
57+
bb3: {
58+
StorageDead(_4); // scope 0 at $DIR/issue-59352.rs:14:40: 14:41
59+
StorageLive(_9); // scope 0 at $DIR/issue-59352.rs:14:26: 14:50
60+
_9 = discriminant(_3); // scope 3 at $DIR/issue-59352.rs:14:26: 14:50
61+
switchInt(move _9) -> [0_isize: bb6, 1_isize: bb8, otherwise: bb7]; // scope 3 at $DIR/issue-59352.rs:14:26: 14:50
62+
}
63+
64+
bb4: {
65+
StorageDead(_2); // scope 0 at $DIR/issue-59352.rs:14:62: 14:63
66+
return; // scope 0 at $DIR/issue-59352.rs:15:2: 15:2
67+
}
68+
69+
bb5: {
70+
_6 = &_7; // scope 1 at $DIR/issue-59352.rs:14:8: 14:23
71+
_10 = discriminant((*_6)); // scope 2 at $DIR/issue-59352.rs:14:8: 14:23
72+
_2 = Eq(_10, const 1_isize); // scope 2 at $DIR/issue-59352.rs:14:8: 14:23
73+
StorageDead(_6); // scope 1 at $DIR/issue-59352.rs:14:8: 14:23
74+
StorageDead(_7); // scope 1 at $DIR/issue-59352.rs:14:8: 14:23
75+
StorageDead(_5); // scope 0 at $DIR/issue-59352.rs:14:8: 14:23
76+
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/issue-59352.rs:14:5: 14:63
77+
}
78+
79+
bb6: {
80+
core::panicking::panic(const "called `Option::unwrap()` on a `None` value"); // scope 3 at $DIR/issue-59352.rs:14:26: 14:50
81+
// mir::Constant
82+
// + span: $DIR/issue-59352.rs:14:26: 14:50
83+
// + literal: Const { ty: fn(&'static str) -> ! {core::panicking::panic}, val: Value(Scalar(<ZST>)) }
84+
// ty::Const
85+
// + ty: &str
86+
// + val: Value(Slice { data: Allocation { bytes: [99, 97, 108, 108, 101, 100, 32, 96, 79, 112, 116, 105, 111, 110, 58, 58, 117, 110, 119, 114, 97, 112, 40, 41, 96, 32, 111, 110, 32, 97, 32, 96, 78, 111, 110, 101, 96, 32, 118, 97, 108, 117, 101], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [8796093022207], len: Size { raw: 43 } }, size: Size { raw: 43 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 43 })
87+
// mir::Constant
88+
// + span: $DIR/issue-59352.rs:14:26: 14:50
89+
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [99, 97, 108, 108, 101, 100, 32, 96, 79, 112, 116, 105, 111, 110, 58, 58, 117, 110, 119, 114, 97, 112, 40, 41, 96, 32, 111, 110, 32, 97, 32, 96, 78, 111, 110, 101, 96, 32, 118, 97, 108, 117, 101], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [8796093022207], len: Size { raw: 43 } }, size: Size { raw: 43 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 43 }) }
90+
}
91+
92+
bb7: {
93+
unreachable; // scope 3 at $DIR/issue-59352.rs:14:26: 14:50
94+
}
95+
96+
bb8: {
97+
_0 = move ((_3 as Some).0: u32); // scope 3 at $DIR/issue-59352.rs:14:26: 14:50
98+
StorageDead(_9); // scope 0 at $DIR/issue-59352.rs:14:26: 14:50
99+
StorageDead(_3); // scope 0 at $DIR/issue-59352.rs:14:49: 14:50
100+
goto -> bb4; // scope 0 at $DIR/issue-59352.rs:14:5: 14:63
101+
}
102+
}

‎src/tools/rustbook/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ clap = "2.25.0"
1010
env_logger = "0.7.1"
1111

1212
[dependencies.mdbook]
13-
version = "0.4.5"
13+
version = "0.4.6"
1414
default-features = false
1515
features = ["search"]

0 commit comments

Comments
 (0)
Please sign in to comment.