Skip to content

Rollup of 7 pull requests #137236

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 30 commits into from

Conversation

matthiaskrgr
Copy link
Member

Successful merges:

r? @ghost
@rustbot modify labels: rollup

Create a similar rollup

elichai and others added 30 commits October 28, 2024 17:28
Const-stabilizes `slice::as_flattened{,_mut}`:
```rust
// core::slice
impl<T, const N: usize> [[T; N]] {
    pub const fn as_flattened(&self) -> &[T];
    pub const fn as_flattened_mut(&mut self) -> &mut [T];
}
```

Tracking issue: rust-lang#95629

Requires separate libs-api FCP, as per rust-lang#95629 (comment).

Closes rust-lang#95629.
When `Foo.field` or `Foo.method()` exprs are encountered, suggest `Foo::field` or `Foo::method()` when Foo is a type alias, not just
a struct, trait, or module.

Also rename test for this suggestion from issue-22692.rs to something more meaningful.
Suggest replacing `.` with `::` when encountering "expected value, found enum":
- in a method-call expression and the method has the same name as a tuple variant
- in a field-access expression and the field has the same name as a unit or tuple variant
…cro giving a type,

make it also work when the rhs is a type alias, not just a struct.
…l` field in `LayoutData`.

Also update comments that refered to BackendRepr::Uninhabited.
Add codegen test for uninhabited PassMode::Indirect return types.
* Order IDEs alphabetically so that manually searching for an IDE
  is easier, both when running `./x setup` and when editing the
  source code behind `./x setup`
* Prepare for IDEs with spaces in their names
* Allow explicitly typing 'none' for the IDE
* Change capitalization of `Vscode` to the more standard `VsCode`
* Make minor efficiency improvements
* Add `'static` annotations where they apply
* Order items as the average of the two adaptors. Enables easier diffs.
* Consistently apply #[inline].
* Implement FromInner<Vec<u8>> for bytes::Buf.
* Implement Clone::clone_from for wtf8::Buf.
Co-authored-by: Jubilee <workingjubilee@gmail.com>
Added project-specific Zed IDE settings

This repository currently has project-specific VS Code IDE settings in `.vscode` and `compiler/rustc_codegen_cranelift/.vscode`. Now there are equivalent project-specific Zed IDE settings alongside those.

This fixes `rust-analyzer` not being able to properly handle this project.

Note that:

1. The contents of `src/tools/rust-analyzer/.vscode` could not be translated to Zed, as they aren't basic IDE settings.
2. One of the VS Code settings in `.vscode` has no corresponding setting in Zed, and so this has been noted like this:

    ```json
      "_settings_only_in_vs_code_not_yet_in_zed": {
        "git.detectSubmodulesLimit": 20
      },
    ```
…nieu

Impl TryFrom<Vec<u8>> for String

I think this is useful enough to have :)
As a general question, is there any policy around adding "missing" trait implementations? (like adding `AsRef<T> for T` for std types), I mostly stumble upon them when using a lot of "impl Trait in argument position" like (`foo: impl Into<String>`)
…en, r=Amanieu

Stabilize const_slice_flatten

Const-stabilizes `slice::as_flattened{,_mut}`:
```rust
// core::slice
impl<T, const N: usize> [[T; N]] {
    pub const fn as_flattened(&self) -> &[T];
    pub const fn as_flattened_mut(&mut self) -> &mut [T];
}
```

Tracking issue: rust-lang#95629

Requires separate FCP, as per rust-lang#95629 (comment).

Closes rust-lang#95629.

```@rustbot``` modify labels: +T-libs-api

Happy new year!
…_3, r=davidtwco

Suggest replacing `.` with `::` in more error diagnostics.

First commit makes the existing "help: use the path separator to refer to an item" also work when the base is a type alias, not just a trait/module/struct.

The existing unconditional `DefKind::Mod | DefKind::Trait` match arm is changed to a conditional `DefKind::Mod | DefKind::Trait | DefKind::TyAlias` arm that only matches if the `path_sep` suggestion-adding closure succeeds, so as not to stop the later `DefKind::TyAlias`-specific suggestions if the path-sep suggestion does not apply. This shouldn't change behavior for `Mod` or `Trait` (due to the default arm's `return false` etc).

This commit also updates `tests/ui/resolve/issue-22692.rs` to reflect this, and also renames it to something more meaningful.

This commit also makes the `bad_struct_syntax_suggestion` closure take `err` as a parameter instead of capturing it, since otherwise caused borrowing errors due to the change to using `path_sep` in a pattern guard.

<details> <summary> Type alias diagnostic example </summary>

```rust
type S = String;

fn main() {
    let _ = S.new;
}
```

```diff
 error[E0423]: expected value, found type alias `S`
  --> diag7.rs:4:13
   |
 4 |     let _ = S.new;
   |             ^
   |
-  = note: can't use a type alias as a constructor
+  help: use the path separator to refer to an item
+  |
+4 |     let _ = S::new;
+  |              ~~
```

</details>

Second commit adds some cases for `enum`s, where if there is a field/method expression where the field/method has the name of a unit/tuple variant, we assume the user intended to create that variant[^1] and suggest replacing the `.` from the field/method suggestion with a `::` path separator. If no such variant is found (or if the error is not a field/method expression), we give the existing suggestion that suggests adding `::TupleVariant(/* fields */)` after the enum.

<details> <summary> Enum diagnostic example </summary>

```rust
enum Foo {
    A(u32),
    B,
    C { x: u32 },
}

fn main() {
    let _ = Foo.A(42); // changed
    let _ = Foo.B;     // changed
    let _ = Foo.D(42); // no change
    let _ = Foo.D;     // no change
    let _ = Foo(42);   // no change
}
```

```diff
 error[E0423]: expected value, found enum `Foo`
  --> diag8.rs:8:13
   |
 8 |     let _ = Foo.A(42); // changed
   |             ^^^
   |
 note: the enum is defined here
  --> diag8.rs:1:1
   |
 1 | / enum Foo {
 2 | |     A(u32),
 3 | |     B,
 4 | |     C { x: u32 },
 5 | | }
   | |_^
-help: you might have meant to use the following enum variant
-  |
-8 |     let _ = Foo::B.A(42); // changed
-  |             ~~~~~~
-help: alternatively, the following enum variant is available
+help: use the path separator to refer to a variant
   |
-8 |     let _ = (Foo::A(/* fields */)).A(42); // changed
-  |             ~~~~~~~~~~~~~~~~~~~~~~
+8 |     let _ = Foo::A(42); // changed
+  |                ~~

 error[E0423]: expected value, found enum `Foo`
  --> diag8.rs:9:13
   |
 9 |     let _ = Foo.B;     // changed
   |             ^^^
   |
 note: the enum is defined here
  --> diag8.rs:1:1
   |
 1 | / enum Foo {
 2 | |     A(u32),
 3 | |     B,
 4 | |     C { x: u32 },
 5 | | }
   | |_^
-help: you might have meant to use the following enum variant
-  |
-9 |     let _ = Foo::B.B;     // changed
-  |             ~~~~~~
-help: alternatively, the following enum variant is available
+help: use the path separator to refer to a variant
   |
-9 |     let _ = (Foo::A(/* fields */)).B;     // changed
-  |             ~~~~~~~~~~~~~~~~~~~~~~
+9 |     let _ = Foo::B;     // changed
+  |                ~~

 error[E0423]: expected value, found enum `Foo`
   --> diag8.rs:10:13
    |
 10 |     let _ = Foo.D(42); // no change
    |             ^^^
    |
 note: the enum is defined here
   --> diag8.rs:1:1
    |
 1  | / enum Foo {
 2  | |     A(u32),
 3  | |     B,
 4  | |     C { x: u32 },
 5  | | }
    | |_^
 help: you might have meant to use the following enum variant
    |
 10 |     let _ = Foo::B.D(42); // no change
    |             ~~~~~~
 help: alternatively, the following enum variant is available
    |
 10 |     let _ = (Foo::A(/* fields */)).D(42); // no change
    |             ~~~~~~~~~~~~~~~~~~~~~~

 error[E0423]: expected value, found enum `Foo`
   --> diag8.rs:11:13
    |
 11 |     let _ = Foo.D;     // no change
    |             ^^^
    |
 note: the enum is defined here
   --> diag8.rs:1:1
    |
 1  | / enum Foo {
 2  | |     A(u32),
 3  | |     B,
 4  | |     C { x: u32 },
 5  | | }
    | |_^
 help: you might have meant to use the following enum variant
    |
 11 |     let _ = Foo::B.D;     // no change
    |             ~~~~~~
 help: alternatively, the following enum variant is available
    |
 11 |     let _ = (Foo::A(/* fields */)).D;     // no change
    |             ~~~~~~~~~~~~~~~~~~~~~~

 error[E0423]: expected function, tuple struct or tuple variant, found enum `Foo`
   --> diag8.rs:12:13
    |
 12 |     let _ = Foo(42);   // no change
    |             ^^^ help: try to construct one of the enum's variants: `Foo::A`
    |
    = help: you might have meant to construct the enum's non-tuple variant
 note: the enum is defined here
   --> diag8.rs:1:1
    |
 1  | / enum Foo {
 2  | |     A(u32),
 3  | |     B,
 4  | |     C { x: u32 },
 5  | | }
    | |_^

 error: aborting due to 5 previous errors
```

</details>

[^1]: or if it's a field expression and a tuple variant, that they meant to refer the variant constructor.
…bited, r=workingjubilee

Do not ignore uninhabited types for function-call ABI purposes. (Remove BackendRepr::Uninhabited)

Accepted MCP: rust-lang/compiler-team#832

Fixes rust-lang#135802

Do not consider the inhabitedness of a type for function call ABI purposes.

* Remove the [`rustc_abi::BackendRepr::Uninhabited`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/enum.BackendRepr.html) variant
  * Instead calculate the `BackendRepr` of uninhabited types "normally" (as though they were not uninhabited "at the top level", but still considering inhabitedness of variants to determine enum layout, etc)
* Add an `uninhabited: bool` field to [`rustc_abi::LayoutData`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/struct.LayoutData.html) so inhabitedness of a `LayoutData` can still be queried when necessary (e.g. when determining if an enum variant needs a tag value allocated to it).

This should not affect type layouts (size/align/field offset); this should only affect function call ABI, and only of uninhabited types.

cc `@RalfJung`
…Denton

Organize `OsString`/`OsStr` shims

Synchronize the `bytes.rs` and `wtf8.rs` shims for `OsString`/`OsStr` so they're easier to diff between each other. This is mostly ordering items the same between the two. I tried to minimize moves and went for the average locations between the files.

With them in the same order, it is clear that `FromInner<_>` is not implemented for `bytes::Buf` and `Clone::clone_from` is not implemented for `wtf8::Buf`, but they are for the other. Fix that.

I added #[inline] to all inherent methods of the `OsString`/`OsStr` shims, because it seemed that was already the rough pattern. `bytes.rs` has more inlining than `wtf8.rs`, so I added the corresponding ones to `wtf8.rs`. Then, the common missing ones have no discernible pattern to me. They're not divided by non-allocating/allocating. Perhaps the pattern is that UTF-8 validation isn't inlined? Since these types are merely the inner values in `OsStr`/`OsString`, I put inline on all methods and let those public types dictate inlining. I have not inspected codegen or run benchmarks.

Also, touch up some (private) documentation comments.

r? ```@ChrisDenton```
…er-errors

docs(dev): Update the feature-gate instructions

`features_untracked` was removed in rust-lang#114723

features are now functions as of  rust-lang#132027
@rustbot rustbot added A-rustc-dev-guide Area: rustc-dev-guide A-tidy Area: The tidy tool S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. rollup A PR which is a rollup labels Feb 18, 2025
@matthiaskrgr
Copy link
Member Author

@bors r+ rollup=never p=5

@bors
Copy link
Collaborator

bors commented Feb 18, 2025

📌 Commit 4f7987b has been approved by matthiaskrgr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 18, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Feb 18, 2025

#136344 tests/ui/resolve/enum-expected-value-suggest-variants.rs failed.
@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 18, 2025
@jieyouxu jieyouxu closed this Feb 18, 2025
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-18 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#21 exporting to docker image format
#21 sending tarball 28.3s done
#21 DONE 35.6s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-18]
debug: `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` configured.
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-18', '--enable-llvm-link-shared', '--set', 'rust.randomize-layout=true', '--set', 'rust.thin-lto-import-instr-limit=10', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'rust.lld=false', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-18/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.randomize-layout := True
configure: rust.thin-lto-import-instr-limit := 10
---

105    | |_^
106 help: you might have meant to use one of the following enum variants
107    |
- LL -     let _: Bar = Bar.Bad(0);
- LL +     let _: Bar = Bar::E.Bad(0);
-    |
- LL -     let _: Bar = Bar.Bad(0);
- LL +     let _: Bar = Bar::F.Bad(0);
-    |
+ LL |     let _: Bar = Bar::E.Bad(0);
+    |                     +++
+ LL |     let _: Bar = Bar::F.Bad(0);
114 help: alternatively, the following enum variants are also available
115    |
115    |
116 LL -     let _: Bar = Bar.Bad(0);
138    | |_^
139 help: you might have meant to use one of the following enum variants
140    |
140    |
- LL -     let _: Bar = Bar.Bad;
- LL +     let _: Bar = Bar::E.Bad;
-    |
- LL -     let _: Bar = Bar.Bad;
- LL +     let _: Bar = Bar::F.Bad;
-    |
+ LL |     let _: Bar = Bar::E.Bad;
+    |                     +++
+ LL |     let _: Bar = Bar::F.Bad;
147 help: alternatively, the following enum variants are also available
148    |
148    |
149 LL -     let _: Bar = Bar.Bad;
181    | |_^
182 help: try to match against one of the enum's variants
183    |
183    |
- LL -         Foo(..) => {}
- LL +         Foo::A(..) => {}
-    |
- LL -         Foo(..) => {}
- LL +         Foo::B(..) => {}
-    |
+ LL |         Foo::A(..) => {}
+    |            +++
+ LL |         Foo::B(..) => {}
190 
191 error[E0423]: expected function, tuple struct or tuple variant, found enum `Foo`
192   --> $DIR/enum-expected-value-suggest-variants.rs:15:18


205    | |_^
206 help: try to construct one of the enum's variants
207    |
- LL -     let _: Foo = Foo(0);
- LL +     let _: Foo = Foo::A(0);
- LL -     let _: Foo = Foo(0);
- LL -     let _: Foo = Foo(0);
- LL +     let _: Foo = Foo::B(0);
-    |
+ LL |     let _: Foo = Foo::A(0);
+    |                     +++
+ LL |     let _: Foo = Foo::B(0);
214 
215 error[E0423]: expected function, tuple struct or tuple variant, found enum `Bar`
216   --> $DIR/enum-expected-value-suggest-variants.rs:27:18


231    | |_^
232 help: try to construct one of the enum's variants
233    |
- LL -     let _: Bar = Bar(0);
- LL +     let _: Bar = Bar::C(0);
- LL -     let _: Bar = Bar(0);
- LL -     let _: Bar = Bar(0);
- LL +     let _: Bar = Bar::D(0);
-    |
+ LL |     let _: Bar = Bar::C(0);
+    |                     +++
+ LL |     let _: Bar = Bar::D(0);
240 
241 error: aborting due to 10 previous errors
242 



The actual stderr differed from the expected stderr.
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args resolve/enum-expected-value-suggest-variants.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/resolve/enum-expected-value-suggest-variants.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/resolve/enum-expected-value-suggest-variants" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers"
--- stderr -------------------------------
error[E0423]: expected value, found enum `Foo`
##[error]  --> /checkout/tests/ui/resolve/enum-expected-value-suggest-variants.rs:19:18
   |
   |
LL |     let _: Foo = Foo.A(0);
   |
note: the enum is defined here
  --> /checkout/tests/ui/resolve/enum-expected-value-suggest-variants.rs:1:1
   |
---
LL | | }
   | |_^
help: use the path separator to refer to a variant
   |
LL -     let _: Foo = Foo.A(0);
LL +     let _: Foo = Foo::A(0);

error[E0423]: expected value, found enum `Foo`
##[error]  --> /checkout/tests/ui/resolve/enum-expected-value-suggest-variants.rs:23:18
   |
   |
LL |     let _: Foo = Foo.Bad(0);
   |
note: the enum is defined here
  --> /checkout/tests/ui/resolve/enum-expected-value-suggest-variants.rs:1:1
   |
---
LL | | }
   | |_^
help: the following enum variants are available
   |
LL -     let _: Foo = Foo.Bad(0);
LL +     let _: Foo = (Foo::A(/* fields */)).Bad(0);
   |
LL -     let _: Foo = Foo.Bad(0);
LL +     let _: Foo = (Foo::B(/* fields */)).Bad(0);

error[E0423]: expected value, found enum `Bar`
##[error]  --> /checkout/tests/ui/resolve/enum-expected-value-suggest-variants.rs:32:18
   |
---
LL | | }
   | |_^
help: use the path separator to refer to a variant
   |
LL -     let _: Bar = Bar.C(0);
LL +     let _: Bar = Bar::C(0);

error[E0423]: expected value, found enum `Bar`
##[error]  --> /checkout/tests/ui/resolve/enum-expected-value-suggest-variants.rs:36:18
   |
---

error[E0423]: expected value, found enum `Bar`
##[error]  --> /checkout/tests/ui/resolve/enum-expected-value-suggest-variants.rs:40:18
   |
LL |     let _: Bar = Bar.Bad(0);
   |
note: the enum is defined here
  --> /checkout/tests/ui/resolve/enum-expected-value-suggest-variants.rs:7:1
   |
---
LL | | }
   | |_^
help: you might have meant to use one of the following enum variants
   |
LL |     let _: Bar = Bar::E.Bad(0);
   |                     +++
LL |     let _: Bar = Bar::F.Bad(0);
help: alternatively, the following enum variants are also available
   |
   |
LL -     let _: Bar = Bar.Bad(0);
LL +     let _: Bar = (Bar::C(/* fields */)).Bad(0);
   |
LL -     let _: Bar = Bar.Bad(0);
LL +     let _: Bar = (Bar::D(/* fields */)).Bad(0);

error[E0423]: expected value, found enum `Bar`
##[error]  --> /checkout/tests/ui/resolve/enum-expected-value-suggest-variants.rs:45:18
   |
---
LL | | }
   | |_^
help: you might have meant to use one of the following enum variants
   |
LL |     let _: Bar = Bar::E.Bad;
   |                     +++
LL |     let _: Bar = Bar::F.Bad;
help: alternatively, the following enum variants are also available
   |
   |
LL -     let _: Bar = Bar.Bad;
LL +     let _: Bar = (Bar::C(/* fields */)).Bad;
   |
LL -     let _: Bar = Bar.Bad;
LL +     let _: Bar = (Bar::D(/* fields */)).Bad;

error[E0531]: cannot find tuple struct or tuple variant `A` in this scope
##[error]  --> /checkout/tests/ui/resolve/enum-expected-value-suggest-variants.rs:51:9
   |
---
LL | | }
   | |_^
help: try to match against one of the enum's variants
   |
LL |         Foo::A(..) => {}
LL |         Foo::B(..) => {}
   |            +++

error[E0423]: expected function, tuple struct or tuple variant, found enum `Foo`
---
LL | | }
   | |_^
help: try to construct one of the enum's variants
   |
LL |     let _: Foo = Foo::A(0);
LL |     let _: Foo = Foo::B(0);
   |                     +++

error[E0423]: expected function, tuple struct or tuple variant, found enum `Bar`
---
LL | | }
   | |_^
help: try to construct one of the enum's variants
   |
LL |     let _: Bar = Bar::C(0);
   |                     +++
LL |     let _: Bar = Bar::D(0);

error: aborting due to 10 previous errors

Some errors have detailed explanations: E0423, E0531, E0532.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-rustc-dev-guide Area: rustc-dev-guide A-tidy Area: The tidy tool rollup A PR which is a rollup S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.