File tree Expand file tree Collapse file tree 3 files changed +72
-10
lines changed
librustc_mir/borrow_check/nll/region_infer/error_reporting Expand file tree Collapse file tree 3 files changed +72
-10
lines changed Original file line number Diff line number Diff line change @@ -452,16 +452,23 @@ impl<'tcx> RegionInferenceContext<'tcx> {
452
452
ty:: Adt ( _adt_def, substs) ,
453
453
hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , path) ) ,
454
454
) => {
455
- if let Some ( last_segment) = path. segments . last ( ) {
456
- if let Some ( name) = self . match_adt_and_segment (
457
- substs,
458
- needle_fr,
459
- last_segment,
460
- counter,
461
- diag,
462
- search_stack,
463
- ) {
464
- return Some ( name) ;
455
+ match path. def {
456
+ // Type parameters of the type alias have no reason to
457
+ // be the same as those of the ADT.
458
+ // FIXME: We should be able to do something similar to
459
+ // match_adt_and_segment in this case.
460
+ hir:: def:: Def :: TyAlias ( _) => ( ) ,
461
+ _ => if let Some ( last_segment) = path. segments . last ( ) {
462
+ if let Some ( name) = self . match_adt_and_segment (
463
+ substs,
464
+ needle_fr,
465
+ last_segment,
466
+ counter,
467
+ diag,
468
+ search_stack,
469
+ ) {
470
+ return Some ( name) ;
471
+ }
465
472
}
466
473
}
467
474
}
Original file line number Diff line number Diff line change
1
+ // Test that we don't assume that type aliases have the same type parameters
2
+ // as the type they alias and then panic when we see this.
3
+
4
+ #![ feature( nll) ]
5
+
6
+ type a < ' a > = & ' a isize ;
7
+ type b < ' a > = Box < a < ' a > > ;
8
+
9
+ struct c < ' a > {
10
+ f : Box < b < ' a > >
11
+ }
12
+
13
+ trait FromBox < ' a > {
14
+ fn from_box ( b : Box < b > ) -> Self ;
15
+ }
16
+
17
+ impl < ' a > FromBox < ' a > for c < ' a > {
18
+ fn from_box ( b : Box < b > ) -> Self {
19
+ c { f : b } //~ ERROR
20
+ }
21
+ }
22
+
23
+ trait FromTuple < ' a > {
24
+ fn from_tuple ( b : ( b , ) ) -> Self ;
25
+ }
26
+
27
+ impl < ' a > FromTuple < ' a > for c < ' a > {
28
+ fn from_tuple ( b : ( b , ) ) -> Self {
29
+ c { f : Box :: new ( b. 0 ) } //~ ERROR
30
+ }
31
+ }
32
+
33
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: unsatisfied lifetime constraints
2
+ --> $DIR/type-alias-free-regions.rs:19:9
3
+ |
4
+ LL | impl<'a> FromBox<'a> for c<'a> {
5
+ | -- lifetime `'a` defined here
6
+ LL | fn from_box(b: Box<b>) -> Self {
7
+ | - has type `std::boxed::Box<std::boxed::Box<&'1 isize>>`
8
+ LL | c { f: b } //~ ERROR
9
+ | ^^^^^^^^^^ returning this value requires that `'1` must outlive `'a`
10
+
11
+ error: unsatisfied lifetime constraints
12
+ --> $DIR/type-alias-free-regions.rs:29:9
13
+ |
14
+ LL | impl<'a> FromTuple<'a> for c<'a> {
15
+ | -- lifetime `'a` defined here
16
+ LL | fn from_tuple(b: (b,)) -> Self {
17
+ | - has type `(std::boxed::Box<&'1 isize>,)`
18
+ LL | c { f: Box::new(b.0) } //~ ERROR
19
+ | ^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'a`
20
+
21
+ error: aborting due to 2 previous errors
22
+
You can’t perform that action at this time.
0 commit comments