diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-12-25 18:13:43 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-21 12:55:44 +0100 |
commit | 161b9e9828b84b75f64aa0ffdadcefe920c1ed0d (patch) | |
tree | 2dd6f061cdd0e2c4f82adc2fc41e732b9c08d13a /gcc/testsuite | |
parent | cd8547f85e53b42eff5a7c7572b466c023c75daf (diff) | |
download | gcc-161b9e9828b84b75f64aa0ffdadcefe920c1ed0d.zip gcc-161b9e9828b84b75f64aa0ffdadcefe920c1ed0d.tar.gz gcc-161b9e9828b84b75f64aa0ffdadcefe920c1ed0d.tar.bz2 |
gccrs: tychk: Add more support for additional trait bounds in functions
This commit correctly lowers and typechecks parenthesized types, which are used for trait objects with additional bounds.
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-type.cc (ResolveType::visit): New visitor to handle
ParenthesizedType.
* resolve/rust-ast-resolve-type.h: Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): Likewise.
* typecheck/rust-hir-type-check-type.h: Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/auto_traits2.rs: New test.
* rust/compile/auto_traits3.rs: New test.
* rust/compile/nr2/exclude: Add auto_traits2 test.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/rust/compile/auto_traits2.rs | 26 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/auto_traits3.rs | 34 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/nr2/exclude | 2 |
3 files changed, 62 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/compile/auto_traits2.rs b/gcc/testsuite/rust/compile/auto_traits2.rs new file mode 100644 index 0000000..7d0dcc1 --- /dev/null +++ b/gcc/testsuite/rust/compile/auto_traits2.rs @@ -0,0 +1,26 @@ +#![feature(optin_builtin_traits)] + +pub unsafe auto trait Send {} +#[lang = "sync"] +pub unsafe auto trait Sync {} + +trait A { + fn a_method(&self) {} +} + +fn foo(a: &(dyn A + Send + Sync)) { + a.a_method(); +} + +struct S; + +impl A for S { + fn a_method(&self) {} +} + +fn main() { + let s = S; + + foo(&s); // { dg-error "bounds not satisfied" } + // { dg-error "mismatched type" "" { target *-*-* } .-1 } +} diff --git a/gcc/testsuite/rust/compile/auto_traits3.rs b/gcc/testsuite/rust/compile/auto_traits3.rs new file mode 100644 index 0000000..81c39ec --- /dev/null +++ b/gcc/testsuite/rust/compile/auto_traits3.rs @@ -0,0 +1,34 @@ +#![feature(optin_builtin_traits)] + +pub unsafe auto trait Send {} +#[lang = "sync"] +pub unsafe auto trait Sync {} + +trait A { + fn a_method(&self) {} +} + +fn foo(a: &(dyn A + Send + Sync)) { + a.a_method(); +} + +struct S; + +impl A for S { + fn a_method(&self) {} // { dg-warning "unused" } +} + +// These should not be necessary because they are both auto traits +// They need to be removed once we figure out the proper implementation for each of them +// However, it'd be silly to implement other traits in order to ensure the test is okay, +// as these extra trait bounds are only allowed to use auto traits +// FIXME: #3327 +// FIXME: #3326 +unsafe impl Send for S {} +unsafe impl Sync for S {} + +fn main() { + let s = S; + + foo(&s); +} diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude index 2a5bc94..e23669f3 100644 --- a/gcc/testsuite/rust/compile/nr2/exclude +++ b/gcc/testsuite/rust/compile/nr2/exclude @@ -207,4 +207,6 @@ issue-2907.rs issue-2423.rs issue-266.rs additional-trait-bounds2.rs +auto_traits2.rs +auto_traits3.rs # please don't delete the trailing newline |