File tree Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -19,10 +19,21 @@ pub enum Parameter {
1919 Region ( ty:: EarlyBoundRegion ) ,
2020}
2121
22+ /// Returns the list of parameters that are constrained by the type `ty`
23+ /// - i.e. the value of each parameter in the list is uniquely determined
24+ /// by `ty` (see RFC 447).
2225pub fn parameters_for_type < ' tcx > ( ty : Ty < ' tcx > ) -> Vec < Parameter > {
23- ty. walk ( )
24- . flat_map ( |ty| parameters_for_type_shallow ( ty) )
25- . collect ( )
26+ let mut result = vec ! [ ] ;
27+ ty:: maybe_walk_ty ( ty, |t| {
28+ if let ty:: TyProjection ( ..) = t. sty {
29+ false // projections are not injective.
30+ } else {
31+ result. append ( & mut parameters_for_type_shallow ( t) ) ;
32+ // non-projection type constructors are injective.
33+ true
34+ }
35+ } ) ;
36+ result
2637}
2738
2839pub fn parameters_for_trait_ref < ' tcx > ( trait_ref : & ty:: TraitRef < ' tcx > ) -> Vec < Parameter > {
Original file line number Diff line number Diff line change 1+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ // Check that projections don't count as constraining type parameters.
12+
13+ struct S < T > ( T ) ;
14+
15+ trait Tr { type Assoc ; fn test ( ) ; }
16+
17+ impl < T : Tr > S < T :: Assoc > {
18+ //~^ ERROR the type parameter `T` is not constrained
19+ fn foo ( self , _: T ) {
20+ T :: test ( ) ;
21+ }
22+ }
23+
24+ trait Trait1 < T > { type Bar ; }
25+ trait Trait2 < ' x > { type Foo ; }
26+
27+ impl < ' a , T : Trait2 < ' a > > Trait1 < <T as Trait2 < ' a > >:: Foo > for T {
28+ //~^ ERROR the lifetime parameter `'a` is not constrained
29+ type Bar = & ' a ( ) ;
30+ }
31+
32+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments