diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-30 10:00:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-30 10:00:19 +0000 |
commit | bb95f8f5ca0fed11f2c7a9b539a3c120ce054d8e (patch) | |
tree | 005e8634eef039c17d6107e5d7ef88eec8d36834 /gcc | |
parent | 1738bb8c76c499fdec244cea3d746db9438f8a11 (diff) | |
parent | 59897751aa797c9c6e7e1d795bbc1afbb9c81e32 (diff) | |
download | gcc-bb95f8f5ca0fed11f2c7a9b539a3c120ce054d8e.zip gcc-bb95f8f5ca0fed11f2c7a9b539a3c120ce054d8e.tar.gz gcc-bb95f8f5ca0fed11f2c7a9b539a3c120ce054d8e.tar.bz2 |
Merge #536
536: Revert change to ScanUnused to not scan Types r=philberty a=philberty
The scan dead-code pass will take over this role, but let's keep both
running for a while and then we can update ScanUnused to only scan for
unused labels and variables. Dead Code pass is important as it is 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.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
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() {} |