Don't try to use a path to a type alias as a path to the adt it aliases
This commit is contained in:
@@ -452,7 +452,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||||||
ty::Adt(_adt_def, substs),
|
ty::Adt(_adt_def, substs),
|
||||||
hir::TyKind::Path(hir::QPath::Resolved(None, path)),
|
hir::TyKind::Path(hir::QPath::Resolved(None, path)),
|
||||||
) => {
|
) => {
|
||||||
if let Some(last_segment) = path.segments.last() {
|
match path.def {
|
||||||
|
// Type parameters of the type alias have no reason to
|
||||||
|
// be the same as those of the ADT.
|
||||||
|
// FIXME: We should be able to do something similar to
|
||||||
|
// match_adt_and_segment in this case.
|
||||||
|
hir::def::Def::TyAlias(_) => (),
|
||||||
|
_ => if let Some(last_segment) = path.segments.last() {
|
||||||
if let Some(name) = self.match_adt_and_segment(
|
if let Some(name) = self.match_adt_and_segment(
|
||||||
substs,
|
substs,
|
||||||
needle_fr,
|
needle_fr,
|
||||||
@@ -465,6 +471,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The following cases don't have lifetimes, so we
|
// The following cases don't have lifetimes, so we
|
||||||
// just worry about trying to match up the rustc type
|
// just worry about trying to match up the rustc type
|
||||||
|
|||||||
33
src/test/ui/nll/type-alias-free-regions.rs
Normal file
33
src/test/ui/nll/type-alias-free-regions.rs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
// Test that we don't assume that type aliases have the same type parameters
|
||||||
|
// as the type they alias and then panic when we see this.
|
||||||
|
|
||||||
|
#![feature(nll)]
|
||||||
|
|
||||||
|
type a<'a> = &'a isize;
|
||||||
|
type b<'a> = Box<a<'a>>;
|
||||||
|
|
||||||
|
struct c<'a> {
|
||||||
|
f: Box<b<'a>>
|
||||||
|
}
|
||||||
|
|
||||||
|
trait FromBox<'a> {
|
||||||
|
fn from_box(b: Box<b>) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> FromBox<'a> for c<'a> {
|
||||||
|
fn from_box(b: Box<b>) -> Self {
|
||||||
|
c { f: b } //~ ERROR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trait FromTuple<'a> {
|
||||||
|
fn from_tuple( b: (b,)) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> FromTuple<'a> for c<'a> {
|
||||||
|
fn from_tuple(b: (b,)) -> Self {
|
||||||
|
c { f: Box::new(b.0) } //~ ERROR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
22
src/test/ui/nll/type-alias-free-regions.stderr
Normal file
22
src/test/ui/nll/type-alias-free-regions.stderr
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
error: unsatisfied lifetime constraints
|
||||||
|
--> $DIR/type-alias-free-regions.rs:19:9
|
||||||
|
|
|
||||||
|
LL | impl<'a> FromBox<'a> for c<'a> {
|
||||||
|
| -- lifetime `'a` defined here
|
||||||
|
LL | fn from_box(b: Box<b>) -> Self {
|
||||||
|
| - has type `std::boxed::Box<std::boxed::Box<&'1 isize>>`
|
||||||
|
LL | c { f: b } //~ ERROR
|
||||||
|
| ^^^^^^^^^^ returning this value requires that `'1` must outlive `'a`
|
||||||
|
|
||||||
|
error: unsatisfied lifetime constraints
|
||||||
|
--> $DIR/type-alias-free-regions.rs:29:9
|
||||||
|
|
|
||||||
|
LL | impl<'a> FromTuple<'a> for c<'a> {
|
||||||
|
| -- lifetime `'a` defined here
|
||||||
|
LL | fn from_tuple(b: (b,)) -> Self {
|
||||||
|
| - has type `(std::boxed::Box<&'1 isize>,)`
|
||||||
|
LL | c { f: Box::new(b.0) } //~ ERROR
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'a`
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
Reference in New Issue
Block a user