-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deref
and DerefMut
cause ambiguity issues when resolving
#3032
Comments
the issue only arises upon adding this implementation: impl<T: ?Sized> DerefMut for &mut T {
fn deref_mut(&mut self) -> &mut T {
*self
}
} which is part of the |
we're also running into this with this code example - I suspect the fix would be the same and there is something wrong when it comes to references/pointers and mutability: #![feature(intrinsics)]
#[lang = "sized"]
trait Sized {}
pub struct VaListImpl<'f>;
mod sealed_trait {
pub trait VaArgSafe {}
}
impl<T> sealed_trait::VaArgSafe for *mut T {}
impl<T> sealed_trait::VaArgSafe for *const T {}
impl<'f> VaListImpl<'f> {
/// Advance to the next arg.
#[inline]
pub unsafe fn arg<T: sealed_trait::VaArgSafe>(&mut self) {
va_arg2(self);
}
}
fn va_arg2<T: sealed_trait::VaArgSafe>(ap: &mut VaListImpl<'_>) {} |
I don't even understand how it makes sense for the last example - the type bound is unused, so it shouldn't affect anything |
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: * rust/compile/issue-3032-1.rs: New test. * rust/compile/issue-3032-2.rs: New test. Signed-off-by: Philip Herron <[email protected]>
This is a seperate issue i am going to open this into a seperate issue as the original issue is different and fix is up now |
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]>
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]>
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]>
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]>
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]>
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 Rust-GCC#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]>
This code is the base implementation of
Deref
andDerefMut
:If we remove the
#[lang = "deref{_mut}"]
attributes, then the code works, but otherwise it errors out:the reason is that there is an ambiguity and that the compiler finds two associated trait impls:
Deref
for&mut T
andDeref
for&T
The text was updated successfully, but these errors were encountered: