Skip to content

Commit 2fa1390

Browse files
committed
Auto merge of #54389 - kennytm:rollup, r=kennytm
Rollup of 15 pull requests Successful merges: - #52813 (Duration div mul extras) - #53470 (Warn about metadata loader errors) - #54233 (Remove LLVM 3.9 workaround.) - #54257 (Switch wasm math symbols to their original names) - #54258 (Enable fatal warnings for the wasm32 linker) - #54266 (Update LLVM to fix "bool" arguments on PPC32) - #54290 (Switch linker for aarch64-pc-windows-msvc from LLD to MSVC) - #54292 (Suggest array indexing when tuple indexing on an array) - #54295 (A few cleanups and minor improvements to rustc/traits) - #54298 (miri: correctly compute expected alignment for field) - #54333 (Update The Book to latest) - #54337 (Remove unneeded clone() from tests in librustdoc) - #54346 (rustc: future-proof error reporting for polymorphic constants in types.) - #54362 (Pass --batch to gdb) - #54367 (Add regression test for thread local static mut borrows)
2 parents 3bc2ca7 + ec08596 commit 2fa1390

35 files changed

+636
-525
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ after_failure:
301301
EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|');
302302
if [ -f "$EXE" ]; then
303303
printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE";
304-
gdb -q -c "$CORE" "$EXE"
304+
gdb --batch -q -c "$CORE" "$EXE"
305305
-iex 'set auto-load off'
306306
-iex 'dir src/'
307307
-iex 'set sysroot .'

src/doc/book

Submodule book updated 58 files

src/libcore/time.rs

+120-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//! assert_eq!(Duration::new(5, 0), Duration::from_secs(5));
2222
//! ```
2323
24-
use fmt;
24+
use {fmt, u64};
2525
use iter::Sum;
2626
use ops::{Add, Sub, Mul, Div, AddAssign, SubAssign, MulAssign, DivAssign};
2727

@@ -30,6 +30,7 @@ const NANOS_PER_MILLI: u32 = 1_000_000;
3030
const NANOS_PER_MICRO: u32 = 1_000;
3131
const MILLIS_PER_SEC: u64 = 1_000;
3232
const MICROS_PER_SEC: u64 = 1_000_000;
33+
const MAX_NANOS_F64: f64 = ((u64::MAX as u128 + 1)*(NANOS_PER_SEC as u128)) as f64;
3334

3435
/// A `Duration` type to represent a span of time, typically used for system
3536
/// timeouts.
@@ -458,6 +459,115 @@ impl Duration {
458459
None
459460
}
460461
}
462+
463+
/// Returns the number of seconds contained by this `Duration` as `f64`.
464+
///
465+
/// The returned value does include the fractional (nanosecond) part of the duration.
466+
///
467+
/// # Examples
468+
/// ```
469+
/// #![feature(duration_float)]
470+
/// use std::time::Duration;
471+
///
472+
/// let dur = Duration::new(2, 700_000_000);
473+
/// assert_eq!(dur.as_float_secs(), 2.7);
474+
/// ```
475+
#[unstable(feature = "duration_float", issue = "54361")]
476+
#[inline]
477+
pub fn as_float_secs(&self) -> f64 {
478+
(self.secs as f64) + (self.nanos as f64) / (NANOS_PER_SEC as f64)
479+
}
480+
481+
/// Creates a new `Duration` from the specified number of seconds.
482+
///
483+
/// # Panics
484+
/// This constructor will panic if `secs` is not finite, negative or overflows `Duration`.
485+
///
486+
/// # Examples
487+
/// ```
488+
/// #![feature(duration_float)]
489+
/// use std::time::Duration;
490+
///
491+
/// let dur = Duration::from_float_secs(2.7);
492+
/// assert_eq!(dur, Duration::new(2, 700_000_000));
493+
/// ```
494+
#[unstable(feature = "duration_float", issue = "54361")]
495+
#[inline]
496+
pub fn from_float_secs(secs: f64) -> Duration {
497+
let nanos = secs * (NANOS_PER_SEC as f64);
498+
if !nanos.is_finite() {
499+
panic!("got non-finite value when converting float to duration");
500+
}
501+
if nanos >= MAX_NANOS_F64 {
502+
panic!("overflow when converting float to duration");
503+
}
504+
if nanos < 0.0 {
505+
panic!("underflow when converting float to duration");
506+
}
507+
let nanos = nanos as u128;
508+
Duration {
509+
secs: (nanos / (NANOS_PER_SEC as u128)) as u64,
510+
nanos: (nanos % (NANOS_PER_SEC as u128)) as u32,
511+
}
512+
}
513+
514+
/// Multiply `Duration` by `f64`.
515+
///
516+
/// # Panics
517+
/// This method will panic if result is not finite, negative or overflows `Duration`.
518+
///
519+
/// # Examples
520+
/// ```
521+
/// #![feature(duration_float)]
522+
/// use std::time::Duration;
523+
///
524+
/// let dur = Duration::new(2, 700_000_000);
525+
/// assert_eq!(dur.mul_f64(3.14), Duration::new(8, 478_000_000));
526+
/// assert_eq!(dur.mul_f64(3.14e5), Duration::new(847_800, 0));
527+
/// ```
528+
#[unstable(feature = "duration_float", issue = "54361")]
529+
#[inline]
530+
pub fn mul_f64(self, rhs: f64) -> Duration {
531+
Duration::from_float_secs(rhs * self.as_float_secs())
532+
}
533+
534+
/// Divide `Duration` by `f64`.
535+
///
536+
/// # Panics
537+
/// This method will panic if result is not finite, negative or overflows `Duration`.
538+
///
539+
/// # Examples
540+
/// ```
541+
/// #![feature(duration_float)]
542+
/// use std::time::Duration;
543+
///
544+
/// let dur = Duration::new(2, 700_000_000);
545+
/// assert_eq!(dur.div_f64(3.14), Duration::new(0, 859_872_611));
546+
/// // note that truncation is used, not rounding
547+
/// assert_eq!(dur.div_f64(3.14e5), Duration::new(0, 8_598));
548+
/// ```
549+
#[unstable(feature = "duration_float", issue = "54361")]
550+
#[inline]
551+
pub fn div_f64(self, rhs: f64) -> Duration {
552+
Duration::from_float_secs(self.as_float_secs() / rhs)
553+
}
554+
555+
/// Divide `Duration` by `Duration` and return `f64`.
556+
///
557+
/// # Examples
558+
/// ```
559+
/// #![feature(duration_float)]
560+
/// use std::time::Duration;
561+
///
562+
/// let dur1 = Duration::new(2, 700_000_000);
563+
/// let dur2 = Duration::new(5, 400_000_000);
564+
/// assert_eq!(dur1.div_duration(dur2), 0.5);
565+
/// ```
566+
#[unstable(feature = "duration_float", issue = "54361")]
567+
#[inline]
568+
pub fn div_duration(self, rhs: Duration) -> f64 {
569+
self.as_float_secs() / rhs.as_float_secs()
570+
}
461571
}
462572

