aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-03-09 16:09:09 +0000
committerPhilip Herron <philip.herron@embecosm.com>2022-03-10 11:40:11 +0000
commit178cabde9f99023559922318ad54ad47c1fce803 (patch)
treef7d55dd5b6aab841a055dde00b3abfb637d3ae8b /gcc
parent94990a843b6df9ff6010957d724dbb70bea94ceb (diff)
downloadgcc-178cabde9f99023559922318ad54ad47c1fce803.zip
gcc-178cabde9f99023559922318ad54ad47c1fce803.tar.gz
gcc-178cabde9f99023559922318ad54ad47c1fce803.tar.bz2
Add missing builtin mappings for never type
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/hir/rust-ast-lower-type.h13
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-type.cc6
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-type.h2
-rw-r--r--gcc/rust/resolve/rust-ast-resolve.cc2
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-type.h9
-rw-r--r--gcc/testsuite/rust/compile/never_type_err2.rs4
6 files changed, 32 insertions, 4 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-type.h b/gcc/rust/hir/rust-ast-lower-type.h
index 3d1690f..a9b4dd8 100644
--- a/gcc/rust/hir/rust-ast-lower-type.h
+++ b/gcc/rust/hir/rust-ast-lower-type.h
@@ -291,6 +291,19 @@ public:
translated);
}
+ void visit (AST::NeverType &type) override
+ {
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, type.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (crate_num));
+
+ translated = new HIR::NeverType (mapping, type.get_locus ());
+
+ mappings->insert_hir_type (mapping.get_crate_num (), mapping.get_hirid (),
+ translated);
+ }
+
void visit (AST::TraitObjectTypeOneBound &type) override;
void visit (AST::TraitObjectType &type) override;
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc
index 252d1ca..fd5c056 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -198,6 +198,12 @@ ResolveType::visit (AST::InferredType &type)
}
void
+ResolveType::visit (AST::NeverType &type)
+{
+ ok = true;
+}
+
+void
ResolveType::visit (AST::SliceType &type)
{
type.get_elem_type ()->accept_vis (*this);
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h
index d835e00..e534423 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -386,6 +386,8 @@ public:
void visit (AST::InferredType &type) override;
+ void visit (AST::NeverType &type) override;
+
void visit (AST::RawPointerType &type) override;
void visit (AST::TraitObjectTypeOneBound &type) override;
diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc
index 094fa4a..86c159d 100644
--- a/gcc/rust/resolve/rust-ast-resolve.cc
+++ b/gcc/rust/resolve/rust-ast-resolve.cc
@@ -187,6 +187,7 @@ Resolver::generate_builtins ()
auto isize = new TyTy::ISizeType (mappings->get_next_hir_id ());
auto char_tyty = new TyTy::CharType (mappings->get_next_hir_id ());
auto str = new TyTy::StrType (mappings->get_next_hir_id ());
+ auto never = new TyTy::NeverType (mappings->get_next_hir_id ());
MKBUILTIN_TYPE ("u8", builtins, u8);
MKBUILTIN_TYPE ("u16", builtins, u16);
@@ -205,6 +206,7 @@ Resolver::generate_builtins ()
MKBUILTIN_TYPE ("isize", builtins, isize);
MKBUILTIN_TYPE ("char", builtins, char_tyty);
MKBUILTIN_TYPE ("str", builtins, str);
+ MKBUILTIN_TYPE ("!", builtins, never);
// unit type ()
TyTy::TupleType *unit_tyty
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.h b/gcc/rust/typecheck/rust-hir-type-check-type.h
index 400328c..74298e4 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.h
@@ -145,6 +145,15 @@ public:
type.get_locus ());
}
+ void visit (HIR::NeverType &type) override
+ {
+ TyTy::BaseType *lookup = nullptr;
+ bool ok = context->lookup_builtin ("!", &lookup);
+ rust_assert (ok);
+
+ translated = lookup->clone ();
+ }
+
void visit (HIR::TraitObjectType &type) override;
private:
diff --git a/gcc/testsuite/rust/compile/never_type_err2.rs b/gcc/testsuite/rust/compile/never_type_err2.rs
deleted file mode 100644
index c94cb82..0000000
--- a/gcc/testsuite/rust/compile/never_type_err2.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-// FIXME: Unimplemented features
-fn foo() -> ! { // { dg-error "unresolved type" }
- let a: !; // { dg-error "unresolved type" }
-}