@@ -217,6 +217,8 @@ pub struct Inherited<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
217217 /// environment is for an item or something where the "callee" is
218218 /// not clear.
219219 implicit_region_bound : Option < ty:: Region < ' tcx > > ,
220+
221+ body_id : Option < hir:: BodyId > ,
220222}
221223
222224impl < ' a , ' gcx , ' tcx > Deref for Inherited < ' a , ' gcx , ' tcx > {
@@ -605,6 +607,7 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
605607 deferred_cast_checks : RefCell :: new ( Vec :: new ( ) ) ,
606608 anon_types : RefCell :: new ( NodeMap ( ) ) ,
607609 implicit_region_bound,
610+ body_id,
608611 }
609612 }
610613
@@ -993,16 +996,17 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
993996
994997 // Add formal parameters.
995998 for ( arg_ty, arg) in fn_sig. inputs ( ) . iter ( ) . zip ( & body. arguments ) {
996- // The type of the argument must be well-formed.
997- //
998- // NB -- this is now checked in wfcheck, but that
999- // currently only results in warnings, so we issue an
1000- // old-style WF obligation here so that we still get the
1001- // errors that we used to get.
1002- fcx. register_old_wf_obligation ( arg_ty, arg. pat . span , traits:: MiscObligation ) ;
1003-
1004999 // Check the pattern.
10051000 fcx. check_pat_arg ( & arg. pat , arg_ty, true ) ;
1001+
1002+ // Check that argument is Sized.
1003+ // The check for a non-trivial pattern is a hack to avoid duplicate warnings
1004+ // for simple cases like `fn foo(x: Trait)`,
1005+ // where we would error once on the parameter as a whole, and once on the binding `x`.
1006+ if arg. pat . simple_name ( ) . is_none ( ) {
1007+ fcx. require_type_is_sized ( arg_ty, decl. output . span ( ) , traits:: MiscObligation ) ;
1008+ }
1009+
10061010 fcx. write_ty ( arg. id , arg_ty) ;
10071011 }
10081012
@@ -1978,17 +1982,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
19781982 }
19791983 }
19801984
1981- /// Registers an obligation for checking later, during regionck, that the type `ty` must
1982- /// outlive the region `r`.
1983- pub fn register_region_obligation ( & self ,
1984- ty : Ty < ' tcx > ,
1985- region : ty:: Region < ' tcx > ,
1986- cause : traits:: ObligationCause < ' tcx > )
1987- {
1988- let mut fulfillment_cx = self . fulfillment_cx . borrow_mut ( ) ;
1989- fulfillment_cx. register_region_obligation ( ty, region, cause) ;
1990- }
1991-
19921985 /// Registers an obligation for checking later, during regionck, that the type `ty` must
19931986 /// outlive the region `r`.
19941987 pub fn register_wf_obligation ( & self ,
@@ -2003,21 +1996,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
20031996 ty:: Predicate :: WellFormed ( ty) ) ) ;
20041997 }
20051998
2006- pub fn register_old_wf_obligation ( & self ,
2007- ty : Ty < ' tcx > ,
2008- span : Span ,
2009- code : traits:: ObligationCauseCode < ' tcx > )
2010- {
2011- // Registers an "old-style" WF obligation that uses the
2012- // implicator code. This is basically a buggy version of
2013- // `register_wf_obligation` that is being kept around
2014- // temporarily just to help with phasing in the newer rules.
2015- //
2016- // FIXME(#27579) all uses of this should be migrated to register_wf_obligation eventually
2017- let cause = traits:: ObligationCause :: new ( span, self . body_id , code) ;
2018- self . register_region_obligation ( ty, self . tcx . types . re_empty , cause) ;
2019- }
2020-
20211999 /// Registers obligations that all types appearing in `substs` are well-formed.
20222000 pub fn add_wf_bounds ( & self , substs : & Substs < ' tcx > , expr : & hir:: Expr )
20232001 {
@@ -2145,15 +2123,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
21452123
21462124 match fulfillment_cx. select_all_or_error ( self ) {
21472125 Ok ( ( ) ) => { }
2148- Err ( errors) => { self . report_fulfillment_errors ( & errors) ; }
2126+ Err ( errors) => { self . report_fulfillment_errors ( & errors, self . inh . body_id ) ; }
21492127 }
21502128 }
21512129
21522130 /// Select as many obligations as we can at present.
21532131 fn select_obligations_where_possible ( & self ) {
21542132 match self . fulfillment_cx . borrow_mut ( ) . select_where_possible ( self ) {
21552133 Ok ( ( ) ) => { }
2156- Err ( errors) => { self . report_fulfillment_errors ( & errors) ; }
2134+ Err ( errors) => { self . report_fulfillment_errors ( & errors, self . inh . body_id ) ; }
21572135 }
21582136 }
21592137
0 commit comments