Skip to content

Conversation

@pull
Copy link

@pull pull bot commented Nov 4, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

Kivooeo and others added 23 commits October 25, 2025 13:27
When a binding needs to be mutably reborrowed multiple times, suggesting removing `&mut` will lead to follow up errors. Instead suggest both making the binding mutable and removing the reborrow.

```
error[E0596]: cannot borrow `outer` as mutable, as it is not declared as mutable
 --> f14.rs:2:12
  |
2 |     match (&mut outer, 23) {
  |            ^^^^^^^^^^ cannot borrow as mutable
  |
note: the binding is already a mutable borrow
 --> f14.rs:1:16
  |
1 | fn test(outer: &mut Option<i32>) {
  |                ^^^^^^^^^^^^^^^^
help: consider making the binding mutable if you need to reborrow multiple times
  |
1 | fn test(mut outer: &mut Option<i32>) {
  |         +++
help: if there is only one mutable reborrow, remove the `&mut`
  |
2 -     match (&mut outer, 23) {
2 +     match (outer, 23) {
  |
```
This commit fixes an accidental regression from 144678 where wasm
targets would now accidentally use the wrong import module map for a
symbol causing a symbol to skip mangling. This can result in compilation
failures when symbols are used in cross-crate situations.

Closes 148347
```
error[E0401]: can't use `Self` from outer item
  --> $DIR/E0401.rs:22:25
   |
LL | impl<T> Iterator for A<T> {
   | ---- `Self` type implicitly declared here, by this `impl`
...
LL |         fn helper(sel: &Self) -> u8 {
   |            ------       ^^^^ use of `Self` from outer item
   |            |
   |            `Self` used in this inner function
   |
help: refer to the type directly here instead
   |
LL -         fn helper(sel: &Self) -> u8 {
LL +         fn helper(sel: &A<T>) -> u8 {
   |
```
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
…ouwer,davidtwco

Add LLVM range attributes to slice length parameters

It'll take a bunch more work to do this in layout -- because of cycles in `struct Foo<'a>(&'a Foo<'a>);` -- so until we figure out how to do that well, just look for slices specifically and add the proper range for the length.
Suggest making binding `mut` on `&mut` reborrow

When a binding needs to be mutably reborrowed multiple times, suggesting removing `&mut` will lead to follow up errors. Instead suggest both making the binding mutable and removing the reborrow.

```
error[E0596]: cannot borrow `outer` as mutable, as it is not declared as mutable
 --> f14.rs:2:12
  |
2 |     match (&mut outer, 23) {
  |            ^^^^^^^^^^ cannot borrow as mutable
  |
note: the binding is already a mutable borrow
 --> f14.rs:1:16
  |
1 | fn test(outer: &mut Option<i32>) {
  |                ^^^^^^^^^^^^^^^^
help: consider making the binding mutable if you need to reborrow multiple times
  |
1 | fn test(mut outer: &mut Option<i32>) {
  |         +++
help: if there is only one mutable reborrow, remove the `&mut`
  |
2 -     match (&mut outer, 23) {
2 +     match (outer, 23) {
  |
```

Address #81059.
Port `cfg!()` macro to the new attribute parsing system

r? ``@jdonszelmann``
Add check for `+=` typo in let chains

Fixes #147664

it does affect only cases where variable exist in scope, because if the variable is not exist in scope, the suggestion will not make any sense

I wanted to add suggestion for case where variable does not in scope to fix `y += 1` to `let y = 1` but I guess it's too much (not too much work, but too much wild predict of what user wants)? if it's good addition in your opinion I can add this in follow up

in other things I guess impl is pretty much self-explanatory, if you see there is some possibilities to improve code or/and some _edge-cases_ that I could overlooked feel free to tell about it

ah, also about why I think this change is good and why I originally took it, so it seems to me that this is possible to make this typo (I explained this in comment a little), like, both `+` and `=` is the same button (in most of layouts) and for this reasons I didn't added something like `-=` it seems more harder to make this typo

r? diagnostics
…r=estebank

fix: Only special case single line item attribute suggestions

`rustc` currently special cases suggestions to add [`#[derive(_)]\n` and other attributes](https://github.com/rust-lang/rust/blob/dc1feabef242259d61bd930713de3250577c1c71/compiler/rustc_errors/src/emitter.rs#L2288C36-L2288C72), to add more context to the suggestions.

> // The suggestion adds an entire line of code, ending on a newline, so we'll also
> // print the *following* line, to provide context of what we're advising people to
> // do. Otherwise you would only see contextless code that can be confused for
> // already existing code, despite the colors and UI elements.
> // We special case `#[derive(_)]\n` and other attribute suggestions, because those
> // are the ones where context is most useful.

This special case is a bit broad at the moment and applies to suggestions just to add an attribute, as well as suggestions that contain an attribute and other code, i.e.
```rust
#[derive(Clone)]
```
and
```rust
#[cfg(not(test))]
impl Default for NewWithCfg {
    fn default() -> Self {
        Self::new()
    }
}
```

In the latter case, adding a line for context after the suggestion doesn't provide much benefit. Example:
![temp](https://github.com/user-attachments/assets/6859b400-aa99-4c1b-9eb0-0cd67ae35bf9)

This PR makes it so that this special case only applies to suggestions that just add an attribute and nothing else. This will also make `rustc`'s output match `annotate-snippets`.
reflect that type and const parameter can be intermixed

Also, add reference id
Fix `wasm_import_module` attribute cross-crate

This commit fixes an accidental regression from #144678 where wasm targets would now accidentally use the wrong import module map for a symbol causing a symbol to skip mangling. This can result in compilation failures when symbols are used in cross-crate situations.

Closes #148347
Tweak E0401

More accurate span pointing at use place of outer param (at ident instead of full path).

Add note explaining why outer item params can't be used in inner item.

Use structured suggestion for what `Self` should have been.

Follow up to #148370.

Fix #37892.
Rollup of 7 pull requests

Successful merges:

 - #147141 (Suggest making binding `mut` on `&mut` reborrow)
 - #147945 (Port `cfg!()` macro to the new attribute parsing system )
 - #147951 (Add check for `+=` typo in let chains)
 - #148004 (fix: Only special case single line item attribute suggestions)
 - #148264 (reflect that type and const parameter can be intermixed)
 - #148363 (Fix `wasm_import_module` attribute cross-crate)
 - #148447 (Tweak E0401)

r? `@ghost`
`@rustbot` modify labels: rollup
@pull pull bot locked and limited conversation to collaborators Nov 4, 2025
@pull pull bot added the ⤵️ pull label Nov 4, 2025
@pull pull bot merged commit 5f9dd05 into relaxcn:master Nov 4, 2025
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants