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

migration failure: -W keyword-idents misfires on dyn Trait in a macro expansion #6359

Closed
ExpHP opened this issue Nov 28, 2018 · 2 comments
Closed

Comments

@ExpHP
Copy link
Contributor

ExpHP commented Nov 28, 2018

This code is valid in both edition 2015 and 2018, but cargo fix --edition tries to fix it and fails.

Cargo.toml

[package]
name = "error"
version = "0.1.0"
edition = "2015"

[dependencies]

src/main.rs

pub trait PotentialBuilder: DynCloneDetail {}

pub trait DynCloneDetail {
    fn box_clone(&self) -> Box<dyn PotentialBuilder>;

    fn _as_ref_dyn(&self) -> &dyn PotentialBuilder;
}

#[macro_export]
macro_rules! impl_dyn_clone_detail {
    (impl[$($bnd:tt)*] DynCloneDetail for $Type:ty { ... }) => {
        impl<$($bnd)*> DynCloneDetail for $Type {
            fn box_clone(&self) -> Box<dyn PotentialBuilder> {
                Box::new(<$Type as Clone>::clone(self))
            }
            fn _as_ref_dyn(&self) -> &dyn PotentialBuilder { self }
        }
    };
}

#[derive(Clone)]
struct Pot;
impl PotentialBuilder for Pot {}
impl_dyn_clone_detail!{
    impl[] DynCloneDetail for Pot { ... }
}

fn main() {}

Command & output

$ cargo +nightly fix --edition
    Checking error v0.1.0 (/home/lampam/cpp/throwaway/error)
warning: failed to automatically apply fixes suggested by rustc to crate `error`

after fixes were automatically applied the compiler reported errors within these files:

  * src/main.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see 
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/cargo/issues
quoting the full output of this command we'd be very appreciative!

warning: `dyn` is a keyword in the 2018 edition
warning: `dyn` is a keyword in the 2018 edition
  --> src/main.rs:13:40
   |
13 |             fn box_clone(&self) -> Box<dyn PotentialBuilder> {
   |                                        ^^^ help: you can use a raw identifier to stay compatible: `r#dyn`
  --> src/main.rs:13:40
   |
13 |             fn box_clone(&self) -> Box<dyn PotentialBuilder> {
   |                                        ^^^ help: you can use a raw identifier to stay compatible: `r#dyn`
   |
   |
   = note: `-W keyword-idents` implied by `-W rust-2018-compatibility`
   = note: `-W keyword-idents` implied by `-W rust-2018-compatibility`
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
   = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

   = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

warning: `dyn` is a keyword in the 2018 edition
  --> src/main.rs:16:39
   |
16 |             fn _as_ref_dyn(&self) -> &dyn PotentialBuilder { self }
   |                                       ^^^ help: you can use a raw identifier to stay compatible: `r#dyn`
warning: `dyn` is a keyword in the 2018 edition
  --> src/main.rs:16:39
   |
16 |             fn _as_ref_dyn(&self) -> &dyn PotentialBuilder { self }
   |                                       ^^^ help: you can use a raw identifier to stay compatible: `r#dyn`
   |
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
   = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
   = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>


    Finished dev [unoptimized + debuginfo] target(s) in 0.31s

$ cargo +nightly --version
cargo 1.32.0-nightly (b3d0b2e54 2018-11-15)
@ExpHP ExpHP changed the title migration failure: -W keyword-idents misfires on usage of dyn Trait in a macro migration failure: -W keyword-idents misfires on usage of dyn Trait in a macro Nov 28, 2018
@ExpHP ExpHP changed the title migration failure: -W keyword-idents misfires on usage of dyn Trait in a macro migration failure: -W keyword-idents misfires on dyn Trait in a macro expansion Nov 28, 2018
@ExpHP
Copy link
Contributor Author

ExpHP commented Nov 28, 2018

It also fails on dyn Trait usage in the invocation, inside a type matched by :Ty:

pub trait PotentialBuilder: DynCloneDetail {}

pub trait DynCloneDetail {
    fn box_clone(&self) -> Box<dyn PotentialBuilder>;

    fn _as_ref_dyn(&self) -> &dyn PotentialBuilder;
}

#[macro_export]
macro_rules! impl_dyn_clone_detail {
    (impl[$($bnd:tt)*] DynCloneDetail for $Type:ty { ... }) => {
        impl<$($bnd)*> DynCloneDetail for $Type {
            fn box_clone(&self) -> Box<PotentialBuilder> {
                Box::new(<$Type as Clone>::clone(self))
            }
            fn _as_ref_dyn(&self) -> &PotentialBuilder { self }
        }
    };
}

impl PotentialBuilder for Box<dyn PotentialBuilder> {}
impl Clone for Box<dyn PotentialBuilder> {
    fn clone(&self) -> Self { self.box_clone() }
}
impl_dyn_clone_detail!{
    impl[] DynCloneDetail for Box<dyn PotentialBuilder> { ... }
}
fn main() {}
warning: `dyn` is a keyword in the 2018 edition
  --> src/main.rs:26:35
   |
26 |     impl[] DynCloneDetail for Box<dyn PotentialBuilder> { ... }
   |                                   ^^^ help: you can use a raw identifier to stay compatible: `r#dyn`

@alexcrichton
Copy link
Member

Thanks for the report! I've moved this over to rust-lang/rust#56327 as this is a bug in rustc, and we can track it from there

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

No branches or pull requests

2 participants