-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
6 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#![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 | ||
} | ||
} | ||
|
||
// this is added because of #3030 | ||
extern "C" { | ||
fn never() -> !; | ||
} | ||
|
||
impl<T: ?Sized> !DerefMut for &T { | ||
fn deref_mut(&mut self) -> &mut T { | ||
unsafe { never() } | ||
} | ||
} | ||
|
||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters