Commit graph

30941 commits

Author SHA1 Message Date
bors
269843fcb4 Auto merge of #127629 - tesuji:suggest-option-ref-unwrap_or, r=estebank
Suggest using `map_or` when `Option<&T>::unwrap_or where T: Deref` fails

Fix #127545

Split from https://github.com/rust-lang/rust/pull/127596#pullrequestreview-2171898588
2024-07-15 23:36:22 +00:00
bors
8ebc294af3 Auto merge of #127020 - tgross35:f16-f128-classify, r=workingjubilee
Add classify and related methods for f16 and f128

Also constify some functions where that was blocked on classify being available.

r? libs
2024-07-15 17:20:33 +00:00
bors
0c95aaa08e Auto merge of #17601 - Veykril:proc-macro-fix, r=Veykril
Fix incorrect encoding of literals in the proc-macro-api on version 4

Quick follow up on https://github.com/rust-lang/rust-analyzer/pull/17559 breaking things
2024-07-15 12:55:09 +00:00
Lukas Wirth
05ce57efd5 Fix incorrect encoding of literals in the proc-macro-api on version 4 2024-07-15 14:51:01 +02:00
bors
f913901399 Auto merge of #17559 - Veykril:tokentree, r=Veykril
Encode ident rawness and literal kind separately in tt::Leaf
2024-07-15 11:25:51 +00:00
Lukas Wirth
dcfda55c82 Escape fetched env vars in env! expansion 2024-07-15 13:08:29 +02:00
Lukas Wirth
c0136070a7 Add cargo xtask install proc-macro-server 2024-07-15 12:41:02 +02:00
Lukas Wirth
e846c04fbe Encode ident rawness and literal kind separately in tt::Leaf 2024-07-15 12:24:40 +02:00
bors
5ece16cf17 Auto merge of #17588 - CamWass:more-rename, r=Veykril
feat: Add incorrect case diagnostics for enum variant fields and all variables/params

Updates the incorrect case diagnostic to check:

1. Fields of enum variants. Example:
```rust
enum Foo {
    Variant { nonSnake: u8 }
}
```
2. All variable bindings, instead of just let bindings and certain match arm patters. Examples:
```rust
match 1 { nonSnake => () }
match 1 { nonSnake @ 1 => () }
match 1 { nonSnake1 @ nonSnake2 => () } // slightly cursed, but these both introduce new
                                        // bindings that are bound to the same value.

const ONE: i32 = 1;
match 1 { nonSnake @ ONE } //  ONE is ignored since it is not a binding

match Some(1) { Some(nonSnake) => () }

struct Foo { field: u8 }
match (Foo { field: 1 } ) {
    Foo { field: nonSnake } => ();
}

struct Foo { nonSnake: u8 } // diagnostic here, at definition
match (Foo { nonSnake: 1 } ) { // no diagnostic here...
    Foo { nonSnake } => ();    // ...or here, since these are not where the name is introduced
}

for nonSnake in [] {}

struct Foo(u8);
for Foo(nonSnake) in [] {}
```
3. All parameter bindings, instead of just top-level binding identifiers. Examples:
```rust
fn func(nonSnake: u8) {} // worked before

struct Foo { field: u8 }
fn func(Foo { field: nonSnake }: Foo) {} // now get diagnostic for nonSnake
```

This is accomplished by changing the way binding identifier patterns are filtered:
- Previously, all binding idents were skipped, except a few classes of "good" binding locations that were checked.
- Now, all binding idents are checked, except field shorthands which are skipped.

Moving from a whitelist to a blacklist potentially makes the analysis more brittle:
If new pattern types are added in the future where ident pats don't introduce new names, then they may incorrectly create diagnostics.

But the benefit of the blacklist approach is simplicity: I think a whitelist approach would need to recursively visit patterns to collect renaming candidates?
2024-07-15 10:07:37 +00:00
bors
e961b1aece Auto merge of #17587 - joshka:jm/edit-name-after-refactor, r=Veykril
Trigger VSCode to rename after extract variable assist is applied

When the user applies the "Extract Variable" assist, the cursor is
positioned at the newly inserted variable. This commit adds a command
to the assist that triggers the rename action in VSCode. This way, the
user can quickly rename the variable after applying the assist.

Fixes part of: #17579

https://github.com/user-attachments/assets/4cf38740-ab22-4b94-b0f1-eddd51c26c29

I haven't yet looked at the module or function extraction assists yet.
2024-07-15 09:53:39 +00:00
bors
5784915618 Auto merge of #17584 - Veykril:landing-page, r=Veykril
Implement symbol interning infra

Will fix https://github.com/rust-lang/rust-analyzer/issues/15590

My unsafe-fu is not the best but it does satisfy miri.

There is still some follow up work to do, notably a lot of places using strings instead of symbols/names, most notably the token tree.
2024-07-15 09:39:22 +00:00
Lukas Wirth
cde0f69cae Fix stable iteration ordering for Map<Name, ...> usages 2024-07-15 11:25:46 +02:00
bors
ed214710f7 Auto merge of #127265 - harmou01:dev/harmou01/target-spec-metadata, r=Nilstrieb
Fill out target-spec metadata for all targets

**What does this PR try to resolve?**

This PR completes the target-spec metadata fields for all targets. This is required for a corresponding Cargo PR which adds a check for whether a target supports building the standard library when the `-Zbuild-std=std` flag is passed ([see this issue](https://github.com/rust-lang/wg-cargo-std-aware/issues/87). This functionality in Cargo is reliant on the output of `--print=target-spec-json`.

**How should we test and review this PR?**

Check that a given target-spec metadata has been updated with:
```
$ ./x.py build library/std
$ build/host/stage1/bin/rustc --print=target-spec-json --target <target_name> -Zunstable-options
```

**Additional Information**

A few things to note:
* Where a targets 'std' or 'host tools' support is listed as '?' in the rust docs, these are left as 'None' with this PR. The corresponding changes in cargo will only reject an attempt to build std if the 'std' field is 'Some(false)'. In the case it is 'None', cargo will continue trying to build
* There's no rush for this to be merged. I understand that the format for this is not finalised yet.
* Related: #120745
2024-07-15 08:37:39 +00:00
bors
46dd88e8dd Auto merge of #127726 - RalfJung:miri-sync, r=RalfJung
Miri subtree update

r? `@ghost`
2024-07-14 21:14:02 +00:00
bors
9695cdd86f Auto merge of #125935 - madsmtm:merge-os-apple, r=workingjubilee
Merge Apple `std::os` extensions modules into `std::os::darwin`

The functionality available on Apple platforms are very similar, and were (basically) duplicated for each platform.

This PR rectifies that by merging the code into one module.

Ultimately, I've done this to fix `./x build library --target=aarch64-apple-tvos,aarch64-apple-watchos,aarch64-apple-visionos`, as that currently fails because of dead code warnings.

Publically exposing these to tvOS/watchOS/visionOS targets is considered in https://github.com/rust-lang/rust/pull/123723, but that seems to be dragging out, and in any case I think it makes sense to do the refactor separately from stabilization.

r? libs

Fixes https://github.com/rust-lang/rust/issues/121640 and https://github.com/rust-lang/rust/issues/124825.
2024-07-14 16:28:07 +00:00
Lukas Wirth
f2d51073d2 Use statics + clone instead of const until const can access statics 2024-07-14 17:52:59 +02:00
bors
ab2d1fdd64 Auto merge of #127670 - compiler-errors:no-type-length-limit, r=jackh726
Gate the type length limit check behind a nightly flag

Effectively disables the type length limit by introducing a `-Zenforce-type-length-limit` which defaults to **`false`**, since making the length limit actually be enforced ended up having a worse fallout than expected. We still keep the code around, but the type length limit attr is now a noop (except for its usage in some diagnostics code?).

r? `@lcnr` -- up to you to decide what team consensus we need here since this reverses an FCP decision.

Reopens #125460 (if we decide to reopen it or keep it closed)
Effectively reverses the decision FCP'd in #125507
Closes #127346
2024-07-14 12:44:07 +00:00
bors
e9afba57a5 Auto merge of #17594 - anitahammer:patch-1, r=lnicola
minor: Update manual.adoc
2024-07-14 10:30:53 +00:00
Anita Hammer
70d20e1ca1
Update manual.adoc 2024-07-14 11:26:41 +01:00
bors
2b611ea7d9 Auto merge of #127087 - cjgillot:small-map, r=oli-obk
Only track mentioned places for jump threading

This PR aims to reduce the state space size in jump threading and dataflow const-prop opts.

The current implementation walks the types of all locals, and creates a place for each possible projection. This can easily lead to a large number of places and tracked values, most being useless to the actual pass.

With this PR, we instead collect places that appear syntactically in the MIR (first commit). However, this is not sufficient (second commit), and we miss places that we could track in aggregate assignments. The third commit tracks such assignments to mirror place projections, see the inline comment.

This is complementary to https://github.com/rust-lang/rust/pull/127036

r? `@oli-obk`
2024-07-14 08:01:21 +00:00
bors
8210d53650 Auto merge of #127706 - workingjubilee:rollup-d07ij30, r=workingjubilee
Rollup of 6 pull requests

Successful merges:

 - #122300 (Add FileCheck annotations to mir-opt/dest-prop tests)
 - #127434 (use "bootstrap" instead of "rustbuild" in comments and docs)
 - #127477 (Clear `inner_attr_ranges` regularly.)
 - #127558 (More attribute cleanups)
 - #127659 (Use ManuallyDrop in BufWriter::into_parts)
 - #127671 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 8))

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-14 05:41:24 +00:00
Jubilee
c993d7bd63
Rollup merge of #127671 - notriddle:notriddle/issue-d, r=Mark-Simulacrum
rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 8)

Follow up

* https://github.com/rust-lang/rust/pull/116214
* https://github.com/rust-lang/rust/pull/116432
* https://github.com/rust-lang/rust/pull/116824
* https://github.com/rust-lang/rust/pull/118105
* https://github.com/rust-lang/rust/pull/119561
* https://github.com/rust-lang/rust/pull/123574
* https://github.com/rust-lang/rust/pull/125382

As always, it's easier to review the commits one at a time. Don't use the Files Changed tab. It's confusing.
2024-07-13 20:19:48 -07:00
Jubilee
9ca944878d
Rollup merge of #127659 - saethlin:manually-drop-bufwriter, r=joboet
Use ManuallyDrop in BufWriter::into_parts

The fact that `mem::forget` takes by value means that it interacts very poorly with Stacked Borrows; generally users think of calling it as a no-op, but in Stacked Borrows, the field retagging tends to cause surprise tag invalidation.
2024-07-13 20:19:47 -07:00
Jubilee
3126b7914d
Rollup merge of #127558 - nnethercote:more-Attribute-cleanups, r=petrochenkov
More attribute cleanups

A follow-up to #127308.

r? ```@petrochenkov```
2024-07-13 20:19:46 -07:00
Jubilee
5f45019410
Rollup merge of #127477 - nnethercote:tweak-inner_attr_ranges, r=petrochenkov
Clear `inner_attr_ranges` regularly.

There's a comment saying we don't do it for performance reasons, but it doesn't actually affect performance.

The commit also tweaks the control flow, to make clearer that two code paths are mutually exclusive.

r? ````@petrochenkov````
2024-07-13 20:19:46 -07:00
Jubilee
312db81e07
Rollup merge of #127434 - onur-ozkan:use-bootstrap-instead-of-rustbuild, r=Mark-Simulacrum
use "bootstrap" instead of "rustbuild" in comments and docs

Let's stick with the single name "bootstrap" to refer to the bootstrap project to avoid confusion. This should make it clearer, especially for new contributors.
2024-07-13 20:19:45 -07:00
Jubilee
1a10b41d62
Rollup merge of #122300 - CastilloDel:master, r=cjgillot
Add FileCheck annotations to mir-opt/dest-prop tests

Part of https://github.com/rust-lang/rust/issues/116971, adds FileCheck annotations to MIR-opt tests in tests/mir-opt/dest-prop.

I would like some feedback. Also, I don't know how to approach `union.rs`.  I couldn't figure out what it is testing.

r? cjgillot
2024-07-13 20:19:45 -07:00
Josh McKinney
bfa6a5ca84
Address feedback from @DropDemBits
- move `edit.rename()` to the end of the function
- use a match statement to set `res.command`
2024-07-13 19:33:35 -07:00
bors
16684c7e60 Auto merge of #126958 - dtolnay:u32char, r=Mark-Simulacrum
Stabilize const unchecked conversion from u32 to char

Closes https://github.com/rust-lang/rust/issues/89259.

The functions in this PR were left out of the initial set of `feature(const_char_convert)` stabilizations in https://github.com/rust-lang/rust/pull/102470, but have since been unblocked by https://github.com/rust-lang/rust/pull/118979.

If `unsafe { from_u32_unchecked(u) }` is called in const with a value for which `from_u32(u)` returns None, we get the following compile error.

```rust
fn main() {
    let _ = const { unsafe { char::from_u32_unchecked(0xd800) } };
}
```

```console
error[E0080]: it is undefined behavior to use this value
 --> src/main.rs:2:19
  |
2 |     let _ = const { unsafe { char::from_u32_unchecked(0xd800) } };
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0x0000d800, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`)
  |
  = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
  = note: the raw bytes of the constant (size: 4, align: 4) {
              00 d8 00 00                                     │ ....
          }

note: erroneous constant encountered
 --> src/main.rs:2:13
  |
2 |     let _ = const { unsafe { char::from_u32_unchecked(0xd800) } };
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
2024-07-13 18:41:08 +00:00
bors
9e343d2388 Auto merge of #127435 - GrigorenkoPV:tests-for-112905, r=cjgillot
Add tests for #112905

This is a part of #105107. Adds the tests from the OP in #112905.
2024-07-13 13:12:52 +00:00
Campbell
af30111b1c feat: Add incorrect case diagnostics for enum variant fields and all variables 2024-07-13 21:54:22 +12:00
bors
9ca33a9b21 Auto merge of #127397 - jyn514:multi-thread-panic-hook, r=workingjubilee
fix interleaved output in the default panic hook when multiple threads panic simultaneously

previously, we only held a lock for printing the backtrace itself. since all threads were printing to the same file descriptor, that meant random output in the default panic hook from one thread would be interleaved with the backtrace from another. now, we hold the lock for the full duration of the hook, and the output is ordered.

---

i noticed some odd things while working on this you may or may not already be aware of.

- libbacktrace is included as a submodule instead of a normal rustc crate, and as a result uses `cfg(backtrace_in_std)` instead of a more normal `cfg(feature = "rustc-dep-of-std")`. probably this is left over from before rust used a cargo-based build system?
- the default panic handler uses `trace_unsynchronized`, etc, in `sys::backtrace::print`. as a result, the lock only applies to concurrent *panic handlers*, not concurrent *threads*.  in other words, if another, non-panicking, thread tried to print a backtrace at the same time as the panic handler, we may have UB, especially on windows.
    - we have the option of changing backtrace to enable locking when `backtrace_in_std` is set so we can reuse their lock instead of trying to add our own.
2024-07-13 03:42:24 +00:00
bors
8efe8a8528
Trigger VSCode to rename after extract variable assist is applied
When the user applies the "Extract Variable" assist, the cursor is
positioned at the newly inserted variable. This commit adds a command
to the assist that triggers the rename action in VSCode. This way, the
user can quickly rename the variable after applying the assist.

Fixes part of: #17579
2024-07-12 19:06:19 -07:00
bors
d4d2c45ef3 Auto merge of #126606 - zachs18:patch-2, r=joboet
Guard against calling `libc::exit` multiple times on Linux.

Mitigates (but does not fix) #126600 by ensuring only one thread which calls Rust `exit` actually calls `libc::exit`, and all other callers of Rust `exit` block.
2024-07-13 01:18:59 +00:00
Shoyu Vanilla
b238855892 Allow macro expansions into RestPat in tuple args work as ellipsis like plain RestPat 2024-07-13 07:09:17 +09:00
bors
498345715e Auto merge of #123351 - beetrees:x86-ret-snan-rust, r=nikic,workingjubilee
Ensure floats are returned losslessly by the Rust ABI on 32-bit x86

Solves #115567 for the (default) `"Rust"` ABI. When compiling for 32-bit x86, this PR changes the `"Rust"` ABI to return floats indirectly instead of in x87 registers (with the exception of single `f32`s, which this PR returns in general purpose registers as they are small enough to fit in one). No change is made to the `"C"` ABI as that ABI requires x87 register usage and therefore will need a different solution.
2024-07-12 20:36:43 +00:00
bors
8365154f7d Auto merge of #127636 - nnethercote:fix-Parser-look_ahead, r=oli-obk
Fix `Parser::look_ahead`

`Parser::look_ahead` has a slow but simple general case, and a fast special case that is hit most of the time. But the special case is buggy and behaves differently to the general case. There are also no unit tests. This PR fixes all of this, resulting in a `Parser::look_ahead` that is equally fast, slightly simpler, more correct, and better tested.

r? `@davidtwco`
2024-07-12 17:28:21 +00:00
Lukas Wirth
dd626e78c7 Fix cloning Symbols not increasing their ref count 2024-07-12 17:13:12 +02:00
Lukas Wirth
3fe815b0f3 Use Symbol in Name 2024-07-12 16:06:44 +02:00
Lukas Wirth
843806b79f Add missing docs 2024-07-12 16:01:47 +02:00
Lukas Wirth
6275eb140e Implement rough symbol interning infra 2024-07-12 16:01:47 +02:00
bors
ffbc5ad993 Auto merge of #17581 - lnicola:sync-from-rust, r=lnicola
minor: Sync from rust
2024-07-11 17:10:09 +00:00
Laurențiu Nicola
bd6de0cb57 Merge from rust-lang/rust 2024-07-11 20:06:05 +03:00
Laurențiu Nicola
206730b2d3 Preparing for merge from rust-lang/rust 2024-07-11 20:05:52 +03:00
bors
886248d683 Auto merge of #127487 - tgross35:f16-f128-simd, r=Amanieu
Add `f16` and `f128` as simd types in LLVM

`@sayantn` is working on adding SIMD for `f16` and hitting the `FloatingPointVector` error. This should fix it and unblock adding support for `simd_fma` and `simd_fabs` in stdarch.
2024-07-11 14:08:58 +00:00
bors
5577e4e3b1 Auto merge of #17571 - winstxnhdw:bool-to-enum-no-dupe, r=Veykril
feat: do not add new enum if it already exists

## Summary

This PR introduces a check for the existence of another enum within the current scope, and if it exist, we skip `add_enum_def`.

## Why?

Currently, when using the `bool_to_enum` assist more than once, it is possible to add multiple enum definitions. For example, the following snippet,

```rs
#[derive(PartialEq, Eq)]
enum Bool {
    True,
    False,
}

fn main() {
    let a = Bool::True;
    let b = true;
    println!("Hello, world!");
}
```

will be transformed into,

```rs
#[derive(PartialEq, Eq)]
enum Bool {
    True,
    False,
}

#[derive(PartialEq, Eq)]
enum Bool {
    True,
    False,
}

fn main() {
    let a = Bool::True;
    let b = Bool::True;
    println!("Hello, world!");
}
```

This can be annoying for users to clean up.
2024-07-11 08:55:34 +00:00
bors
5ed3e05fe5 Auto merge of #127097 - compiler-errors:async-closure-lint, r=oli-obk
Implement simple, unstable lint to suggest turning closure-of-async-block into async-closure

We want to eventually suggest people to turn `|| async {}` to `async || {}`. This begins doing that. It's a pretty rudimentary lint, but I wanted to get something down so I wouldn't lose the code.

Tracking:
* #62290
2024-07-11 06:59:10 +00:00
winstxnhdw
c4bcec214a refactor: search for enum semantically 2024-07-10 21:13:13 +01:00
bors
9a48173e3b Auto merge of #127419 - trevyn:issue-125446, r=fee1-dead
Add suggestions for possible missing `fn`, `struct`, or `enum` keywords

Closes #125446
Closes #65381
2024-07-10 18:27:32 +00:00
bors
13ac073ea9 Auto merge of #17576 - Veykril:landing-page, r=Veykril
internal: Remove faq landing page, improve main one

Having more than one is potentialyl annoying as both will get opened upon install, using walkthroughs for this is not ideal. So this merges the two and also adds a couple tips, fixes https://github.com/rust-lang/rust-analyzer/issues/17569
2024-07-10 17:21:44 +00:00