Skip to content

Commit 05e3c96

Browse files
committedSep 7, 2017
Auto merge of #44380 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 23 pull requests - Successful merges: #44097, #44206, #44218, #44276, #44277, #44296, #44303, #44313, #44315, #44317, #44319, #44321, #44325, #44326, #44327, #44328, #44330, #44351, #44353, #44354, #44361, #44362, #44377 - Failed merges:
2 parents 3681220 + 6667058 commit 05e3c96

File tree

33 files changed

+559
-83
lines changed

33 files changed

+559
-83
lines changed
 

‎RELEASES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Compatibility Notes
170170
[`slice::sort_unstable_by_key`]: https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable_by_key
171171
[`slice::sort_unstable_by`]: https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable_by
172172
[`slice::sort_unstable`]: https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable
173-
[`ste::from_boxed_utf8_unchecked`]: https://doc.rust-lang.org/std/str/fn.from_boxed_utf8_unchecked.html
173+
[`str::from_boxed_utf8_unchecked`]: https://doc.rust-lang.org/std/str/fn.from_boxed_utf8_unchecked.html
174174
[`str::as_bytes_mut`]: https://doc.rust-lang.org/std/primitive.str.html#method.as_bytes_mut
175175
[`str::from_utf8_mut`]: https://doc.rust-lang.org/std/str/fn.from_utf8_mut.html
176176
[`str::from_utf8_unchecked_mut`]: https://doc.rust-lang.org/std/str/fn.from_utf8_unchecked_mut.html

‎config.toml.example

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@
146146
# option to true.
147147
#full-bootstrap = false
148148

149-
# Enable a build of the and extended rust tool set which is not only the
150-
# compiler but also tools such as Cargo. This will also produce "combined
151-
# installers" which are used to install Rust and Cargo together. This is
152-
# disabled by default.
149+
# Enable a build of the extended rust tool set which is not only the compiler
150+
# but also tools such as Cargo. This will also produce "combined installers"
151+
# which are used to install Rust and Cargo together. This is disabled by
152+
# default.
153153
#extended = false
154154

155155
# Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose
@@ -175,7 +175,7 @@
175175
# script.
176176
#configure-args = []
177177

178-
# Indicates that a local rebuild is ocurring instead of a full bootstrap,
178+
# Indicates that a local rebuild is occurring instead of a full bootstrap,
179179
# essentially skipping stage0 as the local compiler is recompiling itself again.
180180
#local-rebuild = false
181181

