|  | 
|  | 1 | +#![crate_name = "allow_unsized"] | 
|  | 2 | + | 
|  | 3 | +use std::fmt::Debug; | 
|  | 4 | +use std::marker::PhantomData; | 
|  | 5 | + | 
|  | 6 | +pub trait CustomSized: Sized {} | 
|  | 7 | +impl CustomSized for u8 {} | 
|  | 8 | + | 
|  | 9 | +// Generic functions | 
|  | 10 | +//@ is "$.index[?(@.name=='func_custom')].inner.function.generics.params[0].kind.type.allow_unsized" false | 
|  | 11 | +pub fn func_custom<T: ?Sized + CustomSized>() {} | 
|  | 12 | + | 
|  | 13 | +//@ is "$.index[?(@.name=='func_custom')].inner.function.generics.params[0].kind.type.allow_unsized" false | 
|  | 14 | +pub fn func_custom_where_denies<T: ?Sized>() | 
|  | 15 | +where | 
|  | 16 | +    T: CustomSized, | 
|  | 17 | +{ | 
|  | 18 | +} | 
|  | 19 | + | 
|  | 20 | +//@ is "$.index[?(@.name=='func_custom')].inner.function.generics.params[0].kind.type.allow_unsized" false | 
|  | 21 | +pub fn func_custom_where_allows<T: CustomSized>() | 
|  | 22 | +where | 
|  | 23 | +    T: ?Sized, | 
|  | 24 | +{ | 
|  | 25 | +} | 
|  | 26 | + | 
|  | 27 | +//@ is "$.index[?(@.name=='func_custom')].inner.function.generics.params[0].kind.type.allow_unsized" false | 
|  | 28 | +pub fn func_custom_where_both<T>() | 
|  | 29 | +where | 
|  | 30 | +    T: ?Sized + CustomSized, | 
|  | 31 | +{ | 
|  | 32 | +} | 
|  | 33 | + | 
|  | 34 | +//@ is "$.index[?(@.name=='func_unsized')].inner.function.generics.params[0].kind.type.allow_unsized" true | 
|  | 35 | +pub fn func_unsized<T: ?Sized>() {} | 
|  | 36 | + | 
|  | 37 | +//@ is "$.index[?(@.name=='func_clone')].inner.function.generics.params[0].kind.type.allow_unsized" false | 
|  | 38 | +pub fn func_clone<T: ?Sized + Clone>() {} | 
|  | 39 | + | 
|  | 40 | +//@ is "$.index[?(@.name=='func_debug')].inner.function.generics.params[0].kind.type.allow_unsized" true | 
|  | 41 | +pub fn func_debug<T: ?Sized + Debug>() {} | 
|  | 42 | + | 
|  | 43 | +// Generic structs | 
|  | 44 | +//@ is "$.index[?(@.name=='StructCustom')].inner.struct.generics.params[0].kind.type.allow_unsized" false | 
|  | 45 | +pub struct StructCustom<T: ?Sized + CustomSized>(PhantomData<T>); | 
|  | 46 | + | 
|  | 47 | +//@ is "$.index[?(@.name=='StructUnsized')].inner.struct.generics.params[0].kind.type.allow_unsized" true | 
|  | 48 | +pub struct StructUnsized<T: ?Sized>(PhantomData<T>); | 
|  | 49 | + | 
|  | 50 | +//@ is "$.index[?(@.name=='StructClone')].inner.struct.generics.params[0].kind.type.allow_unsized" false | 
|  | 51 | +pub struct StructClone<T: ?Sized + Clone>(PhantomData<T>); | 
|  | 52 | + | 
|  | 53 | +//@ is "$.index[?(@.name=='StructDebug')].inner.struct.generics.params[0].kind.type.allow_unsized" true | 
|  | 54 | +pub struct StructDebug<T: ?Sized + Debug>(PhantomData<T>); | 
|  | 55 | + | 
|  | 56 | +// Struct with `?Sized` bound, and impl blocks that add additional bounds | 
|  | 57 | +//@ is "$.index[?(@.name=='Wrapper')].inner.struct.generics.params[0].kind.type.allow_unsized" true | 
|  | 58 | +pub struct Wrapper<T: ?Sized>(PhantomData<T>); | 
|  | 59 | + | 
|  | 60 | +//@ is "$.index[?(@.docs=='impl custom')].inner.impl.generics.params[0].kind.type.allow_unsized" false | 
|  | 61 | +/// impl custom | 
|  | 62 | +impl<T: ?Sized + CustomSized> Wrapper<T> { | 
|  | 63 | +    pub fn impl_custom() {} | 
|  | 64 | +} | 
|  | 65 | + | 
|  | 66 | +//@ is "$.index[?(@.docs=='impl clone')].inner.impl.generics.params[0].kind.type.allow_unsized" false | 
|  | 67 | +/// impl clone | 
|  | 68 | +impl<T: ?Sized + Clone> Wrapper<T> { | 
|  | 69 | +    pub fn impl_clone() {} | 
|  | 70 | +} | 
|  | 71 | + | 
|  | 72 | +//@ is "$.index[?(@.docs=='impl debug')].inner.impl.generics.params[0].kind.type.allow_unsized" true | 
|  | 73 | +/// impl debug | 
|  | 74 | +impl<T: ?Sized + Debug> Wrapper<T> { | 
|  | 75 | +    pub fn impl_debug() {} | 
|  | 76 | +} | 
|  | 77 | + | 
|  | 78 | +impl<T: ?Sized> Wrapper<T> { | 
|  | 79 | +    //@ is "$.index[?(@.name=='assoc_custom')].inner.function.generics.params[0].kind.type.allow_unsized" false | 
|  | 80 | +    pub fn assoc_custom<U: ?Sized + CustomSized>(&self) {} | 
|  | 81 | + | 
|  | 82 | +    //@ is "$.index[?(@.name=='assoc_unsized')].inner.function.generics.params[0].kind.type.allow_unsized" true | 
|  | 83 | +    pub fn assoc_unsized<U: ?Sized>(&self) {} | 
|  | 84 | + | 
|  | 85 | +    //@ is "$.index[?(@.name=='assoc_clone')].inner.function.generics.params[0].kind.type.allow_unsized" false | 
|  | 86 | +    pub fn assoc_clone<U: ?Sized + Clone>(&self) {} | 
|  | 87 | + | 
|  | 88 | +    //@ is "$.index[?(@.name=='assoc_debug')].inner.function.generics.params[0].kind.type.allow_unsized" true | 
|  | 89 | +    pub fn assoc_debug<U: ?Sized + Debug>(&self) {} | 
|  | 90 | +} | 
|  | 91 | + | 
|  | 92 | +// Traits with generic parameters | 
|  | 93 | +//@ is "$.index[?(@.name=='TraitCustom')].inner.trait.generics.params[0].kind.type.allow_unsized" false | 
|  | 94 | +pub trait TraitCustom<T: ?Sized + CustomSized> {} | 
|  | 95 | + | 
|  | 96 | +//@ is "$.index[?(@.name=='TraitUnsized')].inner.trait.generics.params[0].kind.type.allow_unsized" true | 
|  | 97 | +pub trait TraitUnsized<T: ?Sized> {} | 
|  | 98 | + | 
|  | 99 | +//@ is "$.index[?(@.name=='TraitClone')].inner.trait.generics.params[0].kind.type.allow_unsized" false | 
|  | 100 | +pub trait TraitClone<T: ?Sized + Clone> {} | 
|  | 101 | + | 
|  | 102 | +//@ is "$.index[?(@.name=='TraitDebug')].inner.trait.generics.params[0].kind.type.allow_unsized" true | 
|  | 103 | +pub trait TraitDebug<T: ?Sized + Debug> {} | 
|  | 104 | + | 
|  | 105 | +pub trait TraitMethods { | 
|  | 106 | +    //@ is "$.index[?(@.name=='method_custom')].inner.function.generics.params[0].kind.type.allow_unsized" false | 
|  | 107 | +    fn method_custom<T: ?Sized + CustomSized>(); | 
|  | 108 | + | 
|  | 109 | +    //@ is "$.index[?(@.name=='method_unsized')].inner.function.generics.params[0].kind.type.allow_unsized" true | 
|  | 110 | +    fn method_unsized<T: ?Sized>(); | 
|  | 111 | + | 
|  | 112 | +    //@ is "$.index[?(@.name=='method_clone')].inner.function.generics.params[0].kind.type.allow_unsized" false | 
|  | 113 | +    fn method_clone<T: ?Sized + Clone>(); | 
|  | 114 | + | 
|  | 115 | +    //@ is "$.index[?(@.name=='method_debug')].inner.function.generics.params[0].kind.type.allow_unsized" true | 
|  | 116 | +    fn method_debug<T: ?Sized + Debug>(); | 
|  | 117 | +} | 
|  | 118 | + | 
|  | 119 | +// `where` clauses on trait functions, which only affect `T` for that function | 
|  | 120 | +//@ is "$.index[?(@.name=='OuterDebug')].inner.trait.generics.params[0].kind.type.allow_unsized" true | 
|  | 121 | +pub trait OuterDebug<T: ?Sized> { | 
|  | 122 | +    fn foo() | 
|  | 123 | +    where | 
|  | 124 | +        T: Debug; | 
|  | 125 | +} | 
|  | 126 | + | 
|  | 127 | +//@ is "$.index[?(@.name=='OuterClone')].inner.trait.generics.params[0].kind.type.allow_unsized" true | 
|  | 128 | +pub trait OuterClone<T: ?Sized> { | 
|  | 129 | +    fn foo() | 
|  | 130 | +    where | 
|  | 131 | +        T: Clone; | 
|  | 132 | +} | 
|  | 133 | + | 
|  | 134 | +// Synthetic generic parameters | 
|  | 135 | +//@ is "$.index[?(@.name=='synth_clone')].inner.function.generics.params[0].kind.type.allow_unsized" false | 
|  | 136 | +pub fn synth_clone(_: impl Clone + ?Sized) {} | 
|  | 137 | + | 
|  | 138 | +//@ is "$.index[?(@.name=='synth_debug')].inner.function.generics.params[0].kind.type.allow_unsized" true | 
|  | 139 | +pub fn synth_debug(_: impl Debug + ?Sized) {} | 
0 commit comments