diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-01-16 17:10:02 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-24 13:06:51 +0100 |
commit | 3ee9affeb3bd5e5ef6f2b6f9a73252b937536f4e (patch) | |
tree | 19e79fc544a9ee5b1bbbfeb32b1660293f10e0ff /gcc/testsuite/rust/compile | |
parent | ecb0e17c41944d340595816e2890f2a7d2053044 (diff) | |
download | gcc-3ee9affeb3bd5e5ef6f2b6f9a73252b937536f4e.zip gcc-3ee9affeb3bd5e5ef6f2b6f9a73252b937536f4e.tar.gz gcc-3ee9affeb3bd5e5ef6f2b6f9a73252b937536f4e.tar.bz2 |
gccrs: typecheck: Add basic handling for applying auto trait bounds
gcc/rust/ChangeLog:
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Register auto traits in mappings.
* util/rust-hir-map.cc (Mappings::insert_auto_trait): New.
(Mappings::get_auto_traits): New.
* util/rust-hir-map.h: Declare them.
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Add auto trait bounds when
scanning.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Some parts of nr2.0 can't handle auto traits yet.
* rust/compile/auto_traits3.rs: Removed in favor of...
* rust/compile/auto_traits2.rs: ...this one.
* rust/compile/auto_traits4.rs: New test.
Diffstat (limited to 'gcc/testsuite/rust/compile')
-rw-r--r-- | gcc/testsuite/rust/compile/auto_traits2.rs | 5 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/auto_traits3.rs | 34 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/auto_traits4.rs | 14 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/nr2/exclude | 3 |
4 files changed, 18 insertions, 38 deletions
diff --git a/gcc/testsuite/rust/compile/auto_traits2.rs b/gcc/testsuite/rust/compile/auto_traits2.rs index 7d0dcc1..382d446 100644 --- a/gcc/testsuite/rust/compile/auto_traits2.rs +++ b/gcc/testsuite/rust/compile/auto_traits2.rs @@ -15,12 +15,11 @@ fn foo(a: &(dyn A + Send + Sync)) { struct S; impl A for S { - fn a_method(&self) {} + fn a_method(&self) {} // { dg-warning "unused name" } } fn main() { let s = S; - foo(&s); // { dg-error "bounds not satisfied" } - // { dg-error "mismatched type" "" { target *-*-* } .-1 } + foo(&s); } diff --git a/gcc/testsuite/rust/compile/auto_traits3.rs b/gcc/testsuite/rust/compile/auto_traits3.rs deleted file mode 100644 index 81c39ec..0000000 --- a/gcc/testsuite/rust/compile/auto_traits3.rs +++ /dev/null @@ -1,34 +0,0 @@ -#![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/auto_traits4.rs b/gcc/testsuite/rust/compile/auto_traits4.rs new file mode 100644 index 0000000..f1cd1e4 --- /dev/null +++ b/gcc/testsuite/rust/compile/auto_traits4.rs @@ -0,0 +1,14 @@ +#![feature(optin_builtin_traits)] + +unsafe auto trait Send {} +unsafe auto trait Sync {} + +fn take_send(_: &dyn Send) {} +fn take_sync(_: &dyn Sync) {} + +fn main() { + let a = i32; + + take_send(&a); + take_sync(&a); +} diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude index 60322f3..a8e3ba5 100644 --- a/gcc/testsuite/rust/compile/nr2/exclude +++ b/gcc/testsuite/rust/compile/nr2/exclude @@ -140,7 +140,8 @@ issue-2907.rs issue-2423.rs issue-266.rs additional-trait-bounds2.rs -auto_traits3.rs +auto_traits2.rs +auto_traits4.rs issue-3140.rs cmp1.rs derive_clone_enum1.rs |