@@ -31,7 +31,7 @@ use rustc_span::symbol::sym;
31
31
use rustc_span:: { MultiSpan , Span , DUMMY_SP } ;
32
32
use rustc_target:: spec:: abi;
33
33
use smallvec:: SmallVec ;
34
- use syntax:: ast;
34
+ use syntax:: ast:: { self , Constness } ;
35
35
use syntax:: util:: lev_distance:: find_best_match_for_name;
36
36
37
37
use std:: collections:: BTreeSet ;
@@ -49,6 +49,8 @@ pub trait AstConv<'tcx> {
49
49
50
50
fn item_def_id ( & self ) -> Option < DefId > ;
51
51
52
+ fn default_constness_for_trait_bounds ( & self ) -> Constness ;
53
+
52
54
/// Returns predicates in scope of the form `X: Foo`, where `X` is
53
55
/// a type parameter `X` with the given id `def_id`. This is a
54
56
/// subset of the full set of predicates.
@@ -919,6 +921,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
919
921
& self ,
920
922
trait_ref : & hir:: TraitRef < ' _ > ,
921
923
span : Span ,
924
+ constness : Constness ,
922
925
self_ty : Ty < ' tcx > ,
923
926
bounds : & mut Bounds < ' tcx > ,
924
927
speculative : bool ,
@@ -947,7 +950,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
947
950
) ;
948
951
let poly_trait_ref = ty:: Binder :: bind ( ty:: TraitRef :: new ( trait_def_id, substs) ) ;
949
952
950
- bounds. trait_bounds . push ( ( poly_trait_ref, span) ) ;
953
+ bounds. trait_bounds . push ( ( poly_trait_ref, span, constness ) ) ;
951
954
952
955
let mut dup_bindings = FxHashMap :: default ( ) ;
953
956
for binding in & assoc_bindings {
@@ -993,12 +996,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
993
996
pub fn instantiate_poly_trait_ref (
994
997
& self ,
995
998
poly_trait_ref : & hir:: PolyTraitRef < ' _ > ,
999
+ constness : Constness ,
996
1000
self_ty : Ty < ' tcx > ,
997
1001
bounds : & mut Bounds < ' tcx > ,
998
1002
) -> Option < Vec < Span > > {
999
1003
self . instantiate_poly_trait_ref_inner (
1000
1004
& poly_trait_ref. trait_ref ,
1001
1005
poly_trait_ref. span ,
1006
+ constness,
1002
1007
self_ty,
1003
1008
bounds,
1004
1009
false ,
@@ -1181,18 +1186,22 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1181
1186
let mut trait_bounds = Vec :: new ( ) ;
1182
1187
let mut region_bounds = Vec :: new ( ) ;
1183
1188
1189
+ let constness = self . default_constness_for_trait_bounds ( ) ;
1184
1190
for ast_bound in ast_bounds {
1185
1191
match * ast_bound {
1186
1192
hir:: GenericBound :: Trait ( ref b, hir:: TraitBoundModifier :: None ) => {
1187
- trait_bounds. push ( b)
1193
+ trait_bounds. push ( ( b, constness) )
1194
+ }
1195
+ hir:: GenericBound :: Trait ( ref b, hir:: TraitBoundModifier :: MaybeConst ) => {
1196
+ trait_bounds. push ( ( b, Constness :: NotConst ) )
1188
1197
}
1189
1198
hir:: GenericBound :: Trait ( _, hir:: TraitBoundModifier :: Maybe ) => { }
1190
1199
hir:: GenericBound :: Outlives ( ref l) => region_bounds. push ( l) ,
1191
1200
}
1192
1201
}
1193
1202
1194
- for bound in trait_bounds {
1195
- let _ = self . instantiate_poly_trait_ref ( bound, param_ty, bounds) ;
1203
+ for ( bound, constness ) in trait_bounds {
1204
+ let _ = self . instantiate_poly_trait_ref ( bound, constness , param_ty, bounds) ;
1196
1205
}
1197
1206
1198
1207
bounds. region_bounds . extend (
@@ -1226,7 +1235,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1226
1235
let mut bounds = Bounds :: default ( ) ;
1227
1236
1228
1237
self . add_bounds ( param_ty, ast_bounds, & mut bounds) ;
1229
- bounds. trait_bounds . sort_by_key ( |( t, _) | t. def_id ( ) ) ;
1238
+ bounds. trait_bounds . sort_by_key ( |( t, _, _ ) | t. def_id ( ) ) ;
1230
1239
1231
1240
bounds. implicitly_sized = if let SizedByDefault :: Yes = sized_by_default {
1232
1241
if !self . is_unsized ( ast_bounds, span) { Some ( span) } else { None }
@@ -1417,15 +1426,21 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1417
1426
let mut potential_assoc_types = Vec :: new ( ) ;
1418
1427
let dummy_self = self . tcx ( ) . types . trait_object_dummy_self ;
1419
1428
for trait_bound in trait_bounds. iter ( ) . rev ( ) {
1420
- let cur_potential_assoc_types =
1421
- self . instantiate_poly_trait_ref ( trait_bound, dummy_self, & mut bounds) ;
1429
+ let cur_potential_assoc_types = self . instantiate_poly_trait_ref (
1430
+ trait_bound,
1431
+ Constness :: NotConst ,
1432
+ dummy_self,
1433
+ & mut bounds,
1434
+ ) ;
1422
1435
potential_assoc_types. extend ( cur_potential_assoc_types. into_iter ( ) . flatten ( ) ) ;
1423
1436
}
1424
1437
1425
1438
// Expand trait aliases recursively and check that only one regular (non-auto) trait
1426
1439
// is used and no 'maybe' bounds are used.
1427
- let expanded_traits =
1428
- traits:: expand_trait_aliases ( tcx, bounds. trait_bounds . iter ( ) . cloned ( ) ) ;
1440
+ let expanded_traits = traits:: expand_trait_aliases (
1441
+ tcx,
1442
+ bounds. trait_bounds . iter ( ) . map ( |& ( a, b, _) | ( a. clone ( ) , b) ) ,
1443
+ ) ;
1429
1444
let ( mut auto_traits, regular_traits) : ( Vec < _ > , Vec < _ > ) =
1430
1445
expanded_traits. partition ( |i| tcx. trait_is_auto ( i. trait_ref ( ) . def_id ( ) ) ) ;
1431
1446
if regular_traits. len ( ) > 1 {
@@ -1481,16 +1496,18 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1481
1496
let regular_traits_refs_spans = bounds
1482
1497
. trait_bounds
1483
1498
. into_iter ( )
1484
- . filter ( |( trait_ref, _) | !tcx. trait_is_auto ( trait_ref. def_id ( ) ) ) ;
1499
+ . filter ( |( trait_ref, _, _) | !tcx. trait_is_auto ( trait_ref. def_id ( ) ) ) ;
1500
+
1501
+ for ( base_trait_ref, span, constness) in regular_traits_refs_spans {
1502
+ assert_eq ! ( constness, ast:: Constness :: NotConst ) ;
1485
1503
1486
- for ( base_trait_ref, span) in regular_traits_refs_spans {
1487
1504
for trait_ref in traits:: elaborate_trait_ref ( tcx, base_trait_ref) {
1488
1505
debug ! (
1489
1506
"conv_object_ty_poly_trait_ref: observing object predicate `{:?}`" ,
1490
1507
trait_ref
1491
1508
) ;
1492
1509
match trait_ref {
1493
- ty:: Predicate :: Trait ( pred, constness ) => {
1510
+ ty:: Predicate :: Trait ( pred, _ ) => {
1494
1511
associated_types. entry ( span) . or_default ( ) . extend (
1495
1512
tcx. associated_items ( pred. def_id ( ) )
1496
1513
. filter ( |item| item. kind == ty:: AssocKind :: Type )
@@ -2949,7 +2966,7 @@ pub struct Bounds<'tcx> {
2949
2966
2950
2967
/// A list of trait bounds. So if you had `T: Debug` this would be
2951
2968
/// `T: Debug`. Note that the self-type is explicit here.
2952
- pub trait_bounds : Vec < ( ty:: PolyTraitRef < ' tcx > , Span ) > ,
2969
+ pub trait_bounds : Vec < ( ty:: PolyTraitRef < ' tcx > , Span , Constness ) > ,
2953
2970
2954
2971
/// A list of projection equality bounds. So if you had `T:
2955
2972
/// Iterator<Item = u32>` this would include `<T as
@@ -2997,11 +3014,10 @@ impl<'tcx> Bounds<'tcx> {
2997
3014
let outlives = ty:: OutlivesPredicate ( param_ty, region_bound) ;
2998
3015
( ty:: Binder :: bind ( outlives) . to_predicate ( ) , span)
2999
3016
} )
3000
- . chain (
3001
- self . trait_bounds
3002
- . iter ( )
3003
- . map ( |& ( bound_trait_ref, span) | ( bound_trait_ref. to_predicate ( ) , span) ) ,
3004
- )
3017
+ . chain ( self . trait_bounds . iter ( ) . map ( |& ( bound_trait_ref, span, constness) | {
3018
+ let predicate = bound_trait_ref. with_constness ( constness) . to_predicate ( ) ;
3019
+ ( predicate, span)
3020
+ } ) )
3005
3021
. chain (
3006
3022
self . projection_bounds
3007
3023
. iter ( )
0 commit comments