Skip to content

Commit

Permalink
Auto merge of #54389 - kennytm:rollup, r=kennytm
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
bors committed Sep 20, 2018
2 parents 3bc2ca7 + ec08596 commit 2fa1390
Show file tree
Hide file tree
Showing 35 changed files with 636 additions and 525 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ after_failure:
EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|');
if [ -f "$EXE" ]; then
printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE";
gdb -q -c "$CORE" "$EXE"
gdb --batch -q -c "$CORE" "$EXE"
-iex 'set auto-load off'
-iex 'dir src/'
-iex 'set sysroot .'
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book
Submodule book updated 58 files
+4 −0 2018-edition/book.toml
+33 −0 2018-edition/ferris.css
+51 −0 2018-edition/ferris.js
+13 −2 2018-edition/src/ch00-00-introduction.md
+1 −1 2018-edition/src/ch02-00-guessing-game-tutorial.md
+2 −2 2018-edition/src/ch03-01-variables-and-mutability.md
+1 −1 2018-edition/src/ch03-02-data-types.md
+2 −2 2018-edition/src/ch03-03-how-functions-work.md
+2 −2 2018-edition/src/ch03-05-control-flow.md
+1 −1 2018-edition/src/ch04-01-what-is-ownership.md
+4 −4 2018-edition/src/ch04-02-references-and-borrowing.md
+1 −1 2018-edition/src/ch04-03-slices.md
+1 −1 2018-edition/src/ch05-01-defining-structs.md
+1 −1 2018-edition/src/ch05-02-example-structs.md
+1 −1 2018-edition/src/ch06-01-defining-an-enum.md
+1 −1 2018-edition/src/ch06-02-match.md
+1 −1 2018-edition/src/ch07-01-mod-and-the-filesystem.md
+1 −1 2018-edition/src/ch07-02-controlling-visibility-with-pub.md
+1 −1 2018-edition/src/ch07-03-importing-names-with-use.md
+2 −2 2018-edition/src/ch08-01-vectors.md
+2 −2 2018-edition/src/ch08-02-strings.md
+3 −1 2018-edition/src/ch08-03-hash-maps.md
+2 −2 2018-edition/src/ch09-01-unrecoverable-errors-with-panic.md
+0 −1 2018-edition/src/ch09-02-recoverable-errors-with-result.md
+1 −1 2018-edition/src/ch09-03-to-panic-or-not-to-panic.md
+2 −2 2018-edition/src/ch10-01-syntax.md
+1 −1 2018-edition/src/ch10-02-traits.md
+5 −5 2018-edition/src/ch10-03-lifetime-syntax.md
+6 −6 2018-edition/src/ch11-01-writing-tests.md
+1 −1 2018-edition/src/ch11-02-running-tests.md
+1 −1 2018-edition/src/ch12-02-reading-a-file.md
+4 −4 2018-edition/src/ch13-01-closures.md
+1 −1 2018-edition/src/ch13-02-iterators.md
+1 −1 2018-edition/src/ch15-01-box.md
+1 −1 2018-edition/src/ch15-02-deref.md
+1 −1 2018-edition/src/ch15-03-drop.md
+1 −1 2018-edition/src/ch15-04-rc.md
+3 −3 2018-edition/src/ch15-05-interior-mutability.md
+2 −2 2018-edition/src/ch16-01-threads.md
+1 −1 2018-edition/src/ch16-02-message-passing.md
+3 −3 2018-edition/src/ch16-03-shared-state.md
+2 −2 2018-edition/src/ch17-02-trait-objects.md
+1 −1 2018-edition/src/ch18-01-all-the-places-for-patterns.md
+2 −2 2018-edition/src/ch18-02-refutability.md
+2 −2 2018-edition/src/ch18-03-pattern-syntax.md
+8 −8 2018-edition/src/ch19-01-unsafe-rust.md
+4 −4 2018-edition/src/ch19-02-advanced-lifetimes.md
+1 −1 2018-edition/src/ch19-03-advanced-traits.md
+2 −2 2018-edition/src/ch19-04-advanced-types.md
+1 −1 2018-edition/src/ch19-05-advanced-functions-and-closures.md
+13 −13 2018-edition/src/ch20-02-multithreaded.md
+2 −2 2018-edition/src/ch20-03-graceful-shutdown-and-cleanup.md
+72 −0 2018-edition/src/img/ferris/does_not_compile.svg
+75 −0 2018-edition/src/img/ferris/not_desired_behavior.svg
+70 −0 2018-edition/src/img/ferris/panics.svg
+291 −0 2018-edition/src/img/ferris/unsafe.svg
+18 −18 second-edition/src/ch11-01-writing-tests.md
+1 −1 second-edition/src/ch20-03-graceful-shutdown-and-cleanup.md
121 changes: 120 additions & 1 deletion src/libcore/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! assert_eq!(Duration::new(5, 0), Duration::from_secs(5));
//! ```

use fmt;
use {fmt, u64};
use iter::Sum;
use ops::{Add, Sub, Mul, Div, AddAssign, SubAssign, MulAssign, DivAssign};

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

/// A `Duration` type to represent a span of time, typically used for system
/// timeouts.
Expand Down Expand Up @@ -458,6 +459,115 @@ impl Duration {
None
}
}

/// Returns the number of seconds contained by this `Duration` as `f64`.
///
/// The returned value does include the fractional (nanosecond) part of the duration.
///
/// # Examples
/// ```
/// #![feature(duration_float)]
/// use std::time::Duration;
///
/// let dur = Duration::new(2, 700_000_000);
/// assert_eq!(dur.as_float_secs(), 2.7);
/// ```
#[unstable(feature = "duration_float", issue = "54361")]
#[inline]
pub fn as_float_secs(&self) -> f64 {
(self.secs as f64) + (self.nanos as f64) / (NANOS_PER_SEC as f64)
}

/// Creates a new `Duration` from the specified number of seconds.
///
/// # Panics
/// This constructor will panic if `secs` is not finite, negative or overflows `Duration`.
///
/// # Examples
/// ```
/// #![feature(duration_float)]
/// use std::time::Duration;
///
/// let dur = Duration::from_float_secs(2.7);
/// assert_eq!(dur, Duration::new(2, 700_000_000));
/// ```
#[unstable(feature = "duration_float", issue = "54361")]
#[inline]
pub fn from_float_secs(secs: f64) -> Duration {
let nanos = secs * (NANOS_PER_SEC as f64);
if !nanos.is_finite() {
panic!("got non-finite value when converting float to duration");
}
if nanos >= MAX_NANOS_F64 {
panic!("overflow when converting float to duration");
}
if nanos < 0.0 {
panic!("underflow when converting float to duration");
}
let nanos = nanos as u128;
Duration {
secs: (nanos / (NANOS_PER_SEC as u128)) as u64,
nanos: (nanos % (NANOS_PER_SEC as u128)) as u32,
}
}

/// Multiply `Duration` by `f64`.
///
/// # Panics
/// This method will panic if result is not finite, negative or overflows `Duration`.
///
/// # Examples
/// ```
/// #![feature(duration_float)]
/// use std::time::Duration;
///
/// let dur = Duration::new(2, 700_000_000);
/// assert_eq!(dur.mul_f64(3.14), Duration::new(8, 478_000_000));
/// assert_eq!(dur.mul_f64(3.14e5), Duration::new(847_800, 0));
/// ```
#[unstable(feature = "duration_float", issue = "54361")]
#[inline]
pub fn mul_f64(self, rhs: f64) -> Duration {
Duration::from_float_secs(rhs * self.as_float_secs())
}

/// Divide `Duration` by `f64`.
///
/// # Panics
/// This method will panic if result is not finite, negative or overflows `Duration`.
///
/// # Examples
/// ```
/// #![feature(duration_float)]
/// use std::time::Duration;
///
/// let dur = Duration::new(2, 700_000_000);
/// assert_eq!(dur.div_f64(3.14), Duration::new(0, 859_872_611));
/// // note that truncation is used, not rounding
/// assert_eq!(dur.div_f64(3.14e5), Duration::new(0, 8_598));
/// ```
#[unstable(feature = "duration_float", issue = "54361")]
#[inline]
pub fn div_f64(self, rhs: f64) -> Duration {
Duration::from_float_secs(self.as_float_secs() / rhs)
}

/// Divide `Duration` by `Duration` and return `f64`.
///
/// # Examples
/// ```
/// #![feature(duration_float)]
/// use std::time::Duration;
///
/// let dur1 = Duration::new(2, 700_000_000);
/// let dur2 = Duration::new(5, 400_000_000);
/// assert_eq!(dur1.div_duration(dur2), 0.5);
/// ```
#[unstable(feature = "duration_float", issue = "54361")]
#[inline]
pub fn div_duration(self, rhs: Duration) -> f64 {
self.as_float_secs() / rhs.as_float_secs()
}
}

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

