Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Rollup of 15 pull requests #138072

Closed
wants to merge 38 commits into from
Closed

Conversation

jieyouxu
Copy link
Member

@jieyouxu jieyouxu commented Mar 5, 2025

Successful merges:

r? @ghost
@rustbot modify labels: rollup

Create a similar rollup

arlosi and others added 30 commits February 20, 2025 11:47
All other methods in this file have #[inline] and these methods are very
similar to those of &[u8] which are already inlined here.
This patch makes BufReader::peek()'s doctest call read_more() to refill
the buffer before the inner reader hits EOF. This exposes a bug in
read_more() that causes an out-of-bounds slice access and segfault.
Buffer::read_more() is supposed to refill the buffer without discarding
its contents, which are in the range `pos .. filled`.

It mistakenly borrows the range `pos ..`, fills that, and then
increments `filled` by the amount read. This overwrites the buffer's
existing contents and sets `filled` to a too-large value that either
exposes uninitialized bytes or walks off the end of the buffer entirely.

This patch makes it correctly fill only the unfilled portion of the
buffer, which should maintain all the type invariants and fix the test
failure introduced in commit b119671.
This will help stabilization of lld.
…er, r=oli-obk

Implement `&pin const self` and `&pin mut self` sugars

This PR implements part of rust-lang#130494.

It introduces the sugars `&pin const self` and `&pin mut self` for `self: Pin<&Self>` and `self: Pin<&mut Self>`.
…rsors, r=joboet

Override default `Write` methods for cursor-like types

Override the default `io::Write` methods for cursor-like types to provide more efficient versions.

Writes to resizable containers already write everything, so implement `write_all` and `write_all_vectored` in terms of those. For fixed-sized containers, cut out unnecessary error checking and looping for those same methods.

| `impl Write for T`              | `vectored` | `all` | `all_vectored` | `fmt`   |
| ------------------------------- | ---------- | ----- | -------------- | ------- |
| `&mut [u8]`                     | Y          | Y     | new            |         |
| `Vec<u8>`                       | Y          | Y     | new            | rust-lang#137762 |
| `VecDeque<u8>`                  | Y          | Y     | new            | rust-lang#137762 |
| `std::io::Cursor<&mut [u8]>`    | Y          | new   | new            |         |
| `std::io::Cursor<&mut Vec<u8>>` | Y          | new   | new            | rust-lang#137762 |
| `std::io::Cursor<Vec<u8>>`      | Y          | new   | new            | rust-lang#137762 |
| `std::io::Cursor<Box<[u8]>>`    | Y          | new   | new            |         |
| `std::io::Cursor<[u8; N]>`      | Y          | new   | new            |         |
| `core::io::BorrowedCursor<'_>`  | new        | new   | new            |         |

Tracked in rust-lang#136756.

# Open questions

Is it guaranteed by `Write::write_all` that the maximal write is performed when not everything can be written? Its documentation describes the behavior of the default implementation, which writes until a 0-length write is encountered, thus implying that a maximal write is expected. In contrast, `Read::read_exact` declares that the contents of the buffer are unspecified for short reads. If it were allowed, these cursor-like types could bail on the write altogether if it has insufficient capacity.
…gillot

Remove `MaybeForgetReturn` suggestion

rust-lang#115196 implemented a suggestion to add a missing `return` when there is an ambiguity error, when that ambiguity error could be constrained by the return type of the function.

I initially reviewed it and thought it could be useful; however, looking back at that code now, I feel like it's a bit too much of a hack to be worth keeping around in typeck, especially given how rare it's expected to fire in practice. This is especially true because it depends on `StashKey::MaybeForgetReturn`, which is only stashed when we have *Sized* obligation ambiguity errors. Let's remove it for now.

I'd like to note that it's basically impossible to get this suggestion to apply in its current state except for what I'd consider somewhat artificial examples, involving no generic trait bounds. For example, it's not triggered for:

```rust
struct W<T>(T);

fn bar<T: Default>() -> W<T> { todo!() }

fn foo() -> W<i32> {
    if true {
        bar();
    }
    W(0)
}
```

Nor is it triggered for:

```
fn foo() -> i32 {
    if true {
        Default::default();
    }
    0
}
```

It's basically only triggered iff there's only one ambiguity error on the type, which is `Sized`.

Generally, suggesting something that affects control flow is a pretty dramatic suggestion; therefore, both the accuracy and precision of this diagnostic should be pretty high.

One other, somewhat unrelated observation is that this might be using stashed diagnostics incorrectly (or at least unnecessarily). Stashed diagnostics are used when error detection is fragmented over several major stages of the compiler, like a parse or resolver error which later can be recovered in typeck. However, this one is a bit different since it is fully handled within typeck -- perhaps that suggests that if this were to be reimplemented, it wouldn't need to be so complicated of an implementation.
Undeprecate env::home_dir

rust-lang#132515 fixed the implementation of `env::home_dir`, but didn't remove the deprecation.

Based on [this comment](rust-lang#132515 (comment)), libs-api decided to undeprecate in the next release. Let's do that!

cc rust-lang#132650
…es, r=Nadrieril

Match Ergonomics 2024: add context and examples to the unstable book

The examples here are pretty limited and don't illustrate the differences between the two feature gates, but my hope is that they get the general idea across. I can try and add some more nuance or more comprehensive examples too if that would help.

Hopefully the doctest isn't too sneaky. I wanted to make the bindings' types explicit, and the most readable way I could think of was to use a helper.

~~Unfortunately it looks like the "run this code" button doesn't work yet, but I made sure the examples are cross-edition, so that should resolve on its own once playground's nightly updates (or if playground's default becomes edition 2024, or if the edition in the markdown gets forwarded to playground).~~ It looks like the default edition on playground is now 2024, so the run button works! There's no output, but having a button to show that it compiles is nice, I think.

Relevant tracking issue: rust-lang#123076

r? ```@Nadrieril```
Try to point of macro expansion from resolver and method errors if it involves macro var

In the case that a macro caller passes an identifier into a macro generating a path or method expression, point out that identifier in the context of the *macro* so it's a bit more clear how the macro is involved in causing the error.

r? ```````@estebank``````` or reassign
jieyouxu added 8 commits March 6, 2025 06:26
…star, r=oli-obk

Check dyn flavor before registering upcast goal on wide pointer cast in MIR typeck

See the comment on the test :)

Fixes rust-lang#137579
…t, r=jieyouxu

Add DWARF test case for non-C-like `repr128` enums

LLVM 20 fixes DWARF debuginfo for non-C-like 128-bit enums: this PR adds a test case to the `repr128-dwarf` test to ensure that LLVM doesn't regress in the future.

Tracking issue: rust-lang#56071
self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux

To help stabilization, this PR disables an LLD optimization on  x64 linux with respect to `--gc-sections` and encapsulation symbols: it will reduce the number of crates needing to opt-out of lld due to this bfd / lld difference. For example, all the people using [linkme](https://github.com/dtolnay/linkme), which [doesn't work with lld](dtolnay/linkme#63) or on nightly, need to disable lld.

More information about all this, and the historical differences, can be found in:
- https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order
- https://lld.llvm.org/ELF/start-stop-gc

This optimization has [no visible impact](rust-lang#137685 (comment)) on our benchmarks, so we can use it by default and have a safer/more conservative starting point to remove friction during migration. We can them emit an FCW for the cases where lld detects reliance on encapsulation symbols without `-znostart-stop-gc`, and then revert back to lld's default after a while. No one compiling on nightly relies on this difference, obviously, so doing an FCW is not necessary until after lld is used on stable.

I've tested that this correctly links on `linkme` examples. I've also quickly tried to crate an rmake test but the setup with encapsulation symbols is annoying to reproduce: a few link section/name attributes is not enough, we also need to collect symbols between the encapsulation symbols, without referencing them in code, for `-znostart-stop-gc` to only impact this... It should of course be doable though, maybe ``@Kobzol`` will look into it if they have time.

r? ``@petrochenkov``
Re-add `Clone`-derive on `Thir`

This PR adds back `Clone` for `Thir`.

If a tool wants to access a `thir_body` query result in the `Callbacks::after_analysis` hook, it can't do so (I think) without a `Clone` impl on `Thir`, because `check_unsafety` steals the value. With `Clone`, the `thir_body` query provider can be overriden to cache a clone of the `Thir`, circumventing that issue.

Specifically, we need it for https://github.com/rust-corpus/qrates, [here](https://github.com/skius/qrates/blob/ca7a2301968a43862f2c04daffed71a9de8c333c/extractor/src/lib.rs#L205).

Please let me know if there are issues with this PR/if there's another way to solve the problem at hand
…cote

fix usage of ty decl macro fragments in attributes

See the test case. Due to one missing code path (and also the changes in rust-lang#137517), using $ty or other specific fragments as part of an attr wouldn't work. $tt used to work since it wouldn't be parsed anywhere along the way.

Closes rust-lang#137662
Add timestamp to unstable feature usage metrics

part of rust-lang#129485

with this we should be able to temporarily enable metrics on docs.rs to gather a nice test dataset for the initial PoC dashboard

r? ``@estebank``
Fix crash in BufReader::peek()

`bufreader_peek` tracking issue: rust-lang#128405

This fixes a logic error in `Buffer::read_more()` that would make `BufReader::peek()` expose uninitialized data and/or segfault if `read_more()` was called with a partially-full buffer and a non-empty inner reader.
strip `-Wlinker-messages` wrappers from `rust-lld` rmake test

The `tests/run-make/rust-lld` rmake test is failing locally on my M1, due to linker messages being in a different shape than the test expects: it asserts that the LLD version is the first linker message, which is seemingly not always the case on osx I guess.

```console
thread 'main' panicked at /Users/lqd/rust/lqd-rust/tests/run-make/rust-lld/rmake.rs:24:5:
the LLD version string should be present in the output logs:
warning: linker stderr: rust-lld: directory not found for option -L/usr/local/lib
         LLD 20.1.0 (https://github.com/rust-lang/llvm-project.git 1c3bb96fdb6db7b8e8f24edb016099c223fdd27e)
         Library search paths:
             /Users/lqd/rust/lqd-rust/build/aarch64-apple-darwin/test/run-make/rust-lld/rmake_out
             /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib
         Framework search paths:
             /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
```

This PR normalizes away the `-Wlinker-messages` wrappers around the linker output, to remove the requirement that the linker version is the first linker message / is prefixed with the warning wrapper in the regex.

(also another strange thing to explain the pre-existing regex: it seems the LLD version is sometimes output on stderr sometimes on stdout cool stuff)

We could do this for the other lld rmake tests, but they're only enabled on x64 linux so less likely to have random linker messages appearing without anyone noticing.
@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. rollup A PR which is a rollup labels Mar 5, 2025
@jieyouxu
Copy link
Member Author

jieyouxu commented Mar 5, 2025

@bors r+ rollup=never p=5

@bors
Copy link
Contributor

bors commented Mar 5, 2025

📌 Commit 97ae7d6 has been approved by jieyouxu

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 Mar 5, 2025
@jieyouxu
Copy link
Member Author

jieyouxu commented Mar 5, 2025

Actually @bors r- (won't be around to triage this timely)

@jieyouxu jieyouxu closed this Mar 5, 2025
@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 Mar 5, 2025
@jieyouxu jieyouxu deleted the rollup-0yj9u9b branch March 5, 2025 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-run-make Area: port run-make Makefiles to rmake.rs 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-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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.