@@ -217,6 +217,8 @@ pub struct Inherited<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
217
217
/// environment is for an item or something where the "callee" is
218
218
/// not clear.
219
219
implicit_region_bound : Option < ty:: Region < ' tcx > > ,
220
+
221
+ body_id : Option < hir:: BodyId > ,
220
222
}
221
223
222
224
impl < ' a , ' gcx , ' tcx > Deref for Inherited < ' a , ' gcx , ' tcx > {
@@ -605,6 +607,7 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
605
607
deferred_cast_checks : RefCell :: new ( Vec :: new ( ) ) ,
606
608
anon_types : RefCell :: new ( NodeMap ( ) ) ,
607
609
implicit_region_bound,
610
+ body_id,
608
611
}
609
612
}
610
613
@@ -993,16 +996,17 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
993
996
994
997
// Add formal parameters.
995
998
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
-
1004
999
// Check the pattern.
1005
1000
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
+
1006
1010
fcx. write_ty ( arg. id , arg_ty) ;
1007
1011
}
1008
1012
@@ -1978,17 +1982,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
1978
1982
}
1979
1983
}
1980
1984
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
-
1992
1985
/// Registers an obligation for checking later, during regionck, that the type `ty` must
1993
1986
/// outlive the region `r`.
1994
1987
pub fn register_wf_obligation ( & self ,
@@ -2003,21 +1996,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2003
1996
ty:: Predicate :: WellFormed ( ty) ) ) ;
2004
1997
}
2005
1998
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
-
2021
1999
/// Registers obligations that all types appearing in `substs` are well-formed.
2022
2000
pub fn add_wf_bounds ( & self , substs : & Substs < ' tcx > , expr : & hir:: Expr )
2023
2001
{
@@ -2145,15 +2123,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2145
2123
2146
2124
match fulfillment_cx. select_all_or_error ( self ) {
2147
2125
Ok ( ( ) ) => { }
2148
- Err ( errors) => { self . report_fulfillment_errors ( & errors) ; }
2126
+ Err ( errors) => { self . report_fulfillment_errors ( & errors, self . inh . body_id ) ; }
2149
2127
}
2150
2128
}
2151
2129
2152
2130
/// Select as many obligations as we can at present.
2153
2131
fn select_obligations_where_possible ( & self ) {
2154
2132
match self . fulfillment_cx . borrow_mut ( ) . select_where_possible ( self ) {
2155
2133
Ok ( ( ) ) => { }
2156
- Err ( errors) => { self . report_fulfillment_errors ( & errors) ; }
2134
+ Err ( errors) => { self . report_fulfillment_errors ( & errors, self . inh . body_id ) ; }
2157
2135
}
2158
2136
}
2159
2137
0 commit comments