@@ -154,6 +154,23 @@ pub fn expand_deriving_smart_ptr(
154154 {
155155 let pointee = & mut impl_generics. params [ pointee_param_idx] ;
156156 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+ }
157174 let arg = GenericArg :: Type ( s_ty. clone ( ) ) ;
158175 let unsize = cx. path_all ( span, true , path ! ( span, core:: marker:: Unsize ) , vec ! [ arg] ) ;
159176 pointee. bounds . push ( cx. trait_bound ( unsize, false ) ) ;
@@ -218,23 +235,6 @@ pub fn expand_deriving_smart_ptr(
218235 //
219236 // We now insert `__S` with the missing bounds marked with (*) above.
220237 // 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- }
238238 {
239239 let mut substitution =
240240 TypeSubstitution { from_name : pointee_ty_ident. name , to_ty : & s_ty, rewritten : false } ;
0 commit comments