rust/tests/ui/traits/final/positions.rs
mu001999 3572d482a0 Validate no override impl definitions
Co-authored-by: Michael Goulet <michael@errs.io>
2026-02-12 15:18:15 +08:00

72 lines
2.2 KiB
Rust

#![feature(final_associated_functions)]
// Just for exercising the syntax positions
#![feature(associated_type_defaults, extern_types, inherent_associated_types)]
#![allow(incomplete_features)]
final struct Foo {}
//~^ ERROR a struct cannot be `final`
final trait Trait {
//~^ ERROR a trait cannot be `final`
final fn method() {}
// OK!
final type Foo = ();
//~^ ERROR `final` is only allowed on associated functions in traits
final const FOO: usize = 1;
//~^ ERROR `final` is only allowed on associated functions in traits
}
final impl Foo {
final fn method() {}
//~^ ERROR `final` is only allowed on associated functions in traits
final type Foo = ();
//~^ ERROR `final` is only allowed on associated functions in traits
final const FOO: usize = 1;
//~^ ERROR `final` is only allowed on associated functions in traits
}
final impl Trait for Foo {
final fn method() {}
//~^ ERROR `final` is only allowed on associated functions in traits
//~^^ ERROR cannot override `method` because it already has a `final` definition in the trait
final type Foo = ();
//~^ ERROR `final` is only allowed on associated functions in traits
//~^^ ERROR cannot override `Foo` because it already has a `final` definition in the trait
final const FOO: usize = 1;
//~^ ERROR `final` is only allowed on associated functions in traits
//~^^ ERROR cannot override `FOO` because it already has a `final` definition in the trait
}
final fn foo() {}
//~^ ERROR `final` is only allowed on associated functions in traits
final type FooTy = ();
//~^ ERROR `final` is only allowed on associated functions in traits
final const FOO: usize = 0;
//~^ ERROR `final` is only allowed on associated functions in traits
final unsafe extern "C" {
//~^ ERROR an extern block cannot be `final`
final fn foo_extern();
//~^ ERROR `final` is only allowed on associated functions in traits
final type FooExtern;
//~^ ERROR `final` is only allowed on associated functions in traits
final static FOO_EXTERN: usize = 0;
//~^ ERROR a static item cannot be `final`
//~| ERROR incorrect `static` inside `extern` block
}
fn main() {}