Skip to content

edition idioms: Trickiness with $crate in local macros #56683

Closed
@alexcrichton

Description

@alexcrichton

Originally reported with Cargo this code:

#![warn(rust_2018_compatibility)]
extern crate serde;
#[macro_use]
extern crate serde_derive;

use serde::{Deserialize, Deserializer};

macro_rules! event {
    (
        pub struct $name:ident() {}
    ) => {
        #[derive(Deserialize)]
        pub struct $name {
            pub event_type: $crate::EventType,
        }
    }
}

pub enum EventType {}

event! {
    pub struct CustomEvent() {}
}

impl<'de> Deserialize<'de> for EventType {
    fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        unimplemented!()
    }
}

gives an erroneous suggestion

which causes it to fail to be migrated by cargo fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-2018Area: The 2018 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions