Skip to content
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

Add <'_> to Formatter in Visitor::expecting #2806

Open
zacknewman opened this issue Aug 17, 2024 · 1 comment
Open

Add <'_> to Formatter in Visitor::expecting #2806

zacknewman opened this issue Aug 17, 2024 · 1 comment

Comments

@zacknewman
Copy link

zacknewman commented Aug 17, 2024

The lint group rust-2018-idioms enables elided-lifetimes-in-paths. Visitor::expecting omits the lifetime from Formatter. When relying on autocompletion, this requires one to manually add a lifetime argument to silence this warning. Would it be difficult to change this?

#![warn(rust_2018_idioms)]
use core::fmt;
use serde::de::{Error, Visitor};
pub struct Foo;
impl<'de> Visitor<'de> for Foo {
    type Value = ();
    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        formatter.write_str("()")
    }
    fn visit_unit<E>(self) -> Result<Self::Value, E>
    where
        E: Error,
    {
        Ok(())
    }
}

expecting was autocompleted in Helix.

[zack@laptop src]$ cargo check
    Checking bar v0.1.0 (/home/zack/projects/bar)
warning: hidden lifetime parameters in types are deprecated
 --> src/lib.rs:7:46
  |
7 |     fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
  |                                         -----^^^^^^^^^
  |                                         |
  |                                         expected lifetime parameter
  |
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(rust_2018_idioms)]
  |         ^^^^^^^^^^^^^^^^
  = note: `#[warn(elided_lifetimes_in_paths)]` implied by `#[warn(rust_2018_idioms)]`
help: indicate the anonymous lifetime
  |
7 |     fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
  |                                                       ++++

warning: `bar` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s

In contrast if the definition were defined with an explicit lifetime, autocompletion retains it; and no warning is issued:

#![warn(rust_2018_idioms)]
use core::fmt;
pub struct Foo;
pub trait Bar<'de>: Sized {
    type Value;
    fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result;
}
impl<'de> Bar<'de> for Foo {
    type Value = ();
    fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter.write_str("()")
    }
}
[zack@laptop src]$ cargo check
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s
@devnetsec
Copy link

I just ran the test suite successfully, that change should be trivial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants