Code
fn main() {
_ = std::env::var_os("RUST_LOG").map_or("warn".into(), |x| x.to_string_lossy().to_owned());
}
Current output
error[E0515]: cannot return value referencing function parameter `x`
--> src/main.rs:2:64
|
2 | _ = std::env::var_os("RUST_LOG").map_or("warn".into(), |x| x.to_string_lossy().to_owned());
| -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| returns a value referencing data owned by the current function
| `x` is borrowed here
For more information about this error, try `rustc --explain E0515`.
Desired output
error[E0515]: cannot return value referencing function parameter `x`
--> src/main.rs:2:64
|
2 | _ = std::env::var_os("RUST_LOG").map_or("warn".into(), |x| x.to_string_lossy().to_owned());
| -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| returns a value referencing data owned by the current function
| `x` is borrowed here
|
help: Try using `.into_owned()` if you meant to convert a `Cow<'_, T>` to an owned `T`
|
2 | _ = std::env::var_os("RUST_LOG").map_or("warn".into(), |x| x.to_string_lossy().into_owned());
| ++
For more information about this error, try `rustc --explain E0515`.
Rationale and extra context
The current error message isn't very helpful, and the two method names are very similar.
Other cases
Rust Version
rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5
Anything else?
No response
Code
Current output
Desired output
Rationale and extra context
The current error message isn't very helpful, and the two method names are very similar.
Other cases
Rust Version
Anything else?
No response