Skip to content

Turn label into structured suggestion for .as_ref() and .as_mut()#153887

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
estebank:as_ref-suggestion
Mar 15, 2026
Merged

Turn label into structured suggestion for .as_ref() and .as_mut()#153887
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
estebank:as_ref-suggestion

Conversation

@estebank
Copy link
Contributor

error[E0382]: use of moved value: `foo`
  --> $DIR/as-ref-2.rs:10:14
   |
LL |     let foo = Some(Struct);
   |         --- move occurs because `foo` has type `Option<Struct>`, which does not implement the `Copy` trait
LL |     let _x: Option<Struct> = foo.map(|s| bar(&s));
   |                                  ---------------- `foo` moved due to this method call
LL |     let _y = foo;
   |              ^^^ value used here after move
   |
note: `Option::<T>::map` takes ownership of the receiver `self`, which moves `foo`
  --> $SRC_DIR/core/src/option.rs:LL:COL
help: consider calling `.as_ref()` to borrow the value's contents
   |
LL |     let _x: Option<Struct> = foo.as_ref().map(|s| bar(&s));
   |                                 +++++++++
help: consider calling `.as_mut()` to mutably borrow the value's contents
   |
LL |     let _x: Option<Struct> = foo.as_mut().map(|s| bar(&s));
   |                                 +++++++++

```
error[E0382]: use of moved value: `foo`
  --> $DIR/as-ref-2.rs:10:14
   |
LL |     let foo = Some(Struct);
   |         --- move occurs because `foo` has type `Option<Struct>`, which does not implement the `Copy` trait
LL |     let _x: Option<Struct> = foo.map(|s| bar(&s));
   |                                  ---------------- `foo` moved due to this method call
LL |     let _y = foo;
   |              ^^^ value used here after move
   |
note: `Option::<T>::map` takes ownership of the receiver `self`, which moves `foo`
  --> $SRC_DIR/core/src/option.rs:LL:COL
help: consider calling `.as_ref()` to borrow the value's contents
   |
LL |     let _x: Option<Struct> = foo.as_ref().map(|s| bar(&s));
   |                                 +++++++++
help: consider calling `.as_mut()` to mutably borrow the value's contents
   |
LL |     let _x: Option<Struct> = foo.as_mut().map(|s| bar(&s));
   |                                 +++++++++
```
@rustbot rustbot added 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. labels Mar 14, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 14, 2026

r? @mati865

rustbot has assigned @mati865.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 15 candidates

Copy link
Member

@JohnTitor JohnTitor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 15, 2026

📌 Commit 7551181 has been approved by JohnTitor

It is now in the queue for this repository.

@rustbot rustbot assigned JohnTitor and unassigned mati865 Mar 15, 2026
@rust-bors rust-bors bot 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 15, 2026
rust-bors bot pushed a commit that referenced this pull request Mar 15, 2026
Rollup of 6 pull requests

Successful merges:

 - #153870 (docs: remove stale reference to `check_let_chain`)
 - #153881 (Provide more context on type errors in const context)
 - #153887 (Turn label into structured suggestion for `.as_ref()` and `.as_mut()`)
 - #153897 (Use less `#[macro_use]` in the query system)
 - #153914 (add test for param-env shadowing)
 - #153917 (compiletest: show rustdoc logs when `--no-capture`)
@rust-bors rust-bors bot merged commit 6da1cc2 into rust-lang:main Mar 15, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 15, 2026
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Mar 16, 2026
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#153870 (docs: remove stale reference to `check_let_chain`)
 - rust-lang/rust#153881 (Provide more context on type errors in const context)
 - rust-lang/rust#153887 (Turn label into structured suggestion for `.as_ref()` and `.as_mut()`)
 - rust-lang/rust#153897 (Use less `#[macro_use]` in the query system)
 - rust-lang/rust#153914 (add test for param-env shadowing)
 - rust-lang/rust#153917 (compiletest: show rustdoc logs when `--no-capture`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants