learning-rust.github.io icon indicating copy to clipboard operation
learning-rust.github.io copied to clipboard

about the Impls of lifetimes example

Open savageKarl opened this issue 7 months ago • 0 comments

https://learning-rust.github.io/docs/lifetimes/#03-with-impls-and-traits

struct Struct<'a> {
    x: &'a str
}
    impl<'a> Struct<'a> {
        fn function<'a>(&self) -> &'a str {
            self.x
        }
    }

error[E0496]: lifetime name 'a shadows a lifetime name that is already in scope --> src/lib.rs:5:21 | 4 | impl<'a> Struct<'a> { | -- first declared here 5 | fn function<'a>(&self) -> &'a str { | ^^ lifetime 'a already in scope

For more information about this error, try rustc --explain E0496. error: could not compile playground (lib) due to 1 previous error

savageKarl avatar Jun 19 '25 15:06 savageKarl