Commit Graph

2432 Commits

Author SHA1 Message Date
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
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
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
bors
fa55f668e5 Auto merge of #79721 - Aaron1011:fix/reuse-def-path-hash, r=wesleywiser
Properly re-use def path hash in incremental mode

Fixes #79661

In incremental compilation mode, we update a `DefPathHash -> DefId`
mapping every time we create a `DepNode` for a foreign `DefId`.
This mapping is written out to the on-disk incremental cache, and is
read by the next compilation session to allow us to lazily decode
`DefId`s.

When we decode a `DepNode` from the current incremental cache, we need
to ensure that any previously-recorded `DefPathHash -> DefId` mapping
gets recorded in the new mapping that we write out. However, PR #74967
didn't do this in all cases, leading to us being unable to decode a
`DefPathHash` in certain circumstances.

This PR refactors some of the code around `DepNode` deserialization to
prevent this kind of mistake from happening again.
2020-12-09 13:54:07 +00:00
bors
cc03ee6702 Auto merge of #78679 - oli-obk:temp_lifetime, r=eddyb
Also generate `StorageDead` in constants

r? `@eddyb`

None of this special casing is actually necessary since we started promoting within constants and statics.

We may want to keep some of it around out of perf reasons, but it's not required for user visible behaviour

somewhat related: #68622
2020-12-09 11:31:32 +00:00
oli
84fe7cf24e Also generate StorageDead in constants 2020-12-09 10:59:10 +00:00
bors
c0bfe3485f Auto merge of #78363 - RalfJung:promotion, r=oli-obk
remove this weird special case from promotion

Promotion has a special case to ignore interior mutability under some specific circumstances. The purpose of this PR is to figure out what changes if we remove that. Since `Cell::new` and friends only get promoted inside `const`/`static` initializers these days, it actually is not easy to exploit this case: you need something like
```rust
const TEST_INTERIOR_MUT: () = {
    // The "0." case is already ruled out by not permitting any interior mutability in `const`.
    let _val: &'static _ = &(Cell::new(1), 2).1;
};
```

I assume something like `&Some(&(Cell::new(1), 2).1)` would hit the nested case inside `validate_rvalue`... though I am not sure why that would not just trigger nested promotion, first promoting the inner reference and then the outer one?

Fixes https://github.com/rust-lang/rust/issues/67534 (by simply rejecting that code^^)

r? `@oli-obk` (but for now this is not meant to be merged!)
Cc `@rust-lang/wg-const-eval`
2020-12-09 09:13:54 +00:00
Ralf Jung
99a44ed086 remove a hack that seems to only benefit a few very special cases 2020-12-09 09:46:22 +01:00
bors
db85512bd8 Auto merge of #79767 - tmiasko:malformed-required-const, r=matthewjasper
Don't ICE on malformed `rustc_args_required_const` attribute
2020-12-09 06:31:49 +00:00
Camelid
4e21942ba4 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-08 21:56:22 -08:00
Tomasz Miąsko
c7d7bc917d Move RWUTable to a separate module 2020-12-09 00:00:00 +00:00
Tomasz Miąsko
d711c3006b Remove first_merge from liveness debug logs 2020-12-09 00:00:00 +00:00
bors
1700ca07c6 Auto merge of #79727 - tmiasko:8bit-rwu, r=lcnr
Compress RWU from at least 32 bits to 4 bits

The liveness uses a mixed representation of RWUs based on the
observation that most of them have invalid reader and invalid
writer. The packed variant uses 32 bits and unpacked 96 bits.
Unpacked data contains reader live node and writer live node.

Since live nodes are used only to determine their validity,
RWUs can always be stored in a packed form with four bits for
each: reader bit, writer bit, used bit, and one extra padding
bit to simplify packing and unpacking operations.
2020-12-08 20:58:20 +00:00
Eric Arellano
989edf4a5f Review feedback
* Use a match statement.
* Clarify why we can't use `file_stem()`.
* Error if the `:` is missing for Tidy error codes, rather than no-oping.
2020-12-08 12:51:00 -07:00
Matthias Krüger
20f8538d1f simplify if let Some(_) = x to if x.is_some() (clippy::redundant_pattern_matching) 2020-12-08 20:27:49 +01:00
Matthias Krüger
c37e19843a don't create owned values for comparison (clippy::cmp_owned) 2020-12-08 20:27:48 +01:00
Matthias Krüger
0fa461558c use .contains() or .any() instead of find(x).is_some() (clippy::search_is_some) 2020-12-08 20:27:48 +01:00
Aaron Hill
a332e2b38f
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-08 13:02:53 -05:00
LingMan
7654b12112 Simplify visit_{foreign,trait}_item
Using an `if` seems like a better semantic fit and saves a few lines.
2020-12-08 15:56:15 +01:00
bors
5e6e1e33a1 Auto merge of #79817 - LingMan:if_map, r=lcnr
Replace simple `if let` constructs with Option::map

Replaces a few constructs of the form

```
if let Some(x) = var {
    Some(...)
} else {
    None
}
```

with calls to `Option::map`.

`@rustbot` modify labels +C-cleanup +T-compiler
2020-12-08 13:58:15 +00:00
LingMan
06aa7a7601 Strip prefix instead of replacing it with empty string 2020-12-08 14:46:19 +01:00
bors
5019791e2d Auto merge of #79752 - cjgillot:dead-alien, r=lcnr
Visit ForeignItems when marking dead code

Follow-up to #79318

r? `@lcnr`
2020-12-08 11:16:19 +00:00
bors
4fd4a98d47 Auto merge of #79806 - LeSeulArtichaut:fixup-filter-is-none, r=jyn514
Fixup: `filter().is_none()` -> `!any()`
2020-12-08 08:51:51 +00:00
Camille GILLOT
37853f925f Visit ForeignItems when marking dead code. 2020-12-08 08:07:55 +01:00
Rich Kadel
95c268f64d 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-07 17:56:19 -08:00
LingMan
af9402af0f Replace simple if let constructs with Option::map
Replaces a few constructs of the form

if let Some(x) = var {
    Some(...)
} else {
    None
}

with calls to Option::map.
2020-12-08 02:40:14 +01:00
bors
bda05cc471 Auto merge of #79653 - tmiasko:naked-functions, r=Amanieu
Validate naked functions definitions

Validate that naked functions are defined in terms of a single inline assembly
block that uses only `const` and `sym` operands and has `noreturn` option.

Implemented as future incompatibility lint with intention to migrate it into
hard error. When it becomes a hard error it will ensure that naked functions are
either unsafe or contain an unsafe block around the inline assembly. It will
guarantee that naked functions do not reference functions parameters (obsoleting
part of existing checks from #79411). It will limit the definitions of naked
functions to what can be reliably supported. It will also reject naked functions
implemented using legacy LLVM style assembly since it cannot satisfy those
conditions.

https://github.com/rust-lang/rfcs/pull/2774
https://github.com/rust-lang/rfcs/pull/2972
2020-12-07 22:47:20 +00:00
LeSeulArtichaut
9cc563b70b Fixup: filter().is_none() -> !any() 2020-12-07 21:40:20 +01:00
Eric Arellano
12db2225b6 Dogfood 'str_split_once() with compiler/ 2020-12-07 12:48:44 -07:00
Albin Hedman
bdda98aaba
Add comment for assert_inhabited in compiler/rustc_mir/src/interpret/intrinsics.rs
Co-authored-by: Ralf Jung <post@ralfj.de>
2020-12-07 18:59:10 +01:00
Eduard-Mihai Burtescu
97c7022d08 rustc_codegen_ssa: use bitcasts instead of type punning for scalar transmutes. 2020-12-07 18:19:43 +02:00
bors
b5ff9c3d05 Auto merge of #79773 - lcnr:type-visitor, r=oli-obk
small `TypeVisitor` refactor

cc `@LeSeulArtichaut` `@scottmcm`

adds `ControlFlow::map_break`
2020-12-07 15:07:09 +00:00
Bastian Kauschke
e3e4870bce small TypeVisitor refactor 2020-12-07 15:52:59 +01:00
bors
2b76c48328 Auto merge of #79772 - ethanboxx:79760-wrongly-speaks-of-methods, r=oli-obk
smarter E0390

Should fix #79760

I am fairly new to the compiler so am hoping I did things correctly :).
2020-12-07 09:28:25 +00:00
Tomasz Miąsko
8065dabd17 Validate naked functions definitions 2020-12-07 00:00:00 +00:00