serde
serde copied to clipboard
Add `<'_>` to `Formatter` in `Visitor::expecting`
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