diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-06-29 21:24:47 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-06-29 21:24:47 +0100 |
commit | 59897751aa797c9c6e7e1d795bbc1afbb9c81e32 (patch) | |
tree | df151d2709a246dd0d5d2aba94327d7227eb0b30 /gcc | |
parent | e0c0ef46d21609326927986f4f8efb0e24638ab9 (diff) | |
download | gcc-59897751aa797c9c6e7e1d795bbc1afbb9c81e32.zip gcc-59897751aa797c9c6e7e1d795bbc1afbb9c81e32.tar.gz gcc-59897751aa797c9c6e7e1d795bbc1afbb9c81e32.tar.bz2 |
Revert change to ScanUnused to not scan Types
The scan dead-code pass will take over this role, but lets keep both
running for a while and then we can update ScanUnused to only scan for
unused labels and variables. Its not possible to rely on name resolution
to know what symbols are used or not used. Further resolution occurs during
type resolution and the dead code pass runs after type resolution.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-unused.h | 19 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/cfg_attr.rs | 4 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/unused1.rs | 1 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/unused_struct.rs | 8 |
4 files changed, 10 insertions, 22 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-unused.h b/gcc/rust/resolve/rust-ast-resolve-unused.h index f60093c..18d02a1 100644 --- a/gcc/rust/resolve/rust-ast-resolve-unused.h +++ b/gcc/rust/resolve/rust-ast-resolve-unused.h @@ -19,7 +19,6 @@ #ifndef RUST_AST_RESOLVE_UNUSED_H #define RUST_AST_RESOLVE_UNUSED_H -#include "rust-hir-map.h" #include "rust-ast-resolve-base.h" namespace Rust { @@ -36,20 +35,9 @@ public: bool ok = r->lookup_canonical_path (decl_node_id, &ident); rust_assert (ok); - Analysis::Mappings *map = Analysis::Mappings::get (); - HirId decl_hir_id; - // ScanUnused is conflicting with the dead code analysis here on types and - // functions. So just ignoring the warnings of item which will be handled - // by dead code analysis. - HIR::Item *found_item = nullptr; - if (map->lookup_node_to_hir (r->get_crate_num (), decl_node_id, - &decl_hir_id)) - { - found_item = map->lookup_hir_item (r->get_crate_num (), decl_hir_id); - } - + bool name_starts_with_underscore = ident.get ().at (0) == '_'; if (!r->have_references_for_node (decl_node_id) - && ident.get ().at (0) != '_' && !found_item) + && !name_starts_with_underscore) { rust_warning_at (locus, 0, "unused name '%s'", ident.get ().c_str ()); } @@ -61,8 +49,7 @@ public: { auto resolver = Resolver::get (); resolver->iterate_name_ribs ([&] (Rib *r) -> void { ScanRib (r); }); - // ScanUnused is conflicting with the dead code analysis here on types. - // resolver->iterate_type_ribs ([&] (Rib *r) -> void { ScanRib (r); }); + resolver->iterate_type_ribs ([&] (Rib *r) -> void { ScanRib (r); }); resolver->iterate_label_ribs ([&] (Rib *r) -> void { ScanRib (r); }); } }; diff --git a/gcc/testsuite/rust/compile/torture/cfg_attr.rs b/gcc/testsuite/rust/compile/torture/cfg_attr.rs index 885221f..bc02e2a 100644 --- a/gcc/testsuite/rust/compile/torture/cfg_attr.rs +++ b/gcc/testsuite/rust/compile/torture/cfg_attr.rs @@ -3,6 +3,6 @@ use std::env; // Add one line so gccrs doesn't believe we're parsing a shebang #[cfg_attr(feature = "somefeature", attribute = "someattr")] struct Feature; // { dg-warning "struct is never constructed" "" { target *-*-* } .-1 } +// { dg-warning "unused name" "" { target *-*-* } .-2 } -fn main() { -} +fn main() {} diff --git a/gcc/testsuite/rust/compile/torture/unused1.rs b/gcc/testsuite/rust/compile/torture/unused1.rs index db7eb8f..74297e0 100644 --- a/gcc/testsuite/rust/compile/torture/unused1.rs +++ b/gcc/testsuite/rust/compile/torture/unused1.rs @@ -4,6 +4,7 @@ fn test() -> i32 { fn unused() -> i32 { // { dg-warning "function is never used: 'unused'" "" { target *-*-* } .-1 } + // { dg-warning "unused name" "" { target *-*-* } .-2 } 2 } diff --git a/gcc/testsuite/rust/compile/torture/unused_struct.rs b/gcc/testsuite/rust/compile/torture/unused_struct.rs index 3a20d6b..a282c73 100644 --- a/gcc/testsuite/rust/compile/torture/unused_struct.rs +++ b/gcc/testsuite/rust/compile/torture/unused_struct.rs @@ -1,8 +1,8 @@ struct Foo { -// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 } + // { dg-warning "struct is never constructed" "" { target *-*-* } .-1 } + // { dg-warning "unused name" "" { target *-*-* } .-2 } one: i32, - two: i32 + two: i32, } -fn main() { -}
\ No newline at end of file +fn main() {} |