Closed
Description
I have the following code, split into two files:
// src/main.rs
// this appears in the error
mod name;
use name::Name;
fn main() {
let name_1 = Name::from("John Cena");
let name_2 = Name::from("Not John Cena");
println!("{}", name_1 == name_2);
}
// src/name.rs
pub struct Name {
pub first: String,
pub middle: String,
pub last: String,
}
impl From<&str> for Name {
fn from(name: &str) -> Self {
let mut parts = name.split_whitespace();
let first = parts.next().unwrap_or_default();
let last = parts.clone().last().unwrap_or_default();
let middle = parts.collect::<Vec<_>>().join(" ");
Self {
first: first.to_owned(),
middle,
last: last.to_owned(),
}
}
}
This code, as expected, produces E0369
, shown below. However, the help message at the bottom of the error appears to be referencing line 2 in src/main.rs
, while displaying the filename src/name.rs
, thus suggesting we add the derive
annotation to a comment in src/main.rs
. It should instead point to the struct
in src/name.rs
.
error[E0369]: binary operation `==` cannot be applied to type `Name`
--> src/main.rs:11:27
|
11 | println!("{}", name_1 == name_2);
| ------ ^^ ------ Name
| |
| Name
|
note: an implementation of `PartialEq` might be missing for `Name`
--> src/name.rs:2:1
|
2 | pub struct Name {
| ^^^^^^^^^^^^^^^ must implement `PartialEq`
help: consider annotating `Name` with `#[derive(PartialEq)]`
--> src/name.rs:2:1
|
2 + #[derive(PartialEq)]
3 | // this appears in the error
|
Meta
rustc --version --verbose
:
rustc 1.73.0-nightly (903e279f4 2023-07-18)
binary: rustc
commit-hash: 903e279f468590fa3425f8aff7f3d61a5a873dbb
commit-date: 2023-07-18
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5