diff options
author | Thomas Young <wenzhang5800@gmail.com> | 2021-07-04 17:30:38 +0800 |
---|---|---|
committer | Thomas Young <wenzhang5800@gmail.com> | 2021-07-04 20:13:52 +0800 |
commit | 2e00415a117eb4fe2b98a3d80faee8c118ab0e82 (patch) | |
tree | 3477f54090bfc021c34b37e0ee6b888f53a7421c /gcc | |
parent | 210ae4f7b0fea9671482b8f01354fd5b9274f878 (diff) | |
download | gcc-2e00415a117eb4fe2b98a3d80faee8c118ab0e82.zip gcc-2e00415a117eb4fe2b98a3d80faee8c118ab0e82.tar.gz gcc-2e00415a117eb4fe2b98a3d80faee8c118ab0e82.tar.bz2 |
mark live symbol support type alias and tuple struct
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/lint/rust-lint-marklive.cc | 13 | ||||
-rw-r--r-- | gcc/rust/lint/rust-lint-marklive.h | 6 | ||||
-rw-r--r-- | gcc/rust/lint/rust-lint-scan-deadcode.h | 12 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/struct_base_init_1.rs | 1 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/struct_init_5.rs | 2 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/struct_init_6.rs | 3 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/struct_init_7.rs | 5 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/tuple_struct_unused.rs | 6 |
8 files changed, 40 insertions, 8 deletions
diff --git a/gcc/rust/lint/rust-lint-marklive.cc b/gcc/rust/lint/rust-lint-marklive.cc index af871a5..8210b65 100644 --- a/gcc/rust/lint/rust-lint-marklive.cc +++ b/gcc/rust/lint/rust-lint-marklive.cc @@ -123,6 +123,7 @@ MarkLive::visit_path_segment (HIR::PathExprSegment seg) { NodeId ast_node_id = seg.get_mappings ().get_nodeid (); NodeId ref_node_id = UNKNOWN_NODEID; + if (resolver->lookup_resolved_name (ast_node_id, &ref_node_id)) { Resolver::Definition def; @@ -200,6 +201,18 @@ MarkLive::visit (HIR::IdentifierExpr &expr) } void +MarkLive::visit (HIR::TypeAlias &alias) +{ + NodeId ast_node_id; + resolver->lookup_resolved_type ( + alias.get_type_aliased ()->get_mappings ().get_nodeid (), &ast_node_id); + HirId hir_id; + node_id_to_hir_id (alias.get_mappings ().get_crate_num (), ast_node_id, + hir_id, alias.get_locus ()); + mark_hir_id (hir_id); +} + +void MarkLive::mark_hir_id (HirId id) { if (scannedSymbols.find (id) == scannedSymbols.end ()) diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h index 5bc23e3..083d7b5 100644 --- a/gcc/rust/lint/rust-lint-marklive.h +++ b/gcc/rust/lint/rust-lint-marklive.h @@ -41,6 +41,7 @@ public: void visit (HIR::FieldAccessExpr &expr) override; void visit (HIR::TupleIndexExpr &expr) override; void visit (HIR::MethodCallExpr &expr) override; + void visit (HIR::TypeAlias &alias) override; void visit (HIR::BorrowExpr &expr) override { @@ -242,6 +243,11 @@ public: } } + virtual void visit (HIR::StructExprFieldIdentifierValue &field) override + { + field.get_value ()->accept_vis (*this); + } + void visit (HIR::StructExprStructBase &stct) override { stct.get_struct_base ()->base_struct.get ()->accept_vis (*this); diff --git a/gcc/rust/lint/rust-lint-scan-deadcode.h b/gcc/rust/lint/rust-lint-scan-deadcode.h index ad48a47..6ecf3a5 100644 --- a/gcc/rust/lint/rust-lint-scan-deadcode.h +++ b/gcc/rust/lint/rust-lint-scan-deadcode.h @@ -79,6 +79,18 @@ public: } } + void visit (HIR::TupleStruct &stct) override + { + // only warn tuple struct unconstructed, and ignoring unused field + HirId hirId = stct.get_mappings ().get_hirid (); + if (should_warn (hirId)) + { + rust_warning_at (stct.get_locus (), 0, "%s is never %s: %<%s%>", + "struct", "constructed", + stct.get_identifier ().c_str ()); + } + } + private: std::set<HirId> live_symbols; Resolver::Resolver *resolver; diff --git a/gcc/testsuite/rust/compile/torture/struct_base_init_1.rs b/gcc/testsuite/rust/compile/torture/struct_base_init_1.rs index 39dc61a..ee00c2c 100644 --- a/gcc/testsuite/rust/compile/torture/struct_base_init_1.rs +++ b/gcc/testsuite/rust/compile/torture/struct_base_init_1.rs @@ -2,7 +2,6 @@ struct Foo { a: i32, // { dg-warning "field is never read" "" { target *-*-* } .-1 } b: i32, -// { dg-warning "field is never read" "" { target *-*-* } .-1 } } fn foo() -> Foo { diff --git a/gcc/testsuite/rust/compile/torture/struct_init_5.rs b/gcc/testsuite/rust/compile/torture/struct_init_5.rs index e7f9d16..891f645 100644 --- a/gcc/testsuite/rust/compile/torture/struct_init_5.rs +++ b/gcc/testsuite/rust/compile/torture/struct_init_5.rs @@ -1,8 +1,6 @@ struct Foo { a: i32, -// { dg-warning "field is never read" "" { target *-*-* } .-1 } b: i32, -// { dg-warning "field is never read" "" { target *-*-* } .-1 } } fn main() { diff --git a/gcc/testsuite/rust/compile/torture/struct_init_6.rs b/gcc/testsuite/rust/compile/torture/struct_init_6.rs index 9a6241a..9fc52ed 100644 --- a/gcc/testsuite/rust/compile/torture/struct_init_6.rs +++ b/gcc/testsuite/rust/compile/torture/struct_init_6.rs @@ -1,8 +1,7 @@ struct Foo { a: i32, -// { dg-warning "field is never read" "" { target *-*-* } .-1 } + // { dg-warning "field is never read" "" { target *-*-* } .-1 } b: i32, -// { dg-warning "field is never read" "" { target *-*-* } .-1 } } fn main() { diff --git a/gcc/testsuite/rust/compile/torture/struct_init_7.rs b/gcc/testsuite/rust/compile/torture/struct_init_7.rs index a73d642..36dc00a 100644 --- a/gcc/testsuite/rust/compile/torture/struct_init_7.rs +++ b/gcc/testsuite/rust/compile/torture/struct_init_7.rs @@ -1,12 +1,11 @@ struct Foo { a: i32, -// { dg-warning "field is never read" "" { target *-*-* } .-1 } b: f32, // { dg-warning "field is never read" "" { target *-*-* } .-1 } } fn main() { - let a = Foo { a: 1, b: 2f32 }; - let b = Foo { b: 4f32, ..a }; + let c = Foo { a: 1, b: 2f32 }; + let b = Foo { b: 4f32, ..c }; // { dg-warning "unused name" "" { target *-*-* } .-1 } } diff --git a/gcc/testsuite/rust/compile/torture/tuple_struct_unused.rs b/gcc/testsuite/rust/compile/torture/tuple_struct_unused.rs new file mode 100644 index 0000000..26689e6 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/tuple_struct_unused.rs @@ -0,0 +1,6 @@ +struct Foo(i32, i32); +// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 } +// { dg-warning "unused name" "" { target *-*-* } .-2 } + +fn main() { +}
\ No newline at end of file |