aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-06-10 21:07:27 +0100
committerPhilip Herron <philip.herron@embecosm.com>2023-06-11 18:13:29 +0000
commiteedab85e02b8bd5841a36c0600cf397a255a718e (patch)
treeb73972b6517e104ad6c15571500674ccc2a0edcf
parentedff04f5ddcacfb3ae8a00c5eaee8459415bb1c4 (diff)
downloadgcc-eedab85e02b8bd5841a36c0600cf397a255a718e.zip
gcc-eedab85e02b8bd5841a36c0600cf397a255a718e.tar.gz
gcc-eedab85e02b8bd5841a36c0600cf397a255a718e.tar.bz2
gccrs: introduce new types_compatable
This is an initiative to begin getting rid of the can_eq interface. Addresses #2019 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItemWithTrait::visit): use new interface * typecheck/rust-type-util.cc (types_compatable): implementation of new interface * typecheck/rust-type-util.h (types_compatable): prototype * typecheck/rust-unify.cc (UnifyRules::expect_placeholder): It is allow for unification against placeholders gcc/testsuite/ChangeLog: * rust/compile/traits2.rs: update error message * rust/compile/traits3.rs: update error message Signed-off-by: Philip Herron <herron.philip@googlemail.com>
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-implitem.cc12
-rw-r--r--gcc/rust/typecheck/rust-type-util.cc10
-rw-r--r--gcc/rust/typecheck/rust-type-util.h4
-rw-r--r--gcc/rust/typecheck/rust-unify.cc17
-rw-r--r--gcc/testsuite/rust/compile/traits2.rs2
-rw-r--r--gcc/testsuite/rust/compile/traits3.rs4
6 files changed, 32 insertions, 17 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
index 15846fd..111c219 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
@@ -411,7 +411,9 @@ TypeCheckImplItemWithTrait::visit (HIR::ConstantItem &constant)
// check the types are compatible
auto trait_item_type = resolved_trait_item.get_tyty_for_receiver (self);
- if (!trait_item_type->can_eq (lookup, true))
+ if (!types_compatable (TyTy::TyWithLocation (trait_item_type),
+ TyTy::TyWithLocation (lookup), constant.get_locus (),
+ true /*emit_errors*/))
{
RichLocation r (constant.get_locus ());
r.add_range (resolved_trait_item.get_locus ());
@@ -460,7 +462,9 @@ TypeCheckImplItemWithTrait::visit (HIR::TypeAlias &type)
// check the types are compatible
auto trait_item_type = resolved_trait_item.get_tyty_for_receiver (self);
- if (!trait_item_type->can_eq (lookup, true))
+ if (!types_compatable (TyTy::TyWithLocation (trait_item_type),
+ TyTy::TyWithLocation (lookup), type.get_locus (),
+ true /*emit_errors*/))
{
RichLocation r (type.get_locus ());
r.add_range (resolved_trait_item.get_locus ());
@@ -519,7 +523,9 @@ TypeCheckImplItemWithTrait::visit (HIR::Function &function)
// check the types are compatible
auto trait_item_type = resolved_trait_item.get_tyty_for_receiver (self);
- if (!trait_item_type->can_eq (lookup, true))
+ if (!types_compatable (TyTy::TyWithLocation (trait_item_type),
+ TyTy::TyWithLocation (lookup), function.get_locus (),
+ true /*emit_errors*/))
{
RichLocation r (function.get_locus ());
r.add_range (resolved_trait_item.get_locus ());
diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc
index d77175e..1c93c60 100644
--- a/gcc/rust/typecheck/rust-type-util.cc
+++ b/gcc/rust/typecheck/rust-type-util.cc
@@ -123,6 +123,16 @@ query_type (HirId reference, TyTy::BaseType **result)
return false;
}
+bool
+types_compatable (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
+ Location unify_locus, bool emit_errors)
+{
+ TyTy::BaseType *result
+ = unify_site_and (UNKNOWN_HIRID, lhs, rhs, unify_locus, emit_errors,
+ false /*commit*/, true /*infer*/, true /*cleanup*/);
+ return result->get_kind () != TyTy::TypeKind::ERROR;
+}
+
TyTy::BaseType *
unify_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
Location unify_locus)
diff --git a/gcc/rust/typecheck/rust-type-util.h b/gcc/rust/typecheck/rust-type-util.h
index 89e4a18..d6f1b8c 100644
--- a/gcc/rust/typecheck/rust-type-util.h
+++ b/gcc/rust/typecheck/rust-type-util.h
@@ -28,6 +28,10 @@ namespace Resolver {
bool
query_type (HirId reference, TyTy::BaseType **result);
+bool
+types_compatable (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
+ Location unify_locus, bool emit_errors);
+
TyTy::BaseType *
unify_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
Location unify_locus);
diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc
index 19a4e23..d7c5c18 100644
--- a/gcc/rust/typecheck/rust-unify.cc
+++ b/gcc/rust/typecheck/rust-unify.cc
@@ -1576,17 +1576,8 @@ UnifyRules::expect_placeholder (TyTy::PlaceholderType *ltype,
}
break;
- case TyTy::PLACEHOLDER: {
- TyTy::PlaceholderType &type
- = *static_cast<TyTy::PlaceholderType *> (rtype);
- bool symbol_match
- = ltype->get_symbol ().compare (type.get_symbol ()) == 0;
- if (symbol_match)
- {
- return type.clone ();
- }
- }
- break;
+ case TyTy::PLACEHOLDER:
+ return ltype->clone ();
case TyTy::PROJECTION:
case TyTy::DYNAMIC:
@@ -1609,6 +1600,10 @@ UnifyRules::expect_placeholder (TyTy::PlaceholderType *ltype,
case TyTy::USIZE:
case TyTy::ISIZE:
case TyTy::NEVER:
+ if (infer_flag)
+ return rtype->clone ();
+ gcc_fallthrough ();
+
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
diff --git a/gcc/testsuite/rust/compile/traits2.rs b/gcc/testsuite/rust/compile/traits2.rs
index 7357c22..376b3c9 100644
--- a/gcc/testsuite/rust/compile/traits2.rs
+++ b/gcc/testsuite/rust/compile/traits2.rs
@@ -7,7 +7,7 @@ struct Baz;
impl Foo for Baz {
fn Bar() {}
- // { dg-error "expected .i32. got .()." "" { target *-*-* } .-1 }
+ // { dg-error "expected" "" { target *-*-* } .-1 }
// { dg-error "method .Bar. has an incompatible type for trait .Foo." "" { target *-*-* } .-2 }
}
diff --git a/gcc/testsuite/rust/compile/traits3.rs b/gcc/testsuite/rust/compile/traits3.rs
index fd3fa45..d6d0814 100644
--- a/gcc/testsuite/rust/compile/traits3.rs
+++ b/gcc/testsuite/rust/compile/traits3.rs
@@ -10,9 +10,9 @@ impl<T> Foo for Bar<T> {
type A = i32;
fn baz(a: f32) -> f32 {
- // { dg-error "method .baz. has an incompatible type for trait .Foo." "" { target *-*-* } .-1 }
+ // { dg-error "expected" "" { target *-*-* } .-1 }
+ // { dg-error "method .baz. has an incompatible type for trait .Foo." "" { target *-*-* } .-2 }
a
- // { dg-error "expected .i32. got .f32." "" { target *-*-* } .-1 }
}
}