diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-03-29 13:35:53 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2023-03-30 16:52:24 +0000 |
commit | 1ef39479434ce54879e46926d1ac1c12009c5c07 (patch) | |
tree | 7e317d9daab85ca97416f1f752ad74f91493566a /gcc/rust | |
parent | 3cc5c9360c9454f7aa20717b6cfcc7085836233b (diff) | |
download | gcc-1ef39479434ce54879e46926d1ac1c12009c5c07.zip gcc-1ef39479434ce54879e46926d1ac1c12009c5c07.tar.gz gcc-1ef39479434ce54879e46926d1ac1c12009c5c07.tar.bz2 |
gccrs: Fix handling of generic arguments for lifetimes only
We might have generics that are only for lifetimes this is a bad error
check. We can simply rely on the function to marshall the HIR generics
arguements for the type system to do the error handling for us which will
be more acurate anyway.
Fixes #2043 #2039
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit):
add check for reference marker and type's in self params
(ResolveItem::visit): likewise
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path):
remove bad generics check
(TypeCheckExpr::resolve_segments): likewise
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): likewise
gcc/testsuite/ChangeLog:
* rust/compile/const_generics_5.rs: update test case
* rust/compile/issue-2043.rs: New test.
* rust/compile/issue-2039.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.cc | 18 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-path.cc | 15 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-type.cc | 18 |
3 files changed, 6 insertions, 45 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 0605acc..9758984 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -142,13 +142,8 @@ ResolveTraitItems::visit (AST::TraitItemMethod &func) if (self_param.has_type ()) { - if (self_param.get_has_ref ()) - { - // FIXME is this true? - rust_error_at ( - self_param.get_locus (), - "it is not possible to mark self as reference and specify type"); - } + // This shouldn't happen the parser should already error for this + rust_assert (!self_param.get_has_ref ()); ResolveType::go (self_param.get_type ().get ()); } else @@ -655,13 +650,8 @@ ResolveItem::visit (AST::Method &method) if (self_param.has_type ()) { - if (self_param.get_has_ref ()) - { - // FIXME is this true? - rust_error_at ( - self_param.get_locus (), - "it is not possible to mark self as reference and specify type"); - } + // This shouldn't happen the parser should already error for this + rust_assert (!self_param.get_has_ref ()); ResolveType::go (self_param.get_type ().get ()); } else diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index 88c927d..68ff995 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -280,14 +280,6 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression &expr, size_t *offset, // turbo-fish segment path::<ty> if (seg.has_generic_args ()) { - if (!lookup->has_subsititions_defined ()) - { - rust_error_at (expr.get_locus (), - "substitutions not supported for %s", - root_tyty->as_string ().c_str ()); - return new TyTy::ErrorType (expr.get_mappings ().get_hirid ()); - } - lookup = SubstMapper::Resolve (lookup, expr.get_locus (), &seg.get_generic_args ()); if (lookup->get_kind () == TyTy::TypeKind::ERROR) @@ -456,13 +448,6 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id, if (seg.has_generic_args ()) { - if (!tyseg->has_subsititions_defined ()) - { - rust_error_at (expr_locus, "substitutions not supported for %s", - tyseg->as_string ().c_str ()); - return; - } - tyseg = SubstMapper::Resolve (tyseg, expr_locus, &seg.get_generic_args ()); if (tyseg->get_kind () == TyTy::TypeKind::ERROR) diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index ee683d8..dad0c41 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -398,17 +398,10 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset, HIR::TypePathSegmentGeneric *generic_segment = static_cast<HIR::TypePathSegmentGeneric *> (seg.get ()); - if (!lookup->has_subsititions_defined ()) - { - rust_error_at (path.get_locus (), - "TypePath %s declares generic arguments but the " - "type %s does not have any", - path.as_string ().c_str (), - lookup->as_string ().c_str ()); - return new TyTy::ErrorType (lookup->get_ref ()); - } lookup = SubstMapper::Resolve (lookup, path.get_locus (), &generic_segment->get_generic_args ()); + if (lookup->get_kind () == TyTy::TypeKind::ERROR) + return new TyTy::ErrorType (seg->get_mappings ().get_hirid ()); } else if (lookup->needs_generic_substitutions ()) { @@ -494,13 +487,6 @@ TypeCheckType::resolve_segments ( HIR::TypePathSegmentGeneric *generic_segment = static_cast<HIR::TypePathSegmentGeneric *> (seg.get ()); - if (!tyseg->has_subsititions_defined ()) - { - rust_error_at (expr_locus, "substitutions not supported for %s", - tyseg->as_string ().c_str ()); - return new TyTy::ErrorType (expr_id); - } - tyseg = SubstMapper::Resolve (tyseg, expr_locus, &generic_segment->get_generic_args ()); if (tyseg->get_kind () == TyTy::TypeKind::ERROR) |