463573
#[stable(feature = "duration", since = "1.3.0")]
@@ -501,6 +611,15 @@ impl Mul<u32> for Duration {
501611
}
502612
}
503613

614+
#[stable(feature = "symmetric_u32_duration_mul", since = "1.31.0")]
615+
impl Mul<Duration> for u32 {
616+
type Output = Duration;
617+
618+
fn mul(self, rhs: Duration) -> Duration {
619+
rhs * self
620+
}
621+
}
622+
504623
#[stable(feature = "time_augmented_assignment", since = "1.9.0")]
505624
impl MulAssign<u32> for Duration {
506625
fn mul_assign(&mut self, rhs: u32) {

src/librustc/traits/auto_trait.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,18 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
112112
orig_params,
113113
trait_pred.to_poly_trait_predicate(),
114114
));
115+
115116
match result {
116117
Ok(Some(Vtable::VtableImpl(_))) => {
117118
debug!(
118119
"find_auto_trait_generics(did={:?}, trait_did={:?}, generics={:?}): \
119120
manual impl found, bailing out",
120121
did, trait_did, generics
121122
);
122-
return true;
123+
true
123124
}
124-
_ => return false,
125-
};
125+
_ => false
126+
}
126127
});
127128

128129
// If an explicit impl exists, it always takes priority over an auto impl
@@ -426,6 +427,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
426427
if new_trait.def_id() == old_trait.def_id() {
427428
let new_substs = new_trait.skip_binder().trait_ref.substs;
428429
let old_substs = old_trait.skip_binder().trait_ref.substs;
430+
429431
if !new_substs.types().eq(old_substs.types()) {
430432
// We can't compare lifetimes if the types are different,
431433
// so skip checking old_pred
@@ -489,12 +491,12 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
489491

490492
pub fn get_lifetime(&self, region: Region, names_map: &FxHashMap<String, String>) -> String {
491493
self.region_name(region)
492-
.map(|name| {
493-
names_map.get(&name).unwrap_or_else(|| {
494+
.map(|name|
495+
names_map.get(&name).unwrap_or_else(||
494496
panic!("Missing lifetime with name {:?} for {:?}", name, region)
495-
})
496-
})
497-
.unwrap_or(&"'static".to_string())
497+
)
498+
)
499+
.unwrap_or(&"'static".to_owned())
498500
.clone()
499501
}
500502

src/librustc/traits/codegen/mod.rs

+12-19
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn codegen_fulfill_obligation<'a, 'tcx>(ty: TyCtxt<'a, 'tcx, 'tcx>,
3939
let trait_ref = ty.erase_regions(&trait_ref);
4040

4141
debug!("codegen_fulfill_obligation(trait_ref={:?}, def_id={:?})",
42-
(param_env, trait_ref), trait_ref.def_id());
42+
(param_env, trait_ref), trait_ref.def_id());
4343

4444
// Do the initial selection for the obligation. This yields the
4545
// shallow result we are looking for -- that is, what specific impl.
@@ -48,8 +48,8 @@ pub fn codegen_fulfill_obligation<'a, 'tcx>(ty: TyCtxt<'a, 'tcx, 'tcx>,
4848

4949
let obligation_cause = ObligationCause::dummy();
5050
let obligation = Obligation::new(obligation_cause,
51-
param_env,
52-
trait_ref.to_poly_trait_predicate());
51+
param_env,
52+
trait_ref.to_poly_trait_predicate());
5353

5454
let selection = match selcx.select(&obligation) {
5555
Ok(Some(selection)) => selection,
@@ -61,12 +61,11 @@ pub fn codegen_fulfill_obligation<'a, 'tcx>(ty: TyCtxt<'a, 'tcx, 'tcx>,
6161
// overflow bug, since I believe this is the only case
6262
// where ambiguity can result.
6363
bug!("Encountered ambiguity selecting `{:?}` during codegen, \
64-
presuming due to overflow",
65-
trait_ref)
64+
presuming due to overflow",
65+
trait_ref)
6666
}
6767
Err(e) => {
68-
bug!("Encountered error `{:?}` selecting `{:?}` during codegen",
69-
e, trait_ref)
68+
bug!("Encountered error `{:?}` selecting `{:?}` during codegen", e, trait_ref)
7069
}
7170
};
7271

@@ -163,22 +162,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
163162
// In principle, we only need to do this so long as `result`
164163
// contains unbound type parameters. It could be a slight
165164
// optimization to stop iterating early.
166-
match fulfill_cx.select_all_or_error(self) {
167-
Ok(()) => { }
168-
Err(errors) => {
169-
span_bug!(span, "Encountered errors `{:?}` resolving bounds after type-checking",
170-
errors);
171-
}
165+
if let Err(errors) = fulfill_cx.select_all_or_error(self) {
166+
span_bug!(span, "Encountered errors `{:?}` resolving bounds after type-checking",
167+
errors);
172168
}
173169

174170
let result = self.resolve_type_vars_if_possible(result);
175171
let result = self.tcx.erase_regions(&result);
176172

177-
match self.tcx.lift_to_global(&result) {
178-
Some(result) => result,
179-
None => {
180-
span_bug!(span, "Uninferred types/regions in `{:?}`", result);
181-
}
182-
}
173+
self.tcx.lift_to_global(&result).unwrap_or_else(||
174+
span_bug!(span, "Uninferred types/regions in `{:?}`", result)
175+
)
183176
}
184177
}

src/librustc/traits/coherence.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ fn overlap<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
115115
b_def_id: DefId)
116116
-> Option<OverlapResult<'tcx>>
117117
{
118-
debug!("overlap(a_def_id={:?}, b_def_id={:?})",
119-
a_def_id,
120-
b_def_id);
118+
debug!("overlap(a_def_id={:?}, b_def_id={:?})", a_def_id, b_def_id);
121119

122120
// For the purposes of this check, we don't bring any skolemized
123121
// types into scope; instead, we replace the generic types with
@@ -133,10 +131,9 @@ fn overlap<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
133131

134132
// Do `a` and `b` unify? If not, no overlap.
135133
let obligations = match selcx.infcx().at(&ObligationCause::dummy(), param_env)
136-
.eq_impl_headers(&a_impl_header, &b_impl_header) {
137-
Ok(InferOk { obligations, value: () }) => {
138-
obligations
139-
}
134+
.eq_impl_headers(&a_impl_header, &b_impl_header)
135+
{
136+
Ok(InferOk { obligations, value: () }) => obligations,
140137
Err(_) => return None
141138
};
142139

@@ -164,7 +161,7 @@ fn overlap<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
164161
return None
165162
}
166163

167-
let impl_header = selcx.infcx().resolve_type_vars_if_possible(&a_impl_header);
164+
let impl_header = selcx.infcx().resolve_type_vars_if_possible(&a_impl_header);
168165
let intercrate_ambiguity_causes = selcx.take_intercrate_ambiguity_causes();
169166
debug!("overlap: intercrate_ambiguity_causes={:#?}", intercrate_ambiguity_causes);
170167
Some(OverlapResult { impl_header, intercrate_ambiguity_causes })
@@ -471,14 +468,12 @@ fn ty_is_local_constructor(ty: Ty, in_crate: InCrate) -> bool {
471468
ty::Foreign(did) => def_id_is_local(did, in_crate),
472469

473470
ty::Dynamic(ref tt, ..) => {
474-
tt.principal().map_or(false, |p| {
471+
tt.principal().map_or(false, |p|
475472
def_id_is_local(p.def_id(), in_crate)
476-
})
473+
)
477474
}
478475

479-
ty::Error => {
480-
true
481-
}
476+
ty::Error => true,
482477

483478
ty::Closure(..) |
484479
ty::Generator(..) |

0 commit comments

Comments
 (0)