diff options
author | Philip Herron <herron.philip@googlemail.com> | 2024-10-11 17:53:50 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-21 12:32:53 +0100 |
commit | 0c0f33bc439a98f9923a48be592bb9a2be540ac3 (patch) | |
tree | 643383c52089cd44082083d7c8069ef1cdee5a4c /gcc/testsuite/rust/compile/issue-3032-2.rs | |
parent | 28caa267dc757d80ffe37d638d981d3572c164ae (diff) | |
download | gcc-0c0f33bc439a98f9923a48be592bb9a2be540ac3.zip gcc-0c0f33bc439a98f9923a48be592bb9a2be540ac3.tar.gz gcc-0c0f33bc439a98f9923a48be592bb9a2be540ac3.tar.bz2 |
gccrs: Fix bad recursive operator overload call
When we are typechecking the impl block for DerefMut for &mut T
the implementation follows the usual operator overload check
but this ended up just resolving directly to the Trait definition
which ends up being recursive which we usually handle. The issue
we had is that a dereference call can be for either the DEREF
or DEREF_MUT lang item here it was looking for a recurisve call
to the DEREF lang item but we were in the DEREF_MUT lang item
so this case was not accounted for.
Fixes #3032
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-reference.h: new get locus helper
* typecheck/rust-hir-trait-resolve.cc (AssociatedImplTrait::get_locus): implemention
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_operator_overload):
fix overload
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3032-1.rs: New test.
* rust/compile/issue-3032-2.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/testsuite/rust/compile/issue-3032-2.rs')
-rw-r--r-- | gcc/testsuite/rust/compile/issue-3032-2.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/compile/issue-3032-2.rs b/gcc/testsuite/rust/compile/issue-3032-2.rs new file mode 100644 index 0000000..9e09d41 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3032-2.rs @@ -0,0 +1,49 @@ +#![feature(negative_impls)] + +#[lang = "sized"] +trait Sized {} + +#[lang = "deref"] +pub trait Deref { + /// The resulting type after dereferencing. + #[stable(feature = "rust1", since = "1.0.0")] + // #[rustc_diagnostic_item = "deref_target"] + type Target: ?Sized; + + /// Dereferences the value. + #[must_use] + #[stable(feature = "rust1", since = "1.0.0")] + // #[rustc_diagnostic_item = "deref_method"] + fn deref(&self) -> &Self::Target; +} + +impl<T: ?Sized> Deref for &T { + type Target = T; + + fn deref(&self) -> &T { + *self + } +} + +impl<T: ?Sized> !DerefMut for &T {} + +impl<T: ?Sized> Deref for &mut T { + type Target = T; + + fn deref(&self) -> &T { + *self + } +} + +#[lang = "deref_mut"] +pub trait DerefMut: Deref { + /// Mutably dereferences the value. + #[stable(feature = "rust1", since = "1.0.0")] + fn deref_mut(&mut self) -> &mut Self::Target; +} + +impl<T: ?Sized> DerefMut for &mut T { + fn deref_mut(&mut self) -> &mut T { + *self + } +} |