Closed
Description
I tried this code:
mod my {
pub struct Foo(&'static str);
}
impl AsRef<str> for my::Foo {
fn as_ref(&self) -> &str {
let Self(s) = self;
s
}
}
I expected to see this happen: compilation should fail because the trait impl is defined outside of the module for the type but refers to its private field.
Instead, this happened: this compiled successfully
Meta
This reproduces on the playground for stable Rust, version 1.69.0: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=20f12a0f682d8dd6530d75f1b5e7a8dd