Skip to content

Commit

Permalink
Auto merge of #81057 - GuillaumeGomez:rollup-yl2kqst, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jan 16, 2021
2 parents fcbd305 + f8b1baa commit 6c869d3
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 112 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1973,9 +1973,9 @@ dependencies = [

[[package]]
name = "mdbook"
version = "0.4.5"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21251d3eb9ca5e8ac5b73384ddaa483a9bbc7d7dcd656b1fa8f266634810334a"
checksum = "b3d948b64449003363127ed6c6139f03273982c3fe97da4cb3dee933e38ce38f"
dependencies = [
"ammonia",
"anyhow",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl Inliner<'tcx> {
// Cost of the var is the size in machine-words, if we know
// it.
if let Some(size) = type_size_of(tcx, self.param_env, ty) {
cost += (size / ptr_size) as usize;
cost += ((size + ptr_size - 1) / ptr_size) as usize;
} else {
cost += UNKNOWN_SIZE_COST;
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,25 +813,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if ty.is_never() {
None
} else {
Some(match &elem.kind {
Some(match elem.kind {
// Point at the tail expression when possible.
hir::ExprKind::Block(block, _) => {
block.expr.as_ref().map_or(block.span, |e| e.span)
block.expr.map_or(block.span, |e| e.span)
}
_ => elem.span,
})
}
})
};

if let hir::ExprKind::If(_, _, Some(el)) = &expr.kind {
if let hir::ExprKind::If(_, _, Some(el)) = expr.kind {
if let Some(rslt) = check_in_progress(el) {
return rslt;
}
}

if let hir::ExprKind::Match(_, arms, _) = &expr.kind {
let mut iter = arms.iter().filter_map(|arm| check_in_progress(&arm.body));
if let hir::ExprKind::Match(_, arms, _) = expr.kind {
let mut iter = arms.iter().filter_map(|arm| check_in_progress(arm.body));
if let Some(span) = iter.next() {
if iter.next().is_none() {
return span;
Expand Down
26 changes: 11 additions & 15 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1840,11 +1840,11 @@ impl Clean<VariantStruct> for rustc_hir::VariantData<'_> {
impl Clean<Item> for ty::VariantDef {
fn clean(&self, cx: &DocContext<'_>) -> Item {
let kind = match self.ctor_kind {
CtorKind::Const => VariantKind::CLike,
CtorKind::Fn => VariantKind::Tuple(
CtorKind::Const => Variant::CLike,
CtorKind::Fn => Variant::Tuple(
self.fields.iter().map(|f| cx.tcx.type_of(f.did).clean(cx)).collect(),
),
CtorKind::Fictive => VariantKind::Struct(VariantStruct {
CtorKind::Fictive => Variant::Struct(VariantStruct {
struct_type: doctree::Plain,
fields_stripped: false,
fields: self
Expand All @@ -1861,25 +1861,21 @@ impl Clean<Item> for ty::VariantDef {
.collect(),
}),
};
let what_rustc_thinks = Item::from_def_id_and_parts(
self.def_id,
Some(self.ident.name),
VariantItem(Variant { kind }),
cx,
);
let what_rustc_thinks =
Item::from_def_id_and_parts(self.def_id, Some(self.ident.name), VariantItem(kind), cx);
// don't show `pub` for fields, which are always public
Item { visibility: Inherited, ..what_rustc_thinks }
}
}

impl Clean<VariantKind> for hir::VariantData<'_> {
fn clean(&self, cx: &DocContext<'_>) -> VariantKind {
impl Clean<Variant> for hir::VariantData<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Variant {
match self {
hir::VariantData::Struct(..) => VariantKind::Struct(self.clean(cx)),
hir::VariantData::Struct(..) => Variant::Struct(self.clean(cx)),
hir::VariantData::Tuple(..) => {
VariantKind::Tuple(self.fields().iter().map(|x| x.ty.clean(cx)).collect())
Variant::Tuple(self.fields().iter().map(|x| x.ty.clean(cx)).collect())
}
hir::VariantData::Unit(..) => VariantKind::CLike,
hir::VariantData::Unit(..) => Variant::CLike,
}
}
}
Expand Down Expand Up @@ -2048,7 +2044,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {

impl Clean<Item> for hir::Variant<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
let kind = VariantItem(Variant { kind: self.data.clean(cx) });
let kind = VariantItem(self.data.clean(cx));
let what_rustc_thinks =
Item::from_hir_id_and_parts(self.id, Some(self.ident.name), kind, cx);
// don't show `pub` for variants, which are always public
Expand Down
13 changes: 3 additions & 10 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,7 @@ impl Item {
match *self.kind {
StructItem(ref _struct) => Some(_struct.fields_stripped),
UnionItem(ref union) => Some(union.fields_stripped),
VariantItem(Variant { kind: VariantKind::Struct(ref vstruct) }) => {
Some(vstruct.fields_stripped)
}
VariantItem(Variant::Struct(ref vstruct)) => Some(vstruct.fields_stripped),
_ => None,
}
}
Expand Down Expand Up @@ -353,7 +351,7 @@ impl ItemKind {
match self {
StructItem(s) => s.fields.iter(),
UnionItem(u) => u.fields.iter(),
VariantItem(Variant { kind: VariantKind::Struct(v) }) => v.fields.iter(),
VariantItem(Variant::Struct(v)) => v.fields.iter(),
EnumItem(e) => e.variants.iter(),
TraitItem(t) => t.items.iter(),
ImplItem(i) => i.items.iter(),
Expand Down Expand Up @@ -1719,12 +1717,7 @@ crate struct Enum {
}

#[derive(Clone, Debug)]
crate struct Variant {
crate kind: VariantKind,
}

#[derive(Clone, Debug)]
crate enum VariantKind {
crate enum Variant {
CLike,
Tuple(Vec<Type>),
Struct(VariantStruct),
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ crate trait DocFolder: Sized {
}
VariantItem(i) => {
let i2 = i.clone(); // this clone is small
match i.kind {
VariantKind::Struct(mut j) => {
match i {
Variant::Struct(mut j) => {
let num_fields = j.fields.len();
j.fields = j.fields.into_iter().filter_map(|x| self.fold_item(x)).collect();
j.fields_stripped |= num_fields != j.fields.len()
|| j.fields.iter().any(|f| f.is_stripped());
VariantItem(Variant { kind: VariantKind::Struct(j) })
VariantItem(Variant::Struct(j))
}
_ => VariantItem(i2),
}
Expand Down
29 changes: 13 additions & 16 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3200,9 +3200,9 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
write!(w, " ");
let name = v.name.as_ref().unwrap();
match *v.kind {
clean::VariantItem(ref var) => match var.kind {
clean::VariantKind::CLike => write!(w, "{}", name),
clean::VariantKind::Tuple(ref tys) => {
clean::VariantItem(ref var) => match var {
clean::Variant::CLike => write!(w, "{}", name),
clean::Variant::Tuple(ref tys) => {
write!(w, "{}(", name);
for (i, ty) in tys.iter().enumerate() {
if i > 0 {
Expand All @@ -3212,7 +3212,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
}
write!(w, ")");
}
clean::VariantKind::Struct(ref s) => {
clean::Variant::Struct(ref s) => {
render_struct(w, v, None, s.struct_type, &s.fields, " ", false, cx);
}
},
Expand Down Expand Up @@ -3249,25 +3249,22 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
id = id,
name = variant.name.as_ref().unwrap()
);
if let clean::VariantItem(ref var) = *variant.kind {
if let clean::VariantKind::Tuple(ref tys) = var.kind {
write!(w, "(");
for (i, ty) in tys.iter().enumerate() {
if i > 0 {
write!(w, ",&nbsp;");
}
write!(w, "{}", ty.print());
if let clean::VariantItem(clean::Variant::Tuple(ref tys)) = *variant.kind {
write!(w, "(");
for (i, ty) in tys.iter().enumerate() {
if i > 0 {
write!(w, ",&nbsp;");
}
write!(w, ")");
write!(w, "{}", ty.print());
}
write!(w, ")");
}
write!(w, "</code></div>");
document(w, cx, variant, Some(it));
document_non_exhaustive(w, variant);

use crate::clean::{Variant, VariantKind};
if let clean::VariantItem(Variant { kind: VariantKind::Struct(ref s) }) = *variant.kind
{
use crate::clean::Variant;
if let clean::VariantItem(Variant::Struct(ref s)) = *variant.kind {
let variant_id = cx.derive_id(format!(
"{}.{}.fields",
ItemType::Variant,
Expand Down
Loading

0 comments on commit 6c869d3

Please sign in to comment.