Skip to content

Multiple candidate method resolution error #2304

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
philberty opened this issue Jun 16, 2023 · 6 comments · Fixed by #2321
Closed

Multiple candidate method resolution error #2304

philberty opened this issue Jun 16, 2023 · 6 comments · Fixed by #2321
Assignees
Labels

Comments

@philberty
Copy link
Member

philberty commented Jun 16, 2023

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

#[lang = "add"]
pub trait Add<RHS = Self> {
    type Output;

    fn add(self, rhs: RHS) -> Self::Output;
}
macro_rules! add_impl {
    ($($t:ty)*) => ($(
        impl Add for $t {
            type Output = $t;

            fn add(self, other: $t) -> $t { self + other }
        }
    )*)
}

add_impl! { usize u8 u16 u32 u64  /*isize i8 i16 i32 i64*/  f32 f64 }

pub fn test() {
    let x:usize = 123;
    let mut i = 0;
    let bug = i + x;
}

I expected to see this happen: compile without error

Instead, this happened:

<source>:22:15: error: multiple candidates found for possible operator overload
   12 |             fn add(self, other: $t) -> $t { self + other }
      |             ~~ 
......
   22 |     let bug = i + x;
      |               ^

Its not obvious from the error message but adding in some debugging shows there are multiple candidates:

test.rs:147:15: error: multiple candidates found for possible operator overload
  147 |         while i + block_size <= len {
      |               ^
......
  288 |             fn add(self, other: $t) -> $t { self + other }
      |             ~~ 
crab1: note: [0x3fd0610] <integer> -> self
crab1: note: [0x3fd0d60] usize -> other
crab1: note: [0x3fdb5d0] fn (self usize,other usize,) -> usize
crab1: note: [0x3fe7be0] fn (self u8,other u8,) -> u8
crab1: note: [0x3ff4040] fn (self u16,other u16,) -> u16
crab1: note: [0x4001490] fn (self u32,other u32,) -> u32
crab1: note: [0x400f660] fn (self u64,other u64,) -> u64

Meta

  • What version of Rust GCC were you using, git sha if possible. c021eef
@philberty
Copy link
Member Author

Method selection needs to take into account the other arguments to help resolve this case

@CohenArthur
Copy link
Member

This is the output of rustc -Zunpretty=hir,typed:

pub fn test() ({
                   let x: usize = (123 as usize);
                   let mut i = (0 as usize);
                   let bug = ((i as usize) + (x as usize) as usize);
               } as ())

@philberty
Copy link
Member Author

Yeah i think the method selection is meant to see i + x and turn i into a usize.

@powerboat9
Copy link
Collaborator

What are you using to debug?

@philberty
Copy link
Member Author

@powerboat9 i use -frust-debug but i also added in a few calls to TyTy::BaseType::debug to emit each of the candidates.

@philberty
Copy link
Member Author

The fix here should also fix #1586

philberty added a commit that referenced this issue Jun 25, 2023
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes #2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
github-merge-queue bot pushed a commit that referenced this issue Jun 25, 2023
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes #2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
@github-project-automation github-project-automation bot moved this from Todo to Done in libcore 1.49 Jun 25, 2023
@philberty philberty mentioned this issue Jun 26, 2023
41 tasks
jdupak pushed a commit to jdupak/gccrs that referenced this issue Aug 19, 2023
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 15, 2023
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 15, 2023
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 21, 2023
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 21, 2023
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 21, 2023
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 21, 2023
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 5, 2024
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 5, 2024
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 8, 2024
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 8, 2024
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 11, 2024
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 11, 2024
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 12, 2024
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 12, 2024
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 16, 2024
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 16, 2024
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 16, 2024
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 16, 2024
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 17, 2024
Addresses Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <[email protected]>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 17, 2024
When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes Rust-GCC#2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants