Description
There is a strange/inconsistent behaviour in the name resolution of models placed in constants.
In detail placing a module inside of a constant works.
Referring directly to types inside the module also works.
const _DUMMY: () = {
mod some_mod {
pub struct Bar;
}
fn foo(_: some_mod::Bar) {}
};
compiles successfully.
Trying to use use
statements or starting the path otherwise with self::
results in compiler errors that some_mod
is not found:
const _DUMMY: () = {
mod some_mod {
pub struct Bar;
}
// This fails
use self::some_mod::Bar;
// This also fails
fn foo(_: self::some_mod::Bar) {}
};
This behaviour seems inconsistent for me. Either it should not be allowed to place modules inside of constants, or it should be possible to use relative paths to reference items inside of such modules (in scope of the constant block).
I would guess that the scope of self is not associated with the inner scope of the constant, but with the current module. From there the module inside of the constant is not visible.
This happens on all channels.
Playground links: