diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-08-31 21:38:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-31 21:38:32 +0000 |
commit | 4f0a2729d78d77f14140531ca809d1c45311f0c9 (patch) | |
tree | 69e9a51279bce8099b757e17670af963193cf754 /gcc | |
parent | ceb43210f8a6dfec98f634c326964328d1247f57 (diff) | |
parent | 63403f0af7203f3b3c4bc2fef52fee884bb728b8 (diff) | |
download | gcc-4f0a2729d78d77f14140531ca809d1c45311f0c9.zip gcc-4f0a2729d78d77f14140531ca809d1c45311f0c9.tar.gz gcc-4f0a2729d78d77f14140531ca809d1c45311f0c9.tar.bz2 |
Merge #1519
1519: Fix generic substitution on unit structs r=philberty a=philberty
Fixes #1518
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-trait-resolve.cc | 3 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.cc | 12 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-bounds.cc | 15 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.h | 7 |
4 files changed, 37 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index 7357585..146fe26 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -368,6 +368,9 @@ void AssociatedImplTrait::setup_associated_types ( const TyTy::BaseType *self, const TyTy::TypeBoundPredicate &bound) { + if (!bound.contains_associated_types ()) + return; + // compute the constrained impl block generic arguments based on self and the // higher ranked trait bound TyTy::BaseType *receiver = self->clone (); diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 57ed370..9a0d144 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1024,6 +1024,11 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) return; } + rust_debug_loc (expr.get_method_name ().get_locus (), + "resolved method to: {%u} {%s}", + candidate.candidate.ty->get_ref (), + candidate.candidate.ty->debug_str ().c_str ()); + // Get the adjusted self Adjuster adj (receiver_tyty); TyTy::BaseType *adjusted_self = adj.adjust_type (candidate.adjustments); @@ -1120,6 +1125,9 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) // apply any remaining generic arguments if (expr.get_method_name ().has_generic_args ()) { + rust_debug_loc (expr.get_method_name ().get_generic_args ().get_locus (), + "applying generic arguments to method_call: {%s}", + lookup->debug_str ().c_str ()); HIR::GenericArgs &args = expr.get_method_name ().get_generic_args (); lookup = SubstMapper::Resolve (lookup, expr.get_method_name ().get_locus (), @@ -1129,10 +1137,14 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) } else if (lookup->needs_generic_substitutions ()) { + rust_debug ("method needs inference: {%s}", + lookup->debug_str ().c_str ()); lookup = SubstMapper::InferSubst (lookup, expr.get_method_name ().get_locus ()); } + rust_debug ("type-checking method_call: {%s}", lookup->debug_str ().c_str ()); + TyTy::BaseType *function_ret_tyty = TyTy::TypeCheckMethodCallExpr::go (lookup, expr, adjusted_self, context); if (function_ret_tyty == nullptr diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index 7a1562a..811d64b 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -374,6 +374,21 @@ TypeBoundPredicate::requires_generic_args () const return substitutions.size () > 1; } +bool +TypeBoundPredicate::contains_associated_types () const +{ + auto trait_ref = get (); + for (const auto &trait_item : trait_ref->get_trait_items ()) + { + bool is_associated_type + = trait_item.get_trait_item_type () + == Resolver::TraitItemReference::TraitItemType::TYPE; + if (is_associated_type) + return true; + } + return false; +} + // trait item reference const Resolver::TraitItemReference * diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index a351932..74c8c35 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -1057,6 +1057,8 @@ public: bool requires_generic_args () const; + bool contains_associated_types () const; + private: DefId reference; Location locus; @@ -1360,6 +1362,11 @@ public: bool is_concrete () const override final { + if (is_unit ()) + { + return !needs_substitution (); + } + for (auto &variant : variants) { for (auto &field : variant->get_fields ()) |