Skip to content

Instantly share code, notes, and snippets.

@metatoaster
Last active May 27, 2023 00:43
Show Gist options
  • Save metatoaster/74eaa1906a58b5daad47c210241143a6 to your computer and use it in GitHub Desktop.
Save metatoaster/74eaa1906a58b5daad47c210241143a6 to your computer and use it in GitHub Desktop.
Thankfully the way errors get generated appeared to be fixed in 1.70.0-beta
// Compare between
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=74eaa1906a58b5daad47c210241143a6
// and
// https://play.rust-lang.org/?version=beta&mode=debug&edition=2021&gist=74eaa1906a58b5daad47c210241143a6
struct Thing(String);
struct View<'a>(&'a str);
impl<'a> From<&'a Thing> for View<'a>
{
fn from(value: &'a Thing) -> Self {
Self(&value.0[value.0.find('@').unwrap_or(0)..])
}
}
fn lookat_view(view: &View) {
println!("looking at view: {}", view.0);
}
fn discard_view(view: View) {
println!("view discarded: {}", view.0);
}
fn main() {
let thing = Thing("thing@somewhere".to_string());
// correct invocation
lookat_view(&(&thing).into());
discard_view((&thing).into());
// incorrect invocation
discard_view(thing.into());
discard_view(&thing.into());
lookat_view(&thing.into());
lookat_view(&&thing.into());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment