@@ -154,6 +154,23 @@ pub fn expand_deriving_smart_ptr(
154
154
{
155
155
let pointee = & mut impl_generics. params [ pointee_param_idx] ;
156
156
self_bounds = pointee. bounds . clone ( ) ;
157
+ if !contains_maybe_sized_bound ( & self_bounds)
158
+ && !contains_maybe_sized_bound_on_pointee (
159
+ & generics. where_clause . predicates ,
160
+ pointee_ty_ident. name ,
161
+ )
162
+ {
163
+ cx. dcx ( )
164
+ . struct_span_err (
165
+ pointee_ty_ident. span ,
166
+ format ! (
167
+ "`SmartPointer` is meaningless because `{}` is not `?Sized`" ,
168
+ pointee_ty_ident. name
169
+ ) ,
170
+ )
171
+ . emit ( ) ;
172
+ return ;
173
+ }
157
174
let arg = GenericArg :: Type ( s_ty. clone ( ) ) ;
158
175
let unsize = cx. path_all ( span, true , path ! ( span, core:: marker:: Unsize ) , vec ! [ arg] ) ;
159
176
pointee. bounds . push ( cx. trait_bound ( unsize, false ) ) ;
@@ -218,23 +235,6 @@ pub fn expand_deriving_smart_ptr(
218
235
//
219
236
// We now insert `__S` with the missing bounds marked with (*) above.
220
237
// We should also write the bounds from `#[pointee]` to `__S` as required by `Unsize<__S>`.
221
- let sized = cx. path_global ( span, path ! ( span, core:: marker:: Sized ) ) ;
222
- // For some reason, we are not allowed to write `?Sized` bound twice like `__S: ?Sized + ?Sized`.
223
- if !contains_maybe_sized_bound ( & self_bounds)
224
- && !contains_maybe_sized_bound_on_pointee (
225
- & generics. where_clause . predicates ,
226
- pointee_ty_ident. name ,
227
- )
228
- {
229
- self_bounds. push ( GenericBound :: Trait (
230
- cx. poly_trait_ref ( span, sized) ,
231
- TraitBoundModifiers {
232
- polarity : ast:: BoundPolarity :: Maybe ( span) ,
233
- constness : ast:: BoundConstness :: Never ,
234
- asyncness : ast:: BoundAsyncness :: Normal ,
235
- } ,
236
- ) ) ;
237
- }
238
238
{
239
239
let mut substitution =
240
240
TypeSubstitution { from_name : pointee_ty_ident. name , to_ty : & s_ty, rewritten : false } ;
0 commit comments