Commit graph

39419 commits

Author SHA1 Message Date
Eduard Burtescu
48fba76c7d Fix compile-fail error messages after integer suffix removal. 2015-03-04 15:48:33 +02:00
Eduard Burtescu
8e50853b54 Remove integer suffixes where the types in compiled code are identical. 2015-03-04 07:03:05 +02:00
bors
fed12499e7 Auto merge of #23002 - pnkfelix:fsk-box-place-runway, r=nikomatsakis
Runway for RFC 809 (overloaded box/placement-in) by adding type annotations or explicit calls to `Box::new` where I found it necessary on PR #22086.

I have broken this up into more than one PR because the entire commit chain (see PR #22086) is long, widespread and unwieldy to rebase frequently.

To my knowledge this is not a breaking change.  Also, there is in principle nothing stopping someone from reverting some/all of these annotations, since without the rest of the commit chain in #22086, the associated code would continue to compile.

All I can do is ask: Try to discourage others from removing seemingly "unnecessary" uses of the `Box` type or the `Box::new()` function, until the rest of RFC 809 lands.
2015-03-03 20:17:08 +00:00
Felix S. Klock II
cb1b0dd589 Fix doc example to accommodate overloaded-box. 2015-03-03 21:16:03 +01:00
Felix S. Klock II
0d5bcb14ad Switched to Box::new in many places.
Many of the modifications putting in `Box::new` calls also include a
pointer to Issue 22405, which tracks going back to `box <expr>` if
possible in the future.

(Still tried to use `Box<_>` where it sufficed; thus some tests still
have `box_syntax` enabled, as they use a mix of `box` and `Box::new`.)

Precursor for overloaded-`box` and placement-`in`; see Issue 22181.
2015-03-03 21:05:55 +01:00
Felix S. Klock II
b03279aaa2 inline Box::new always.
(You shouldn't use it, but it is a semi-reasonable way to annotate
types when necessary.)
2015-03-03 20:29:01 +01:00
Felix S. Klock II
270f0eef73 Add : Box<_> or ::Box<_> type annotations to various places.
This is the kind of change that one is expected to need to make to
accommodate overloaded-`box`.

----

Note that this is not *all* of the changes necessary to accommodate
Issue 22181.  It is merely the subset of those cases where there was
already a let-binding in place that made it easy to add the necesasry
type ascription.

(For unnamed intermediate `Box` values, one must go down a different
route; `Box::new` is the option that maximizes portability, but has
potential inefficiency depending on whether the call is inlined.)

----

There is one place worth note, `run-pass/coerce-match.rs`, where I
used an ugly form of `Box<_>` type ascription where I would have
preferred to use `Box::new` to accommodate overloaded-`box`.  I
deliberately did not use `Box::new` here, because that is already done
in coerce-match-calls.rs.

----

Precursor for overloaded-`box` and placement-`in`; see Issue 22181.
2015-03-03 20:29:01 +01:00
bors
129173f198 Auto merge of #22997 - pnkfelix:make-timestamps-robust-to-concurrent-edits, r=nikomatsakis
Make build timestamp files robust in face of concurrent source modification.

Strategy: If the end goal is to touch e.g. `stamp.std`, then we first touch `stamp.std.start_time` before doing anything else.  Then when the receipe finishes, we touch `stamp.std` using the timestamp from `stamp.std.start_time` as the reference time, and remove `stamp.std.start_time`.

Fix #6518.
2015-03-03 17:07:57 +00:00
bors
14f0942a49 Auto merge of #22532 - pnkfelix:arith-overflow, r=pnkfelix,eddyb
Rebase and follow-through on work done by @cmr and @aatch.

Implements most of rust-lang/rfcs#560. Errors encountered from the checks during building were fixed.

The checks for division, remainder and bit-shifting have not been implemented yet.

See also PR #20795

cc @Aatch ; cc @nikomatsakis
2015-03-03 14:18:03 +00:00
Felix S. Klock II
62aa899e3d Make build timestamp files robust in face of concurrent source modification.
Strategy: If the end goal is to touch e.g. `stamp.std`, then we first
touch `stamp.std.start_time` before doing anything else.  Then when
the receipe finishes, we touch `stamp.std` using the timestamp from
`stamp.std.start_time` as the reference time, and remove
`stamp.std.start_time`.

Fix #6518.
2015-03-03 15:11:01 +01:00
Felix S. Klock II
243c5164ea sidestep potential over- and underflow in estimated stack bounds.
See buildlog here for evidence of such occurring:
  http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/3910/steps/test/logs/stdio
2015-03-03 13:12:38 +01:00
bors
38e97b99a6 Auto merge of #22995 - Manishearth:rollup, r=Manishearth 2015-03-03 11:32:11 +00:00
Manish Goregaokar
4f1f5eb1ab Rollup merge of #22988 - dcrewi:slice-swap-inline, r=alexcrichton 2015-03-03 17:02:24 +05:30
Manish Goregaokar
415c42ecc4 Rollup merge of #22982 - tbu-:pr_fixup_22510, r=Manishearth
r? @Manishearth
2015-03-03 17:02:24 +05:30
Manish Goregaokar
2e15a7d92e Rollup merge of #22977 - kmcallister:issue-15778, r=sfackler
Fixes #15778.

r? @sfackler
2015-03-03 17:02:24 +05:30
Tobias Bucher
d18897cadf Revert incorrect usize -> u32 replacements from #22510
Conflicts:
	src/libstd/thread.rs
2015-03-03 17:02:24 +05:30
Manish Goregaokar
394a9c57ad Rollup merge of #22974 - nagisa:reintuint-std, r=alexcrichton
Reverts a small part of c74d49c804 because compilation pukes with warnings now.
2015-03-03 17:02:23 +05:30
Manish Goregaokar
e7cc9774b9 Rollup merge of #22970 - pnkfelix:fsk-robust-backtrace-test-against-env, r=alexcrichton
Make `test/run-pass/backtrace.rs` more robust about own host environment

Namely, I have been annoyed in the past when I have done `RUST_BACKTRACE=1 make check` only to discover (again) that such a trick causes this test to fail, because it assumes that the `RUST_BACKTRACE` environment variable is not set.

Fix #22870
2015-03-03 17:02:23 +05:30
Manish Goregaokar
d7a44beb55 Rollup merge of #22956 - ejjeong:aarch64-linux-android, r=alexcrichton
aarch64-linux-android build has been broken since #22839.
Aarch64 android has _Unwind_GetIPInfo, so re-define this only for arm32 android.
r? @alexcrichton
2015-03-03 17:02:23 +05:30
Manish Goregaokar
d8a91b95d1 Rollup merge of #22952 - huonw:missing-stable, r=alexcrichton
Unstable is the conservative choice.

cc #22950.
2015-03-03 17:02:22 +05:30
Manish Goregaokar
e9ca8acb0f Rollup merge of #22951 - huonw:weak-chuck-slice, r=alexcrichton
`#[derive(Clone)]` unnecessarily requires the element type to also be
`Clone`.
2015-03-03 17:02:22 +05:30
Manish Goregaokar
393ce1820e Rollup merge of #22876 - Florob:const, r=nikomatsakis
This changes the type of some public constants/statics in libunicode.
Notably some `&'static &'static [(char, char)]` have changed
to `&'static [(char, char)]`. The regexp crate seems to be the
sole user of these, yet this is technically a [breaking-change]
2015-03-03 17:02:20 +05:30
Manish Goregaokar
d0fcb1f53c Rollup merge of #22990 - japaric:privATe, r=alexcrichton
Associated types are now treated as part of the public API by the privacy checker.

If you were exposing a private type in your public API via an associated type, make that type public:

``` diff
  pub struct PublicType { .. }

- struct Struct { .. }
+ pub struct Struct { .. }

  pub trait PublicTrait {
      type Output;

      fn foo(&self) -> Self::Output;
  }

  impl PublicTrait for PublicType {
      type Output = Struct;

      fn foo(&self) -> Struct {  // `Struct` is part of the public API, it must be marked as `pub`lic
          ..
      }
  }
```

[breaking-change]

---

r? @nikomatsakis
closes #22912
2015-03-03 17:01:16 +05:30
Manish Goregaokar
ea208a87a5 Rollup merge of #22989 - laijs:fix_FromStr_bool_comment, r=alexcrichton
Fix the return type in the comments.

An old commit 082bfde412 (\"Fallout of std::str stabilization\") removed
the example of FromStr::from_str(), this commit adds it back. But
the example of StrExt::parse() is still kept with an additinal note.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2015-03-03 17:01:16 +05:30
Manish Goregaokar
873d312d62 Rollup merge of #22969 - dotdash:no_alloca_zeroed, r=huonw
Its only user was lvalue_scratch_datum which is called with zero=true
anymore, so it's effectively unused.
2015-03-03 17:01:16 +05:30
Manish Goregaokar
90686df18c Rollup merge of #22960 - huonw:static-assert, r=huonw
The API this exposes is a little strange (being attached to `static`s),
so it makes sense to conservatively feature gate it. If it is highly
popular, it is possible to reverse this gating.
2015-03-03 17:01:15 +05:30
Manish Goregaokar
3b30b74692 Rollup merge of #22943 - ipetkov:lint-recursion, r=alexcrichton
* The lint visitor's visit_ty method did not recurse, and had a
  reference to the now closed #10894
* The newly enabled recursion has only affected the `deprectated` lint
  which now detects uses of deprecated items in trait impls and
  function return types
* Renamed some references to `CowString` and `CowVec` to `Cow<str>` and
  `Cow<[T]>`, respectively, which appear outside of the crate which
  defines them
* Replaced a few instances of `InvariantType<T>` with
  `PhantomData<Cell<T>>`
* Disabled the `deprecated` lint in several places that
  reference/implement traits on deprecated items which will get cleaned
  up in the future
* Unfortunately, this means that if a library declares
  `#![deny(deprecated)]` and marks anything as deprecated, it will have
  to disable the lint for any uses of said item, e.g. any impl the now
  deprecated item

For any library that denies deprecated items but has deprecated items
of its own, this is a [breaking-change]

I had originally intended for the lint to ignore uses of deprecated items that are declared in the same crate, but this goes against some previous test cases that expect the lint to capture *all* uses of deprecated items, so I maintained the previous approach to avoid changing the expected behavior of the lint.

Tested locally on OS X, so hopefully there aren't any deprecated item uses behind a `cfg` that I may have missed.
2015-03-03 17:01:15 +05:30
Manish Goregaokar
63a91c21d3 Rollup merge of #22916 - rprichard:fmt-num-cleanup, r=alexcrichton
* Make num::UpperHex private.  I was unable to determine why this struct
   is public.  The num module itself is not public, and the UpperHex struct
   is not referenced anywhere in the core::fmt module.  (Only the UpperHex
   trait is reference.)  num::LowerHex is not public.

 * Remove the suffix parameters from the macros that generate integral
   display traits.

   The code to print the Debug::fmt suffixes was removed when Show was
   renamed to Debug.  It was an intentional change.  From RFC 0565:

    * Focus on the *runtime* aspects of a type; repeating information such
      as suffixes for integer literals is not generally useful since that
      data is readily available from the type definition.

 * Because Show was renamed to Debug, rename show! to debug!.
2015-03-03 17:01:15 +05:30
Manish Goregaokar
185c074798 Fix backtrace tests for Linux 2015-03-03 12:10:58 +01:00
Felix S. Klock II
4e23179c85 Incorporated second review suggestion from eddyb. 2015-03-03 12:10:58 +01:00
Felix S. Klock II
11057fee08 Incorporated first review sugestion from eddyb.
Suggestion was here:

  https://github.com/rust-lang/rust/pull/22532#discussion_r25505609
2015-03-03 12:10:58 +01:00
Felix S. Klock II
b85b3c9b2b Fix span typo in the arithmetic overflow for array length reporting.
Added pair of regression tests that I should have made when I thought
of doing this in the first place.
2015-03-03 12:10:58 +01:00
Felix S. Klock II
8491c82c90 Update tests for const-eval error handling changes. 2015-03-03 12:10:58 +01:00
Felix S. Klock II
46de12ad00 Switch to eval_const_expr_partial in trans::consts.
However, I left the ICEs rather than switching to nicer error
reporting there; these cases *should* be detected prior to hitting
trans, and thus ICE'ing here is appropriate.

(So why switch to `eval_const_expr_partial`? Because I want to try to
eliminate all uses of `eval_const_expr` entirely.)
2015-03-03 12:10:58 +01:00
Felix S. Klock II
5d950bd37d Switch to eval_const_expr_partial when check_match.rs checks for NaN. 2015-03-03 12:10:58 +01:00
Felix S. Klock II
e919f82da1 Address arith-overflow and error-handling in const_eval.rs.
1. Detect and report arithmetic overflow during const-expr eval.

 2. Instead `eval_const_expr_partial` returning `Err(String)`, it now
    has a dedicated enum of different cases. The main benefit of this
    is the ability to pass along an interpretable payload, namely the
    two inputs that caused an overlfow.

I attempted to minimize fallout to error output in tests, but some was
unavoidable. Those changes are in a follow-on commit.
2015-03-03 12:10:57 +01:00
Felix S. Klock II
f9bbef7f44 Avoid fatal errors in astconv; just err and return ty_err instead.
This allows computation to proceed and find further errors.

(However, this is also annoying at times when the subsequent errors
are just reporting that a ty_err occurred. I have thoughts on ways to
fix this that I will experiment with separately.)
2015-03-03 12:10:57 +01:00
Felix S. Klock II
f1ea2b3094 Catch arith-overflow explicitly during rustc::middle::const_eval.
This only replaces the conditional arith-overflow asserts with
unconditional errors from the guts of const-eval; it does *not*
attempt to sanely handle such errors e.g. with a nice error message
from `rustc`.  So the same test that led me to add this commit are
still failing, and must be addressed.
2015-03-03 12:10:57 +01:00
Felix S. Klock II
faf3bcd72c Accommodate simple cases of arith-overflow in rustc related crates. 2015-03-03 12:10:57 +01:00
Felix S. Klock II
f0404c39f2 core::iter: fix bug uncovered by arith-overflow.
(The bug was in `impl RandomAccessIterator for Rev`; it may or may not
have been innocuous, depending on what guarantees one has about the
behavior of `idx` for the underlying iterator.)
2015-03-03 12:10:57 +01:00
Felix S. Klock II
6189e99c86 Accommodate arith-overflow in rand and std::rand.
Regarding the `rand` changes: It is unfortunate that Wrapping(T) does
not support the `+=` operator.  We may want to try to fix that before
1.0 to make porting code like this palatable.

Regarding `std::rand`, just arith-overflow in first example from
`std::rand::random()` doc.
2015-03-03 12:10:57 +01:00
Felix S. Klock II
7c8edabac8 Accommodate arith-overflow in serialize::json numeric parsing. 2015-03-03 12:10:57 +01:00
Felix S. Klock II
c8db89aa82 Accommodate arith-overflow in core::num, std::num, coretest::num.
* `core::num`: adjust `UnsignedInt::is_power_of_two`,
   `UnsignedInt::next_power_of_two`, `Int::pow`.

   In particular for `Int::pow`: (1.) do not panic when `base`
   overflows if `acc` never observes the overflowed `base`, and (2.)
   if `acc` does observe the overflowed `base`, make sure we only
   panic if we would have otherwise (e.g. during a computation of
   `base * base`).

 * also in `core::num`: avoid underflow during computation of `uint::MAX`.

 * `std::num`: adjust tests `uint::test_uint_from_str_overflow`,
   `uint::test_uint_to_str_overflow`, `strconv`

 * `coretest::num`: adjust `test::test_int_from_str_overflow`.
2015-03-03 12:10:57 +01:00
Felix S. Klock II
4394720dae Fix the overflowing tests in run-fail.
* The error patterns had a typo.

* Our current constant evaluation would silently allow the overflow
  (filed as Issue 22531).

* The overflowing-mul test was accidentally doing addition instead of
  multiplication.
2015-03-03 12:10:20 +01:00
Felix S. Klock II
e7c986105f Fixes to collections to accommodate arith-overflow changes.
* `collections::btree::node`: accommodate (transient) underflow.

* `collections::btree::map`: avoid underflow during `fn next`
  for `BTreeMap::range` methods.

* `collections::slice`: note that pnkfelix deliberately used
  `new_pos_wrapping` only once; the other cases of arithmetic do not
  over- nor underflow, which is a useful property to leave implicitly
  checked/documented via the remaining calls to `fn new_pos(..)`.

* `collections::vec_deque` applied wrapping ops (somewhat blindly)
  to two implementation methods, and many tests.

* `std::collections:#️⃣:table` : Use `OverflowingOps` trait to
  track overflow during `calculate_offsets` and `calculate_allocation`
  functions.
2015-03-03 12:10:20 +01:00
Niko Matsakis
cf18e9c331 fix test generic-extern-mangle.rs 2015-03-03 12:10:19 +01:00
Felix S. Klock II
eadc8a7b45 fix Iter::rposition for new arith-overflow checking. 2015-03-03 12:10:19 +01:00
Felix S. Klock II
6d6038a194 Added OverflowingOps trait to core::num::wrapping.
These return the result of the operation *plus* an overflow/underflow bit.

This can make it easier to write operations where you want to chain
some arithmetic together, but also want to return a flag signalling if
overflow every occurred.
2015-03-03 12:10:19 +01:00
James Miller
280dea743b Implement parse_opt_bool better
During my clean-up of rebase errors, I took the opportunity to implement
parse_opt_bool so that it isn't identical to parse_bool wrapped in
`Some`.

parse_opt_bool considers no value to be true, a value of 'y', 'yes' or
'on' to be true and 'n', 'no' or 'off' to be false. All other values are
an error.
2015-03-03 12:10:19 +01:00
James Miller
1246d4067f Add core::num::wrapping and fix overflow errors.
Many of the core rust libraries have places that rely on integer
wrapping behaviour. These places have been altered to use the wrapping_*
methods:

 * core:#️⃣:sip - A number of macros
 * core::str - The `maximal_suffix` method in `TwoWaySearcher`
 * rustc::util::nodemap - Implementation of FnvHash
 * rustc_back::sha2 - A number of macros and other places
 * rand::isaac - Isaac64Rng, changed to use the Wrapping helper type

Some places had "benign" underflow. This is when underflow or overflow
occurs, but the unspecified value is not used due to other conditions.

 * collections::bit::Bitv - underflow when `self.nbits` is zero.
 * collections:#️⃣:{map,table} - Underflow when searching an empty
   table. Did cause undefined behaviour in this case due to an
   out-of-bounds ptr::offset based on the underflowed index. However the
   resulting pointers would never be read from.
 * syntax::ext::deriving::encodable - Underflow when calculating the
   index of the last field in a variant with no fields.

These cases were altered to avoid the underflow, often by moving the
underflowing operation to a place where underflow could not happen.

There was one case that relied on the fact that unsigned arithmetic and
two's complement arithmetic are identical with wrapping semantics. This
was changed to use the wrapping_* methods.

Finally, the calculation of variant discriminants could overflow if the
preceeding discriminant was `U64_MAX`. The logic in `rustc::middle::ty`
for this was altered to avoid the overflow completely, while the
remaining places were changed to use wrapping methods. This is because
`rustc::middle::ty::enum_variants` now throws an error when the
calculated discriminant value overflows a `u64`.

This behaviour can be triggered by the following code:

```
enum Foo {
  A = U64_MAX,
  B
}
```

This commit also implements the remaining integer operators for
Wrapped<T>.
2015-03-03 12:10:19 +01:00