-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
static lifetime being required too often #13323
Comments
Replacing |
Woops, I guess I forgot to add the .as_slice() fix in the Gist... sorry. |
This now works fine (only changes were updating to make it compile): struct StrWrap {
s: String
}
impl StrWrap {
fn new(s: &str) -> StrWrap {
StrWrap { s: s.into_string() }
}
fn get_s<'a>(&'a self) -> &'a str {
self.s.as_slice()
}
}
struct MyStruct {
s: StrWrap
}
impl MyStruct {
fn new(s: &str) -> MyStruct {
MyStruct { s: StrWrap::new(s) }
}
fn get_str_wrap<'a>(&'a self) -> &'a StrWrap {
&self.s
}
}
trait Matcher<T> {
fn matches(&self, actual: T) -> bool;
}
fn assert_that<T, U: Matcher<T>>(actual: T, matcher: &U) {
assert!(matcher.matches(actual));
}
struct EqualTo<T> {
expected: T
}
impl<T: Eq> Matcher<T> for EqualTo<T> {
fn matches(&self, actual: T) -> bool {
self.expected.eq(&actual)
}
}
fn equal_to<T: Eq>(expected: T) -> Box<EqualTo<T>> {
box EqualTo { expected: expected }
}
pub fn main() {
let my_struct = MyStruct::new("zomg");
let s = my_struct.get_str_wrap();
assert_that(s.get_s(), &*equal_to("zomg"));
} Changing the second last line to assert_that(s.get_s(), &*equal_to::<&'static str>("zomg")); causes the same compilation error as in the original code, suggesting that this is actually rustc being more intelligent, and is not just being disguised by the language changes since this was filed; yay! Flagging as needstest. |
This should have been closed by #19780! See https://github.com/rust-lang/rust/blob/master/src/test/run-pass/issue-13323.rs cc @jakub- |
Thanks @tamird! |
Changelog for Clippy 1.81 🔰 Roses are red, Violets are blue, Expectations are stable, And reasons are set --- ### The cat of this release is *Keepy* submitted by `@blyxyas:` <img height=500 src="https://github.com/rust-lang/rust-clippy/assets/73757586/902dd802-5ac8-471e-bb93-e195526ba580" alt="The cats of this Clippy release" /> Cats for the next release can be nominated in the comments :D --- changelog: none
Repro:
https://gist.github.com/carllerche/c426ece39be0705ba6c2
I am not really sure what is going on. Maybe this is a dup of #8874? Unsure.
The text was updated successfully, but these errors were encountered: