Commit graph

121105 commits

Author SHA1 Message Date
Bastian Kauschke 49b1b4c438 more LocalDefIds 2020-05-30 12:22:29 +02:00
Ralf Jung 9c627c33dd also expose and use encode_utf16_raw for wtf8 2020-05-30 12:11:21 +02:00
Ralf Jung 3182cdf9ba wtf8: use encode_utf8_raw 2020-05-30 11:53:50 +02:00
Ralf Jung 72d85db6ee expose char::encode_utf8_raw for libstd 2020-05-30 11:49:31 +02:00
Ralf Jung 8ef9392828 multiple Return terminators are possible 2020-05-30 11:22:56 +02:00
bors 91fb72a8a9 Auto merge of #72768 - JohnTitor:rollup-6kwokh6, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #72033 (Update RELEASES.md for 1.44.0)
 - #72162 (Add Extend::{extend_one,extend_reserve})
 - #72419 (Miri read_discriminant: return a scalar instead of raw underlying bytes)
 - #72621 (Don't bail out of trait selection when predicate references an error)
 - #72677 (Fix diagnostics for `@ ..` binding pattern in tuples and tuple structs)
 - #72710 (Add test to make sure -Wunused-crate-dependencies works with tests)
 - #72724 (Revert recursive `TokenKind::Interpolated` expansion for now)
 - #72741 (Remove unused mut from long-linker-command-lines test)
 - #72750 (Remove remaining calls to `as_local_node_id`)
 - #72752 (remove mk_bool)

Failed merges:

r? @ghost
2020-05-30 07:56:05 +00:00
Ralf Jung f8d3805733 miri validation: clarify valid values of 'char' 2020-05-30 09:33:05 +02:00
Yuki Okushi 025058f2aa
Rollup merge of #72752 - lcnr:remove-mk_bool, r=estebank
remove mk_bool
2020-05-30 12:39:24 +09:00
Yuki Okushi c20a97dd53
Rollup merge of #72750 - marmeladema:remove-as-local-node-id, r=petrochenkov
Remove remaining calls to `as_local_node_id`

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

cc https://github.com/rust-lang/rust/issues/50928
2020-05-30 12:39:23 +09:00
Yuki Okushi 990195faf8
Rollup merge of #72741 - tmiasko:unused-mut, r=Mark-Simulacrum
Remove unused mut from long-linker-command-lines test
2020-05-30 12:39:21 +09:00
Yuki Okushi 047b3bd4df
Rollup merge of #72724 - Aaron1011:revert-tokenstream-expand, r=petrochenkov
Revert recursive `TokenKind::Interpolated` expansion for now

The crater run https://github.com/rust-lang/rust/issues/72622 revealed many root regressions, at least one of which is going to take some time to fix.

For now, let's revert https://github.com/rust-lang/rust/pull/72388 to allow the 709 affected crates to continue building on the latest nightly.
2020-05-30 12:39:19 +09:00
Yuki Okushi 875c6b281d
Rollup merge of #72710 - jsgf:unused-deps-test, r=jsgf
Add test to make sure -Wunused-crate-dependencies works with tests

Make sure code in `#[test]` blocks counts as a use of a crate.
2020-05-30 12:39:18 +09:00
Yuki Okushi ca8640e128
Rollup merge of #72677 - chrissimpkins:fix-72574, r=estebank
Fix diagnostics for `@ ..` binding pattern in tuples and tuple structs

Fixes #72574
Associated https://github.com/rust-lang/rust/pull/72534 https://github.com/rust-lang/rust/issues/72373

Includes a new suggestion with `Applicability::MaybeIncorrect` confidence level.

### Before

#### tuple

```
error: `..` patterns are not allowed here
 --> src/main.rs:4:19
  |
4 |         (_a, _x @ ..) => {}
  |                   ^^
  |
  = note: only allowed in tuple, tuple struct, and slice patterns

error[E0308]: mismatched types
 --> src/main.rs:4:9
  |
3 |     match x {
  |           - this expression has type `({integer}, {integer}, {integer})`
4 |         (_a, _x @ ..) => {}
  |         ^^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 2 elements
  |
  = note: expected tuple `({integer}, {integer}, {integer})`
             found tuple `(_, _)`

error: aborting due to 2 previous errors
```

#### tuple struct

```
error: `..` patterns are not allowed here
 --> src/main.rs:6:25
  |
6 |         Binder(_a, _x @ ..) => {}
  |                         ^^
  |
  = note: only allowed in tuple, tuple struct, and slice patterns

error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 3 fields
 --> src/main.rs:6:9
  |
1 | struct Binder(i32, i32, i32);
  | ----------------------------- tuple struct defined here
...
6 |         Binder(_a, _x @ ..) => {}
  |         ^^^^^^^^^^^^^^^^^^^ expected 3 fields, found 2

error: aborting due to 2 previous errors
```

### After

*Note: final output edited during source review discussion, see thread for details*

#### tuple

```
error: `_x @` is not allowed in a tuple
 --> src/main.rs:4:14
  |
4 |         (_a, _x @ ..) => {}
  |              ^^^^^^^ is only allowed in a slice
  |
help: replace with `..` or use a different valid pattern
  |
4 |         (_a, ..) => {}
  |              ^^

error[E0308]: mismatched types
 --> src/main.rs:4:9
  |
3 |     match x {
  |           - this expression has type `({integer}, {integer}, {integer})`
4 |         (_a, _x @ ..) => {}
  |         ^^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 1 element
  |
  = note: expected tuple `({integer}, {integer}, {integer})`
             found tuple `(_,)`

error: aborting due to 2 previous errors
```

#### tuple struct

```
error: `_x @` is not allowed in a tuple struct
 --> src/main.rs:6:20
  |
6 |         Binder(_a, _x @ ..) => {}
  |                    ^^^^^^^ is only allowed in a slice
  |
help: replace with `..` or use a different valid pattern
  |
6 |         Binder(_a, ..) => {}
  |                    ^^

error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 3 fields
 --> src/main.rs:6:9
  |
1 | struct Binder(i32, i32, i32);
  | ----------------------------- tuple struct defined here
...
6 |         Binder(_a, _x @ ..) => {}
  |         ^^^^^^^^^^^^^^^^^^^ expected 3 fields, found 1

error: aborting due to 2 previous errors
```

r? @estebank
2020-05-30 12:39:16 +09:00
Yuki Okushi 7624ac7dc4
Rollup merge of #72621 - Aaron1011:fix/trait-select-error, r=nikomatsakis
Don't bail out of trait selection when predicate references an error

Fixes #72590

With PR #70551, observing a `ty::Error` guarantees that compilation is
going to fail. Therefore, there are no soundness impliciations to
continuing on when we encounter a `ty::Error` - we can only affect
whether or not additional error messags are emitted.

By not bailing out, we avoid incorrectly determining that types are
`!Sized` when a type error is present, which allows us to avoid emitting
additional spurious error messages.

The original comment mentioned this code being shared by coherence -
howver, this change resulted in no diagnostic changes in any of the
existing tests.
2020-05-30 12:39:14 +09:00
Yuki Okushi a5fb7fcab3
Rollup merge of #72419 - RalfJung:read-discriminant, r=oli-obk,eddyb
Miri read_discriminant: return a scalar instead of raw underlying bytes

r? @oli-obk @eddyb
2020-05-30 12:39:12 +09:00
Yuki Okushi 3459eae96c
Rollup merge of #72162 - cuviper:extend_one, r=Mark-Simulacrum
Add Extend::{extend_one,extend_reserve}

This adds new optional methods on `Extend`: `extend_one` add a single
element to the collection, and `extend_reserve` pre-allocates space for
the predicted number of incoming elements. These are used in `Iterator`
for `partition` and `unzip` as they shuffle elements one-at-a-time into
their respective collections.
2020-05-30 12:39:10 +09:00
Yuki Okushi a578ac52ba
Rollup merge of #72033 - XAMPPRocky:relnotes-1.44.0, r=Mark-Simulacrum
Update RELEASES.md for 1.44.0

### [Rendered](https://github.com/XAMPPRocky/rust/blob/relnotes-1.44.0/RELEASES.md)

r? @Mark-Simulacrum
cc @rust-lang/release
2020-05-30 12:39:09 +09:00
Josh Stone a51b22a9fd Add extend_one tracking issue 72631 2020-05-29 17:05:17 -07:00
Josh Stone 10efaa37de Remove an old comment from HashMap::extend_reserve 2020-05-29 17:05:17 -07:00
Josh Stone e4345547b9 Use a canonical name for extend_reserve(additional)
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2020-05-29 17:05:17 -07:00
Josh Stone 6700e18688 Add Extend::{extend_one,extend_reserve}
This adds new optional methods on `Extend`: `extend_one` add a single
element to the collection, and `extend_reserve` pre-allocates space for
the predicted number of incoming elements. These are used in `Iterator`
for `partition` and `unzip` as they shuffle elements one-at-a-time into
their respective collections.
2020-05-29 17:05:17 -07:00
bors 0e9e408310 Auto merge of #72756 - RalfJung:rollup-tbjmtx2, r=RalfJung
Rollup of 9 pull requests

Successful merges:

 - #67460 (Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes)
 - #71095 (impl From<[T; N]> for Box<[T]>)
 - #71500 (Make pointer offset methods/intrinsics const)
 - #71804 (linker: Support `-static-pie` and `-static -shared`)
 - #71862 (Implement RFC 2585: unsafe blocks in unsafe fn)
 - #72103 (borrowck `DefId` -> `LocalDefId`)
 - #72407 (Various minor improvements to Ipv6Addr::Display)
 - #72413 (impl Step for char (make Range*<char> iterable))
 - #72439 (NVPTX support for new asm!)

Failed merges:

r? @ghost
2020-05-29 23:43:20 +00:00
Ralf Jung c4b6224ea4 more type sanity checks in Miri 2020-05-30 00:02:30 +02:00
Alex Crichton 16469a123e Update compiler-builtins
Pulls in a fix for #72758, more details on the linked issue.

[Crate changes included here][changes]

[changes]: https://github.com/rust-lang/compiler-builtins/compare/0.1.28...0.1.31
2020-05-29 13:44:40 -07:00
Chris Simpkins 27ed143ba9
fix diagnostics for @ .. binding pattern in tuples and tuple structs
fix comment


add newline for tidy fmt error...


edit suggestion message


change the suggestion message to better handle cases with binding modes


Apply suggestions from estebank code review

Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
edits to address source review


Apply suggestions from estebank code review #2

Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
update test files
2020-05-29 16:03:46 -04:00
Ralf Jung 37894559ab
Rollup merge of #72439 - westernmagic:master, r=Amanieu
NVPTX support for new asm!

This PR implements the new `asm!` syntax for the `nvptx64-nvidia-cuda` target.

r? @Amanieu
2020-05-29 21:58:34 +02:00
Ralf Jung b965196ce0
Rollup merge of #72413 - CAD97:char-range, r=dtolnay
impl Step for char (make Range*<char> iterable)

[[irlo thread]](https://internals.rust-lang.org/t/mini-rfc-make-range-char-work/12392?u=cad97) [[godbolt asm example]](https://rust.godbolt.org/z/fdveKo)

Add an implementation of the `Step` trait for `char`, which has the effect of making `RangeInclusive<char>` (and the other range types) iterable.

I've used the surrogate range magic numbers as magic numbers here rather than e.g. a `const SURROGATE_RANGE = 0xD800..0xE000` because these numbers appear to be used as magic numbers elsewhere and there doesn't exist constants for them yet. These files definitely aren't where surrogate range constants should live.

`ExactSizeIterator` is not implemented because `0x10FFFF` is bigger than fits in a `usize == u16`. However, given we already provide some `ExactSizeIterator` that are not correct on 16 bit targets, we might still want to consider providing it for `Range`[`Inclusive`]`<char>`, as it is definitely _very_ convenient. (At the very least, we want to make sure `.count()` doesn't bother iterating the range.)

The second commit in this PR changes a call to `Step::forward` to use `Step::forward_unchecked` in `RangeInclusive::next`. This is because without this patch, iteration over all codepoints (`'\0'..=char::MAX`) does not successfully optimize out the panicking branch. This was mentioned in the PR that updated `Step` to its current design, but was deemed not yet necessary as it did not impact codegen for integral types.

More of `Range*`'s implementations' calls to `Step` methods will probably want to see if they can use the `_unchecked` version as (if) we open up `Step` to being implemented on more types.

---

cc @rust-lang/libs, this is insta-stable and a fairly significant addition to `Range*`'s capabilities; this is the first instance of a noncontinuous domain being iterable with `Range` (or, well, anything other than primitive integers). I don't think this needs a full RFC, but it should definitely get some decent eyes on it.
2020-05-29 21:58:32 +02:00
Ralf Jung de561a9d3d
Rollup merge of #72407 - Lucretiel:ipv6-display, r=Mark-Simulacrum
Various minor improvements to Ipv6Addr::Display

Cleaned up `Ipv6Addr::Display`, especially with an eye towards simplifying and reducing duplicated logic. Also added a fast-path optimization, similar to #72399 and #72398.

- Defer to `Ipv4Addr::fmt` when printing an Ipv4 address
- Fast path: write directly to `f` without an intermediary buffer when there are no alignment options
- Simplify finding the inner zeroes-span
2020-05-29 21:58:29 +02:00
Ralf Jung e229d6e73b
Rollup merge of #72103 - lcnr:borrowck-localdefid, r=jonas-schievink
borrowck `DefId` -> `LocalDefId`

Replaces some `DefId`s which must always be local with `LocalDefId` in `librustc_mir/borrowck`.

cc @marmeladema
2020-05-29 21:58:27 +02:00
Ralf Jung c442e43b3a
Rollup merge of #71862 - LeSeulArtichaut:unsafe-block-in-unsafe-fn, r=nikomatsakis
Implement RFC 2585: unsafe blocks in unsafe fn

Tracking issue: #71668
r? @RalfJung cc @nikomatsakis
2020-05-29 21:58:25 +02:00
Ralf Jung 7aef3a0f6f
Rollup merge of #71804 - petrochenkov:static-pie, r=cuviper
linker: Support `-static-pie` and `-static -shared`

This PR adds support for passing linker arguments for creating statically linked position-independent executables and "statically linked" shared libraries.

Therefore it incorporates the majority of https://github.com/rust-lang/rust/pull/70740 except for the linker rerun hack and actually flipping the "`static-pie` is supported" switch for musl targets.
2020-05-29 21:58:24 +02:00
Ralf Jung 1cfe0e9c63
Rollup merge of #71500 - josephlr:offset, r=oli-obk,RalfJung
Make pointer offset methods/intrinsics const

Implements #71499 using [the implementations from miri](52f5d202bd/src/shims/intrinsics.rs (L96-L112)).

I added some tests what's allowed and what's UB. Let me know if any other cases should be added.

CC: @RalfJung @oli-obk
2020-05-29 21:58:22 +02:00
Ralf Jung b387a11636
Rollup merge of #71095 - pickfire:box-from-array, r=dtolnay
impl From<[T; N]> for Box<[T]>

Based on https://github.com/rust-lang/rust/pull/68692
2020-05-29 21:58:19 +02:00
Ralf Jung 81207802a0
Rollup merge of #67460 - estebank:named-lts, r=nikomatsakis
Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes

Fix #66406, fix #72106.

```
error: `impl` item signature doesn't match `trait` item signature
  --> $DIR/trait-param-without-lifetime-constraint.rs:14:5
   |
LL |     fn get_relation(&self) -> To;
   |     ----------------------------- expected `fn(&Article) -> &ProofReader`
...
LL |     fn get_relation(&self) -> &ProofReader {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&Article) -> &ProofReader`
   |
   = note: expected `fn(&Article) -> &ProofReader`
              found `fn(&Article) -> &ProofReader`
help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
  --> $DIR/trait-param-without-lifetime-constraint.rs:10:31
   |
LL |     fn get_relation(&self) -> To;
   |                               ^^ consider borrowing this type parameter in the trait
```

r? @nikomatsakis
2020-05-29 21:58:14 +02:00
Vadim Petrochenkov 21755b58c9 rustc_lexer: Optimize shebang detection slightly 2020-05-29 22:55:58 +03:00
bors 4bd32c9804 Auto merge of #72747 - Dylan-DPC:rollup-vvydkgl, r=Dylan-DPC
Rollup of 9 pull requests

Successful merges:

 - #72310 (Add Peekable::next_if)
 - #72383 (Suggest using std::mem::drop function instead of explicit destructor call)
 - #72398 (SocketAddr and friends now correctly pad its content)
 - #72465 (Warn about unused captured variables)
 - #72568 (Implement total_cmp for f32, f64)
 - #72572 (Add some regression tests)
 - #72591 (librustc_middle: Rename upvar_list to closure_captures)
 - #72701 (Fix grammar in liballoc raw_vec)
 - #72731 (Add missing empty line in E0619 explanation)

Failed merges:

r? @ghost
2020-05-29 19:50:22 +00:00
marmeladema 2f3dd7b187 Remove remaining calls to as_local_node_id 2020-05-29 20:05:44 +01:00
Bastian Kauschke 25bafc24db remove mk_bool 2020-05-29 20:41:26 +02:00
Dylan DPC 180a92cad7
Rollup merge of #72731 - GuillaumeGomez:cleanup-e0619, r=Dylan-DPC
Add missing empty line in E0619 explanation

r? @Dylan-DPC
2020-05-29 20:21:26 +02:00
Dylan DPC 510793bcb3
Rollup merge of #72701 - pickfire:patch-1, r=Mark-Simulacrum
Fix grammar in liballoc raw_vec
2020-05-29 20:21:24 +02:00
Dylan DPC ed80e8e3e0
Rollup merge of #72591 - sexxi-goose:rename_upvar_list-to-closure_captures, r=matthewjasper
librustc_middle: Rename upvar_list to closure_captures

As part of supporting RFC 2229, we will be capturing all the places that
are mentioned in a closure. Currently the `upvar_list` field gives access to a `FxIndexMap<HirId, Upvar>` map. Eventually this will change, with the `upvar_list` having a more general structure that expresses captured paths, not just the mentioned `upvars`. We will make those changes in subsequent PRs.

This commit modifies the name of the `upvar_list` map to `closure_captures` in `TypeckTables`.

r? @matthewjasper
2020-05-29 20:21:22 +02:00
Dylan DPC 89cb4d75a1
Rollup merge of #72572 - JohnTitor:add-tests, r=matthewjasper
Add some regression tests

Closes #68532
Closes #70121
Closes #71042
CC #56445

r? @matthewjasper since they (except for #71042) are related to #72362.
2020-05-29 20:21:20 +02:00
Dylan DPC c09f0eb3eb
Rollup merge of #72568 - golddranks:add_total_cmp_to_floats, r=sfackler
Implement total_cmp for f32, f64

# Overview
* Implements method `total_cmp` on `f32` and `f64`. This method implements a float comparison that, unlike the standard `partial_cmp`, is total (defined on all values) in accordance to the IEEE 754 (rev 2008) §5.10 `totalOrder` predicate.
* The method has an API similar to `cmp`: `pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering { ... }`.
* Implements tests.
* Has documentation.

# Justification for the API
* Total ordering for `f32` and `f64` has been discussed many time before:
  * https://internals.rust-lang.org/t/pre-pre-rfc-range-restricting-wrappers-for-floating-point-types/6701
  * https://github.com/rust-lang/rfcs/issues/1249
  * https://github.com/rust-lang/rust/pull/53938
  * https://github.com/rust-lang/rust/issues/5585
* The lack of total ordering leads to frequent complaints, especially from people new to Rust.
  * This is an ergonomics issue that needs to be addressed.
  * However, the default behaviour of implementing only `PartialOrd` is intentional, as relaxing it might lead to correctness issues.
* Most earlier implementations and discussions have been focusing on a wrapper type that implements trait `Ord`. Such a wrapper type is, however not easy to add because of the large API surface added.
* As a minimal step that hopefully proves uncontroversial, we can implement a stand-alone method `total_cmp` on floating point types.
  * I expect adding such methods should be uncontroversial because...
    * Similar methods on `f32` and `f64` would be warranted even in case stdlib would provide a wrapper type that implements `Ord` some day.
    * It implements functionality that is standardised. (IEEE 754, 2008 rev. §5.10 Note, that the 2019 revision relaxes the ordering. The way we do ordering in this method conforms to the stricter 2008 standard.)
* With stdlib APIs such as `slice::sort_by` and `slice::binary_search_by` that allow users to provide a custom ordering criterion, providing additional helper methods is a minimal way of adding ordering functionality.
  * Not also does it allow easily using aforementioned APIs, it also provides an easy and well-tested primitive for the users and library authors to implement an `Ord`-implementing wrapper, if needed.
2020-05-29 20:21:18 +02:00
Dylan DPC 9ef6227117
Rollup merge of #72465 - tmiasko:liveness-upvars, r=nikomatsakis
Warn about unused captured variables

Include captured variables in liveness analysis. Warn when captured variables
are unused (but possibly read or written to). Warn about dead assignments to
captured variables.

Fixes #37707.
Fixes #47128.
Fixes #63220.
2020-05-29 20:21:17 +02:00
Dylan DPC 8bce2404a8
Rollup merge of #72398 - Lucretiel:ip-socket-display, r=Mark-Simulacrum
SocketAddr and friends now correctly pad its content

Currently, `IpAddr` and friends correctly respect formatting parameters when printing via `Display`. This PR makes SocketAddr and friends do the same thing.
2020-05-29 20:21:15 +02:00
Dylan DPC 9c1f2035a9
Rollup merge of #72383 - DarkEld3r:issue-72322, r=matthewjasper
Suggest using std::mem::drop function instead of explicit destructor call

I would prefer to give a better suggestion that includes code example, but I'm currently stuck on getting the correct span for that.

Closes #72322.
2020-05-29 20:21:13 +02:00
Dylan DPC cbcc4c4f05
Rollup merge of #72310 - jyn514:peekable-next-if, r=dtolnay
Add Peekable::next_if

Prior art:

`rust_analyzer` uses [`Parser::eat`](50f4ae798b/crates/ra_parser/src/parser.rs (L94)), which is `next_if` specialized to `|y| self.next_if(|x| x == y)`.

Basically every other parser I've run into in Rust has an equivalent of `Parser::eat`; see for example

- [cranelift](94190d5724/cranelift/reader/src/parser.rs (L498))
- [rcc](a8159c3904/src/parse/mod.rs (L231))
- [crunch](8521874fab/crates/crunch-parser/src/parser/mod.rs (L213-L241))

Possible extensions: A specialization of `next_if` to using `Eq::eq`. The only difficulty here is the naming - maybe `next_if_eq`?

Alternatives:
- Instead of `func: impl FnOnce(&I::Item) -> bool`, use `func: impl FnOnce(I::Item) -> Option<I::Item>`. This has the advantage that `func` can move the value if necessary, but means that there is no guarantee `func` will return the same value it was given.
- Instead of `fn next_if(...) -> Option<I::Item>`, use `fn next_if(...) -> bool`. This makes the common case of `iter.next_if(f).is_some()` easier, but makes the unusual case impossible.

Bikeshedding on naming:
- `next_if` could be renamed to `consume_if` (to match `eat`, but a little more formally)
- `next_if_eq` could be renamed to `consume`. This is more concise but less self-explanatory if you haven't written a lot of parsers.
- Both of the above, but with `consume` replaced by `eat`.
2020-05-29 20:21:11 +02:00
Bastian Kauschke 1595577227 Borrow<[T]> for Interned<'tcx, List<T>> 2020-05-29 19:48:47 +02:00
Esteban Küber 0d18136b77 Move common code to WhereClause 2020-05-29 10:11:59 -07:00
Bastian Kauschke 222fbd20f2 fix encode with shorthand for Predicate 2020-05-29 18:47:52 +02:00