diff options
| author | David Wood <david@davidtw.co> | 2020-08-14 12:33:20 +0100 |
|---|---|---|
| committer | David Wood <david@davidtw.co> | 2020-08-14 23:01:14 +0100 |
| commit | bf3ef26713b8208e0127f4c51725897dbcd11bd9 (patch) | |
| tree | 885a852b01789a6ddec14806197a7dd8eb02ede3 /src/test/ui/polymorphization | |
| parent | 3fbed1739c384faabf00cd8a62abedbf506e949b (diff) | |
| download | rust-bf3ef26713b8208e0127f4c51725897dbcd11bd9.tar.gz rust-bf3ef26713b8208e0127f4c51725897dbcd11bd9.zip | |
polymorphize: `I` used if `T` used in `I: Foo<T>`
This commit adjusts polymorphization's handling of predicates so that after ensuring that `T` is used in `I: Foo<T>` if `I` is used, it now ensures that `I` is used if `T` is used in `I: Foo<T>`. This is necessary to mark generic parameters that only exist in impl parameters as used - thereby avoiding symbol clashes when using the new mangling scheme. Signed-off-by: David Wood <david@davidtw.co>
Diffstat (limited to 'src/test/ui/polymorphization')
| -rw-r--r-- | src/test/ui/polymorphization/predicates.rs | 48 | ||||
| -rw-r--r-- | src/test/ui/polymorphization/symbol-ambiguity.rs | 22 |
2 files changed, 70 insertions, 0 deletions
diff --git a/src/test/ui/polymorphization/predicates.rs b/src/test/ui/polymorphization/predicates.rs index 82a94933b47..60555dc12dc 100644 --- a/src/test/ui/polymorphization/predicates.rs +++ b/src/test/ui/polymorphization/predicates.rs @@ -18,7 +18,55 @@ where bar::<I>() } +#[rustc_polymorphize_error] +fn baz<I, T>(_: I) +where + std::iter::Repeat<I>: Iterator<Item = T>, +{ + bar::<I>() +} + +// In addition, check that `I` is considered used in `next::{{closure}}`, because `T` is used and +// `T` is really just `I::Item`. `E` is used due to the fixed-point marking of predicates. + +pub(crate) struct Foo<'a, I, E>(I, &'a E); + +impl<'a, I, T: 'a, E> Iterator for Foo<'a, I, E> +where + I: Iterator<Item = &'a (T, E)>, +{ + type Item = T; + + #[rustc_polymorphize_error] + fn next(&mut self) -> Option<Self::Item> { + self.find(|_| true) + } +} + +// Furthermore, check that `B` is considered used because `C` is used, and that `A` is considered +// used because `B` is now used. + +trait Baz<Z> {} + +impl Baz<u16> for u8 {} +impl Baz<u32> for u16 {} + +#[rustc_polymorphize_error] +fn quux<A, B, C: Default>() -> usize +where + A: Baz<B>, + B: Baz<C>, +{ + std::mem::size_of::<C>() +} + fn main() { let x = &[2u32]; foo(x.iter()); + baz(x.iter()); + + let mut a = Foo([(1u32, 1u16)].iter(), &1u16); + let _ = a.next(); + + let _ = quux::<u8, u16, u32>(); } diff --git a/src/test/ui/polymorphization/symbol-ambiguity.rs b/src/test/ui/polymorphization/symbol-ambiguity.rs new file mode 100644 index 00000000000..d97bae183d9 --- /dev/null +++ b/src/test/ui/polymorphization/symbol-ambiguity.rs @@ -0,0 +1,22 @@ +// build-pass +// compile-flags: -Zpolymorphize=on -Zsymbol-mangling-version=v0 + +pub(crate) struct Foo<'a, I, E>(I, &'a E); + +impl<'a, I, T: 'a, E> Iterator for Foo<'a, I, E> +where + I: Iterator<Item = &'a (T, E)>, +{ + type Item = T; + + fn next(&mut self) -> Option<Self::Item> { + self.find(|_| true) + } +} + +fn main() { + let mut a = Foo([(1u32, 1u16)].iter(), &1u16); + let mut b = Foo([(1u16, 1u32)].iter(), &1u32); + let _ = a.next(); + let _ = b.next(); +} |