#[stable(feature = "symmetric_u32_duration_mul", since = "1.31.0")]
impl Mul<Duration> for u32 {
type Output = Duration;

fn mul(self, rhs: Duration) -> Duration {
rhs * self
}
}

#[stable(feature = "time_augmented_assignment", since = "1.9.0")]
impl MulAssign<u32> for Duration {
fn mul_assign(&mut self, rhs: u32) {
Expand Down
18 changes: 10 additions & 8 deletions src/librustc/traits/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,18 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
orig_params,
trait_pred.to_poly_trait_predicate(),
));

match result {
Ok(Some(Vtable::VtableImpl(_))) => {
debug!(
"find_auto_trait_generics(did={:?}, trait_did={:?}, generics={:?}): \
manual impl found, bailing out",
did, trait_did, generics
);
return true;
true
}
_ => return false,
};
_ => false
}
});

// If an explicit impl exists, it always takes priority over an auto impl
Expand Down Expand Up @@ -426,6 +427,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
if new_trait.def_id() == old_trait.def_id() {
let new_substs = new_trait.skip_binder().trait_ref.substs;
let old_substs = old_trait.skip_binder().trait_ref.substs;

if !new_substs.types().eq(old_substs.types()) {
// We can't compare lifetimes if the types are different,
// so skip checking old_pred
Expand Down Expand Up @@ -489,12 +491,12 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {

pub fn get_lifetime(&self, region: Region, names_map: &FxHashMap<String, String>) -> String {
self.region_name(region)
.map(|name| {
names_map.get(&name).unwrap_or_else(|| {
.map(|name|
names_map.get(&name).unwrap_or_else(||
panic!("Missing lifetime with name {:?} for {:?}", name, region)
})
})
.unwrap_or(&"'static".to_string())
)
)
.unwrap_or(&"'static".to_owned())
.clone()
}

Expand Down
31 changes: 12 additions & 19 deletions src/librustc/traits/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn codegen_fulfill_obligation<'a, 'tcx>(ty: TyCtxt<'a, 'tcx, 'tcx>,
let trait_ref = ty.erase_regions(&trait_ref);

debug!("codegen_fulfill_obligation(trait_ref={:?}, def_id={:?})",
(param_env, trait_ref), trait_ref.def_id());
(param_env, trait_ref), trait_ref.def_id());

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

let obligation_cause = ObligationCause::dummy();
let obligation = Obligation::new(obligation_cause,
param_env,
trait_ref.to_poly_trait_predicate());
param_env,
trait_ref.to_poly_trait_predicate());

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

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

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

match self.tcx.lift_to_global(&result) {
Some(result) => result,
None => {
span_bug!(span, "Uninferred types/regions in `{:?}`", result);
}
}
self.tcx.lift_to_global(&result).unwrap_or_else(||
span_bug!(span, "Uninferred types/regions in `{:?}`", result)
)
}
}
21 changes: 8 additions & 13 deletions src/librustc/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ fn overlap<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
b_def_id: DefId)
-> Option<OverlapResult<'tcx>>
{
debug!("overlap(a_def_id={:?}, b_def_id={:?})",
a_def_id,
b_def_id);
debug!("overlap(a_def_id={:?}, b_def_id={:?})", a_def_id, b_def_id);

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

// Do `a` and `b` unify? If not, no overlap.
let obligations = match selcx.infcx().at(&ObligationCause::dummy(), param_env)
.eq_impl_headers(&a_impl_header, &b_impl_header) {
Ok(InferOk { obligations, value: () }) => {
obligations
}
.eq_impl_headers(&a_impl_header, &b_impl_header)
{
Ok(InferOk { obligations, value: () }) => obligations,
Err(_) => return None
};

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

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

ty::Dynamic(ref tt, ..) => {
tt.principal().map_or(false, |p| {
tt.principal().map_or(false, |p|
def_id_is_local(p.def_id(), in_crate)
})
)
}

ty::Error => {
true
}
ty::Error => true,

ty::Closure(..) |
ty::Generator(..) |
Expand Down
Loading

0 comments on commit 2fa1390

Please sign in to comment.