Commit Graph

2468 Commits

Author SHA1 Message Date
bors
057937bdda Auto merge of #79668 - coolreader18:recover-const-impl, r=petrochenkov
Recover on `const impl<> X for Y`

`@leonardo-m` mentioned that `const impl Foo for Bar` could be recovered from in #79287.

I'm not sure about the error strings as they are, I think it should probably be something like the error that `expected_one_of_not_found` makes + the suggestion to flip the keywords, but I'm not sure how exactly to do that. Also, I decided not to try to handle `const unsafe impl` or `unsafe const impl` cause I figured that `unsafe impl const` would be pretty rare anyway (if it's even valid?), and it wouldn't be worth making the code more messy.
2020-12-13 10:52:29 +00:00
bors
d149b6579f Auto merge of #79956 - camelid:variant-field-vis, r=petrochenkov
Resolve enum field visibility correctly

Fixes #79593. 🎉

Previously, this code treated enum fields' visibility as if they were
struct fields. However, that's not correct because the visibility of a
struct field with `ast::VisibilityKind::Inherited` is private to the
module it's defined in, whereas the visibility of an *enum* field with
`ast::VisibilityKind::Inherited` is the visibility of the enum it
belongs to.
2020-12-13 08:40:07 +00:00
Yuki Okushi
424e44af00
Rollup merge of #79984 - Nadrieril:remove-unused-dep, r=jyn514
Remove an unused dependency that made `rustdoc` crash

Whilst struggling with https://github.com/rust-lang/rust/issues/79980 I discovered that this dependency was unused, and that made rustdoc crash. This PR removes it.
2020-12-13 11:05:47 +09:00
Yuki Okushi
e4a663cbaa
Rollup merge of #79963 - LeSeulArtichaut:debruijn-typo, r=Dylan-DPC
Fix typo in `DebruijnIndex` documentation

Suggested in https://github.com/rust-lang/rust/pull/79169#discussion_r541564114.
r? ``@lqd``
2020-12-13 11:05:41 +09:00
Yuki Okushi
2b43980ef4
Rollup merge of #79942 - JCTyblaidd:static-mem-init, r=RalfJung
Add post-init hook for static memory for miri.

Adds a post-initialization hook to treat memory initialized using the interpreter as if it was initialized in a static context.

See: https://github.com/rust-lang/miri/pull/1644 & https://github.com/rust-lang/miri/issues/1643
2020-12-13 11:05:38 +09:00
Yuki Okushi
1b81f08d4c
Rollup merge of #79940 - matthiaskrgr:cl15ppy, r=Dylan-DPC
fix more clippy::complexity findings

fix clippy::unnecessary_filter_map
use if let Some(x) = ..  instead of ...map(|x|) to conditionally run fns that return () (clippy::option_map_unit_fn)
fix clippy::{needless_bool, manual_unwrap_or}
don't clone types that are copy (clippy::clone_on_copy)
don't convert types into identical types with .into() (clippy::useless_conversion)
use strip_prefix over slicing (clippy::manual_strip)

r? ``@Dylan-DPC``
2020-12-13 11:05:36 +09:00
Nadrieril
600efe7f10 Remove an unused dependency that made rustdoc crash 2020-12-12 22:13:03 +00:00
Camelid
5ce3f4c166 Resolve enum field visibility correctly
Previously, this code treated enum fields' visibility as if they were
struct fields. However, that's not correct because the visibility of a
struct field with `ast::VisibilityKind::Inherited` is private to the
module it's defined in, whereas the visibility of an *enum* field with
`ast::VisibilityKind::Inherited` is the visibility of the enum it
belongs to.
2020-12-12 14:04:59 -08:00
Noah
1e27b65d8e
Recover on const impl<> X for Y 2020-12-12 14:45:54 -06:00
Vadim Petrochenkov
05b557cfc9 Remove some no longer necessary #[cfg(test)]s
With https://github.com/rust-lang/rust/pull/69838 inner modules are never touched in the outer module is unconfigured.
2020-12-12 19:20:37 +03:00
Vadim Petrochenkov
ec09616078 tidy: Re-enable check for inline unit tests 2020-12-12 19:18:44 +03:00
LeSeulArtichaut
6a1f92b896 Fix typo in DebruijnIndex documentation
Co-authored-by: Rémy Rakic <lqd@users.noreply.github.com>
2020-12-12 16:13:06 +01:00
bors
3f2088aa60 Auto merge of #79169 - LeSeulArtichaut:ty-lib, r=nikomatsakis
Create `rustc_type_ir`

Decided to start small 😄

This PR creates a `rustc_type_ir` crate as part of the WG-Traits plan to create a shared type library.
~~There already exists a `rustc_ty` crate, so I named the new crate `rustc_ty_library`. However I think it would make sense to rename the current `rustc_ty` to something else (e.g. `rustc_ty_passes`) to free the name for this new crate.~~

r? `@jackh726`
2020-12-12 12:36:18 +00:00
bors
602899cd01 Auto merge of #79931 - RalfJung:no-redundant-storage-live, r=oli-obk
make redundant StorageLive UB

The interesting behavior of StorageLive in loops (https://github.com/rust-lang/rust/issues/42371) has been fixed, so we can now finally make it a hard error to mark a local as live that is already live. :)

r? `@oli-obk`
Fixes https://github.com/rust-lang/rust/issues/42371
2020-12-12 02:40:17 +00:00
bors
5bd9b60333 Auto merge of #79553 - sexxi-goose:mir_min_cap_writeback, r=nikomatsakis
Capture precise paths in THIR and MIR

This PR allows THIR and MIR to use the result of the new capture analysis to actually capture precise paths

To achieve we:
- Writeback min capture results to TypeckResults
- Move handling upvars to PlaceBuilder in mir_build
- Lower precise paths in THIR build by reading min_captures
- Search for ancestors in min_capture when trying to build a MIR place which starts off of an upvar

Closes: https://github.com/rust-lang/project-rfc-2229/issues/10

Partly implements: rust-lang/project-rfc-2229#18

Work that remains (not in this PR):
- [ ] [Known bugs when feature gate is enabled](https://github.com/rust-lang/project-rfc-2229/projects/1?card_filter_query=label%3Abug)
- [ ] Use min_capure_map for
  - [ ] Liveness analysis
  - [ ] rustc_mir/interpret/validity.rs
  - [ ] regionck
- [ ] rust-lang/project-rfc-2229#8
- [ ] remove closure_captures and upvar_capture_map

r? `@ghost`
2020-12-12 00:23:29 +00:00
Matthias Krüger
cf10a0abf2 fix clippy::unnecessary_filter_map 2020-12-11 23:02:19 +01:00
Matthias Krüger
5833f74a9c use if let Some(x) = .. instead of ...map(|x|) to conditionally run fns that return () (clippy::option_map_unit_fn) 2020-12-11 23:02:19 +01:00
Matthias Krüger
b7795e135a fix clippy::{needless_bool, manual_unwrap_or} 2020-12-11 23:02:19 +01:00
Matthias Krüger
db6c50998c don't clone types that are copy (clippy::clone_on_copy) 2020-12-11 23:02:19 +01:00
Matthias Krüger
82fe5c1662 don't convert types into identical types with .into() (clippy::useless_conversion) 2020-12-11 23:02:19 +01:00
Matthias Krüger
5c8de1cf49 use strip_prefix over slicing (clippy::manual_strip) 2020-12-11 23:02:17 +01:00
JCTyblaidd
175226a01c Rustfmt 2020-12-11 19:28:20 +00:00
JCTyblaidd
6ce29906f1
Fix rustfmt failure 2020-12-11 19:11:39 +00:00
JCTyblaidd
56d89364a5 Add post-initialization hook for static memory initialized using the interpereter. 2020-12-11 18:42:36 +00:00
bors
a9f7d19a91 Auto merge of #79910 - RalfJung:abort-msg, r=oli-obk
CTFE: tweak abort-on-uninhabited message

Having an "aborted execution:" makes it more consistent with the `Abort` terminator saying "the program aborted execution". Right now, at least one of the two errors will look weird in Miri.

r? `@oli-obk`
2020-12-11 12:30:05 +00:00
Ralf Jung
78deacc2ec make redundant StorageLive UB 2020-12-11 13:18:44 +01:00
bors
19eb1c4c52 Auto merge of #79915 - Aaron1011:fix/fix-reuse-def-path-hash, r=petrochenkov
Use `def_path_hash_to_def_id` when re-using a `RawDefId`

Fixes #79890

Previously, we just copied a `RawDefId` from the 'old' map to the 'new'
map. However, the `RawDefId` for a given `DefPathHash` may be different
in the current compilation session. Using `def_path_hash_to_def_id`
ensures that the `RawDefId` we use is valid in the current session.
2020-12-11 10:20:43 +00:00
Tyler Mandry
0327b5dac5
Rollup merge of #79917 - sivadeilra:asm_symbols, r=petrochenkov
Use Symbol for inline asm register class names

This takes care of one "FIXME":
// FIXME: use direct symbol comparison for register class names

Instead of using string literals, this uses Symbol for register
class names.

This is part of work I am doing to improve how Symbol interning works.
2020-12-10 21:33:19 -08:00
Tyler Mandry
dc90573454
Rollup merge of #79851 - camelid:better-error-for-default-fn, r=davidtwco
Clarify the 'default is only allowed on...' error

Code like

    impl Foo {
        default fn foo() {}
    }

will trigger the error

    error: `default` is only allowed on items in `impl` definitions
     --> src/lib.rs:5:5
      |
    5 |     default fn foo() {}
      |     -------^^^^^^^^^
      |     |
      |     `default` because of this

but that's very confusing! I *did* put it on an item in an impl!

So this commit changes the message to

    error: `default` is only allowed on items in trait impls
     --> src/lib.rs:5:5
      |
    5 |     default fn foo() {}
      |     -------^^^^^^^^^
      |     |
      |     `default` because of this
2020-12-10 21:33:10 -08:00
Tyler Mandry
17ec4b8258
Rollup merge of #79809 - Eric-Arellano:split-once, r=matklad
Dogfood `str_split_once()`

Part of https://github.com/rust-lang/rust/issues/74773.

Beyond increased clarity, this fixes some instances of a common confusion with how `splitn(2)` behaves: the first element will always be `Some()`, regardless of the delimiter, and even if the value is empty.

Given this code:

```rust
fn main() {
    let val = "...";
    let mut iter = val.splitn(2, '=');
    println!("Input: {:?}, first: {:?}, second: {:?}", val, iter.next(), iter.next());
}
```

We get:

```
Input: "no_delimiter", first: Some("no_delimiter"), second: None
Input: "k=v", first: Some("k"), second: Some("v")
Input: "=", first: Some(""), second: Some("")
```

Using `str_split_once()` makes more clear what happens when the delimiter is not found.
2020-12-10 21:33:08 -08:00
Tyler Mandry
f3a3fc900c
Rollup merge of #79639 - sasurau4:feature/add-long-explanation-E0212, r=GuillaumeGomez
Add long explanation for E0212

Helps with #61137
2020-12-10 21:33:04 -08:00
Arlie Davis
40ed0f6857 Use Symbol for inline asm register class names
This takes care of one "FIXME":
// FIXME: use direct symbol comparison for register class names

Instead of using string literals, this uses Symbol for register
class names.
2020-12-10 13:51:56 -08:00
Aaron Hill
3918b82993
Use def_path_hash_to_def_id when re-using a RawDefId
Fixes #79890

Previously, we just copied a `RawDefId` from the 'old' map to the 'new'
map. However, the `RawDefId` for a given `DefPathHash` may be different
in the current compilation session. Using `def_path_hash_to_def_id`
ensures that the `RawDefId` we use is valid in the current session.
2020-12-10 16:04:19 -05:00
Ralf Jung
2443f642e3 CTFE: tweak abort-on-uninhabited message 2020-12-10 19:59:31 +01:00
bors
d7560e8968 Auto merge of #79801 - eddyb:scalar-transmute, r=nagisa
rustc_codegen_ssa: use bitcasts instead of type punning for scalar transmutes.

This specifically helps with `f32` <-> `u32` (`from_bits`, `to_bits`) in Rust-GPU (`rustc_codegen_spirv`), where (AFAIK) we don't yet have enough infrastructure to turn type punning memory accesses into SSA bitcasts.
(There may be more instances, but the one I've seen myself is `f32::signum` from `num-traits` inspecting e.g. the sign bit)

Sadly I've had to make an exception for `transmute`s between pointers and non-pointers, as LLVM disallows using `bitcast` for them.

r? `@nagisa` cc `@khyperia`
2020-12-10 12:55:12 +00:00
bors
39b841dfe3 Auto merge of #79621 - usbalbin:constier_maybe_uninit, r=RalfJung
Constier maybe uninit

I was playing around trying to make `[T; N]::zip()` in #79451 be `const fn`. One of the things I bumped into was `MaybeUninit::assume_init`. Is there any reason for the intrinsic `assert_inhabited<T>()` and therefore `MaybeUninit::assume_init` not being `const`?

---

I have as best as I could tried to follow the instruction in [library/core/src/intrinsics.rs](https://github.com/rust-lang/rust/blob/master/library/core/src/intrinsics.rs#L11). I have no idea what I am doing but it seems to compile after some slight changes after the copy paste. Is this anywhere near how this should be done?

Also any ideas for name of the feature gate? I guess `const_maybe_assume_init` is quite misleading since I have added some more methods. Should I add test? If so what should be tested?
2020-12-10 10:46:38 +00:00
Aman Arora
237ad12698 Use closure_min_captures in borrow checker
- Use closure_min_captures to generate the Upvar structure that
  stores information for diagnostics and information about
  mutability of captures.
2020-12-09 22:34:15 -05:00
Aman Arora
e2efdd156b Use precise places when lowering Closures in THIR
- Closures now use closure_min_captures to figure out captured paths
- Build upvar_mutbls using closure_min_captures
- Change logic in limit_capture_mutability to differentiate b/w
  capturing parent's local variable or capturing a variable that is
  captured by the parent (in case of nested closure) using PlaceBase.

Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
2020-12-09 22:34:15 -05:00
Aman Arora
6a1d0699a4 Use Places for captures in MIR
- Use closure_min_capture maps to capture precise paths
- PlaceBuilder now searches for ancestors in min_capture list
- Add API to `Ty` to allow access to the n-th element in a
  tuple in O(1) time.

Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
2020-12-09 22:33:33 -05:00
bors
58d2bad9f7 Auto merge of #78837 - petrochenkov:keyvalexpr, r=davidtwco
Accept arbitrary expressions in key-value attributes at parse time

Continuation of https://github.com/rust-lang/rust/pull/77271.

We now support arbitrary expressions in values of key-value attributes at parse time.
```
#[my_attr = EXPR]
```
Previously only unsuffixed literals and interpolated expressions (`$expr`) were accepted.

There are two immediate motivational cases for this:
- External doc strings (`#[doc = include_str!("my_doc.md")]`, eliminating the need in https://github.com/rust-lang/rust/issues/44732) and expanding macros in this position in general. Currently such macro expansions are supported in this position in interpolated `$expr`s (the `#[doc = $doc]` idiom).
- Paths (`#[namespace = foo::bar] extern "C++" { ... }`) like proposed in https://github.com/rust-lang/rust/pull/76734.

If the attribute in question survives expansion, then the value is still restricted to unsuffixed literals by a semantic check.
This restriction doesn't prevent the use cases listed above, so this PR keeps it in place for now.

Closes https://github.com/rust-lang/rust/issues/52607.
Previous attempt - https://github.com/rust-lang/rust/pull/67121.
Some more detailed write up on internals - https://internals.rust-lang.org/t/macro-expansion-points-in-attributes/11455.
Tracking issue - https://github.com/rust-lang/rust/issues/78835.
2020-12-10 00:42:22 +00:00
bors
1cc4107109 Auto merge of #79867 - tmandry:rollup-7mubs3b, r=tmandry
Rollup of 12 pull requests

Successful merges:

 - #79732 (minor stylistic clippy cleanups)
 - #79750 (Fix trimming of lint docs)
 - #79777 (Remove `first_merge` from liveness debug logs)
 - #79795 (Privatize some of libcore unicode_internals)
 - #79803 (Update xsv to prevent random CI failures)
 - #79810 (Account for gaps in def path table during decoding)
 - #79818 (Fixes to Rust coverage)
 - #79824 (Strip prefix instead of replacing it with empty string)
 - #79826 (Simplify visit_{foreign,trait}_item)
 - #79844 (Move RWUTable to a separate module)
 - #79861 (Update LLVM submodule)
 - #79862 (Remove tab-lock and replace it with ctrl+up/down arrows to switch between search result tabs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-09 22:21:55 +00:00
Tyler Mandry
b867d13d34
Rollup merge of #79844 - tmiasko:rwu-table-mod, r=lcnr
Move RWUTable to a separate module
2020-12-09 13:38:34 -08:00
Tyler Mandry
9ced8dc0f5
Rollup merge of #79826 - LingMan:match_if, r=lcnr
Simplify visit_{foreign,trait}_item

Using an `if` seems like a better semantic fit and saves a few lines.

Noticed while looking at https://github.com/rust-lang/rust/pull/79752, but that's already merged.
r? `@lcnr,` cc `@cjgillot`

`@rustbot` modify labels +C-cleanup +T-compiler
2020-12-09 13:38:33 -08:00
Tyler Mandry
666d1a8951
Rollup merge of #79824 - LingMan:no_replace, r=lcnr
Strip prefix instead of replacing it with empty string

r? `@lcnr,` since you reviewed my other PR in the area.
`@rustbot` modify labels +C-cleanup +T-compiler
2020-12-09 13:38:31 -08:00
Tyler Mandry
3b49a46c6b Rollup merge of #79818 - richkadel:llvm-coverage-counters-2.1.0, r=tmandry
Fixes to Rust coverage

Fixes: #79725

Some macros can create a situation where `fn_sig_span` and `body_span`
map to different files.

New documentation on coverage tests incorrectly assumed multiple test
binaries could just be listed at the end of the `llvm-cov` command,
but it turns out each binary needs a `--object` prefix.

This PR fixes the bug and updates the documentation to correct that
issue. It also fixes a few other minor issues in internal implementation
comments, and adds documentation on getting coverage results for doc
tests.
2020-12-09 13:38:27 -08:00
Tyler Mandry
a410af97a8
Rollup merge of #79810 - Aaron1011:fix/def-path-table-gap, r=lcnr
Account for gaps in def path table during decoding

When encoding a proc-macro crate, there may be gaps in the table (since
we only encode the crate root and proc-macro items). Account for this by
checking if the entry is present, rather than using `unwrap()`
2020-12-09 13:38:25 -08:00
Tyler Mandry
2cca5e11e0
Rollup merge of #79777 - tmiasko:remove-first-merge, r=lcnr
Remove `first_merge` from liveness debug logs
2020-12-09 13:38:20 -08:00
Tyler Mandry
d95948c6d3
Rollup merge of #79732 - matthiaskrgr:cl12ppy, r=Dylan-DPC
minor stylistic clippy cleanups

simplify if let Some(_) = x  to  if x.is_some()  (clippy::redundant_pattern_matching)
don't create owned values for comparison (clippy::cmp_owned)
use .contains() or .any() instead of find(x).is_some() (clippy::search_is_some)
don't wrap code block in Ok()  (clipppy::unit_arg)
2020-12-09 13:38:12 -08:00
bors
f0f68778f7 Auto merge of #77611 - oli-obk:atomic_miri_leakage, r=nagisa
Directly use raw pointers in `AtomicPtr` store/load

I was unable to find any reason for this limitation in the latest source of LLVM or in the documentation [here](http://llvm.org/docs/Atomics.html#libcalls-atomic).

fixes https://github.com/rust-lang/miri/issues/1574
2020-12-09 19:53:23 +00:00
Vadim Petrochenkov
31d72c2658 Accept arbitrary expressions in key-value attributes at parse time 2020-12-09 21:37:32 +03:00