diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-08-22 15:44:32 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-08-22 15:47:20 +0100 |
commit | 2d681bdeda9e6c049457a20c45d045925595a8e9 (patch) | |
tree | c4ec2996ceb9c03ff927ead206b66147f3955404 /gcc | |
parent | ac3be517de2c0ec596eeee754b863243cb071098 (diff) | |
download | gcc-2d681bdeda9e6c049457a20c45d045925595a8e9.zip gcc-2d681bdeda9e6c049457a20c45d045925595a8e9.tar.gz gcc-2d681bdeda9e6c049457a20c45d045925595a8e9.tar.bz2 |
Ignore impl trait blocks in overlap pass
Impls can have items which overlap mostly when generics are involved. Trait
impls are slightly different beacuse they can be handled via qualified
paths. This ignores trait-impls in this pass and some thought should be
required to handle his case later on.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h | 4 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/traits8.rs | 37 |
2 files changed, 41 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h b/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h index 0879360..134d314 100644 --- a/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h +++ b/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h @@ -109,6 +109,10 @@ public: // generate mappings pass.mappings->iterate_impl_items ( [&] (HirId id, HIR::ImplItem *impl_item, HIR::ImplBlock *impl) -> bool { + // ignoring trait-impls might need thought later on + if (impl->has_trait_ref ()) + return true; + pass.process_impl_item (id, impl_item, impl); return true; }); diff --git a/gcc/testsuite/rust/compile/traits8.rs b/gcc/testsuite/rust/compile/traits8.rs new file mode 100644 index 0000000..b25c517 --- /dev/null +++ b/gcc/testsuite/rust/compile/traits8.rs @@ -0,0 +1,37 @@ +trait A { + fn get(self) -> f64; + // { dg-warning "unused name" "" { target *-*-* } .-1 } +} + +trait B { + fn get(self) -> u8; + // { dg-warning "unused name" "" { target *-*-* } .-1 } +} + +struct Foo(u8, f64); + +impl A for Foo { + fn get(self) -> f64 { + self.1 + } +} + +impl B for Foo { + fn get(self) -> u8 { + self.0 + } +} + +fn main() { + let _a; + _a = Foo(123, 456f64); + + let _b: f64; + _b = <Foo as A>::get(_a); + + let _a; + _a = Foo(123, 456f64); + + let _c: u8; + _c = <Foo as B>::get(_a) +} |