From 3aeb9f47187f9b7ad55e32bcd273556823f383c6 Mon Sep 17 00:00:00 2001 From: lrh2000 Date: Sat, 10 Apr 2021 22:53:32 +0800 Subject: Introduce limited support for the never type --- gcc/rust/backend/rust-compile-context.h | 5 +++ gcc/rust/backend/rust-compile-tyty.h | 5 +++ gcc/rust/backend/rust-compile.cc | 8 ++--- gcc/rust/hir/rust-ast-lower.cc | 2 +- gcc/rust/hir/tree/rust-hir-expr.h | 2 +- gcc/rust/typecheck/rust-hir-type-check-expr.h | 38 +++++++++++++------- gcc/rust/typecheck/rust-hir-type-check-item.h | 3 +- gcc/rust/typecheck/rust-hir-type-check.cc | 29 +++++----------- gcc/rust/typecheck/rust-substitution-mapper.h | 4 +++ gcc/rust/typecheck/rust-tycheck-dump.h | 2 +- gcc/rust/typecheck/rust-tyty-call.h | 2 ++ gcc/rust/typecheck/rust-tyty-cmp.h | 17 +++++++++ gcc/rust/typecheck/rust-tyty-rules.h | 23 +++++++++++++ gcc/rust/typecheck/rust-tyty-visitor.h | 1 + gcc/rust/typecheck/rust-tyty.cc | 32 +++++++++++++++++ gcc/rust/typecheck/rust-tyty.h | 39 +++++++++++++++++++++ gcc/testsuite/rust.test/compile/block_expr5.rs | 40 ++++++++++++++++++++++ gcc/testsuite/rust.test/compile/func1.rs | 7 ++++ gcc/testsuite/rust.test/compile/func2.rs | 20 +++++++++++ gcc/testsuite/rust.test/compile/never_type1.rs | 22 ++++++++++++ .../rust.test/compile/stmt_with_block1.rs | 13 +++++++ gcc/testsuite/rust.test/xfail_compile/break1.rs | 5 ++- gcc/testsuite/rust.test/xfail_compile/func1.rs | 2 +- gcc/testsuite/rust.test/xfail_compile/func4.rs | 6 ++++ gcc/testsuite/rust.test/xfail_compile/func5.rs | 7 ++++ .../xfail_compile/implicit_returns_err2.rs | 3 +- .../xfail_compile/implicit_returns_err4.rs | 10 ++++++ .../rust.test/xfail_compile/never_type_err1.rs | 14 ++++++++ .../rust.test/xfail_compile/never_type_err2.rs | 4 +++ 29 files changed, 316 insertions(+), 49 deletions(-) create mode 100644 gcc/testsuite/rust.test/compile/block_expr5.rs create mode 100644 gcc/testsuite/rust.test/compile/func1.rs create mode 100644 gcc/testsuite/rust.test/compile/func2.rs create mode 100644 gcc/testsuite/rust.test/compile/never_type1.rs create mode 100644 gcc/testsuite/rust.test/compile/stmt_with_block1.rs create mode 100644 gcc/testsuite/rust.test/xfail_compile/func4.rs create mode 100644 gcc/testsuite/rust.test/xfail_compile/func5.rs create mode 100644 gcc/testsuite/rust.test/xfail_compile/implicit_returns_err4.rs create mode 100644 gcc/testsuite/rust.test/xfail_compile/never_type_err1.rs create mode 100644 gcc/testsuite/rust.test/xfail_compile/never_type_err2.rs (limited to 'gcc') diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 8866575..2024a6f 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -503,6 +503,11 @@ public: translated = compiled_type; } + void visit (TyTy::NeverType &) override + { + translated = ctx->get_backend ()->void_type (); + } + private: TyTyResolveCompile (Context *ctx) : ctx (ctx), translated (nullptr) {} diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h index 28db289..ba98ac0 100644 --- a/gcc/rust/backend/rust-compile-tyty.h +++ b/gcc/rust/backend/rust-compile-tyty.h @@ -222,6 +222,11 @@ public: = backend->named_type ("str", raw_str, Linemap::predeclared_location ()); } + void visit (TyTy::NeverType &) override + { + translated = backend->void_type (); + } + private: TyTyCompile (::Backend *backend) : backend (backend), translated (nullptr), diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index d0e0c66..9375dd0 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -256,7 +256,7 @@ CompileBlock::visit (HIR::BlockExpr &expr) } } - if (expr.has_expr () && expr.tail_expr_reachable ()) + if (expr.has_expr ()) { // the previous passes will ensure this is a valid return // dead code elimination should remove any bad trailing expressions @@ -410,17 +410,15 @@ HIRCompileBase::compile_function_body ( } } - if (function_body->has_expr () && function_body->tail_expr_reachable ()) + if (function_body->has_expr ()) { // the previous passes will ensure this is a valid return // dead code elimination should remove any bad trailing expressions Bexpression *compiled_expr = CompileExpr::Compile (function_body->expr.get (), ctx); - if (has_return_type) + if (has_return_type && compiled_expr) { - rust_assert (compiled_expr != nullptr); - std::vector retstmts; retstmts.push_back (compiled_expr); diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index 0bacdd2..86b10d5 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -90,7 +90,7 @@ ASTLoweringBlock::visit (AST::BlockExpr &expr) return true; }); - bool tail_reachable = expr.has_tail_expr () && !block_did_terminate; + bool tail_reachable = !block_did_terminate; if (expr.has_tail_expr () && block_did_terminate) { // warning unreachable tail expressions diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 26f36c4d..498c8de 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -2511,7 +2511,7 @@ public: // Returns whether the block contains an expression bool has_expr () const { return expr != nullptr; } - bool tail_expr_reachable () const { return tail_reachable; } + bool is_tail_reachable () const { return tail_reachable; } BlockExpr (Analysis::NodeMapping mappings, std::vector > block_statements, diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index 6b6eed0..c18ad2a 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -145,16 +145,15 @@ public: void visit (HIR::ReturnExpr &expr) override { - if (!expr.has_return_expr ()) - { - infered = new TyTy::TupleType (expr.get_mappings ().get_hirid ()); - return; - } - auto fn_return_tyty = context->peek_return_type (); rust_assert (fn_return_tyty != nullptr); - auto expr_ty = TypeCheckExpr::Resolve (expr.get_expr (), false); + TyTy::BaseType *expr_ty; + if (expr.has_return_expr ()) + expr_ty = TypeCheckExpr::Resolve (expr.get_expr (), false); + else + expr_ty = new TyTy::TupleType (expr.get_mappings ().get_hirid ()); + if (expr_ty == nullptr) { rust_error_at (expr.get_locus (), @@ -166,6 +165,8 @@ public: fn_return_tyty->append_reference (expr_ty->get_ref ()); for (auto &ref : infered->get_combined_refs ()) fn_return_tyty->append_reference (ref); + + infered = new TyTy::NeverType (expr.get_mappings ().get_hirid ()); } void visit (HIR::CallExpr &expr) override @@ -622,17 +623,28 @@ public: auto else_blk_resolved = TypeCheckExpr::Resolve (expr.get_else_block (), inside_loop); - infered = if_blk_resolved->unify (else_blk_resolved); + if (if_blk_resolved->get_kind () == TyTy::NEVER) + infered = else_blk_resolved; + else if (else_blk_resolved->get_kind () == TyTy::NEVER) + infered = if_blk_resolved; + else + infered = if_blk_resolved->unify (else_blk_resolved); } void visit (HIR::IfExprConseqIf &expr) override { TypeCheckExpr::Resolve (expr.get_if_condition (), false); - auto if_blk = TypeCheckExpr::Resolve (expr.get_if_block (), inside_loop); - auto else_blk + auto if_blk_resolved + = TypeCheckExpr::Resolve (expr.get_if_block (), inside_loop); + auto else_blk_resolved = TypeCheckExpr::Resolve (expr.get_conseq_if_expr (), inside_loop); - infered = if_blk->unify (else_blk); + if (if_blk_resolved->get_kind () == TyTy::NEVER) + infered = else_blk_resolved; + else if (else_blk_resolved->get_kind () == TyTy::NEVER) + infered = if_blk_resolved; + else + infered = if_blk_resolved->unify (else_blk_resolved); } void visit (HIR::BlockExpr &expr) override; @@ -929,7 +941,7 @@ public: context->swap_head_loop_context (unified_ty); } - infered = new TyTy::TupleType (expr.get_mappings ().get_hirid ()); + infered = new TyTy::NeverType (expr.get_mappings ().get_hirid ()); } void visit (HIR::ContinueExpr &expr) override @@ -941,7 +953,7 @@ public: return; } - infered = new TyTy::TupleType (expr.get_mappings ().get_hirid ()); + infered = new TyTy::NeverType (expr.get_mappings ().get_hirid ()); } void visit (HIR::BorrowExpr &expr) override diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.h b/gcc/rust/typecheck/rust-hir-type-check-item.h index 44fe943..1205dce 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.h +++ b/gcc/rust/typecheck/rust-hir-type-check-item.h @@ -82,7 +82,8 @@ public: context->pop_return_type (); - expected_ret_tyty->unify (block_expr_ty); + if (block_expr_ty->get_kind () != TyTy::NEVER) + expected_ret_tyty->unify (block_expr_ty); } private: diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc index f1503be..aece188 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.cc +++ b/gcc/rust/typecheck/rust-hir-type-check.cc @@ -123,14 +123,7 @@ TypeResolution::Resolve (HIR::Crate &crate) void TypeCheckExpr::visit (HIR::BlockExpr &expr) { - TyTy::BaseType *block_tyty - = new TyTy::TupleType (expr.get_mappings ().get_hirid ()); - expr.iterate_stmts ([&] (HIR::Stmt *s) mutable -> bool { - bool is_final_stmt = expr.is_final_stmt (s); - bool has_final_expr = expr.has_expr () && expr.tail_expr_reachable (); - bool stmt_is_final_expr = is_final_stmt && !has_final_expr; - auto resolved = TypeCheckStmt::Resolve (s, inside_loop); if (resolved == nullptr) { @@ -138,12 +131,7 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr) return false; } - if (stmt_is_final_expr) - { - delete block_tyty; - block_tyty = resolved; - } - else if (s->is_unit_check_needed () && !resolved->is_unit ()) + if (s->is_unit_check_needed () && !resolved->is_unit ()) { auto unit = new TyTy::TupleType (s->get_mappings ().get_hirid ()); resolved = unit->unify (resolved); @@ -153,14 +141,13 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr) }); if (expr.has_expr ()) - { - delete block_tyty; - - block_tyty - = TypeCheckExpr::Resolve (expr.get_final_expr ().get (), inside_loop); - } - - infered = block_tyty->clone (); + infered + = TypeCheckExpr::Resolve (expr.get_final_expr ().get (), inside_loop) + ->clone (); + else if (expr.is_tail_reachable ()) + infered = new TyTy::TupleType (expr.get_mappings ().get_hirid ()); + else + infered = new TyTy::NeverType (expr.get_mappings ().get_hirid ()); } // RUST_HIR_TYPE_CHECK_STRUCT_FIELD diff --git a/gcc/rust/typecheck/rust-substitution-mapper.h b/gcc/rust/typecheck/rust-substitution-mapper.h index bc20e4b..4cd06bb 100644 --- a/gcc/rust/typecheck/rust-substitution-mapper.h +++ b/gcc/rust/typecheck/rust-substitution-mapper.h @@ -99,6 +99,7 @@ public: void visit (TyTy::ReferenceType &) override { gcc_unreachable (); } void visit (TyTy::ParamType &) override { gcc_unreachable (); } void visit (TyTy::StrType &) override { gcc_unreachable (); } + void visit (TyTy::NeverType &) override { gcc_unreachable (); } private: SubstMapper (HirId ref, HIR::GenericArgs *generics, Location locus) @@ -157,6 +158,7 @@ public: void visit (TyTy::ReferenceType &) override { gcc_unreachable (); } void visit (TyTy::ParamType &) override { gcc_unreachable (); } void visit (TyTy::StrType &) override { gcc_unreachable (); } + void visit (TyTy::NeverType &) override { gcc_unreachable (); } private: SubstMapperInternal (HirId ref, TyTy::SubstitutionArgumentMappings &mappings) @@ -211,6 +213,7 @@ public: void visit (TyTy::ReferenceType &) override { gcc_unreachable (); } void visit (TyTy::ParamType &) override { gcc_unreachable (); } void visit (TyTy::StrType &) override { gcc_unreachable (); } + void visit (TyTy::NeverType &) override { gcc_unreachable (); } private: SubstMapperFromExisting (TyTy::BaseType *concrete, TyTy::BaseType *receiver) @@ -258,6 +261,7 @@ public: void visit (TyTy::ReferenceType &) override { gcc_unreachable (); } void visit (TyTy::ParamType &) override { gcc_unreachable (); } void visit (TyTy::StrType &) override { gcc_unreachable (); } + void visit (TyTy::NeverType &) override { gcc_unreachable (); } private: GetUsedSubstArgs () : args (TyTy::SubstitutionArgumentMappings::error ()) {} diff --git a/gcc/rust/typecheck/rust-tycheck-dump.h b/gcc/rust/typecheck/rust-tycheck-dump.h index 953770e..2ab8abb 100644 --- a/gcc/rust/typecheck/rust-tycheck-dump.h +++ b/gcc/rust/typecheck/rust-tycheck-dump.h @@ -107,7 +107,7 @@ public: return true; }); - if (expr.has_expr () && expr.tail_expr_reachable ()) + if (expr.has_expr ()) { dump += indent (); expr.expr->accept_vis (*this); diff --git a/gcc/rust/typecheck/rust-tyty-call.h b/gcc/rust/typecheck/rust-tyty-call.h index 4171da5..2aba298 100644 --- a/gcc/rust/typecheck/rust-tyty-call.h +++ b/gcc/rust/typecheck/rust-tyty-call.h @@ -53,6 +53,7 @@ public: void visit (ReferenceType &type) override { gcc_unreachable (); } void visit (ParamType &) override { gcc_unreachable (); } void visit (StrType &) override { gcc_unreachable (); } + void visit (NeverType &) override { gcc_unreachable (); } // tuple-structs void visit (ADTType &type) override; @@ -100,6 +101,7 @@ public: void visit (ReferenceType &type) override { gcc_unreachable (); } void visit (ParamType &) override { gcc_unreachable (); } void visit (StrType &) override { gcc_unreachable (); } + void visit (NeverType &) override { gcc_unreachable (); } // FIXME void visit (FnPtr &type) override { gcc_unreachable (); } diff --git a/gcc/rust/typecheck/rust-tyty-cmp.h b/gcc/rust/typecheck/rust-tyty-cmp.h index b195e5c..1641264 100644 --- a/gcc/rust/typecheck/rust-tyty-cmp.h +++ b/gcc/rust/typecheck/rust-tyty-cmp.h @@ -84,6 +84,8 @@ public: virtual void visit (StrType &) override { ok = false; } + virtual void visit (NeverType &) override { ok = false; } + protected: BaseCmp (BaseType *base) : mappings (Analysis::Mappings::get ()), @@ -815,6 +817,21 @@ private: StrType *base; }; +class NeverCmp : public BaseCmp +{ + using Rust::TyTy::BaseCmp::visit; + +public: + NeverCmp (NeverType *base) : BaseCmp (base), base (base) {} + + void visit (NeverType &type) override { ok = true; } + +private: + BaseType *get_base () override { return base; } + + NeverType *base; +}; + } // namespace TyTy } // namespace Rust diff --git a/gcc/rust/typecheck/rust-tyty-rules.h b/gcc/rust/typecheck/rust-tyty-rules.h index 03fe0d8..6f7e663 100644 --- a/gcc/rust/typecheck/rust-tyty-rules.h +++ b/gcc/rust/typecheck/rust-tyty-rules.h @@ -293,6 +293,14 @@ public: type.as_string ().c_str ()); } + virtual void visit (NeverType &type) override + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + rust_error_at (ref_locus, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + protected: BaseRules (BaseType *base) : mappings (Analysis::Mappings::get ()), @@ -1138,6 +1146,21 @@ private: StrType *base; }; +class NeverRules : public BaseRules +{ + using Rust::TyTy::BaseRules::visit; + +public: + NeverRules (NeverType *base) : BaseRules (base), base (base) {} + + virtual void visit (NeverType &type) override { resolved = type.clone (); } + +private: + BaseType *get_base () override { return base; } + + NeverType *base; +}; + } // namespace TyTy } // namespace Rust diff --git a/gcc/rust/typecheck/rust-tyty-visitor.h b/gcc/rust/typecheck/rust-tyty-visitor.h index 453a3b6..0ed7eef 100644 --- a/gcc/rust/typecheck/rust-tyty-visitor.h +++ b/gcc/rust/typecheck/rust-tyty-visitor.h @@ -44,6 +44,7 @@ public: virtual void visit (ReferenceType &type) = 0; virtual void visit (ParamType &type) = 0; virtual void visit (StrType &type) = 0; + virtual void visit (NeverType &type) = 0; }; } // namespace TyTy diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 8378cf2..86b1da0 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -1307,6 +1307,38 @@ StrType::is_equal (const BaseType &other) const return get_kind () == other.get_kind (); } +void +NeverType::accept_vis (TyVisitor &vis) +{ + vis.visit (*this); +} + +std::string +NeverType::as_string () const +{ + return "!"; +} + +BaseType * +NeverType::unify (BaseType *other) +{ + NeverRules r (this); + return r.unify (other); +} + +bool +NeverType::can_eq (BaseType *other) +{ + NeverCmp r (this); + return r.can_eq (other); +} + +BaseType * +NeverType::clone () +{ + return new NeverType (get_ref (), get_ty_ref (), get_combined_refs ()); +} + // rust-tyty-call.h void diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 2f343c1..2b9f304 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -45,6 +45,7 @@ enum TypeKind FLOAT, USIZE, ISIZE, + NEVER, // there are more to add... ERROR }; @@ -1226,6 +1227,41 @@ public: BaseType *clone () final override; }; +// https://doc.rust-lang.org/std/primitive.never.html +// +// Since the `!` type is really complicated and it is even still unstable +// in rustc, only fairly limited support for this type is introduced here. +// Unification between `!` and ANY other type (including ``) is simply +// not allowed. If it is needed, it should be handled manually. For example, +// unifying `!` with other types is very necessary when resolving types of +// `if/else` expressions. +// +// See related discussion at https://github.com/Rust-GCC/gccrs/pull/364 +class NeverType : public BaseType +{ +public: + NeverType (HirId ref, std::set refs = std::set ()) + : BaseType (ref, ref, TypeKind::NEVER, refs) + {} + + NeverType (HirId ref, HirId ty_ref, std::set refs = std::set ()) + : BaseType (ref, ty_ref, TypeKind::NEVER, refs) + {} + + void accept_vis (TyVisitor &vis) override; + + std::string as_string () const override; + + BaseType *unify (BaseType *other) override; + bool can_eq (BaseType *other) override; + + BaseType *clone () final override; + + std::string get_name () const override final { return as_string (); } + + bool is_unit () const override { return true; } +}; + class TypeKindFormat { public: @@ -1281,6 +1317,9 @@ public: case TypeKind::ISIZE: return "Isize"; + case TypeKind::NEVER: + return "Never"; + case TypeKind::ERROR: return "ERROR"; } diff --git a/gcc/testsuite/rust.test/compile/block_expr5.rs b/gcc/testsuite/rust.test/compile/block_expr5.rs new file mode 100644 index 0000000..7e164a9 --- /dev/null +++ b/gcc/testsuite/rust.test/compile/block_expr5.rs @@ -0,0 +1,40 @@ +fn foo() -> i32 { + 0 +} + +fn bar() -> i32 { + foo(); + foo() +} + +fn baz() -> i32 { + { + bar(); + bar(); + } + { + bar(); + bar() + }; + { + bar(); + bar() + } +} + +fn test(ok: i32) -> i32 { + if ok >= 1 { + foo() + } else if ok <= -1 { + bar() + } else { + baz() + } +} + +fn main() { + let a = foo(); + let b = bar(); + let c = baz(); + test(a + b + c); +} diff --git a/gcc/testsuite/rust.test/compile/func1.rs b/gcc/testsuite/rust.test/compile/func1.rs new file mode 100644 index 0000000..df1789e --- /dev/null +++ b/gcc/testsuite/rust.test/compile/func1.rs @@ -0,0 +1,7 @@ +fn not_void() -> i32 { + 8 +} + +fn main() { + not_void(); +} diff --git a/gcc/testsuite/rust.test/compile/func2.rs b/gcc/testsuite/rust.test/compile/func2.rs new file mode 100644 index 0000000..f7dd556 --- /dev/null +++ b/gcc/testsuite/rust.test/compile/func2.rs @@ -0,0 +1,20 @@ +fn foo() { + 8; + 8; +} + +fn bar() -> i32 { + 8; + 8 +} + +fn baz() -> i32 { + 8; + return 8; +} + +fn main() { + let a = foo(); // { dg-warning "unused name" } + let b = bar(); // { dg-warning "unused name" } + let c = baz(); // { dg-warning "unused name" } +} diff --git a/gcc/testsuite/rust.test/compile/never_type1.rs b/gcc/testsuite/rust.test/compile/never_type1.rs new file mode 100644 index 0000000..0f15029 --- /dev/null +++ b/gcc/testsuite/rust.test/compile/never_type1.rs @@ -0,0 +1,22 @@ +fn foo() -> i32 { + let c; + let d; + + c = if false { + return 1; + } else { + 0.0 + }; + + d = if true { + 0.0 + } else { + return 1; + }; + + 0 +} + +fn main() { + foo(); +} diff --git a/gcc/testsuite/rust.test/compile/stmt_with_block1.rs b/gcc/testsuite/rust.test/compile/stmt_with_block1.rs new file mode 100644 index 0000000..b6aa56c --- /dev/null +++ b/gcc/testsuite/rust.test/compile/stmt_with_block1.rs @@ -0,0 +1,13 @@ +fn test(x: i32) -> i32 { + if x > 1 { 1 } else { 2 }; + if x > 1 { 1; } else { 2; } + + { 3; } + { 3 }; + + { 3 } +} + +fn main() { + let a = test(0); // { dg-warning "unused name" } +} diff --git a/gcc/testsuite/rust.test/xfail_compile/break1.rs b/gcc/testsuite/rust.test/xfail_compile/break1.rs index be3c9e8..33053cf 100644 --- a/gcc/testsuite/rust.test/xfail_compile/break1.rs +++ b/gcc/testsuite/rust.test/xfail_compile/break1.rs @@ -1,7 +1,6 @@ -// { dg-excess-errors "Noisy error and debug" } -fn main() { // { dg-error "expected .... got .." } +fn main() { let a; a = 1; - break a; // { dg-error "cannot `break` outside of a loop" + break a; // { dg-error "cannot `break` outside of a loop" } // { dg-error "failed to type resolve expression" "" { target { *-*-* } } .-1 } } diff --git a/gcc/testsuite/rust.test/xfail_compile/func1.rs b/gcc/testsuite/rust.test/xfail_compile/func1.rs index 7c1ce52..6758a38 100644 --- a/gcc/testsuite/rust.test/xfail_compile/func1.rs +++ b/gcc/testsuite/rust.test/xfail_compile/func1.rs @@ -1,4 +1,4 @@ -fn test(x: i32) -> bool { // { dg-error "expected .bool. got ..." } +fn test(x: i32) -> bool { return x + 1; // { dg-error "expected .bool. got .i32." } } diff --git a/gcc/testsuite/rust.test/xfail_compile/func4.rs b/gcc/testsuite/rust.test/xfail_compile/func4.rs new file mode 100644 index 0000000..3b2d2b0 --- /dev/null +++ b/gcc/testsuite/rust.test/xfail_compile/func4.rs @@ -0,0 +1,6 @@ +fn func() -> i32 { // { dg-error "expected .i32. got ...." } +} + +fn main() { + func(); +} diff --git a/gcc/testsuite/rust.test/xfail_compile/func5.rs b/gcc/testsuite/rust.test/xfail_compile/func5.rs new file mode 100644 index 0000000..05624f5 --- /dev/null +++ b/gcc/testsuite/rust.test/xfail_compile/func5.rs @@ -0,0 +1,7 @@ +fn func() -> i32 { + return; // { dg-error "expected .i32. got ...." } +} + +fn main() { + func(); +} diff --git a/gcc/testsuite/rust.test/xfail_compile/implicit_returns_err2.rs b/gcc/testsuite/rust.test/xfail_compile/implicit_returns_err2.rs index 75f4db4..fb90748 100644 --- a/gcc/testsuite/rust.test/xfail_compile/implicit_returns_err2.rs +++ b/gcc/testsuite/rust.test/xfail_compile/implicit_returns_err2.rs @@ -1,6 +1,5 @@ -// { dg-error "expected .* got .*" "" { target { *-*-* } } 0 } - fn test(x: i32) -> i32 { + // { dg-error "expected .i32. got .bool." "" { target *-*-* } .-1 } return 1; // { dg-warning "unreachable expression" "" { target *-*-* } .+1 } true diff --git a/gcc/testsuite/rust.test/xfail_compile/implicit_returns_err4.rs b/gcc/testsuite/rust.test/xfail_compile/implicit_returns_err4.rs new file mode 100644 index 0000000..59c6a02 --- /dev/null +++ b/gcc/testsuite/rust.test/xfail_compile/implicit_returns_err4.rs @@ -0,0 +1,10 @@ +fn test(x: bool) -> bool { + // { dg-error "expected .bool. got ...." "" { target *-*-*} .-1 } + return x; + // { dg-warning "unreachable expression" "" { target *-*-* } .+1 } + () +} + +fn main() { + let a = test(true); +} diff --git a/gcc/testsuite/rust.test/xfail_compile/never_type_err1.rs b/gcc/testsuite/rust.test/xfail_compile/never_type_err1.rs new file mode 100644 index 0000000..52b1283 --- /dev/null +++ b/gcc/testsuite/rust.test/xfail_compile/never_type_err1.rs @@ -0,0 +1,14 @@ +fn test() { + let a; + + // FIXME: Unimplemented features + a = if true { // { dg-error "expected .T.. got .!." } + return; + } else { + return; + }; +} + +fn main() { + test(); +} diff --git a/gcc/testsuite/rust.test/xfail_compile/never_type_err2.rs b/gcc/testsuite/rust.test/xfail_compile/never_type_err2.rs new file mode 100644 index 0000000..c94cb82 --- /dev/null +++ b/gcc/testsuite/rust.test/xfail_compile/never_type_err2.rs @@ -0,0 +1,4 @@ +// FIXME: Unimplemented features +fn foo() -> ! { // { dg-error "unresolved type" } + let a: !; // { dg-error "unresolved type" } +} -- cgit v1.1