‎src/bootstrap/dist.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ impl Step for Rustc {
365365
// tiny morsel of metadata is used by rust-packaging
366366
let version = build.rust_version();
367367
t!(t!(File::create(overlay.join("version"))).write_all(version.as_bytes()));
368+
if let Some(sha) = build.rust_sha() {
369+
t!(t!(File::create(overlay.join("git-commit-hash"))).write_all(sha.as_bytes()));
370+
}
368371

369372
// On MinGW we've got a few runtime DLL dependencies that we need to
370373
// include. The first argument to this script is where to put these DLLs
@@ -844,6 +847,9 @@ impl Step for PlainSourceTarball {
844847

845848
// Create the version file
846849
write_file(&plain_dst_src.join("version"), build.rust_version().as_bytes());
850+
if let Some(sha) = build.rust_sha() {
851+
write_file(&plain_dst_src.join("git-commit-hash"), sha.as_bytes());
852+
}
847853

848854
// If we're building from git sources, we need to vendor a complete distribution.
849855
if build.rust_info.is_git() {
@@ -1157,14 +1163,20 @@ impl Step for Extended {
11571163
install(&build.src.join("LICENSE-MIT"), &overlay, 0o644);
11581164
let version = build.rust_version();
11591165
t!(t!(File::create(overlay.join("version"))).write_all(version.as_bytes()));
1166+
if let Some(sha) = build.rust_sha() {
1167+
t!(t!(File::create(overlay.join("git-commit-hash"))).write_all(sha.as_bytes()));
1168+
}
11601169
install(&etc.join("README.md"), &overlay, 0o644);
11611170

11621171
// When rust-std package split from rustc, we needed to ensure that during
11631172
// upgrades rustc was upgraded before rust-std. To avoid rustc clobbering
11641173
// the std files during uninstall. To do this ensure that rustc comes
11651174
// before rust-std in the list below.
11661175
let mut tarballs = vec![rustc_installer, cargo_installer, rls_installer,
1167-
analysis_installer, docs_installer, std_installer];
1176+
analysis_installer, std_installer];
1177+
if build.config.docs {
1178+
tarballs.push(docs_installer);
1179+
}
11681180
if target.contains("pc-windows-gnu") {
11691181
tarballs.push(mingw_installer.unwrap());
11701182
}

‎src/bootstrap/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ install!((self, builder, _config),
200200
builder.ensure(dist::Src);
201201
install_src(builder, self.stage);
202202
}, ONLY_BUILD;
203-
Rustc, "src/librustc", _config.extended, only_hosts: true, {
203+
Rustc, "src/librustc", true, only_hosts: true, {
204204
builder.ensure(dist::Rustc {
205205
compiler: builder.compiler(self.stage, self.target),
206206
});

‎src/bootstrap/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,11 @@ impl Build {
797797
self.rust_info.version(self, channel::CFG_RELEASE_NUM)
798798
}
799799

800+
/// Return the full commit hash
801+
fn rust_sha(&self) -> Option<&str> {
802+
self.rust_info.sha()
803+
}
804+
800805
/// Returns the `a.b.c` version that the given package is at.
801806
fn release_num(&self, package: &str) -> String {
802807
let mut toml = String::new();

‎src/bootstrap/native.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ impl Step for Openssl {
417417
"powerpc64-unknown-linux-gnu" => "linux-ppc64",
418418
"powerpc64le-unknown-linux-gnu" => "linux-ppc64le",
419419
"s390x-unknown-linux-gnu" => "linux64-s390x",
420+
"sparc64-unknown-netbsd" => "BSD-sparc64",
420421
"x86_64-apple-darwin" => "darwin64-x86_64-cc",
421422
"x86_64-linux-android" => "linux-x86_64",
422423
"x86_64-unknown-freebsd" => "BSD-x86_64",
@@ -436,6 +437,15 @@ impl Step for Openssl {
436437
configure.arg("-mandroid");
437438
configure.arg("-fomit-frame-pointer");
438439
}
440+
if target == "sparc64-unknown-netbsd" {
441+
// Need -m64 to get assembly generated correctly for sparc64.
442+
configure.arg("-m64");
443+
if build.build.contains("netbsd") {
444+
// Disable sparc64 asm on NetBSD builders, it uses
445+
// m4(1)'s -B flag, which NetBSD m4 does not support.
446+
configure.arg("no-asm");
447+
}
448+
}
439449
// Make PIE binaries
440450
// Non-PIE linker support was removed in Lollipop
441451
// https://source.android.com/security/enhancements/enhancements50

‎src/etc/platform-intrinsics/powerpc.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,69 @@
156156
"llvm": "vupkh{1.kind}{1.data_type_short}",
157157
"ret": "s(16-32)",
158158
"args": ["0N"]
159+
},
160+
{
161+
"intrinsic": "madds",
162+
"width": [128],
163+
"llvm": "vmhaddshs",
164+
"ret": "s16",
165+
"args": ["0", "0", "0"]
166+
},
167+
{
168+
"intrinsic": "msumu{1.data_type_short}m",
169+
"width": [128],
170+
"llvm": "vmsumu{1.data_type_short}m",
171+
"ret": "u32",
172+
"args": ["u(8-16)", "1", "u32"]
173+
},
174+
{
175+
"intrinsic": "msummbm",
176+
"width": [128],
177+
"llvm": "vmsummbm",
178+
"ret": "s32",
179+
"args": ["s8", "u8", "s32"]
180+
},
181+
{
182+
"intrinsic": "msumshm",
183+
"width": [128],
184+
"llvm": "vmsumshm",
185+
"ret": "s32",
186+
"args": ["s16", "s16", "s32"]
187+
},
188+
{
189+
"intrinsic": "msum{0.kind}hs",
190+
"width": [128],
191+
"llvm": "vmsum{0.kind}hs",
192+
"ret": "i32",
193+
"args": ["0N", "0N", "0"]
194+
},
195+
{
196+
"intrinsic": "sum2s",
197+
"width": [128],
198+
"llvm": "vsum2sws",
199+
"ret": "s32",
200+
"args": ["0", "0"]
201+
},
202+
{
203+
"intrinsic": "sum4{0.kind}bs",
204+
"width": [128],
205+
"llvm": "vsum4{0.kind}bs",
206+
"ret": "i32",
207+
"args": ["0NN", "0"]
208+
},
209+
{
210+
"intrinsic": "sum4shs",
211+
"width": [128],
212+
"llvm": "vsum4shs",
213+
"ret": "s32",
214+
"args": ["0N", "0"]
215+
},
216+
{
217+
"intrinsic": "sums",
218+
"width": [128],
219+
"llvm": "vsumsws",
220+
"ret": "s32",
221+
"args": ["0", "0"]
159222
}
160223
]
161224
}

‎src/liballoc/slice.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,25 @@ impl<T> [T] {
671671
/// # Examples
672672
///
673673
/// ```
674-
/// let v = [10, 40, 30, 20, 50];
675-
/// let (v1, v2) = v.split_at(2);
676-
/// assert_eq!([10, 40], v1);
677-
/// assert_eq!([30, 20, 50], v2);
674+
/// let v = [1, 2, 3, 4, 5, 6];
675+
///
676+
/// {
677+
/// let (left, right) = v.split_at(0);
678+
/// assert!(left == []);
679+
/// assert!(right == [1, 2, 3, 4, 5, 6]);
680+
/// }
681+
///
682+
/// {
683+
/// let (left, right) = v.split_at(2);
684+
/// assert!(left == [1, 2]);
685+
/// assert!(right == [3, 4, 5, 6]);
686+
/// }
687+
///
688+
/// {
689+
/// let (left, right) = v.split_at(6);
690+
/// assert!(left == [1, 2, 3, 4, 5, 6]);
691+
/// assert!(right == []);
692+
/// }
678693
/// ```
679694
#[stable(feature = "rust1", since = "1.0.0")]
680695
#[inline]
@@ -695,26 +710,16 @@ impl<T> [T] {
695710
/// # Examples
696711
///
697712
/// ```
698-
/// let mut v = [1, 2, 3, 4, 5, 6];
699-
///
713+
/// let mut v = [1, 0, 3, 0, 5, 6];
700714
/// // scoped to restrict the lifetime of the borrows
701715
/// {
702-
/// let (left, right) = v.split_at_mut(0);
703-
/// assert!(left == []);
704-
/// assert!(right == [1, 2, 3, 4, 5, 6]);
705-
/// }
706-
///
707-
/// {
708716
/// let (left, right) = v.split_at_mut(2);
709-
/// assert!(left == [1, 2]);
710-
/// assert!(right == [3, 4, 5, 6]);
711-
/// }
712-
///
713-
/// {
714-
/// let (left, right) = v.split_at_mut(6);
715-
/// assert!(left == [1, 2, 3, 4, 5, 6]);
716-
/// assert!(right == []);
717+
/// assert!(left == [1, 0]);
718+
/// assert!(right == [3, 0, 5, 6]);
719+
/// left[1] = 2;
720+
/// right[1] = 4;
717721
/// }
722+
/// assert!(v == [1, 2, 3, 4, 5, 6]);
718723
/// ```
719724
#[stable(feature = "rust1", since = "1.0.0")]
720725
#[inline]

‎src/libcore/cmp.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,30 @@ pub trait Ord: Eq + PartialOrd<Self> {
481481
where Self: Sized {
482482
if self <= other { self } else { other }
483483
}
484+
485+
/// Returns max if self is greater than max, and min if self is less than min.
486+
/// Otherwise this will return self.
487+
///
488+
/// # Examples
489+
///
490+
/// ```
491+
/// #![feature(clamp)]
492+
///
493+
/// assert!((-3).clamp(-2, 1) == -2);
494+
/// assert!(0.clamp(-2, 1) == 0);
495+
/// assert!(2.clamp(-2, 1) == 1);
496+
/// ```
497+
///
498+
/// # Panics
499+
/// Panics if min > max.
500+
#[unstable(feature = "clamp", issue = "44095")]
501+
fn clamp(self, min: Self, max: Self) -> Self
502+
where Self: Sized {
503+
assert!(min <= max);
504+
if self < min { min }
505+
else if self > max { max }
506+
else { self }
507+
}
484508
}
485509

486510
#[stable(feature = "rust1", since = "1.0.0")]

‎src/libcore/macros.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,15 +531,13 @@ macro_rules! unreachable {
531531

532532
/// A standardized placeholder for marking unfinished code.
533533
///
534-
/// It panics with the message `"not yet implemented"` when executed.
535-
///
536534
/// This can be useful if you are prototyping and are just looking to have your
537535
/// code typecheck, or if you're implementing a trait that requires multiple
538536
/// methods, and you're only planning on using one of them.
539537
///
540538
/// # Panics
541539
///
542-
/// This macro always panics.
540+
/// This will always [panic!](macro.panic.html)
543541
///
544542
/// # Examples
545543
///

‎src/libcore/num/dec2flt/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ macro_rules! from_str_float_impl {
121121
/// * '-3.14'
122122
/// * '2.5E10', or equivalently, '2.5e10'
123123
/// * '2.5E-10'
124-
/// * '.' (understood as 0)
125124
/// * '5.'
126125
/// * '.5', or, equivalently, '0.5'
127126
/// * 'inf', '-inf', 'NaN'

‎src/librustc/hir/def_id.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,19 @@ impl serialize::UseSpecializedDecodable for CrateNum {
9393
///
9494
/// Since the DefIndex is mostly treated as an opaque ID, you probably
9595
/// don't have to care about these ranges.
96-
#[derive(Clone, Debug, Eq, Ord, PartialOrd, PartialEq, RustcEncodable,
96+
#[derive(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable,
9797
RustcDecodable, Hash, Copy)]
9898
pub struct DefIndex(u32);
9999

100+
impl fmt::Debug for DefIndex {
101+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
102+
write!(f,
103+
"DefIndex({}:{})",
104+
self.address_space().index(),
105+
self.as_array_index())
106+
}
107+
}
108+
100109
impl DefIndex {
101110
#[inline]
102111
pub fn new(x: usize) -> DefIndex {

‎src/librustc_mir/transform/inline.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,20 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
606606
_location: Location) {
607607
if *local == RETURN_POINTER {
608608
match self.destination {
609-
Lvalue::Local(l) => *local = l,
609+
Lvalue::Local(l) => {
610+
*local = l;
611+
return;
612+
},
610613
ref lval => bug!("Return lvalue is {:?}, not local", lval)
611614
}
612615
}
613616
let idx = local.index() - 1;
614617
if idx < self.args.len() {
615618
match self.args[idx] {
616-
Operand::Consume(Lvalue::Local(l)) => *local = l,
619+
Operand::Consume(Lvalue::Local(l)) => {
620+
*local = l;
621+
return;
622+
},
617623
ref op => bug!("Arg operand `{:?}` is {:?}, not local", idx, op)
618624
}
619625
}

‎src/librustc_platform_intrinsics/powerpc.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,66 @@ pub fn find(name: &str) -> Option<Intrinsic> {
337337
output: &::I32x4,
338338
definition: Named("llvm.ppc.altivec.vupkhsh")
339339
},
340+
"_vec_madds" => Intrinsic {
341+
inputs: { static INPUTS: [&'static Type; 3] = [&::I16x8, &::I16x8, &::I16x8]; &INPUTS },
342+
output: &::I16x8,
343+
definition: Named("llvm.ppc.altivec.vmhaddshs")
344+
},
345+
"_vec_msumubm" => Intrinsic {
346+
inputs: { static INPUTS: [&'static Type; 3] = [&::U8x16, &::U8x16, &::U32x4]; &INPUTS },
347+
output: &::U32x4,
348+
definition: Named("llvm.ppc.altivec.vmsumubm")
349+
},
350+
"_vec_msumuhm" => Intrinsic {
351+
inputs: { static INPUTS: [&'static Type; 3] = [&::U16x8, &::U16x8, &::U32x4]; &INPUTS },
352+
output: &::U32x4,
353+
definition: Named("llvm.ppc.altivec.vmsumuhm")
354+
},
355+
"_vec_msummbm" => Intrinsic {
356+
inputs: { static INPUTS: [&'static Type; 3] = [&::I8x16, &::U8x16, &::I32x4]; &INPUTS },
357+
output: &::I32x4,
358+
definition: Named("llvm.ppc.altivec.vmsummbm")
359+
},
360+
"_vec_msumshm" => Intrinsic {
361+
inputs: { static INPUTS: [&'static Type; 3] = [&::I16x8, &::I16x8, &::I32x4]; &INPUTS },
362+
output: &::I32x4,
363+
definition: Named("llvm.ppc.altivec.vmsumshm")
364+
},
365+
"_vec_msumshs" => Intrinsic {
366+
inputs: { static INPUTS: [&'static Type; 3] = [&::I16x8, &::I16x8, &::I32x4]; &INPUTS },
367+
output: &::I32x4,
368+
definition: Named("llvm.ppc.altivec.vmsumshs")
369+
},
370+
"_vec_msumuhs" => Intrinsic {
371+
inputs: { static INPUTS: [&'static Type; 3] = [&::U16x8, &::U16x8, &::U32x4]; &INPUTS },
372+
output: &::U32x4,
373+
definition: Named("llvm.ppc.altivec.vmsumuhs")
374+
},
375+
"_vec_sum2s" => Intrinsic {
376+
inputs: { static INPUTS: [&'static Type; 2] = [&::I32x4, &::I32x4]; &INPUTS },
377+
output: &::I32x4,
378+
definition: Named("llvm.ppc.altivec.vsum2sws")
379+
},
380+
"_vec_sum4sbs" => Intrinsic {
381+
inputs: { static INPUTS: [&'static Type; 2] = [&::I8x16, &::I32x4]; &INPUTS },
382+
output: &::I32x4,
383+
definition: Named("llvm.ppc.altivec.vsum4sbs")
384+
},
385+
"_vec_sum4ubs" => Intrinsic {
386+
inputs: { static INPUTS: [&'static Type; 2] = [&::U8x16, &::U32x4]; &INPUTS },
387+
output: &::U32x4,
388+
definition: Named("llvm.ppc.altivec.vsum4ubs")
389+
},
390+
"_vec_sum4shs" => Intrinsic {
391+
inputs: { static INPUTS: [&'static Type; 2] = [&::I16x8, &::I32x4]; &INPUTS },
392+
output: &::I32x4,
393+
definition: Named("llvm.ppc.altivec.vsum4shs")
394+
},
395+
"_vec_sums" => Intrinsic {
396+
inputs: { static INPUTS: [&'static Type; 2] = [&::I32x4, &::I32x4]; &INPUTS },
397+
output: &::I32x4,
398+
definition: Named("llvm.ppc.altivec.vsumsws")
399+
},
340400
_ => return None,
341401
})
342402
}

‎src/librustc_typeck/check/demand.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,29 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
207207
expected: Ty<'tcx>)
208208
-> Option<String> {
209209
match (&expected.sty, &checked_ty.sty) {
210-
(&ty::TyRef(_, _), &ty::TyRef(_, _)) => None,
210+
(&ty::TyRef(_, exp), &ty::TyRef(_, check)) => match (&exp.ty.sty, &check.ty.sty) {
211+
(&ty::TyStr, &ty::TyArray(arr, _)) |
212+
(&ty::TyStr, &ty::TySlice(arr)) if arr == self.tcx.types.u8 => {
213+
if let hir::ExprLit(_) = expr.node {
214+
let sp = self.sess().codemap().call_span_if_macro(expr.span);
215+
if let Ok(src) = self.tcx.sess.codemap().span_to_snippet(sp) {
216+
return Some(format!("try `{}`", &src[1..]));
217+
}
218+
}
219+
None
220+
},
221+
(&ty::TyArray(arr, _), &ty::TyStr) |
222+
(&ty::TySlice(arr), &ty::TyStr) if arr == self.tcx.types.u8 => {
223+
if let hir::ExprLit(_) = expr.node {
224+
let sp = self.sess().codemap().call_span_if_macro(expr.span);
225+
if let Ok(src) = self.tcx.sess.codemap().span_to_snippet(sp) {
226+
return Some(format!("try `b{}`", src));
227+
}
228+
}
229+
None
230+
}
231+
_ => None,
232+
},
211233
(&ty::TyRef(_, mutability), _) => {
212234
// Check if it can work when put into a ref. For example:
213235
//

‎src/libstd/f32.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,32 @@ impl f32 {
10801080
0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()
10811081
}
10821082

1083+
/// Returns max if self is greater than max, and min if self is less than min.
1084+
/// Otherwise this returns self.
1085+
///
1086+
/// # Examples
1087+
///
1088+
/// ```
1089+
/// #![feature(clamp)]
1090+
/// use std::f32::NAN;
1091+
/// assert!((-3.0f32).clamp(-2.0f32, 1.0f32) == -2.0f32);
1092+
/// assert!((0.0f32).clamp(-2.0f32, 1.0f32) == 0.0f32);
1093+
/// assert!((2.0f32).clamp(-2.0f32, 1.0f32) == 1.0f32);
1094+
/// assert!((NAN).clamp(-2.0f32, 1.0f32).is_nan());
1095+
/// ```
1096+
///
1097+
/// # Panics
1098+
/// Panics if min > max, min is NaN, or max is NaN.
1099+
#[unstable(feature = "clamp", issue = "44095")]
1100+
#[inline]
1101+
pub fn clamp(self, min: f32, max: f32) -> f32 {
1102+
assert!(min <= max);
1103+
let mut x = self;
1104+
if x < min { x = min; }
1105+
if x > max { x = max; }
1106+
x
1107+
}
1108+
10831109
/// Raw transmutation to `u32`.
10841110
///
10851111
/// Converts the `f32` into its raw memory representation,
@@ -1751,4 +1777,22 @@ mod tests {
17511777
assert_ne!(nan_masked & QNAN_MASK, 0);
17521778
assert!(nan_masked_fl.is_nan());
17531779
}
1780+
1781+
#[test]
1782+
#[should_panic]
1783+
fn test_clamp_min_greater_than_max() {
1784+
1.0f32.clamp(3.0, 1.0);
1785+
}
1786+
1787+
#[test]
1788+
#[should_panic]
1789+
fn test_clamp_min_is_nan() {
1790+
1.0f32.clamp(NAN, 1.0);
1791+
}
1792+
1793+
#[test]
1794+
#[should_panic]
1795+
fn test_clamp_max_is_nan() {
1796+
1.0f32.clamp(3.0, NAN);
1797+
}
17541798
}

‎src/libstd/f64.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,32 @@ impl f64 {
970970
0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()
971971
}
972972

973+
/// Returns max if self is greater than max, and min if self is less than min.
974+
/// Otherwise this returns self.
975+
///
976+
/// # Examples
977+
///
978+
/// ```
979+
/// #![feature(clamp)]
980+
/// use std::f64::NAN;
981+
/// assert!((-3.0f64).clamp(-2.0f64, 1.0f64) == -2.0f64);
982+
/// assert!((0.0f64).clamp(-2.0f64, 1.0f64) == 0.0f64);
983+
/// assert!((2.0f64).clamp(-2.0f64, 1.0f64) == 1.0f64);
984+
/// assert!((NAN).clamp(-2.0f64, 1.0f64).is_nan());
985+
/// ```
986+
///
987+
/// # Panics
988+
/// Panics if min > max, min is NaN, or max is NaN.
989+
#[unstable(feature = "clamp", issue = "44095")]
990+
#[inline]
991+
pub fn clamp(self, min: f64, max: f64) -> f64 {
992+
assert!(min <= max);
993+
let mut x = self;
994+
if x < min { x = min; }
995+
if x > max { x = max; }
996+
x
997+
}
998+
973999
// Solaris/Illumos requires a wrapper around log, log2, and log10 functions
9741000
// because of their non-standard behavior (e.g. log(-n) returns -Inf instead
9751001
// of expected NaN).
@@ -1642,4 +1668,22 @@ mod tests {
16421668
assert_approx_eq!(f64::from_bits(0x4094e40000000000), 1337.0);
16431669
assert_approx_eq!(f64::from_bits(0xc02c800000000000), -14.25);
16441670
}
1671+
1672+
#[test]
1673+
#[should_panic]
1674+
fn test_clamp_min_greater_than_max() {
1675+
1.0f64.clamp(3.0, 1.0);
1676+
}
1677+
1678+
#[test]
1679+
#[should_panic]
1680+
fn test_clamp_min_is_nan() {
1681+
1.0f64.clamp(NAN, 1.0);
1682+
}
1683+
1684+
#[test]
1685+
#[should_panic]
1686+
fn test_clamp_max_is_nan() {
1687+
1.0f64.clamp(3.0, NAN);
1688+
}
16451689
}

‎src/libstd/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@
249249
#![feature(cfg_target_vendor)]
250250
#![feature(char_error_internals)]
251251
#![feature(char_internals)]
252+
#![feature(clamp)]
252253
#![feature(collections_range)]
253254
#![feature(compiler_builtins_lib)]
254255
#![feature(const_fn)]

‎src/libstd/time/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,17 @@ impl fmt::Debug for SystemTime {
382382
/// [`SystemTime`] instance to represent another fixed point in time.
383383
///
384384
/// [`SystemTime`]: ../../std/time/struct.SystemTime.html
385+
///
386+
/// # Examples
387+
///
388+
/// ```no_run
389+
/// use std::time::{SystemTime, UNIX_EPOCH};
390+
///
391+
/// match SystemTime::now().duration_since(UNIX_EPOCH) {
392+
/// Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()),
393+
/// Err(_) => panic!("SystemTime before UNIX EPOCH!"),
394+
/// }
395+
/// ```
385396
#[stable(feature = "time2", since = "1.8.0")]
386397
pub const UNIX_EPOCH: SystemTime = SystemTime(time::UNIX_EPOCH);
387398

‎src/libstd_unicode/u_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use core::str::Split;
2626
/// [`split_whitespace`]: ../../std/primitive.str.html#method.split_whitespace
2727
/// [`str`]: ../../std/primitive.str.html
2828
#[stable(feature = "split_whitespace", since = "1.1.0")]
29-
#[derive(Clone)]
29+
#[derive(Clone, Debug)]
3030
pub struct SplitWhitespace<'a> {
3131
inner: Filter<Split<'a, IsWhitespace>, IsNotEmpty>,
3232
}

‎src/libsyntax/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,9 @@ pub enum StmtKind {
761761

762762
/// Expr without trailing semi-colon.
763763
Expr(P<Expr>),
764-
764+
/// Expr with a trailing semi-colon.
765765
Semi(P<Expr>),
766-
766+
/// Macro.
767767
Mac(P<(Mac, MacStmtStyle, ThinVec<Attribute>)>),
768768
}
769769

‎src/test/compile-fail/issue-22706.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn is_copy<T: ::std::marker<i32>::Copy>() {}
12+
//~^ ERROR type parameters are not allowed on this type [E0109]
13+
fn main() {}

‎src/test/mir-opt/validate_1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() {
3030
// END RUST SOURCE
3131
// START rustc.node12.EraseRegions.after.mir
3232
// bb0: {
33-
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(5) => validate_1/8cd878b::{{impl}}[0]::foo[0] }, BrAnon(0)) Test, _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(5) => validate_1/8cd878b::{{impl}}[0]::foo[0] }, BrAnon(1)) mut i32]);
33+
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(0:5) => validate_1/8cd878b::{{impl}}[0]::foo[0] }, BrAnon(0)) Test, _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(0:5) => validate_1/8cd878b::{{impl}}[0]::foo[0] }, BrAnon(1)) mut i32]);
3434
// return;
3535
// }
3636
// END rustc.node12.EraseRegions.after.mir
@@ -57,7 +57,7 @@ fn main() {
5757
// START rustc.node50.EraseRegions.after.mir
5858
// fn main::{{closure}}(_1: &ReErased [closure@NodeId(50)], _2: &ReErased mut i32) -> i32 {
5959
// bb0: {
60-
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483663) => validate_1/8cd878b::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(50)], _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483663) => validate_1/8cd878b::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
60+
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(1:15) => validate_1/8cd878b::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(50)], _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(1:15) => validate_1/8cd878b::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
6161
// StorageLive(_3);
6262
// _3 = _2;
6363
// StorageLive(_4);

‎src/test/mir-opt/validate_4.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ fn main() {
4848
// START rustc.node22.EraseRegions.after.mir
4949
// fn write_42::{{closure}}(_1: &ReErased [closure@NodeId(22)], _2: *mut i32) -> () {
5050
// bb0: {
51-
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483659) => validate_4/8cd878b::write_42[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(22)], _2: *mut i32]);
52-
// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483659) => validate_4/8cd878b::write_42[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(22)], _2: *mut i32]);
51+
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(1:11) => validate_4/8cd878b::write_42[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(22)], _2: *mut i32]);
52+
// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(1:11) => validate_4/8cd878b::write_42[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(22)], _2: *mut i32]);
5353
// StorageLive(_3);
5454
// _3 = _2;
5555
// (*_3) = const 23i32;
@@ -61,8 +61,8 @@ fn main() {
6161
// START rustc.node31.EraseRegions.after.mir
6262
// fn test(_1: &ReErased mut i32) -> () {
6363
// bb0: {
64-
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(4) => validate_4/8cd878b::test[0] }, BrAnon(0)) mut i32]);
65-
// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(4) => validate_4/8cd878b::test[0] }, BrAnon(0)) mut i32]);
64+
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(0:4) => validate_4/8cd878b::test[0] }, BrAnon(0)) mut i32]);
65+
// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(0:4) => validate_4/8cd878b::test[0] }, BrAnon(0)) mut i32]);
6666
// _3 = const write_42(_4) -> bb1;
6767
// }
6868
// bb1: {
@@ -74,8 +74,8 @@ fn main() {
7474
// START rustc.node60.EraseRegions.after.mir
7575
// fn main::{{closure}}(_1: &ReErased [closure@NodeId(60)], _2: &ReErased mut i32) -> bool {
7676
// bb0: {
77-
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483663) => validate_4/8cd878b::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(60)], _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483663) => validate_4/8cd878b::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
78-
// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483663) => validate_4/8cd878b::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(60)], _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483663) => validate_4/8cd878b::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
77+
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(1:15) => validate_4/8cd878b::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(60)], _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(1:15) => validate_4/8cd878b::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
78+
// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(1:15) => validate_4/8cd878b::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(60)], _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(1:15) => validate_4/8cd878b::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
7979
// StorageLive(_3);
8080
// _0 = const write_42(_4) -> bb1;
8181
// }

‎src/test/mir-opt/validate_5.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() {
3636
// START rustc.node17.EraseRegions.after.mir
3737
// fn test(_1: &ReErased mut i32) -> () {
3838
// bb0: {
39-
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(4) => validate_5/8cd878b::test[0] }, BrAnon(0)) mut i32]);
39+
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(0:4) => validate_5/8cd878b::test[0] }, BrAnon(0)) mut i32]);
4040
// Validate(Release, [_3: bool, _4: *mut i32]);
4141
// _3 = const write_42(_4) -> bb1;
4242
// }
@@ -45,7 +45,7 @@ fn main() {
4545
// START rustc.node46.EraseRegions.after.mir
4646
// fn main::{{closure}}(_1: &ReErased [closure@NodeId(46)], _2: &ReErased mut i32) -> bool {
4747
// bb0: {
48-
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483660) => validate_5/8cd878b::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(46)], _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483660) => validate_5/8cd878b::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
48+
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(1:12) => validate_5/8cd878b::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(46)], _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(1:12) => validate_5/8cd878b::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
4949
// StorageLive(_3);
5050
// _3 = _2;
5151
// StorageLive(_4);

‎src/test/run-pass/issue-23338-ensure-param-drop-order.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ fn test<'a>(log: d::Log<'a>) {
6464
d::println(&format!("result {}", result));
6565
}
6666

67-
// FIXME(#33490) Remove the double braces when old trans is gone.
68-
fn foo<'a>(da0: D<'a>, de1: D<'a>) -> D<'a> {{
67+
fn foo<'a>(da0: D<'a>, de1: D<'a>) -> D<'a> {
6968
d::println("entered foo");
7069
let de2 = de1.incr(); // creates D(de_2, 2)
7170
let de4 = {
@@ -74,7 +73,7 @@ fn foo<'a>(da0: D<'a>, de1: D<'a>) -> D<'a> {{
7473
};
7574
d::println("eval tail of foo");
7675
de4.incr().incr() // creates D(de_5, 6) and D(de_6, 7)
77-
}}
76+
}
7877

7978
// This module provides simultaneous printouts of the dynamic extents
8079
// of all of the D values, in addition to logging the order that each

‎src/test/run-pass/issue-33185.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![allow(dead_code)]
12+
13+
#[macro_export]
14+
macro_rules! state {
15+
( $( $name:ident : $field:ty )* ) => (
16+
#[derive(Default)]
17+
struct State {
18+
$($name : $field),*
19+
}
20+
)
21+
}
22+
23+
state! { x: i64 }
24+
25+
pub fn main() {
26+
}

‎src/test/run-pass/issue-35376.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(specialization)]
12+
13+
fn main() {}
14+
15+
pub trait Alpha<T> { }
16+
17+
pub trait Beta {
18+
type Event;
19+
}
20+
21+
pub trait Delta {
22+
type Handle;
23+
fn process(&self);
24+
}
25+
26+
pub struct Parent<A, T>(A, T);
27+
28+
impl<A, T> Delta for Parent<A, T>
29+
where A: Alpha<T::Handle>,
30+
T: Delta,
31+
T::Handle: Beta<Event = <Handle as Beta>::Event> {
32+
type Handle = Handle;
33+
default fn process(&self) {
34+
unimplemented!()
35+
}
36+
}
37+
38+
impl<A, T> Delta for Parent<A, T>
39+
where A: Alpha<T::Handle> + Alpha<Handle>,
40+
T: Delta,
41+
T::Handle: Beta<Event = <Handle as Beta>::Event> {
42+
fn process(&self) {
43+
unimplemented!()
44+
}
45+
}
46+
47+
pub struct Handle;
48+
49+
impl Beta for Handle {
50+
type Event = ();
51+
}

‎src/test/run-pass/overloaded-autoderef-order.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ pub fn main() {
7575
assert_eq!(Rc::new(nested).x, true);
7676

7777
let nested_priv = priv_test::DerefWrapperHideX::new(true, DerefWrapper {x: 0, y: 1});
78-
// FIXME(eddyb) #12808 should skip private fields.
79-
// assert_eq!(nested_priv.x, 0);
78+
assert_eq!(nested_priv.x, 0);
8079
assert_eq!((*nested_priv).x, 0);
8180
}

‎src/test/ui/str-lit-type-mismatch.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
fn main() {
13+
let x: &[u8] = "foo";
14+
let y: &[u8; 4] = "baaa";
15+
let z: &str = b"foo";
16+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/str-lit-type-mismatch.rs:13:20
3+
|
4+
13 | let x: &[u8] = "foo";
5+
| ^^^^^ expected slice, found str
6+
|
7+
= note: expected type `&[u8]`
8+
found type `&'static str`
9+
= help: try `b"foo"`
10+
11+
error[E0308]: mismatched types
12+
--> $DIR/str-lit-type-mismatch.rs:14:23
13+
|
14+
14 | let y: &[u8; 4] = "baaa";
15+
| ^^^^^^ expected array of 4 elements, found str
16+
|
17+
= note: expected type `&[u8; 4]`
18+
found type `&'static str`
19+
= help: try `b"baaa"`
20+
21+
error[E0308]: mismatched types
22+
--> $DIR/str-lit-type-mismatch.rs:15:19
23+
|
24+
15 | let z: &str = b"foo";
25+
| ^^^^^^ expected str, found array of 3 elements
26+
|
27+
= note: expected type `&str`
28+
found type `&'static [u8; 3]`
29+
= help: try `"foo"`
30+
31+
error: aborting due to 3 previous errors
32+

‎src/tools/build-manifest/src/main.rs

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct Manifest {
113113
#[derive(Serialize)]
114114
struct Package {
115115
version: String,
116+
git_commit_hash: Option<String>,
116117
target: BTreeMap<String, Target>,
117118
}
118119

@@ -167,6 +168,9 @@ struct Builder {
167168
rust_version: String,
168169
cargo_version: String,
169170
rls_version: String,
171+
rust_git_commit_hash: Option<String>,
172+
cargo_git_commit_hash: Option<String>,
173+
rls_git_commit_hash: Option<String>,
170174
}
171175

172176
fn main() {
@@ -194,6 +198,9 @@ fn main() {
194198
rust_version: String::new(),
195199
cargo_version: String::new(),
196200
rls_version: String::new(),
201+
rust_git_commit_hash: None,
202+
cargo_git_commit_hash: None,
203+
rls_git_commit_hash: None,
197204
}.build();
198205
}
199206

@@ -202,18 +209,16 @@ impl Builder {
202209
self.rust_version = self.version("rust", "x86_64-unknown-linux-gnu");
203210
self.cargo_version = self.version("cargo", "x86_64-unknown-linux-gnu");
204211
self.rls_version = self.version("rls", "x86_64-unknown-linux-gnu");
212+
self.rust_git_commit_hash = self.git_commit_hash("rust", "x86_64-unknown-linux-gnu");
213+
self.cargo_git_commit_hash = self.git_commit_hash("cargo", "x86_64-unknown-linux-gnu");
214+
self.rls_git_commit_hash = self.git_commit_hash("rls", "x86_64-unknown-linux-gnu");
205215

206216
self.digest_and_sign();
207217
let manifest = self.build_manifest();
208-
let filename = format!("channel-rust-{}.toml", self.rust_release);
209-
self.write_manifest(&toml::to_string(&manifest).unwrap(), &filename);
210-
211-
let filename = format!("channel-rust-{}-date.txt", self.rust_release);
212-
self.write_date_stamp(&manifest.date, &filename);
218+
self.write_channel_files(&self.rust_release, &manifest);
213219

214220
if self.rust_release != "beta" && self.rust_release != "nightly" {
215-
self.write_manifest(&toml::to_string(&manifest).unwrap(), "channel-rust-stable.toml");
216-
self.write_date_stamp(&manifest.date, "channel-rust-stable-date.txt");
221+
self.write_channel_files("stable", &manifest);
217222
}
218223
}
219224

@@ -249,6 +254,7 @@ impl Builder {
249254

250255
let mut pkg = Package {
251256
version: self.cached_version("rust").to_string(),
257+
git_commit_hash: self.cached_git_commit_hash("rust").clone(),
252258
target: BTreeMap::new(),
253259
};
254260
for host in HOSTS {
@@ -342,6 +348,7 @@ impl Builder {
342348

343349
dst.insert(pkgname.to_string(), Package {
344350
version: self.cached_version(pkgname).to_string(),
351+
git_commit_hash: self.cached_git_commit_hash(pkgname).clone(),
345352
target: targets,
346353
});
347354
}
@@ -375,21 +382,50 @@ impl Builder {
375382
}
376383
}
377384

385+
fn cached_git_commit_hash(&self, component: &str) -> &Option<String> {
386+
if component == "cargo" {
387+
&self.cargo_git_commit_hash
388+
} else if component == "rls" || component == "rls-preview" {
389+
&self.rls_git_commit_hash
390+
} else {
391+
&self.rust_git_commit_hash
392+
}
393+
}
394+
378395
fn version(&self, component: &str, target: &str) -> String {
379396
let mut cmd = Command::new("tar");
380397
let filename = self.filename(component, target);
381398
cmd.arg("xf")
382399
.arg(self.input.join(&filename))
383400
.arg(format!("{}/version", filename.replace(".tar.gz", "")))
384401
.arg("-O");
385-
let version = t!(cmd.output());
386-
if !version.status.success() {
402+
let output = t!(cmd.output());
403+
if !output.status.success() {
387404
panic!("failed to learn version:\n\n{:?}\n\n{}\n\n{}",
388405
cmd,
389-
String::from_utf8_lossy(&version.stdout),
390-
String::from_utf8_lossy(&version.stderr));
406+
String::from_utf8_lossy(&output.stdout),
407+
String::from_utf8_lossy(&output.stderr));
408+
}
409+
String::from_utf8_lossy(&output.stdout).trim().to_string()
410+
}
411+
412+
fn git_commit_hash(&self, component: &str, target: &str) -> Option<String> {
413+
let mut cmd = Command::new("tar");
414+
let filename = self.filename(component, target);
415+
cmd.arg("xf")
416+
.arg(self.input.join(&filename))
417+
.arg(format!("{}/git-commit-hash", filename.replace(".tar.gz", "")))
418+
.arg("-O");
419+
let output = t!(cmd.output());
420+
if output.status.success() {
421+
Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
422+
} else {
423+
// This is always called after `.version()`.
424+
// So if that didn’t fail but this does,
425+
// that’s very probably because the tarball is valid
426+
// but does not contain a `git-commit-hash` file.
427+
None
391428
}
392-
String::from_utf8_lossy(&version.stdout).trim().to_string()
393429
}
394430

395431
fn hash(&self, path: &Path) -> String {
@@ -425,16 +461,16 @@ impl Builder {
425461
assert!(t!(child.wait()).success());
426462
}
427463

428-
fn write_manifest(&self, manifest: &str, name: &str) {
429-
let dst = self.output.join(name);
430-
t!(t!(File::create(&dst)).write_all(manifest.as_bytes()));
431-
self.hash(&dst);
432-
self.sign(&dst);
464+
fn write_channel_files(&self, channel_name: &str, manifest: &Manifest) {
465+
self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
466+
self.write(&manifest.date, channel_name, "-date.txt");
467+
self.write(manifest.pkg["rust"].git_commit_hash.as_ref().unwrap(),
468+
channel_name, "-git-commit-hash.txt");
433469
}
434470

435-
fn write_date_stamp(&self, date: &str, name: &str) {
436-
let dst = self.output.join(name);
437-
t!(t!(File::create(&dst)).write_all(date.as_bytes()));
471+
fn write(&self, contents: &str, channel_name: &str, suffix: &str) {
472+
let dst = self.output.join(format!("channel-rust-{}{}", channel_name, suffix));
473+
t!(t!(File::create(&dst)).write_all(contents.as_bytes()));
438474
self.hash(&dst);
439475
self.sign(&dst);
440476
}

‎src/tools/rustbook/src/main.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ fn main() {
4141
// Check which subcomamnd the user ran...
4242
let res = match matches.subcommand() {
4343
("build", Some(sub_matches)) => build(sub_matches),
44-
("test", Some(sub_matches)) => test(sub_matches),
4544
(_, _) => unreachable!(),
4645
};
4746

@@ -65,14 +64,6 @@ fn build(args: &ArgMatches) -> Result<(), Box<Error>> {
6564
Ok(())
6665
}
6766

68-
fn test(args: &ArgMatches) -> Result<(), Box<Error>> {
69-
let mut book = build_mdbook_struct(args);
70-
71-
try!(book.test());
72-
73-
Ok(())
74-
}
75-
7667
fn build_mdbook_struct(args: &ArgMatches) -> mdbook::MDBook {
7768
let book_dir = get_book_dir(args);
7869
let mut book = MDBook::new(&book_dir).read_config();

0 commit comments

Comments
 (0)
Please sign in to comment.