Skip to content

Pointers are coerceable #1901

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

Closed
Tracked by #1895 ...
philberty opened this issue Feb 21, 2023 · 0 comments · Fixed by #1931
Closed
Tracked by #1895 ...

Pointers are coerceable #1901

philberty opened this issue Feb 21, 2023 · 0 comments · Fixed by #1931
Assignees
Labels

Comments

@philberty
Copy link
Member

I tried this code: https://godbolt.org/z/aE71GeqjK

 mod intrinsics {
    extern "rust-intrinsic" {
        pub fn offset<T>(ptr: *const T, count: isize) -> *const T;
    }
}
 
 mod ptr{
    #[lang = "const_ptr"]
    impl<T> *const T {
        pub unsafe fn offset(self, count: isize) -> *const T {
            intrinsics::offset(self, count)
        }
    }
}

fn test(x: *mut u8) {
    x.offset(1);
}

I expected to see this happen: compile without error

Instead, this happened:

<source>:17:7: error: failed to resolve method for 'offset'
   17 |     x.offset(1);
      |       ^~~~~~
<source>:17:5: error: failed to type resolve expression
   17 |     x.offset(1);
      |     ^

Meta

  • What version of Rust GCC were you using, git sha if possible. d6e33ad
@philberty philberty added the bug label Feb 21, 2023
@philberty philberty self-assigned this Feb 21, 2023
This was referenced Feb 21, 2023
@philberty philberty changed the title Pointers are coerceable and castable Pointers are coerceable Feb 21, 2023
philberty added a commit that referenced this issue Feb 28, 2023
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes #1901 #878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
@philberty philberty linked a pull request Feb 28, 2023 that will close this issue
philberty added a commit that referenced this issue Feb 28, 2023
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes #1901 #878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
philberty added a commit that referenced this issue Feb 28, 2023
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes #1901 #878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
TuringKi pushed a commit to TuringKi/gccrs that referenced this issue Mar 1, 2023
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Mar 27, 2023
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Apr 6, 2023
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Apr 7, 2023
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 15, 2023
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 21, 2023
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 21, 2023
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 5, 2024
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 11, 2024
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 12, 2024
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 16, 2024
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 16, 2024
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 17, 2024
Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes Rust-GCC#1901 Rust-GCC#878

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
	(TypeCoercionRules::TypeCoercionRules): set new try flag
	(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
	(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
	(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
	* typecheck/rust-coercion.h: update header
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
	(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
	* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1901.rs: New test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant