LYR-SEM0151
a declaration names a type less visible than itself
A declaration's signature or type names a type that is less visible than the declaration: a pub function returning an internal struct, an internal function taking a private one, a field, constant or inferred binding whose type is narrower than it.
Explanation
A declaration is no more visible than the types it names. Whoever may use origin must be able to name what it returns and what it takes; a pub function that hands out an internal type would give other packages a value they cannot write the type of. The check covers parameter and result types, field types, the types of constants and the inferred type of a binding.
Make the named type as visible as the declaration, or make the declaration narrower.
Wrong
struct Point {
x: int,
}
pub fn origin(): Point {
return Point { x = 0 };
}
fn main(): void {
let _ = origin();
}
Right
pub struct Point {
pub x: int,
}
pub fn origin(): Point {
return Point { x = 0 };
}
fn main(): void {
let _ = origin();
}