Commit Graph

91775 Commits

Author SHA1 Message Date
Mazdak Farrokhzad
b78cbe6ddd
Rollup merge of #59663 - matklad:borrow, r=dtolnay
Be more direct about borrow contract

I always was confused by the difference between Borrow and AsRef, despite the fact that I've read all available docs at least a dozen of times.

I finally grokked the difference between the two when I realized the Borrow invariant:

> If you implement Borrow, you **must** make sure that Eq, Ord and Hash implementations are equivalent for borrowed and owned data

My problem was that this invariant is not stated explicitly in documentation, and instead some  vague and philosophical notions are used.

So I suggest to mention the requirements of `Borrow` very explicitly: instead of "use Borrow when X and use AsRef when Y", let's phrase this as `Borrow` differs from `AsRef` in `W`, so that's why `Borrow` is for `X` and `AsRef` is for `Y`.

Note that this change could be seen as tightening contract of the Borrow. Let's say Alice has written the following code:

```rust
#[derive(PartialEq, Eq, Hash, PartialOrd, Ord)]
struct Person {
    first_name: String,
    last_name: String,
}

impl Borrow<str> for Person {
      fn borrow(&self) -> &str { self.first_name.as_str() }
}
```

Now Bob uses this `Person` struct, puts it into `HashMap` and tries to look it up using `&str` for the first name. Bob's code naturally fails.

The question is, who is to blame: Alice, who has written the impl, or Bob, who uses the HashMap. If I read the current docs literally, I would say that `Bob` is to blame: `Eq` and `Hash` bounds appear on HashMap, so it is the HashMap which requires that they are consistent. By using a type for which the `Borrow` impl does not yield well-behaved `Eq`, Bob is violating contract of HashMap.

If, as this PR proposes, we unconditionally require that Eq & friends for borrow should be valid, then the blame shifts to Alice, which I think is more reasonable.

closes https://github.com/rust-lang/rust/issues/44868
2019-04-04 01:49:08 +02:00
Mazdak Farrokhzad
dcccab56ba
Rollup merge of #59316 - flip1995:internal_lints_take_2, r=oli-obk
Internal lints take 2

cc #58701
cc #49509

TODO: Add `#![warn(internal)]` to crates (and fix violations)

Crates depending on `rustc_data_structures`

- [x] librustc_resolve
- [x] librustc_driver
- [x] librustc_passes
- [x] librustc_metadata
- [x] librustc_interface
- [x] librustc_save_analysis
- [x] librustc_lint
- [x] librustc
- [x] librustc_incremental
- [x] librustc_codegen_utils
- [x] libarena
- [x] librustc_target
- [x] librustc_allocator
- [x] librustc_privacy
- [x] librustc_traits
- [x] librustc_borrowck
- [x] libsyntax
- [x] librustc_codegen_ssa
- [x] libsyntax_ext
- [x] librustc_errors
- [x] librustc_mir
- [x] libsyntax_pos
- [x] librustc_typeck

Crates with `feature(rustc_private)`
Excluding crates, which are already in the list above. Also excluding tools and tests.

- [ ] ~~libstd~~
- [x] libfmt_macros
- [x] librustdoc

r? @oli-obk
2019-04-04 01:49:07 +02:00
flip1995
c81ce069b4
Compare Tys directly instead of their TyKinds 2019-04-03 19:18:07 +02:00
flip1995
076abfa0f3
Deny internal lints on two more crates
- libfmt_macros
- librustdoc
2019-04-03 19:18:07 +02:00
flip1995
51a792d01b
Add trait_object_dummy_self to CommonTypes 2019-04-03 19:18:07 +02:00
flip1995
dd7483c750
Remove TyKind arg from report_bin_hex_error function 2019-04-03 19:18:07 +02:00
flip1995
4d2a3bb13b
Deny internal lints on librustc_typeck 2019-04-03 19:18:07 +02:00
flip1995
e4b87f5edb
Deny internal lints on librustc_mir 2019-04-03 19:18:07 +02:00
flip1995
d2bc99135f
Deny internal lints on librustc_lint 2019-04-03 18:24:22 +02:00
flip1995
818d300451
Deny internal lints on librustc_interface 2019-04-03 18:24:21 +02:00
flip1995
d3f0cb9b62
Deny internal lints on non conflicting crates
- libarena
- librustc_allocator
- librustc_borrowck
- librustc_codegen_ssa
- librustc_codegen_utils
- librustc_driver
- librustc_errors
- librustc_incremental
- librustc_metadata
- librustc_passes
- librustc_privacy
- librustc_resolve
- librustc_save_analysis
- librustc_target
- librustc_traits
- libsyntax
- libsyntax_ext
- libsyntax_pos
2019-04-03 18:24:21 +02:00
flip1995
69f74df429
Deny internal lints in librustc 2019-04-03 18:24:21 +02:00
flip1995
dfcd1ef102
Add unstable-options flag to stage!=0 2019-04-03 18:22:19 +02:00
flip1995
2045dfed24
Update tests 2019-04-03 18:22:19 +02:00
flip1995
28a5c414c3
Check for unstable-options flag before register internals 2019-04-03 18:22:19 +02:00
flip1995
e536037af3
Deduplicate code in TyKind lint 2019-04-03 18:22:19 +02:00
flip1995
5a788f0ff7
Fix bug in TyKind lint 2019-04-03 18:22:19 +02:00
flip1995
9b2bf70851
Make internal lints allow-by-default 2019-04-03 18:22:19 +02:00
flip1995
16acf7d618
use check_path instead of check_expr 2019-04-03 18:22:19 +02:00
flip1995
157e7974af
Fix rebase fallout 2019-04-03 18:22:18 +02:00
flip1995
a2a8c44106
Add register_internals function to rustc_lint 2019-04-03 18:22:18 +02:00
flip1995
4c9fb9361a
Uplift match_def_path from Clippy 2019-04-03 18:22:18 +02:00
flip1995
5c0656789d
Add internal lints default_hash_types and usage_of_ty_tykind 2019-04-03 18:22:18 +02:00
flip1995
c796b1f46a
Add tests for internal lints 2019-04-03 18:22:18 +02:00
bors
f8673e0ad8 Auto merge of #59182 - hug-dev:armv8m-base-hf, r=alexcrichton
Add dist builder for Armv8-M Baseline and HF

This commit adds the Armv8-M Baseline and Armv8-M Mainline with
FPU targets in the list of targets that
get their dist components built. It also update the build-manifest
so that this target gets also its dist components uploaded.

Made possible with the recent change merged in `compiler-builtins`:
rust-lang-nursery/compiler-builtins#276

A new `compiler-builtins` might be necessary for successfull compilation of the artefacts of those targets.
2019-04-03 14:23:13 +00:00
Hugues de Valon
e83349975b Add dist builder for Armv8-M Baseline and HF
This commit adds the Armv8-M Baseline and Armv8-M Mainline with
FPU targets in the list of targets that
get their dist components built. It also update the build-manifest
so that this target gets also its dist components uploaded.
2019-04-03 15:02:13 +01:00
bors
0ba7d41b83 Auto merge of #58458 - nnethercote:tweak-Span-encoding, r=petrochenkov
Tweak `Span` encoding.

Failing to fit `base` is more common than failing to fit `len`.
2019-04-03 11:27:38 +00:00
Aleksey Kladov
1cfed0d452 be more direct about borrow requirenments 2019-04-03 11:41:24 +03:00
bors
546cb21f58 Auto merge of #59657 - Centril:rollup-w5p98mc, r=Centril
Rollup of 4 pull requests

Successful merges:

 - #55448 (Add 'partition_at_index/_by/_by_key' for slices.)
 - #59186 (improve worst-case performance of BTreeSet intersection v3)
 - #59514 (Remove adt_def from projections and downcasts in MIR)
 - #59630 (Shrink `mir::Statement`.)

Failed merges:

r? @ghost
2019-04-03 05:30:20 +00:00
Mazdak Farrokhzad
d31d80b7d4
Rollup merge of #59630 - nnethercote:shrink-mir-Statement, r=pnkfelix
Shrink `mir::Statement`.

The `InlineAsm` variant is extremely rare, and `mir::Statement` often
contributes significantly to peak memory usage.
2019-04-03 04:36:14 +02:00
Mazdak Farrokhzad
a96e3883c1
Rollup merge of #59514 - tmandry:remove-adt-def-from-projection-elem, r=eddyb
Remove adt_def from projections and downcasts in MIR

As part of optimizing generator layouts in MIR, we'd like to allow downcasting generators to variants which do not have a corresponding `def_id`, since they are created by the compiler.

This refactor hopes to allow that, without regressing perf.

r? @eddyb
2019-04-03 04:36:12 +02:00
Mazdak Farrokhzad
9898182b47
Rollup merge of #59186 - ssomers:btreeset_intersection_revisited_again, r=KodrAus
improve worst-case performance of BTreeSet intersection v3

Variation of [#59078](https://github.com/rust-lang/rust/pull/59078) with `Intersection` remaining a struct

r? @scottmcm
2019-04-03 04:36:11 +02:00
Mazdak Farrokhzad
2f37c5a358
Rollup merge of #55448 - Mokosha:SortAtIndex, r=bluss
Add 'partition_at_index/_by/_by_key' for slices.

This is an analog to C++'s std::nth_element (a.k.a. quickselect).

Corresponds to tracking bug #55300.
2019-04-03 04:36:09 +02:00
Nicholas Nethercote
ff94feabc2 Tweak Span encoding.
Failing to fit `base` is more common than failing to fit `len`.
2019-04-03 10:03:34 +11:00
Nicholas Nethercote
d00d639c54 Shrink mir::Statement.
The `InlineAsm` variant is extremely rare, and `mir::Statement` often
contributes significantly to peak memory usage.
2019-04-03 09:09:59 +11:00
bors
7641873f59 Auto merge of #59638 - alexcrichton:less-assertions, r=pietroalbini
ci: Disable llvm/debug assertions on x86_64-mingw

Tracked at #59637 for re-enabling this commit disables assertions to
hopefully bring the runtime for this builder under control.
2019-04-02 21:40:20 +00:00
Tyler Mandry
4122d2221e Remove adt_def from PlaceTy and make it a struct 2019-04-02 12:02:17 -07:00
Tyler Mandry
ac29ca75e0 Replace adt_def with name in mir::ProjectionElem::Downcast 2019-04-02 12:02:17 -07:00
Alex Crichton
1334314709 ci: Disable llvm/debug assertions on x86_64-mingw
Tracked at #59637 for re-enabling this commit disables assertions to
hopefully bring the runtime for this builder under control.
2019-04-02 11:13:44 -07:00
bors
428943cc29 Auto merge of #59636 - Centril:rollup, r=Centril
Rollup of 4 pull requests

Successful merges:

 - #59166 (resolve: collect trait aliases along with traits)
 - #59341 (Fix custom relative libdir)
 - #59446 (Fix stack overflow when generating debuginfo for 'recursive' type)
 - #59529 (Added documentation on the remainder (Rem) operator for floating points.)

Failed merges:

r? @ghost
2019-04-02 16:26:10 +00:00
Mazdak Farrokhzad
21e2e98b8c
Rollup merge of #59529 - DevQps:improve-rem-docs, r=cuviper
Added documentation on the remainder (Rem) operator for floating points.

# Description

As has been explained in #57738 the remainder operator on floating points is not clear.
This PR requests adds some information on how the `Rem` / remainder operator on floating points works.

Note also that this description is for both `Rem<f32> for f32` and `Rem<f64> for f64` implementations.

Ps. I wasn't really sure on how to formulate things. So please suggest changes if you have better idea's!

closes #57738
2019-04-02 18:25:17 +02:00
Mazdak Farrokhzad
57a4f17b6e
Rollup merge of #59446 - Aaron1011:fix/debuginfo-overflow, r=oli-obk
Fix stack overflow when generating debuginfo for 'recursive' type

By using 'impl trait', it's possible to create a self-referential
type as follows:

fn foo() -> impl Copy { foo }

This is a function which returns itself.
Normally, the signature of this function would be impossible
to write - it would look like 'fn foo() -> fn() -> fn() ...'
e.g. a function which returns a function, which returns a function...

Using 'impl trait' allows us to avoid writing this infinitely long
type. While it's useless for practical purposes, it does compile and run

However, issues arise when we try to generate llvm debuginfo for such a
type. All 'impl trait' types (e.g. ty::Opaque) are resolved when we
generate debuginfo, which can lead to us recursing back to the original
'fn' type when we try to process its return type.

To resolve this, I've modified debuginfo generation to account for these
kinds of weird types. Unfortunately, there's no 'correct' debuginfo that
we can generate - 'impl trait' does not exist in debuginfo, and this
kind of recursive type is impossible to directly represent.

To ensure that we emit *something*, this commit emits dummy
debuginfo/type names whenever it encounters a self-reference. In
practice, this should never happen - it's just to ensure that we can
emit some kind of debuginfo, even if it's not particularly meaningful

Fixes #58463
2019-04-02 18:25:15 +02:00
Mazdak Farrokhzad
6bd01efcea
Rollup merge of #59341 - o01eg:use-custom-libdir, r=Mark-Simulacrum
Fix custom relative libdir

While working on #58947 I found out relative libdir ignored during setting LD_LIBRARY_PATH.
2019-04-02 18:25:14 +02:00
Mazdak Farrokhzad
a2f3f0cdb3
Rollup merge of #59166 - seanmonstar:trait-alias-import, r=alexreg
resolve: collect trait aliases along with traits

It seems trait aliases weren't being collected as `TraitCandidates` in resolve, this should change that. (I can't compile the full compiler locally, so relying on CI...)

Fixes https://github.com/rust-lang/rust/issues/56485

r? @alexreg
2019-04-02 18:25:12 +02:00
bors
e008e4fde8 Auto merge of #59632 - Centril:rollup, r=Centril
Rollup of 8 pull requests

Successful merges:

 - #59262 (Remove duplicated code from Iterator::{ne, lt, le, gt, ge})
 - #59286 (Refactor async fn return type lowering)
 - #59444 (Implement useful steps_between for all integers)
 - #59452 (Speed up rustdoc run a bit)
 - #59533 (Support allocating iterators with arenas)
 - #59585 (Fixes for shallow borrows)
 - #59607 (Renames `EvalErrorKind` to `InterpError`)
 - #59613 (SGX target: convert a bunch of panics to aborts)

Failed merges:

 - #59630 (Shrink `mir::Statement`.)

r? @ghost
2019-04-02 13:06:12 +00:00
Mazdak Farrokhzad
d0d3466337
Rollup merge of #59613 - jethrogb:jb/waitqueue-wait-unwind, r=alexcrichton
SGX target: convert a bunch of panics to aborts

Fixes https://github.com/fortanix/rust-sgx/issues/86, https://github.com/fortanix/rust-sgx/issues/103 and in general protect preemptively against Iago attacks by aborting instead of unwinding in potentially unexpected situations.
2019-04-02 13:47:31 +02:00
Mazdak Farrokhzad
85a82ac334
Rollup merge of #59607 - kenta7777:renames-EvalErrorKind-to-InterpError, r=oli-obk
Renames `EvalErrorKind` to `InterpError`

This PR renames `EvalErrorKind` to `InterpError`.
This is related to #54395.
2019-04-02 13:47:30 +02:00
Mazdak Farrokhzad
69bc687f20
Rollup merge of #59585 - rust-lang:shallow-borrow-fixes, r=pnkfelix
Fixes for shallow borrows

* Don't promote these borrows if we're going to remove them before
  codegen
* Correctly mark unreachable code
2019-04-02 13:47:28 +02:00
Mazdak Farrokhzad
274f80e4d4
Rollup merge of #59533 - Zoxc:arena-slices, r=michaelwoerister
Support allocating iterators with arenas

Split out from https://github.com/rust-lang/rust/pull/57173.

r? @michaelwoerister
2019-04-02 13:47:27 +02:00
Mazdak Farrokhzad
e655b91b7a
Rollup merge of #59452 - GuillaumeGomez:speedup-rustdoc, r=QuietMisdreavus
Speed up rustdoc run a bit

r? @QuietMisdreavus
2019-04-02 13:47:25 +02:00