proc-macro-workshop:sorted-4

审题

// This test is similar to the previous where want to ensure that the macro
// correctly generates an error when the input enum is out of order, but this
// time it is using an enum that also has data associated with each variant.

use sorted::sorted;

use std::env::VarError;
use std::error::Error as StdError;
use std::fmt;
use std::io;
use std::str::Utf8Error;

#[sorted]
pub enum Error {
    Fmt(fmt::Error),
    Io(io::Error),
    Utf8(Utf8Error),
    Var(VarError),
    Dyn(Box<dyn StdError>),
}

fn main() {}

提示已经说了,和前一题类似,只是携带了结构体。
可能是因为我们懒,也许是因为我们有前瞻,我们并没有解析额外更多的东西。
直接使用的是&i.ident,因此并不涉及携带的其他信息,所以刚好能够解题。

error: Dyn should sort before Fmt
  --> tests/04-variants-with-data.rs:19:5
   |
19 |     Dyn(Box<dyn StdError>),
   |     ^^^

也算瞎猫碰上死耗子?

本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!