@@ -101,6 +101,14 @@ pub fn lower_crate(sess: &Session,
101
101
} . lower_crate ( krate)
102
102
}
103
103
104
+ #[ derive( Copy , Clone , PartialEq , Eq ) ]
105
+ enum ParamMode {
106
+ /// Any path in a type context.
107
+ Explicit ,
108
+ /// The `module::Type` in `module::Type::method` in an expression.
109
+ Optional
110
+ }
111
+
104
112
impl < ' a > LoweringContext < ' a > {
105
113
fn lower_crate ( & mut self , c : & Crate ) -> hir:: Crate {
106
114
struct ItemLowerer < ' lcx , ' interner : ' lcx > {
@@ -179,13 +187,14 @@ impl<'a> LoweringContext<'a> {
179
187
P ( Spanned {
180
188
node : match view_path. node {
181
189
ViewPathSimple ( ident, ref path) => {
182
- hir:: ViewPathSimple ( ident. name , self . lower_path ( path) )
190
+ hir:: ViewPathSimple ( ident. name ,
191
+ self . lower_path ( path, None , ParamMode :: Explicit ) )
183
192
}
184
193
ViewPathGlob ( ref path) => {
185
- hir:: ViewPathGlob ( self . lower_path ( path) )
194
+ hir:: ViewPathGlob ( self . lower_path ( path, None , ParamMode :: Explicit ) )
186
195
}
187
196
ViewPathList ( ref path, ref path_list_idents) => {
188
- hir:: ViewPathList ( self . lower_path ( path) ,
197
+ hir:: ViewPathList ( self . lower_path ( path, None , ParamMode :: Explicit ) ,
189
198
path_list_idents. iter ( )
190
199
. map ( |item| self . lower_path_list_item ( item) )
191
200
. collect ( ) )
@@ -256,7 +265,8 @@ impl<'a> LoweringContext<'a> {
256
265
position : position,
257
266
}
258
267
} ) ;
259
- hir:: TyPath ( qself, self . lower_path ( path) )
268
+ let path = self . lower_path ( path, qself. as_ref ( ) , ParamMode :: Explicit ) ;
269
+ hir:: TyPath ( qself, path)
260
270
}
261
271
TyKind :: ObjectSum ( ref ty, ref bounds) => {
262
272
hir:: TyObjectSum ( self . lower_ty ( ty) , self . lower_bounds ( bounds) )
@@ -298,38 +308,56 @@ impl<'a> LoweringContext<'a> {
298
308
}
299
309
}
300
310
301
- fn lower_path ( & mut self , p : & Path ) -> hir:: Path {
311
+ fn lower_path ( & mut self ,
312
+ p : & Path ,
313
+ qself : Option < & hir:: QSelf > ,
314
+ param_mode : ParamMode )
315
+ -> hir:: Path {
302
316
hir:: Path {
303
317
global : p. global ,
304
- segments : p. segments
305
- . iter ( )
306
- . map ( |& PathSegment { identifier, ref parameters } | {
307
- hir:: PathSegment {
308
- name : identifier. name ,
309
- parameters : self . lower_path_parameters ( parameters) ,
310
- }
311
- } )
312
- . collect ( ) ,
318
+ segments : p. segments . iter ( ) . enumerate ( ) . map ( |( i, segment) | {
319
+ let PathSegment { identifier, ref parameters } = * segment;
320
+ let param_mode = match ( qself, param_mode) {
321
+ ( Some ( qself) , ParamMode :: Optional ) if i < qself. position => {
322
+ // This segment is part of the trait path in a
323
+ // qualified path - one of `a`, `b` or `Trait`
324
+ // in `<X as a::b::Trait>::T::U::method`.
325
+ ParamMode :: Explicit
326
+ }
327
+ _ => param_mode
328
+ } ;
329
+ hir:: PathSegment {
330
+ name : identifier. name ,
331
+ parameters : self . lower_path_parameters ( parameters, param_mode) ,
332
+ }
333
+ } ) . collect ( ) ,
313
334
span : p. span ,
314
335
}
315
336
}
316
337
317
- fn lower_path_parameters ( & mut self , path_parameters : & PathParameters ) -> hir:: PathParameters {
338
+ fn lower_path_parameters ( & mut self ,
339
+ path_parameters : & PathParameters ,
340
+ param_mode : ParamMode )
341
+ -> hir:: PathParameters {
318
342
match * path_parameters {
319
- PathParameters :: AngleBracketed ( ref data) =>
320
- hir:: AngleBracketedParameters ( self . lower_angle_bracketed_parameter_data ( data) ) ,
343
+ PathParameters :: AngleBracketed ( ref data) => {
344
+ let data = self . lower_angle_bracketed_parameter_data ( data, param_mode) ;
345
+ hir:: AngleBracketedParameters ( data)
346
+ }
321
347
PathParameters :: Parenthesized ( ref data) =>
322
348
hir:: ParenthesizedParameters ( self . lower_parenthesized_parameter_data ( data) ) ,
323
349
}
324
350
}
325
351
326
352
fn lower_angle_bracketed_parameter_data ( & mut self ,
327
- data : & AngleBracketedParameterData )
353
+ data : & AngleBracketedParameterData ,
354
+ param_mode : ParamMode )
328
355
-> hir:: AngleBracketedParameterData {
329
356
let & AngleBracketedParameterData { ref lifetimes, ref types, ref bindings } = data;
330
357
hir:: AngleBracketedParameterData {
331
358
lifetimes : self . lower_lifetimes ( lifetimes) ,
332
359
types : types. iter ( ) . map ( |ty| self . lower_ty ( ty) ) . collect ( ) ,
360
+ infer_types : types. is_empty ( ) && param_mode == ParamMode :: Optional ,
333
361
bindings : bindings. iter ( ) . map ( |b| self . lower_ty_binding ( b) ) . collect ( ) ,
334
362
}
335
363
}
@@ -493,7 +521,7 @@ impl<'a> LoweringContext<'a> {
493
521
span} ) => {
494
522
hir:: WherePredicate :: EqPredicate ( hir:: WhereEqPredicate {
495
523
id : id,
496
- path : self . lower_path ( path) ,
524
+ path : self . lower_path ( path, None , ParamMode :: Explicit ) ,
497
525
ty : self . lower_ty ( ty) ,
498
526
span : span,
499
527
} )
@@ -523,7 +551,7 @@ impl<'a> LoweringContext<'a> {
523
551
524
552
fn lower_trait_ref ( & mut self , p : & TraitRef ) -> hir:: TraitRef {
525
553
hir:: TraitRef {
526
- path : self . lower_path ( & p. path ) ,
554
+ path : self . lower_path ( & p. path , None , ParamMode :: Explicit ) ,
527
555
ref_id : p. ref_id ,
528
556
}
529
557
}
@@ -887,17 +915,19 @@ impl<'a> LoweringContext<'a> {
887
915
}
888
916
PatKind :: Lit ( ref e) => hir:: PatKind :: Lit ( P ( self . lower_expr ( e) ) ) ,
889
917
PatKind :: TupleStruct ( ref path, ref pats, ddpos) => {
890
- hir:: PatKind :: TupleStruct ( self . lower_path ( path) ,
891
- pats. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) , ddpos)
918
+ hir:: PatKind :: TupleStruct ( self . lower_path ( path, None , ParamMode :: Optional ) ,
919
+ pats. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) ,
920
+ ddpos)
892
921
}
893
- PatKind :: Path ( ref opt_qself , ref path) => {
894
- let opt_qself = opt_qself . as_ref ( ) . map ( |qself| {
922
+ PatKind :: Path ( ref qself , ref path) => {
923
+ let qself = qself . as_ref ( ) . map ( |qself| {
895
924
hir:: QSelf { ty : self . lower_ty ( & qself. ty ) , position : qself. position }
896
925
} ) ;
897
- hir:: PatKind :: Path ( opt_qself, self . lower_path ( path) )
926
+ let path = self . lower_path ( path, qself. as_ref ( ) , ParamMode :: Optional ) ;
927
+ hir:: PatKind :: Path ( qself, path)
898
928
}
899
929
PatKind :: Struct ( ref pth, ref fields, etc) => {
900
- let pth = self . lower_path ( pth) ;
930
+ let pth = self . lower_path ( pth, None , ParamMode :: Optional ) ;
901
931
let fs = fields. iter ( )
902
932
. map ( |f| {
903
933
Spanned {
@@ -1236,13 +1266,14 @@ impl<'a> LoweringContext<'a> {
1236
1266
} ;
1237
1267
}
1238
1268
ExprKind :: Path ( ref qself, ref path) => {
1239
- let hir_qself = qself. as_ref ( ) . map ( |& QSelf { ref ty, position } | {
1269
+ let qself = qself. as_ref ( ) . map ( |& QSelf { ref ty, position } | {
1240
1270
hir:: QSelf {
1241
1271
ty : self . lower_ty ( ty) ,
1242
1272
position : position,
1243
1273
}
1244
1274
} ) ;
1245
- hir:: ExprPath ( hir_qself, self . lower_path ( path) )
1275
+ let path = self . lower_path ( path, qself. as_ref ( ) , ParamMode :: Optional ) ;
1276
+ hir:: ExprPath ( qself, path)
1246
1277
}
1247
1278
ExprKind :: Break ( opt_ident, ref opt_expr) => {
1248
1279
hir:: ExprBreak ( self . lower_opt_sp_ident ( opt_ident) ,
@@ -1275,7 +1306,7 @@ impl<'a> LoweringContext<'a> {
1275
1306
hir:: ExprInlineAsm ( P ( hir_asm) , outputs, inputs)
1276
1307
}
1277
1308
ExprKind :: Struct ( ref path, ref fields, ref maybe_expr) => {
1278
- hir:: ExprStruct ( P ( self . lower_path ( path) ) ,
1309
+ hir:: ExprStruct ( P ( self . lower_path ( path, None , ParamMode :: Optional ) ) ,
1279
1310
fields. iter ( ) . map ( |x| self . lower_field ( x) ) . collect ( ) ,
1280
1311
maybe_expr. as_ref ( ) . map ( |x| P ( self . lower_expr ( x) ) ) )
1281
1312
}
@@ -1655,8 +1686,12 @@ impl<'a> LoweringContext<'a> {
1655
1686
match * v {
1656
1687
Visibility :: Public => hir:: Public ,
1657
1688
Visibility :: Crate ( _) => hir:: Visibility :: Crate ,
1658
- Visibility :: Restricted { ref path, id } =>
1659
- hir:: Visibility :: Restricted { path : P ( self . lower_path ( path) ) , id : id } ,
1689
+ Visibility :: Restricted { ref path, id } => {
1690
+ hir:: Visibility :: Restricted {
1691
+ path : P ( self . lower_path ( path, None , ParamMode :: Explicit ) ) ,
1692
+ id : id
1693
+ }
1694
+ }
1660
1695
Visibility :: Inherited => hir:: Inherited ,
1661
1696
}
1662
1697
}
@@ -1949,6 +1984,7 @@ impl<'a> LoweringContext<'a> {
1949
1984
parameters : hir:: AngleBracketedParameters ( hir:: AngleBracketedParameterData {
1950
1985
lifetimes : lifetimes,
1951
1986
types : types,
1987
+ infer_types : true ,
1952
1988
bindings : bindings,
1953
1989
} ) ,
1954
1990
} ) ;
0 commit comments