diff --git a/gcc/rust/hir/rust-ast-lower-stmt.cc b/gcc/rust/hir/rust-ast-lower-stmt.cc index 29da916cefc..761a638a80e 100644 --- a/gcc/rust/hir/rust-ast-lower-stmt.cc +++ b/gcc/rust/hir/rust-ast-lower-stmt.cc @@ -163,5 +163,11 @@ ASTLoweringStmt::visit (AST::TraitImpl &impl_block) translated = ASTLoweringItem::translate (impl_block); } +void +ASTLoweringStmt::visit (AST::StaticItem &var) +{ + translated = ASTLoweringItem::translate (var); +} + } // namespace HIR } // namespace Rust diff --git a/gcc/rust/hir/rust-ast-lower-stmt.h b/gcc/rust/hir/rust-ast-lower-stmt.h index 111990d7aa8..ed395123859 100644 --- a/gcc/rust/hir/rust-ast-lower-stmt.h +++ b/gcc/rust/hir/rust-ast-lower-stmt.h @@ -45,6 +45,7 @@ class ASTLoweringStmt : public ASTLoweringBase void visit (AST::Trait &trait) override; void visit (AST::InherentImpl &impl_block) override; void visit (AST::TraitImpl &impl_block) override; + void visit (AST::StaticItem &var) override; private: ASTLoweringStmt () : translated (nullptr), terminated (false) {} diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.cc b/gcc/rust/resolve/rust-ast-resolve-stmt.cc index 7b62d1f7f78..ecd19769194 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.cc +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.cc @@ -56,5 +56,26 @@ ResolveStmt::visit (AST::TraitImpl &impl_block) ResolveItem::go (impl_block, prefix, canonical_prefix); } +void +ResolveStmt::visit (AST::StaticItem &var) +{ + auto decl = CanonicalPath::new_seg (var.get_node_id (), + var.get_identifier ().as_string ()); + auto path = decl; + auto cpath = canonical_prefix.append (decl); + mappings.insert_canonical_path (var.get_node_id (), cpath); + + resolver->get_name_scope ().insert ( + path, var.get_node_id (), var.get_locus (), false, Rib::ItemType::Static, + [&] (const CanonicalPath &, NodeId, location_t locus) -> void { + rich_location r (line_table, var.get_locus ()); + r.add_range (locus); + rust_error_at (r, "redefined multiple times"); + }); + + ResolveType::go (var.get_type ()); + ResolveExpr::go (var.get_expr (), path, cpath); +} + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h index 7118b70d705..fd9880cc21d 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.h +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h @@ -388,6 +388,7 @@ class ResolveStmt : public ResolverBase void visit (AST::Trait &trait) override; void visit (AST::InherentImpl &impl_block) override; void visit (AST::TraitImpl &impl_block) override; + void visit (AST::StaticItem &var) override; private: ResolveStmt (const CanonicalPath &prefix, diff --git a/gcc/testsuite/rust/compile/issue-3350.rs b/gcc/testsuite/rust/compile/issue-3350.rs new file mode 100644 index 00000000000..8880659afe6 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3350.rs @@ -0,0 +1,10 @@ +static FOO: i32 = 0; + +pub fn bar() -> i32 { + FOO +} + +pub fn baz() -> i32 { + static QUX: i32 = 0; + QUX +}