Skip to content

Commit 49c67bd

Browse files
committed
Auto merge of #40806 - frewsxcv:rollup, r=frewsxcv
Rollup of 8 pull requests - Successful merges: #40567, #40602, #40636, #40739, #40756, #40790, #40794, #40803 - Failed merges:
2 parents 3da4023 + 6cd4660 commit 49c67bd

File tree

22 files changed

+188
-122
lines changed

22 files changed

+188
-122
lines changed

CONTRIBUTING.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,13 @@ To save @bors some work, and to get small changes through more quickly, when
311311
the other rollup-eligible patches too, and they'll get tested and merged at
312312
the same time.
313313

314-
To find documentation-related issues, sort by the [A-docs label][adocs].
314+
To find documentation-related issues, sort by the [T-doc label][tdoc].
315315

316-
[adocs]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AA-docs
316+
[tdoc]: https://github.com/rust-lang/rust/issues?q=is%3Aopen%20is%3Aissue%20label%3AT-doc
317+
318+
You can find documentation style guidelines in [RFC 1574][rfc1574].
319+
320+
[rfc1574]: https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
317321

318322
In many cases, you don't need a full `./x.py doc`. You can use `rustdoc` directly
319323
to check small fixes. For example, `rustdoc src/doc/reference.md` will render

src/libcollections/btree/map.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ pub struct BTreeMap<K, V> {
141141
unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for BTreeMap<K, V> {
142142
fn drop(&mut self) {
143143
unsafe {
144-
for _ in ptr::read(self).into_iter() {
145-
}
144+
drop(ptr::read(self).into_iter());
146145
}
147146
}
148147
}

src/libcollections/slice.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ impl<T> [T] {
11621162
///
11631163
/// # Current implementation
11641164
///
1165-
/// The current algorithm is based on Orson Peters' [pdqsort][pattern-defeating quicksort],
1165+
/// The current algorithm is based on Orson Peters' [pattern-defeating quicksort][pdqsort],
11661166
/// which is a quicksort variant designed to be very fast on certain kinds of patterns,
11671167
/// sometimes achieving linear time. It is randomized but deterministic, and falls back to
11681168
/// heapsort on degenerate inputs.
@@ -1199,7 +1199,7 @@ impl<T> [T] {
11991199
///
12001200
/// # Current implementation
12011201
///
1202-
/// The current algorithm is based on Orson Peters' [pdqsort][pattern-defeating quicksort],
1202+
/// The current algorithm is based on Orson Peters' [pattern-defeating quicksort][pdqsort],
12031203
/// which is a quicksort variant designed to be very fast on certain kinds of patterns,
12041204
/// sometimes achieving linear time. It is randomized but deterministic, and falls back to
12051205
/// heapsort on degenerate inputs.
@@ -1239,7 +1239,7 @@ impl<T> [T] {
12391239
///
12401240
/// # Current implementation
12411241
///
1242-
/// The current algorithm is based on Orson Peters' [pdqsort][pattern-defeating quicksort],
1242+
/// The current algorithm is based on Orson Peters' [pattern-defeating quicksort][pdqsort],
12431243
/// which is a quicksort variant designed to be very fast on certain kinds of patterns,
12441244
/// sometimes achieving linear time. It is randomized but deterministic, and falls back to
12451245
/// heapsort on degenerate inputs.

src/librustc/mir/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -983,16 +983,16 @@ impl<'tcx> Debug for Operand<'tcx> {
983983
}
984984

985985
impl<'tcx> Operand<'tcx> {
986-
pub fn item<'a>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
987-
def_id: DefId,
988-
substs: &'tcx Substs<'tcx>,
989-
span: Span)
990-
-> Self
991-
{
986+
pub fn function_handle<'a>(
987+
tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
988+
def_id: DefId,
989+
substs: &'tcx Substs<'tcx>,
990+
span: Span,
991+
) -> Self {
992992
Operand::Constant(Constant {
993993
span: span,
994994
ty: tcx.item_type(def_id).subst(tcx, substs),
995-
literal: Literal::Item { def_id, substs }
995+
literal: Literal::Value { value: ConstVal::Function(def_id, substs) },
996996
})
997997
}
998998

src/librustc_mir/build/scope.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ should go to.
8989
use build::{BlockAnd, BlockAndExtension, Builder, CFG};
9090
use rustc::middle::region::{CodeExtent, CodeExtentData};
9191
use rustc::middle::lang_items;
92+
use rustc::middle::const_val::ConstVal;
9293
use rustc::ty::subst::{Kind, Subst};
9394
use rustc::ty::{Ty, TyCtxt};
9495
use rustc::mir::*;
@@ -784,9 +785,8 @@ fn build_free<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
784785
func: Operand::Constant(Constant {
785786
span: data.span,
786787
ty: tcx.item_type(free_func).subst(tcx, substs),
787-
literal: Literal::Item {
788-
def_id: free_func,
789-
substs: substs
788+
literal: Literal::Value {
789+
value: ConstVal::Function(free_func, substs),
790790
}
791791
}),
792792
args: vec![Operand::Consume(data.value.clone())],

src/librustc_mir/hair/cx/expr.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,8 @@ fn method_callee<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
714714
ty: callee.ty,
715715
span: expr.span,
716716
kind: ExprKind::Literal {
717-
literal: Literal::Item {
718-
def_id: callee.def_id,
719-
substs: callee.substs,
717+
literal: Literal::Value {
718+
value: ConstVal::Function(callee.def_id, callee.substs),
720719
},
721720
},
722721
}
@@ -743,22 +742,32 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
743742
-> ExprKind<'tcx> {
744743
let substs = cx.tables().node_id_item_substs(expr.id)
745744
.unwrap_or_else(|| cx.tcx.intern_substs(&[]));
746-
let def_id = match def {
745+
match def {
747746
// A regular function, constructor function or a constant.
748747
Def::Fn(def_id) |
749748
Def::Method(def_id) |
750749
Def::StructCtor(def_id, CtorKind::Fn) |
751-
Def::VariantCtor(def_id, CtorKind::Fn) |
750+
Def::VariantCtor(def_id, CtorKind::Fn) => ExprKind::Literal {
751+
literal: Literal::Value {
752+
value: ConstVal::Function(def_id, substs),
753+
},
754+
},
755+
752756
Def::Const(def_id) |
753-
Def::AssociatedConst(def_id) => def_id,
757+
Def::AssociatedConst(def_id) => ExprKind::Literal {
758+
literal: Literal::Item {
759+
def_id: def_id,
760+
substs: substs,
761+
},
762+
},
754763

755764
Def::StructCtor(def_id, CtorKind::Const) |
756765
Def::VariantCtor(def_id, CtorKind::Const) => {
757766
match cx.tables().node_id_to_type(expr.id).sty {
758767
// A unit struct/variant which is used as a value.
759768
// We return a completely different ExprKind here to account for this special case.
760769
ty::TyAdt(adt_def, substs) => {
761-
return ExprKind::Adt {
770+
ExprKind::Adt {
762771
adt_def: adt_def,
763772
variant_index: adt_def.variant_index_with_id(def_id),
764773
substs: substs,
@@ -770,17 +779,11 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
770779
}
771780
}
772781

773-
Def::Static(node_id, _) => return ExprKind::StaticRef { id: node_id },
782+
Def::Static(node_id, _) => ExprKind::StaticRef { id: node_id },
774783

775-
Def::Local(..) | Def::Upvar(..) => return convert_var(cx, expr, def),
784+
Def::Local(..) | Def::Upvar(..) => convert_var(cx, expr, def),
776785

777786
_ => span_bug!(expr.span, "def `{:?}` not yet implemented", def),
778-
};
779-
ExprKind::Literal {
780-
literal: Literal::Item {
781-
def_id: def_id,
782-
substs: substs,
783-
},
784787
}
785788
}
786789

src/librustc_mir/hair/cx/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,8 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
132132
let method_ty = self.tcx.item_type(item.def_id);
133133
let method_ty = method_ty.subst(self.tcx, substs);
134134
return (method_ty,
135-
Literal::Item {
136-
def_id: item.def_id,
137-
substs: substs,
135+
Literal::Value {
136+
value: ConstVal::Function(item.def_id, substs),
138137
});
139138
}
140139
}

src/librustc_mir/shim.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc::hir;
1212
use rustc::hir::def_id::DefId;
1313
use rustc::infer;
1414
use rustc::middle::region::ROOT_CODE_EXTENT;
15+
use rustc::middle::const_val::ConstVal;
1516
use rustc::mir::*;
1617
use rustc::mir::transform::MirSource;
1718
use rustc::ty::{self, Ty};
@@ -335,7 +336,9 @@ fn build_call_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
335336
Operand::Constant(Constant {
336337
span: span,
337338
ty: tcx.item_type(def_id).subst(tcx, param_env.free_substs),
338-
literal: Literal::Item { def_id, substs: param_env.free_substs },
339+
literal: Literal::Value {
340+
value: ConstVal::Function(def_id, param_env.free_substs),
341+
},
339342
}),
340343
vec![rcvr]
341344
)

src/librustc_mir/transform/qualify_consts.rs

-5
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
568568
});
569569
}
570570
Operand::Constant(ref constant) => {
571-
// Only functions and methods can have these types.
572-
if let ty::TyFnDef(..) = constant.ty.sty {
573-
return;
574-
}
575-
576571
if let Literal::Item { def_id, substs } = constant.literal {
577572
// Don't peek inside generic (associated) constants.
578573
if substs.types().next().is_some() {

src/librustc_mir/transform/type_check.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc::infer::{self, InferCtxt, InferOk};
1515
use rustc::traits::{self, Reveal};
1616
use rustc::ty::fold::TypeFoldable;
1717
use rustc::ty::{self, Ty, TyCtxt, TypeVariants};
18+
use rustc::middle::const_val::ConstVal;
1819
use rustc::mir::*;
1920
use rustc::mir::tcx::LvalueTy;
2021
use rustc::mir::transform::{MirPass, MirSource, Pass};
@@ -526,7 +527,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
526527
fn is_box_free(&self, operand: &Operand<'tcx>) -> bool {
527528
match operand {
528529
&Operand::Constant(Constant {
529-
literal: Literal::Item { def_id, .. }, ..
530+
literal: Literal::Value {
531+
value: ConstVal::Function(def_id, _), ..
532+
}, ..
530533
}) => {
531534
Some(def_id) == self.tcx().lang_items.box_free_fn()
532535
}

src/librustc_mir/util/elaborate_drops.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
525525
}],
526526
terminator: Some(Terminator {
527527
kind: TerminatorKind::Call {
528-
func: Operand::item(tcx, drop_fn.def_id, substs,
529-
self.source_info.span),
528+
func: Operand::function_handle(tcx, drop_fn.def_id, substs,
529+
self.source_info.span),
530530
args: vec![Operand::Consume(Lvalue::Local(ref_lvalue))],
531531
destination: Some((unit_temp, succ)),
532532
cleanup: unwind,
@@ -629,7 +629,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
629629
let substs = tcx.mk_substs(iter::once(Kind::from(ty)));
630630

631631
let call = TerminatorKind::Call {
632-
func: Operand::item(tcx, free_func, substs, self.source_info.span),
632+
func: Operand::function_handle(tcx, free_func, substs, self.source_info.span),
633633
args: vec![Operand::Consume(self.lvalue.clone())],
634634
destination: Some((unit_temp, target)),
635635
cleanup: None

src/librustc_trans/mir/analyze.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
1414
use rustc_data_structures::bitvec::BitVector;
1515
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
16-
use rustc::mir::{self, Location, TerminatorKind};
16+
use rustc::middle::const_val::ConstVal;
17+
use rustc::mir::{self, Location, TerminatorKind, Literal};
1718
use rustc::mir::visit::{Visitor, LvalueContext};
1819
use rustc::mir::traversal;
1920
use common;
@@ -109,7 +110,9 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
109110
match *kind {
110111
mir::TerminatorKind::Call {
111112
func: mir::Operand::Constant(mir::Constant {
112-
literal: mir::Literal::Item { def_id, .. }, ..
113+
literal: Literal::Value {
114+
value: ConstVal::Function(def_id, _), ..
115+
}, ..
113116
}),
114117
ref args, ..
115118
} if Some(def_id) == self.cx.ccx.tcx().lang_items.box_free_fn() => {

src/librustc_trans/mir/constant.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ impl<'tcx> Const<'tcx> {
101101
ConstVal::Str(ref v) => C_str_slice(ccx, v.clone()),
102102
ConstVal::ByteStr(ref v) => consts::addr_of(ccx, C_bytes(ccx, v), 1, "byte_str"),
103103
ConstVal::Struct(_) | ConstVal::Tuple(_) |
104-
ConstVal::Array(..) | ConstVal::Repeat(..) |
104+
ConstVal::Array(..) | ConstVal::Repeat(..) => {
105+
bug!("MIR must not use `{:?}` (aggregates are expanded to MIR rvalues)", cv)
106+
}
105107
ConstVal::Function(..) => {
106-
bug!("MIR must not use `{:?}` (which refers to a local ID)", cv)
108+
let llty = type_of::type_of(ccx, ty);
109+
return Const::new(C_null(llty), ty);
107110
}
108111
ConstVal::Char(c) => C_integral(Type::char(ccx), c as u64, false),
109112
};
@@ -476,13 +479,6 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
476479
let ty = self.monomorphize(&constant.ty);
477480
match constant.literal.clone() {
478481
mir::Literal::Item { def_id, substs } => {
479-
// Shortcut for zero-sized types, including function item
480-
// types, which would not work with MirConstContext.
481-
if common::type_is_zero_size(self.ccx, ty) {
482-
let llty = type_of::type_of(self.ccx, ty);
483-
return Ok(Const::new(C_null(llty), ty));
484-
}
485-
486482
let substs = self.monomorphize(&substs);
487483
MirConstContext::trans_def(self.ccx, def_id, substs, IndexVec::new())
488484
}
@@ -924,13 +920,6 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
924920
let ty = self.monomorphize(&constant.ty);
925921
let result = match constant.literal.clone() {
926922
mir::Literal::Item { def_id, substs } => {
927-
// Shortcut for zero-sized types, including function item
928-
// types, which would not work with MirConstContext.
929-
if common::type_is_zero_size(bcx.ccx, ty) {
930-
let llty = type_of::type_of(bcx.ccx, ty);
931-
return Const::new(C_null(llty), ty);
932-
}
933-
934923
let substs = self.monomorphize(&substs);
935924
MirConstContext::trans_def(bcx.ccx, def_id, substs, IndexVec::new())
936925
}

src/librustc_typeck/check/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -4099,6 +4099,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
40994099
};
41004100

41014101
if self.diverges.get().always() {
4102+
if let ExpectHasType(ety) = expected {
4103+
// Avoid forcing a type (only `!` for now) in unreachable code.
4104+
// FIXME(aburka) do we need this special case? and should it be is_uninhabited?
4105+
if !ety.is_never() {
4106+
if let Some(ref e) = blk.expr {
4107+
// Coerce the tail expression to the right type.
4108+
self.demand_coerce(e, ty, ety);
4109+
}
4110+
}
4111+
}
4112+
41024113
ty = self.next_diverging_ty_var(TypeVariableOrigin::DivergingBlockExpr(blk.span));
41034114
} else if let ExpectHasType(ety) = expected {
41044115
if let Some(ref e) = blk.expr {

src/librustdoc/html/render.rs

+49-1
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,23 @@ fn document_stability(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item)
17001700
Ok(())
17011701
}
17021702

1703+
fn name_key(name: &str) -> (&str, u64, usize) {
1704+
// find number at end
1705+
let split = name.bytes().rposition(|b| b < b'0' || b'9' < b).map_or(0, |s| s + 1);
1706+
1707+
// count leading zeroes
1708+
let after_zeroes =
1709+
name[split..].bytes().position(|b| b != b'0').map_or(name.len(), |extra| split + extra);
1710+
1711+
// sort leading zeroes last
1712+
let num_zeroes = after_zeroes - split;
1713+
1714+
match name[split..].parse() {
1715+
Ok(n) => (&name[..split], n, num_zeroes),
1716+
Err(_) => (name, 0, num_zeroes),
1717+
}
1718+
}
1719+
17031720
fn item_module(w: &mut fmt::Formatter, cx: &Context,
17041721
item: &clean::Item, items: &[clean::Item]) -> fmt::Result {
17051722
document(w, cx, item)?;
@@ -1744,7 +1761,9 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
17441761
(Some(stability::Stable), Some(stability::Unstable)) => return Ordering::Less,
17451762
_ => {}
17461763
}
1747-
i1.name.cmp(&i2.name)
1764+
let lhs = i1.name.as_ref().map_or("", |s| &**s);
1765+
let rhs = i2.name.as_ref().map_or("", |s| &**s);
1766+
name_key(lhs).cmp(&name_key(rhs))
17481767
}
17491768

17501769
indices.sort_by(|&i1, &i2| cmp(&items[i1], &items[i2], i1, i2));
@@ -3198,3 +3217,32 @@ fn test_unique_id() {
31983217
reset_ids(true);
31993218
test();
32003219
}
3220+
3221+
#[cfg(test)]
3222+
#[test]
3223+
fn test_name_key() {
3224+
assert_eq!(name_key("0"), ("", 0, 1));
3225+
assert_eq!(name_key("123"), ("", 123, 0));
3226+
assert_eq!(name_key("Fruit"), ("Fruit", 0, 0));
3227+
assert_eq!(name_key("Fruit0"), ("Fruit", 0, 1));
3228+
assert_eq!(name_key("Fruit0000"), ("Fruit", 0, 4));
3229+
assert_eq!(name_key("Fruit01"), ("Fruit", 1, 1));
3230+
assert_eq!(name_key("Fruit10"), ("Fruit", 10, 0));
3231+
assert_eq!(name_key("Fruit123"), ("Fruit", 123, 0));
3232+
}
3233+
3234+
#[cfg(test)]
3235+
#[test]
3236+
fn test_name_sorting() {
3237+
let names = ["Apple",
3238+
"Banana",
3239+
"Fruit", "Fruit0", "Fruit00",
3240+
"Fruit1", "Fruit01",
3241+
"Fruit2", "Fruit02",
3242+
"Fruit20",
3243+
"Fruit100",
3244+
"Pear"];
3245+
let mut sorted = names.to_owned();
3246+
sorted.sort_by_key(|&s| name_key(s));
3247+
assert_eq!(names, sorted);
3248+
}

0 commit comments

Comments
 (0)