Repository navigation
Suggest changing argument mutability #159490
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
fn main() {
let input = String::new();
std::io::stdin().read_line(&input).unwrap();
}Current output
error[E0308]: mismatched types
--> src/main.rs:5:27
|
5 | io::stdin().read_line(&input).unwrap();
| --------- ^^^^^^ types differ in mutability
| |
| arguments to this method are incorrect
|
= note: expected mutable reference `&mut String`
found reference `&String`
note: method defined here
--> /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/stdio.rs:412:12
|
412 | pub fn read_line(&self, buf: &mut String) -> io::Result<usize> {
| ^^^^^^^^^Desired output
error[E0308]: mismatched types
--> src/main.rs:5:27
|
5 | io::stdin().read_line(&input).unwrap();
| --------- ^^^^^^ types differ in mutability
| |
| arguments to this method are incorrect
|
= note: expected mutable reference `&mut String`
found reference `&String`
note: method defined here
--> /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/stdio.rs:412:12
|
412 | pub fn read_line(&self, buf: &mut String) -> io::Result<usize> {
| ^^^^^^^^^
help: change the borrow to be mutable
|
5 | io::stdin().read_line(&mut input).unwrap();
| +++Rationale and extra context
No response
Other cases
Rust Version
1.97Anything else?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
EvoPot commentedon Aug 5, 2026
Quick question unrelated to the issue, how much do we need to specify where the standard library is in the user's system? I am talking about this diagnostic right here:
Clearly the user shouldn't need to go to the location of the toolchain in their home system. Imagine this for a scenario where people already do know that they should go to somewhere where they have control over the source code like they are going to trace where a file that they are going to change is in
stdin GitHub or something. I personally think thatstdshould have some more levarage as a central part of the language, which it is for many people. I personally think rather than extra verbosity it should be something more like:Of course this raises a different number of questions (What even is
std, what if you are making a fork of the language and change std's name, what if a contributor is debugging with multiple compiler builds (like they have multiple +stage's added to their toolchain) ) but personally I think it is better than giving the end user a full system path for what they shouldn't change. Is there an issue for this? I cannot seem to find one because I lack the expertise in how to find similar issues, but maybe this is a good place to start.Rollup merge of rust-lang#162106 - TirushOne:addr-mutability-suggesti…
Rollup merge of rust-lang#162106 - TirushOne:addr-mutability-suggesti…
Rollup merge of rust-lang#162106 - TirushOne:addr-mutability-suggesti…
Unrolled build for #162106 in rollup 164052