Commit Graph

93572 Commits

Author SHA1 Message Date
Vadim Petrochenkov
558559e70f syntax: Remove an obsolete hack from literal comparisons 2019-05-23 12:44:05 +03:00
Vadim Petrochenkov
9450e7d142 syntax: Fix spans for boolean literals passed to proc macros 2019-05-23 12:44:05 +03:00
Vadim Petrochenkov
694f76d561 syntax: More consistent wording for some literal parsing errors 2019-05-23 12:44:05 +03:00
Vadim Petrochenkov
fcc2f92f45 syntax: Return named errors from literal parsing functions 2019-05-23 12:44:05 +03:00
bors
85334c5092 Auto merge of #60174 - matthewjasper:add-match-arm-scopes, r=pnkfelix
Add match arm scopes and other scope fixes

* Add drop and lint scopes for match arms.
* Lint attributes are now respected on match arms.
* Make sure we emit a StorageDead if we diverge when initializing a temporary.
* Adjust MIR pretty printing of scopes for locals.
* Don't generate duplicate lint scopes for `let statements`.
* Add some previously missing fake borrows for matches.

closes #46525

cc @rust-lang/compiler
2019-05-23 04:48:21 +00:00
bors
15ccaf7791 Auto merge of #60740 - petrochenkov:kw, r=nnethercote
Simplify use of keyword symbols

They mirror non-keyword symbols now (see https://github.com/rust-lang/rust/pull/60630).

`keywords::MyKeyword.name()` -> `kw::MyKeyword`
`keywords::MyKeyword.ident()` -> `Ident::with_empty_ctxt(kw::MyKeyword)` (not common)
`keywords::Invalid.ident()` -> `Ident::invalid()` (more common)

Keywords are simply `Symbol` constants now, the `Keyword` struct is eliminated.
This means `kw::MyKeyword` can now be used in `match` in particular.
2019-05-23 01:50:55 +00:00
bors
11f01bfb9f Auto merge of #61044 - Centril:rollup-ztsgb9p, r=Centril
Rollup of 8 pull requests

Successful merges:

 - #60300 (Allow null-pointer-optimized enums in FFI if their underlying representation is FFI safe)
 - #60773 (Always try to project predicates when finding auto traits in rustdoc)
 - #60809 (Add FAQ for NLL migration)
 - #61023 (Migrate from recursion to iterate on qualify consts visitor impl)
 - #61029 (Simplify RefCell minimum_spanning_tree example)
 - #61030 (Make maybe_codegen_consume_direct iterate instead of doing recursion)
 - #61034 (rustc_metadata: parametrize schema::CrateRoot by 'tcx and rip out old unused incremental infra.)
 - #61037 (Update clippy submodule)

Failed merges:

r? @ghost
2019-05-22 22:57:48 +00:00
Vadim Petrochenkov
a1885cdba3 Restore the old behavior of the rustdoc keyword check + Fix rebase 2019-05-22 20:20:12 +03:00
Vadim Petrochenkov
c389a39c97 Eliminate unnecessary Ident::with_empty_ctxts 2019-05-22 19:48:56 +03:00
Vadim Petrochenkov
59a382122f Simplify use of keyword symbols 2019-05-22 19:48:56 +03:00
Mazdak Farrokhzad
68065173c7
Rollup merge of #61037 - oli-obk:clippy, r=Manishearth
Update clippy submodule

r? @Manishearth

If anyone is wondering where the odd old commits are coming from, we merged all beta backport commits and so into master in order to make sure we don't need to keep those branches around.
2019-05-22 18:08:26 +02:00
Mazdak Farrokhzad
d327e6e681
Rollup merge of #61034 - eddyb:soa-metadata-prereq, r=michaelwoerister
rustc_metadata: parametrize schema::CrateRoot by 'tcx and rip out old unused incremental infra.

These are the first two commits of #59953, already reviewed and approved by @michaelwoerister.

r? @michaelwoerister
2019-05-22 18:08:24 +02:00
Mazdak Farrokhzad
21ba9310c1
Rollup merge of #61030 - spastorino:make-operand-iterate, r=oli-obk
Make maybe_codegen_consume_direct iterate instead of doing recursion

r? @oli-obk
2019-05-22 18:08:22 +02:00
Mazdak Farrokhzad
9abc9361fa
Rollup merge of #61029 - blkerby:minimum_spanning_tree, r=alexcrichton
Simplify RefCell minimum_spanning_tree example

This simplifies the implementation of the `minimum_spanning_tree` example of `RefCell` in the `cell` module-level docs, avoiding an unnecessary recursive call. This also eliminates the need for a block to contain the scope of the borrow in this example. But since that use of a block served an important didactic purpose, we make up for this by instead introducing a block in the initial, simpler example of `RefCell`, where the point will hopefully be conveyed to the reader more easily.
2019-05-22 18:08:21 +02:00
Mazdak Farrokhzad
fba5ed355a
Rollup merge of #61023 - spastorino:use-iterate-qualify-consts, r=oli-obk
Migrate from recursion to iterate on qualify consts visitor impl

r? @oli-obk
2019-05-22 18:08:19 +02:00
Mazdak Farrokhzad
621231053c
Rollup merge of #60809 - jethrogb:jb/nll-faq, r=pnkfelix
Add FAQ for NLL migration

r? @pnkfelix

cc @oli-obk @davidtwco @Centril Since you've provided feedback on the warning wording before.
2019-05-22 18:08:17 +02:00
Mazdak Farrokhzad
90788159d7
Rollup merge of #60773 - Aaron1011:fix/rustdoc-project-all, r=eddyb
Always try to project predicates when finding auto traits in rustdoc

Fixes #60726

Previous, AutoTraitFinder would only try to project predicates when the
predicate type contained an inference variable. When finding auto
traits, we only project to try to unify inference variables - we don't
otherwise learn any new information about the required bounds.

However, this lead to failing to properly generate a negative auto trait
impl (indicating that a type never implements a certain auto trait) in
the following unusual scenario:

In almost all cases, a type has an (implicit) negative impl of an auto
trait due some other type having an explicit *negative* impl of that
auto trait. For example:

struct MyType<T> {
    field: *const T
}

has an implicit 'impl<T> !Send for MyType<T>', due to the explicit
negative impl (in libcore) 'impl<T: ?Sized> !Send for *const T'.

However, as exposed by the 'abi_stable' crate, this isn't always the
case. This minimzed example shows how a type can never implement
'Send', due to a projection error:

```
pub struct True;
pub struct False;

pub trait MyTrait {
    type Project;
}

pub struct MyStruct<T> {
    field: T
}

impl MyTrait for u8 {
    type Project = False;
}

unsafe impl<T> Send for MyStruct<T>
    where T: MyTrait<Project=True> {}

pub struct Wrapper {
    inner: MyStruct<u8>
}
```

In this example, `<u8 as MyTrait>::Project == True'
must hold for 'MyStruct<u8>: Send' to hold.
However, '<u8 as MyTrait>::Project == False' holds instead

To properly account for this unusual case, we need to call
'poly_project_and_unify' on *all* predicates, not just those with
inference variables. This ensures that we catch the projection error
that occurs above, and don't incorrectly determine that 'Wrapper: Send'
holds.
2019-05-22 18:08:14 +02:00
Mazdak Farrokhzad
7cd8d3d8d0
Rollup merge of #60300 - mjbshaw:ffi_types, r=rkruppe
Allow null-pointer-optimized enums in FFI if their underlying representation is FFI safe

I'm not sure if this requires an RFC. I attempted to start [a discussion on internals.rust-lang.org](https://internals.rust-lang.org/t/options-ffi-safety-and-guarantees-for-abi-compatibility-with-nonnull-optimizations/9784) and when no one really objected I figured I'd go ahead and try implementing this.

This allows types like `Option<NonZeroU8>` to be used in FFI without triggering the `improper_ctypes` lint. This works by changing the `is_repr_nullable_ptr` function to consider an enum `E` to be FFI-safe if:

- `E` has no explicit `#[repr(...)]`.
- It only has two variants.
- One of those variants is empty (meaning it has no fields).
- The other variant has only one field.
- That field is one of the following:
  - `&T`
  - `&mut T`
  - `extern "C" fn`
  - `core::num::NonZero*`
  - `core::ptr::NonNull<T>`
  - `#[repr(transparent)] struct` wrapper around one of the types in this list.
- The size of `E` and its field are both known and are both the same size (implying `E` is participating in the nonnull optimization).

This logic seems consistent with [the Rust nomicon](https://doc.rust-lang.org/nomicon/repr-rust.html).
2019-05-22 18:08:13 +02:00
Michael Bradshaw
a31dc8e3b1 Allow null-pointer-optimized enums in FFI if their underlying representation is FFI safe
This allows types like Option<NonZeroU8> to be used in FFI without triggering the improper_ctypes lint. This works by changing the is_repr_nullable_ptr function to consider an enum E to be FFI-safe if:

- E has no explicit #[repr(...)].
- It only has two variants.
- One of those variants is empty (meaning it has no fields).
- The other variant has only one field.
- That field is one of the following:
  - &T
  - &mut T
  - extern "C" fn
  - core::num::NonZero*
  - core::ptr::NonNull<T>
  - #[repr(transparent)] struct wrapper around one of the types in this list.
- The size of E and its field are both known and are both the same size (implying E is participating in the nonnull optimization).
2019-05-22 07:24:28 -07:00
Santiago Pastorino
3fd4b22bce Make maybe_codegen_consume_direct iterate instead of doing recursion 2019-05-22 14:22:37 +02:00
Oliver Scherer
08c91f8bef Update clippy submodule 2019-05-22 13:12:37 +02:00
Eduard-Mihai Burtescu
7327768a75 rustc_metadata: rip out unused incremental infrastructure. 2019-05-22 12:16:48 +03:00
Eduard-Mihai Burtescu
c99090761c rustc_metadata: parametrize schema::CrateRoot by 'tcx. 2019-05-22 11:52:30 +03:00
bors
37ff5d388f Auto merge of #59445 - alexreg:ban-multi-trait-objects-via-aliases, r=oli-obk
Ban multi-trait objects via trait aliases

Obviously, multi-trait objects are not normally supported, so they should not be supported via trait aliases.

This has been factored out from the previous PR https://github.com/rust-lang/rust/pull/55994 (see point 1).

r? @Centril

CC @nikomatsakis

------------------

### RELNOTES:

We now allow `dyn Send + fmt::Debug` with equivalent semantics to `dyn fmt::Debug + Send`.
That is, the order of the mentioned traits does not matter wrt. principal/not-principal traits.
This is a small change that might deserve a mention in the blog post because it is a language change but most likely not.

See ce2ee305f9/src/test/ui/traits/wf-trait-object-reverse-order.rs.

// @Centril
2019-05-22 08:22:17 +00:00
bors
1cc822c261 Auto merge of #60840 - tmandry:preserve-scope-in-generator-mir, r=cramertj
Preserve local scopes in generator MIR

Part of #52924, depended upon by the generator layout optimization #60187.

This PR adds `StorageDead` statements in more places in generators, so we can see when non-`Drop` locals have gone out of scope and recover their storage.

The reason this is only done for generators is compiler performance. See https://github.com/rust-lang/rust/pull/60187#issuecomment-485637811 for what happens when we do this for all functions.

For `Drop` locals, we modify the `MaybeStorageLive` analysis to use `drop` to indicate that storage is no longer live for the local. Once `drop` returns or unwinds to our function, we implicitly assume that the local is `StorageDead`.

Instead of using `drop`, it is possible to emit more `StorageDead` statements in the MIR for `Drop` locals so we can handle all locals the same. I am fine with doing it that way, but this was the simplest approach for my purposes. It is also likely to be more performant.

r? @Zoxc (feel free to reassign)
cc @cramertj @eddyb @RalfJung @rust-lang/wg-async-await
2019-05-22 04:42:20 +00:00
Santiago Pastorino
f47b87279c Migrate from recursion to iterate on qualify consts visitor impl 2019-05-22 06:00:04 +02:00
Brent Kerby
e641fb47c4 Simplify RefCell minimum_spanning_tree example 2019-05-21 21:52:21 -06:00
bors
dbfe70dfcd Auto merge of #61027 - Centril:rollup-oewauf1, r=Centril
Rollup of 10 pull requests

Successful merges:

 - #59742 (Move `edition` outside the hygiene lock and avoid accessing it)
 - #60581 (convert custom try macro to `?`)
 - #60963 (Update boxed::Box docs on memory layout)
 - #60973 (Avoid symbol interning in `file_metadata`.)
 - #60982 (Do not fail on child without DefId)
 - #60991 (LocalDecl push returns Local len)
 - #60995 (Add stream_to_parser_with_base_dir)
 - #60998 (static_assert: make use of anonymous constants)
 - #61003 (Remove impls for `InternedString`/string equality.)
 - #61006 (adjust deprecation date of mem::uninitialized)

Failed merges:

r? @ghost
2019-05-22 01:51:31 +00:00
Mazdak Farrokhzad
2551a54af1
Rollup merge of #61006 - RalfJung:maybe-uninit, r=Centril
adjust deprecation date of mem::uninitialized

In https://github.com/rust-lang/rust/pull/60445 we [decided](https://github.com/rust-lang/rust/pull/60445#issuecomment-488626308) that we'd deprecate for 1.38 instead of 1.40, but I forgot to adjust for that.
2019-05-22 03:47:43 +02:00
Mazdak Farrokhzad
44cb86bdc8
Rollup merge of #61003 - nnethercote:rm-InternedString-PartialEq-impls, r=petrochenkov
Remove impls for `InternedString`/string equality.

`Symbol` received the same treatment in #60630.

Also, we can derive `PartialEq` for `InternedString`.

r? @petrochenkov
2019-05-22 03:47:41 +02:00
Mazdak Farrokhzad
98172092cf
Rollup merge of #60998 - RalfJung:static_assert, r=Centril
static_assert: make use of anonymous constants
2019-05-22 03:47:40 +02:00
Mazdak Farrokhzad
3c9ac30dd9
Rollup merge of #60995 - topecongiro:parser-from-stream-and-base-dir, r=michaelwoerister
Add stream_to_parser_with_base_dir

This PR adds `stream_to_parser_with_base_dir`, which creates a parser from a token stream and a base directory.

Context: I would like to parse `cfg_if!` macro and get a list of modules defined inside it from rustfmt so that rustfmt can format those modules (cc https://github.com/rust-lang/rustfmt/issues/3253). To do so, I need to create a parser from `TokenStream` and set the directory of `Parser` to the same directory as the parent directory of a file which contains `cfg_if!` invocation. AFAIK there is no way to achieve this, and hence this PR.

Alternatively, I could change the visibility of `Parser.directory` from `crate` to `pub` so that the value can be modified after initializing a parser. I don't have a preference over either approach (or others, as long as it works).
2019-05-22 03:47:38 +02:00
Mazdak Farrokhzad
705b040ea5
Rollup merge of #60991 - spastorino:local-decls-push, r=oli-obk
LocalDecl push returns Local len

r? @oli-obk
2019-05-22 03:47:37 +02:00
Mazdak Farrokhzad
30760cde69
Rollup merge of #60982 - estebank:fix-60976, r=petrochenkov
Do not fail on child without DefId

Addresses https://github.com/rust-lang/rust/issues/60976, leaving open to come up with a repro case.
2019-05-22 03:47:35 +02:00
Mazdak Farrokhzad
1c4582c1ff
Rollup merge of #60973 - nnethercote:fix-file_metadata-more, r=michaelwoerister
Avoid symbol interning in `file_metadata`.

This commit changes `created_files` so it uses strings directly as keys,
rather than symbols derived from the strings. This avoids the cost of
having to do the hash table lookups to produce the symbols from the
strings.

The commit also uses `entry` to avoid doing a repeated hash table lookup
(`get` + `insert`).

Note that PR #60467 improved this code somewhat; this is a further
improvement.

r? @davidtwco
2019-05-22 03:47:34 +02:00
Mazdak Farrokhzad
40a18a1df5
Rollup merge of #60963 - blkerby:boxed_docs, r=alexcrichton
Update boxed::Box docs on memory layout

The existing docs for the `Box` type state that "the way `Box` allocates and releases memory is unspecified", and that therefore the only valid pointer to pass to `Box::from_raw` is one obtained from `Box::into_raw`. This is inconsistent with the module-level docs which specify,

> It is valid to convert both ways between a Box and a raw pointer allocated with the Global allocator, given that the Layout used with the allocator is correct for the type. More precisely, a value: *mut T that has been allocated with the Global allocator with Layout::for_value(&*value) may be converted into a box using Box::<T>::from_raw(value). Conversely, the memory backing a value: *mut T obtained from Box::<T>::into_raw may be deallocated using the Global allocator with Layout::for_value(&*value).

This pull request updates the docs for `Box` to make them consistent with the module-level docs and adds some examples of how to use the global allocator in conjunction with `Box::from_raw` and `Box::into_raw`.
2019-05-22 03:47:32 +02:00
Mazdak Farrokhzad
d69ef04af5
Rollup merge of #60581 - hellow554:fix_60580, r=alexcrichton
convert custom try macro to `?`

resolves #60580

r? @frewsxcv
2019-05-22 03:47:31 +02:00
Mazdak Farrokhzad
a8d1b81ba4
Rollup merge of #59742 - Zoxc:edition-cleanup, r=petrochenkov
Move `edition` outside the hygiene lock and avoid accessing it

r? @petrochenkov
2019-05-22 03:47:29 +02:00
bors
119bbc2056 Auto merge of #61007 - michaelwoerister:limited-debuginfo, r=alexcrichton
debuginfo: Revert to old/more verbose behavior for -Cdebuginfo=1

https://github.com/rust-lang/rust/commit/cff075009 made LLVM emit less debuginfo when compiling with "line-tables-only". The change was essentially correct but the reduced amount of debuginfo broke
a number of tools.

This commit reverts the change so we get back the old behavior, until we figure out how to do this properly and give external tools to adapt to the new format.

See https://github.com/rust-lang/rust/issues/60020 for more info.

r? @cuviper
cc @jrmuizel & @froydnj
2019-05-21 21:37:41 +00:00
Matthew Jasper
0835048ea0 Fix match ergonomics suggestion 2019-05-21 19:37:39 +01:00
Mazdak Farrokhzad
015a45156f Comment style fixes
Co-Authored-By: matthewjasper <mjjasper1@gmail.com>
2019-05-21 19:37:39 +01:00
Matthew Jasper
2420d82a7c Add a test for match scopes 2019-05-21 19:37:38 +01:00
Matthew Jasper
abab9efbdb Schedule storage-dead of temporaries sooner
This ensures that we will correctly generate a storage-dead if the
initializing expression diverges.
2019-05-21 19:37:38 +01:00
Matthew Jasper
b5643f1a49 Emit fake borrows for all tests
I was incorrectly under the impression that this would only lead to
duplicates. See `mir-opt/match-arm-scope.rs` (upcomming commit) for a
case where we didn't emit a fake borrow of `items.1`.
2019-05-21 19:37:38 +01:00
Matthew Jasper
0f507246e7 Remove MIR borrowck hack for old match scopes 2019-05-21 19:37:38 +01:00
Matthew Jasper
f506aea1fa Give match arms a drop/region scope
Also give arms the correct lint scope in MIR.
2019-05-21 19:37:38 +01:00
Matthew Jasper
af6a9a2c62 Handle the visibility/lint scope distinction better
* Don't generate an extra lint scope for each `let` statement.
* Place match guards inside the visiblility scope of the bindings for
  their arm.
2019-05-21 19:37:38 +01:00
Matthew Jasper
e784595c28 Respect lint attributes on match arms 2019-05-21 19:37:38 +01:00
Matthew Jasper
4bfb0453f5 Give match arms an HirId and a Span 2019-05-21 19:37:38 +01:00
Matthew Jasper
615c23f6ec Remove unused parameter from in(_opt)?_scope 2019-05-21 19:37:38 +01:00