|
| 1 | +//@ run-rustfix |
| 2 | +#![deny(redundant_sizedness_bound)] |
| 3 | +#![feature(sized_hierarchy)] |
| 4 | +#![allow(unused)] |
| 5 | +use std::marker::{MetaSized, PointeeSized}; |
| 6 | + |
| 7 | +fn directly<T: Sized>(t: &T) {} |
| 8 | +//~^ ERROR redundant_sizedness_bound |
| 9 | + |
| 10 | +trait A: Sized {} |
| 11 | +trait B: A {} |
| 12 | + |
| 13 | +fn depth_1<T: A>(t: &T) {} |
| 14 | +//~^ ERROR redundant_sizedness_bound |
| 15 | +fn depth_2<T: B>(t: &T) {} |
| 16 | +//~^ ERROR redundant_sizedness_bound |
| 17 | + |
| 18 | +// We only need to show one |
| 19 | +fn multiple_paths<T: A + B>(t: &T) {} |
| 20 | +//~^ ERROR redundant_sizedness_bound |
| 21 | + |
| 22 | +fn in_where<T>(t: &T) |
| 23 | +where |
| 24 | + T: Sized, |
| 25 | + //~^ ERROR redundant_sizedness_bound |
| 26 | +{ |
| 27 | +} |
| 28 | + |
| 29 | +fn mixed_1<T: Sized>(t: &T) |
| 30 | + //~^ ERROR redundant_sizedness_bound |
| 31 | +{ |
| 32 | +} |
| 33 | + |
| 34 | +fn mixed_2<T>(t: &T) |
| 35 | +//~^ ERROR redundant_sizedness_bound |
| 36 | +where |
| 37 | + T: Sized, |
| 38 | +{ |
| 39 | +} |
| 40 | + |
| 41 | +fn mixed_3<T>(t: &T) |
| 42 | +where |
| 43 | + T: Sized, |
| 44 | + //~^ ERROR redundant_sizedness_bound |
| 45 | +{ |
| 46 | +} |
| 47 | + |
| 48 | +struct Struct<T: Sized>(T); |
| 49 | +//~^ ERROR redundant_sizedness_bound |
| 50 | + |
| 51 | +impl<T: Sized> Struct<T> { |
| 52 | + //~^ ERROR redundant_sizedness_bound |
| 53 | + fn method<U: Sized>(&self) {} |
| 54 | + //~^ ERROR redundant_sizedness_bound |
| 55 | +} |
| 56 | + |
| 57 | +enum Enum<T: Sized + 'static> { |
| 58 | + //~^ ERROR redundant_sizedness_bound |
| 59 | + Variant(&'static T), |
| 60 | +} |
| 61 | + |
| 62 | +union Union<'a, T: Sized> { |
| 63 | + //~^ ERROR redundant_sizedness_bound |
| 64 | + a: &'a T, |
| 65 | +} |
| 66 | + |
| 67 | +trait Trait<T: Sized> { |
| 68 | + //~^ ERROR redundant_sizedness_bound |
| 69 | + fn trait_method<U: Sized>() {} |
| 70 | + //~^ ERROR redundant_sizedness_bound |
| 71 | + |
| 72 | + type GAT<U: Sized>; |
| 73 | + //~^ ERROR redundant_sizedness_bound |
| 74 | + |
| 75 | + type Assoc: Sized + ?Sized; // False negative |
| 76 | +} |
| 77 | + |
| 78 | +trait SecondInTrait: Send + Sized {} |
| 79 | +fn second_in_trait<T: SecondInTrait>() {} |
| 80 | +//~^ ERROR redundant_sizedness_bound |
| 81 | + |
| 82 | +fn impl_trait(_: &(impl Sized)) {} |
| 83 | +//~^ ERROR redundant_sizedness_bound |
| 84 | + |
| 85 | +trait GenericTrait<T>: Sized {} |
| 86 | +fn in_generic_trait<T: GenericTrait<U>, U>() {} |
| 87 | +//~^ ERROR redundant_sizedness_bound |
| 88 | + |
| 89 | +mod larger_graph { |
| 90 | + // C1 C2 Sized |
| 91 | + // \ /\ / |
| 92 | + // B1 B2 |
| 93 | + // \ / |
| 94 | + // A1 |
| 95 | + |
| 96 | + trait C1 {} |
| 97 | + trait C2 {} |
| 98 | + trait B1: C1 + C2 {} |
| 99 | + trait B2: C2 + Sized {} |
| 100 | + trait A1: B1 + B2 {} |
| 101 | + |
| 102 | + fn larger_graph<T: A1>() {} |
| 103 | + //~^ ERROR redundant_sizedness_bound |
| 104 | +} |
| 105 | + |
| 106 | +trait S1: Sized {} |
| 107 | +fn meta_sized<T: S1>() {} |
| 108 | +//~^ ERROR redundant_sizedness_bound |
| 109 | +fn pointee_sized<T: S1>() {} |
| 110 | +//~^ ERROR redundant_sizedness_bound |
| 111 | +trait M1: MetaSized {} |
| 112 | +fn pointee_metasized<T: M1>() {} |
| 113 | +//~^ ERROR redundant_sizedness_bound |
| 114 | + |
| 115 | +// Should not lint |
| 116 | + |
| 117 | +fn sized<T: Sized>() {} |
| 118 | +fn maybe_sized<T: ?Sized>() {} |
| 119 | + |
| 120 | +struct SeparateBounds<T: ?Sized>(T); |
| 121 | +impl<T: Sized> SeparateBounds<T> {} |
| 122 | + |
| 123 | +trait P {} |
| 124 | +trait Q: P {} |
| 125 | + |
| 126 | +fn ok_depth_1<T: P + ?Sized>() {} |
| 127 | +fn ok_depth_2<T: Q + ?Sized>() {} |
| 128 | + |
| 129 | +//external! { |
| 130 | +// fn in_macro<T: Clone + ?Sized>(t: &T) {} |
| 131 | + |
| 132 | +// fn with_local_clone<T: $Clone + ?Sized>(t: &T) {} |
| 133 | +//} |
| 134 | + |
| 135 | +#[derive(Clone)] |
| 136 | +struct InDerive<T: ?Sized> { |
| 137 | + t: T, |
| 138 | +} |
| 139 | + |
| 140 | +struct Refined<T: ?Sized>(T); |
| 141 | +impl<T: Sized> Refined<T> {} |
| 142 | + |
| 143 | +fn main() {} |
0 commit comments