Skip to content

Using mod with ?expand can cause errors #79

@ChaiTRex

Description

@ChaiTRex

I made a macro on the Playground (https://play.rust-lang.org/?edition=2024&gist=c97b5c5556702f39458f76c8be1b41bf), where expanding the macro in it worked fine with a few warnings but no errors. However, Ferris seems to wrap everything in fn main() {, and so using mod with it can give errors:

Request:

?expand ```rust
#[derive(PartialEq)]
pub struct Domain;

mod UILayout_template_asset_shelf_popover_icon {
    use super::Domain;

    pub const NONE: Domain = Domain;
    pub const CHAR_NOT_DEF: Domain = Domain;
}

macro_rules! thingy {
    ($val:ident, $prefix:ident : $($variant_name:ident,)*) => {
        match $val {
            $(
                $prefix :: $variant_name => stringify!($variant_name),
            )*
        }
    };
}

fn from(val: Domain) -> &'static str {
    thingy!(val, UILayout_template_asset_shelf_popover_icon:
        NONE,
        CHAR_NOT_DEF,
    )
}
```

Response:

error[E0432]: unresolved import `super::Domain`
 --> src/main.rs:6:9
  |
6 |     use super::Domain;
  |         ^^^^^^^^^^^^^ no `Domain` in the root
  |
help: a similar name exists in the module
  |
6 -     use super::Domain;
6 +     use super::main;
  |
help: consider importing one of these items instead
  |
6 -     use super::Domain;
6 +     use postgres::types::Kind::Domain;
  |
6 -     use super::Domain;
6 +     use postgres_types::Kind::Domain;
  |
6 -     use super::Domain;
6 +     use psl_types::Domain;
  |
6 -     use super::Domain;
6 +     use publicsuffix::Domain;
  |
  = and 4 other candidates

For more information about this error, try `rustc --explain E0432`.
error: could not compile `playground` (bin "playground") due to 1 previous error

pub struct Domain;
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Domain { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Domain {
    #[inline]
    fn eq(&self, other: &Domain) -> bool { true }
}

mod UILayout_template_asset_shelf_popover_icon {
    use super::Domain;

    pub const NONE: Domain = Domain;
    pub const CHAR_NOT_DEF: Domain = Domain;

Output too large. Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=d779e1c226455f3bdaecafd00f2c2365

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions