@@ -10,7 +10,6 @@ use rustc_hir::ItemKind;
10
10
use rustc_infer:: infer:: outlives:: env:: { OutlivesEnvironment , RegionBoundPairs } ;
11
11
use rustc_infer:: infer:: outlives:: obligations:: TypeOutlives ;
12
12
use rustc_infer:: infer:: { self , InferCtxt , TyCtxtInferExt } ;
13
- use rustc_infer:: traits:: Normalized ;
14
13
use rustc_middle:: ty:: query:: Providers ;
15
14
use rustc_middle:: ty:: subst:: { GenericArgKind , InternalSubsts , Subst } ;
16
15
use rustc_middle:: ty:: trait_def:: TraitSpecializationKind ;
@@ -24,8 +23,6 @@ use rustc_span::{Span, DUMMY_SP};
24
23
use rustc_trait_selection:: autoderef:: Autoderef ;
25
24
use rustc_trait_selection:: traits:: error_reporting:: InferCtxtExt ;
26
25
use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
27
- use rustc_trait_selection:: traits:: query:: normalize:: AtExt ;
28
- use rustc_trait_selection:: traits:: query:: NoSolution ;
29
26
use rustc_trait_selection:: traits:: {
30
27
self , ObligationCause , ObligationCauseCode , ObligationCtxt , WellFormedLoc ,
31
28
} ;
@@ -86,26 +83,37 @@ pub(super) fn enter_wf_checking_ctxt<'tcx, F>(
86
83
body_def_id : LocalDefId ,
87
84
f : F ,
88
85
) where
89
- F : for < ' a > FnOnce ( & WfCheckingCtxt < ' a , ' tcx > ) -> FxHashSet < Ty < ' tcx > > ,
86
+ F : for < ' a > FnOnce ( & WfCheckingCtxt < ' a , ' tcx > ) ,
90
87
{
91
88
let param_env = tcx. param_env ( body_def_id) ;
92
89
let body_id = tcx. hir ( ) . local_def_id_to_hir_id ( body_def_id) ;
93
90
tcx. infer_ctxt ( ) . enter ( |ref infcx| {
94
91
let ocx = ObligationCtxt :: new ( infcx) ;
92
+
93
+ let assumed_wf_types = tcx. assumed_wf_types ( body_def_id) ;
94
+ let mut implied_bounds = FxHashSet :: default ( ) ;
95
+ let cause = ObligationCause :: misc ( span, body_id) ;
96
+ for ty in assumed_wf_types {
97
+ implied_bounds. insert ( ty) ;
98
+ let normalized = ocx. normalize ( cause. clone ( ) , param_env, ty) ;
99
+ implied_bounds. insert ( normalized) ;
100
+ }
101
+ let implied_bounds = implied_bounds;
102
+
95
103
let mut wfcx = WfCheckingCtxt { ocx, span, body_id, param_env } ;
96
104
97
105
if !tcx. features ( ) . trivial_bounds {
98
106
wfcx. check_false_global_bounds ( )
99
107
}
100
- let wf_tys = f ( & mut wfcx) ;
108
+ f ( & mut wfcx) ;
101
109
let errors = wfcx. select_all_or_error ( ) ;
102
110
if !errors. is_empty ( ) {
103
111
infcx. report_fulfillment_errors ( & errors, None , false ) ;
104
112
return ;
105
113
}
106
114
107
115
let mut outlives_environment = OutlivesEnvironment :: new ( param_env) ;
108
- outlives_environment. add_implied_bounds ( infcx, wf_tys , body_id) ;
116
+ outlives_environment. add_implied_bounds ( infcx, implied_bounds , body_id) ;
109
117
infcx. check_region_obligations_and_report_errors ( body_def_id, & outlives_environment) ;
110
118
} )
111
119
}
@@ -976,15 +984,9 @@ fn check_associated_item(
976
984
enter_wf_checking_ctxt ( tcx, span, item_id, |wfcx| {
977
985
let item = tcx. associated_item ( item_id) ;
978
986
979
- let ( mut implied_bounds, self_ty) = match item. container {
980
- ty:: TraitContainer => ( FxHashSet :: default ( ) , tcx. types . self_param ) ,
981
- ty:: ImplContainer => {
982
- let def_id = item. container_id ( tcx) ;
983
- (
984
- impl_implied_bounds ( tcx, wfcx. param_env , def_id. expect_local ( ) , span) ,
985
- tcx. type_of ( def_id) ,
986
- )
987
- }
987
+ let self_ty = match item. container {
988
+ ty:: TraitContainer => tcx. types . self_param ,
989
+ ty:: ImplContainer => tcx. type_of ( item. container_id ( tcx) ) ,
988
990
} ;
989
991
990
992
match item. kind {
@@ -1002,7 +1004,6 @@ fn check_associated_item(
1002
1004
sig,
1003
1005
hir_sig. decl ,
1004
1006
item. def_id . expect_local ( ) ,
1005
- & mut implied_bounds,
1006
1007
) ;
1007
1008
check_method_receiver ( wfcx, hir_sig, item, self_ty) ;
1008
1009
}
@@ -1017,8 +1018,6 @@ fn check_associated_item(
1017
1018
}
1018
1019
}
1019
1020
}
1020
-
1021
- implied_bounds
1022
1021
} )
1023
1022
}
1024
1023
@@ -1118,9 +1117,6 @@ fn check_type_defn<'tcx, F>(
1118
1117
}
1119
1118
1120
1119
check_where_clauses ( wfcx, item. span , item. def_id ) ;
1121
-
1122
- // No implied bounds in a struct definition.
1123
- FxHashSet :: default ( )
1124
1120
} ) ;
1125
1121
}
1126
1122
@@ -1144,9 +1140,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
1144
1140
}
1145
1141
1146
1142
enter_wf_checking_ctxt ( tcx, item. span , item. def_id , |wfcx| {
1147
- check_where_clauses ( wfcx, item. span , item. def_id ) ;
1148
-
1149
- FxHashSet :: default ( )
1143
+ check_where_clauses ( wfcx, item. span , item. def_id )
1150
1144
} ) ;
1151
1145
1152
1146
// Only check traits, don't check trait aliases
@@ -1186,9 +1180,7 @@ fn check_item_fn(
1186
1180
) {
1187
1181
enter_wf_checking_ctxt ( tcx, span, def_id, |wfcx| {
1188
1182
let sig = tcx. fn_sig ( def_id) ;
1189
- let mut implied_bounds = FxHashSet :: default ( ) ;
1190
- check_fn_or_method ( wfcx, ident. span , sig, decl, def_id, & mut implied_bounds) ;
1191
- implied_bounds
1183
+ check_fn_or_method ( wfcx, ident. span , sig, decl, def_id) ;
1192
1184
} )
1193
1185
}
1194
1186
@@ -1231,9 +1223,6 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: LocalDefId, ty_span: Span, allow_fo
1231
1223
tcx. require_lang_item ( LangItem :: Sync , Some ( ty_span) ) ,
1232
1224
) ;
1233
1225
}
1234
-
1235
- // No implied bounds in a const, etc.
1236
- FxHashSet :: default ( )
1237
1226
} ) ;
1238
1227
}
1239
1228
@@ -1284,8 +1273,6 @@ fn check_impl<'tcx>(
1284
1273
}
1285
1274
1286
1275
check_where_clauses ( wfcx, item. span , item. def_id ) ;
1287
-
1288
- impl_implied_bounds ( tcx, wfcx. param_env , item. def_id , item. span )
1289
1276
} ) ;
1290
1277
}
1291
1278
@@ -1479,7 +1466,6 @@ fn check_fn_or_method<'tcx>(
1479
1466
sig : ty:: PolyFnSig < ' tcx > ,
1480
1467
hir_decl : & hir:: FnDecl < ' _ > ,
1481
1468
def_id : LocalDefId ,
1482
- implied_bounds : & mut FxHashSet < Ty < ' tcx > > ,
1483
1469
) {
1484
1470
let tcx = wfcx. tcx ( ) ;
1485
1471
let sig = tcx. liberate_late_bound_regions ( def_id. to_def_id ( ) , sig) ;
@@ -1521,15 +1507,8 @@ fn check_fn_or_method<'tcx>(
1521
1507
) ;
1522
1508
}
1523
1509
1524
- implied_bounds. extend ( sig. inputs ( ) ) ;
1525
-
1526
1510
wfcx. register_wf_obligation ( hir_decl. output . span ( ) , None , sig. output ( ) . into ( ) ) ;
1527
1511
1528
- // FIXME(#27579) return types should not be implied bounds
1529
- implied_bounds. insert ( sig. output ( ) ) ;
1530
-
1531
- debug ! ( ?implied_bounds) ;
1532
-
1533
1512
check_where_clauses ( wfcx, span, def_id) ;
1534
1513
}
1535
1514
@@ -1924,40 +1903,6 @@ impl<'a, 'tcx> WfCheckingCtxt<'a, 'tcx> {
1924
1903
}
1925
1904
}
1926
1905
1927
- pub fn impl_implied_bounds < ' tcx > (
1928
- tcx : TyCtxt < ' tcx > ,
1929
- param_env : ty:: ParamEnv < ' tcx > ,
1930
- impl_def_id : LocalDefId ,
1931
- span : Span ,
1932
- ) -> FxHashSet < Ty < ' tcx > > {
1933
- // We completely ignore any obligations caused by normalizing the types
1934
- // we assume to be well formed. Considering that the user of the implied
1935
- // bounds will also normalize them, we leave it to them to emit errors
1936
- // which should result in better causes and spans.
1937
- tcx. infer_ctxt ( ) . enter ( |infcx| {
1938
- let cause = ObligationCause :: misc ( span, tcx. hir ( ) . local_def_id_to_hir_id ( impl_def_id) ) ;
1939
- match tcx. impl_trait_ref ( impl_def_id) {
1940
- Some ( trait_ref) => {
1941
- // Trait impl: take implied bounds from all types that
1942
- // appear in the trait reference.
1943
- match infcx. at ( & cause, param_env) . normalize ( trait_ref) {
1944
- Ok ( Normalized { value, obligations : _ } ) => value. substs . types ( ) . collect ( ) ,
1945
- Err ( NoSolution ) => FxHashSet :: default ( ) ,
1946
- }
1947
- }
1948
-
1949
- None => {
1950
- // Inherent impl: take implied bounds from the `self` type.
1951
- let self_ty = tcx. type_of ( impl_def_id) ;
1952
- match infcx. at ( & cause, param_env) . normalize ( self_ty) {
1953
- Ok ( Normalized { value, obligations : _ } ) => FxHashSet :: from_iter ( [ value] ) ,
1954
- Err ( NoSolution ) => FxHashSet :: default ( ) ,
1955
- }
1956
- }
1957
- }
1958
- } )
1959
- }
1960
-
1961
1906
fn error_392 (
1962
1907
tcx : TyCtxt < ' _ > ,
1963
1908
span : Span ,
0 commit comments