rust/tests/ui/privacy/ufc-method-call.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
772 B
Rust
Raw Permalink Normal View History

2024-05-28 09:34:16 +00:00
//! This test used to report that the method call cannot
//! call the private method `Foo<A>::foo`, even though the user
//! explicitly selected `Foo<B>::foo`. This is because we only
//! looked for methods of the right name, without properly checking
//! the `Self` type
//@ revisions: same_name different_name
2019-05-11 01:22:25 +00:00
pub mod test {
pub struct A;
pub struct B;
pub struct Foo<T>(T);
impl Foo<A> {
fn foo() {}
}
impl Foo<B> {
#[cfg(same_name)]
2019-05-11 01:22:25 +00:00
fn foo() {}
#[cfg(different_name)]
fn bar() {}
2019-05-11 01:22:25 +00:00
}
}
fn main() {
test::Foo::<test::B>::foo();
//[same_name]~^ ERROR associated function `foo` is private
//[different_name]~^^ ERROR no function or associated item named `foo` found for struct `Foo<B>`
2019-05-11 01:22:25 +00:00
}