Fix associated item visibility in block-local impls

This commit is contained in:
Ryo Yoshida 2023-02-19 23:30:49 +09:00
parent 443801755c
commit 83e24fec98
No known key found for this signature in database
GPG key ID: E25698A930586171
5 changed files with 52 additions and 8 deletions

View file

@ -115,6 +115,44 @@ mod module {
fn main(s: module::Struct) {
s.method();
}
"#,
);
}
#[test]
fn can_see_through_top_level_anonymous_const() {
// regression test for #14046.
check_diagnostics(
r#"
struct S;
mod m {
const _: () = {
impl crate::S {
pub(crate) fn method(self) {}
pub(crate) const A: usize = 42;
}
};
mod inner {
const _: () = {
impl crate::S {
pub(crate) fn method2(self) {}
pub(crate) const B: usize = 42;
pub(super) fn private(self) {}
pub(super) const PRIVATE: usize = 42;
}
};
}
}
fn main() {
S.method();
S::A;
S.method2();
S::B;
S.private();
//^^^^^^^^^^^ error: function `private` is private
S::PRIVATE;
//^^^^^^^^^^ error: const `PRIVATE` is private
}
"#,
);
}