Open
Description
pub mod foo {
pub trait Foo: sealed::Bar {
fn foo(&self) {}
}
mod sealed {
pub trait Bar {
fn bar(&self) {}
}
}
impl Foo for u32 {}
impl sealed::Bar for u32 {}
}
fn meow_dyn(f: &dyn foo::Foo) {
f.foo();
f.bar();
}
fn meow_static(f: impl foo::Foo) {
f.foo();
f.bar();
}
fn meow_u32(f: u32) {
use foo::Foo;
// use crate::foo::sealed::Bar;
// ^ doesn't work because it is private
f.foo();
f.bar(); // Why does this error now?
}
fn main() {
meow_static(42);
meow_dyn(&42);
}
error[E0599]: no method named `bar` found for type `u32` in the current scope
--> src/main.rs:30:7
|
30 | f.bar(); // Why does this error now?
| ^^^ method not found in `u32`
|
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
1 | use crate::foo::sealed::Bar;
|
I am reporting this because I believe this is a bug.
Both meow_dyn
and meow_static
type check, but calling .bar()
on a concrete type is currently not possible. Is there a reason for that?
I would expect any of those two cases:
meow_u32
should actually type check, and.bar()
should be callable ifFoo
is visible, becauseBar
is a supertrait.Bar
should not be usable in any other context, because the trait is private.
I could not find any information about this in the reference.