Skip to content

Commit

Permalink
Don't ignore _ in type casts and ascriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Jan 19, 2019
1 parent c76e557 commit 1593ac9
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -2437,9 +2437,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// types that involve projections, since those can resolve to
// `'static` bounds (modulo #54940, which hopefully will be
// fixed by the time you see this comment, dear reader,
// although I have my doubts). Other sorts of things are
// already sufficiently enforced with erased regions. =)
if ty.has_free_regions() || ty.has_projections() {
// although I have my doubts). Also pass in types with inference
// types, because they may be repeated. Other sorts of things
// are already sufficiently enforced with erased regions. =)
if ty.has_free_regions() || ty.has_projections() || ty.has_infer_types() {
let c_ty = self.infcx.canonicalize_response(&UserType::Ty(ty));
debug!("to_ty_saving_user_provided_ty: c_ty={:?}", c_ty);
self.tables.borrow_mut().user_provided_types_mut().insert(ast_ty.hir_id, c_ty);
Expand Down
14 changes: 7 additions & 7 deletions src/test/mir-opt/retag.rs
Expand Up @@ -75,18 +75,18 @@ fn main() {
// _10 = move _8;
// Retag(_10);
// ...
// _14 = &mut (*_10);
// Retag(_14);
// _13 = move _14 as *mut i32 (Misc);
// Retag([raw] _13);
// _15 = &mut (*_10);
// Retag(_15);
// _14 = move _15 as *mut i32 (Misc);
// Retag([raw] _14);
// ...
// _17 = move _18(move _19) -> bb2;
// _18 = move _19(move _20) -> bb2;
// }
//
// bb2: {
// Retag(_17);
// Retag(_18);
// ...
// _21 = const Test::foo_shr(move _22, move _24) -> bb3;
// _22 = const Test::foo_shr(move _23, move _25) -> bb3;
// }
//
// bb3: {
Expand Down
@@ -0,0 +1,40 @@
// Check that repeated type variables are correctly handled

#![allow(unused)]
#![feature(nll, type_ascription)]

type PairUncoupled<'a, 'b, T> = (&'a T, &'b T);
type PairCoupledTypes<T> = (T, T);
type PairCoupledRegions<'a, T> = (&'a T, &'a T);

fn uncoupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
let ((y, _z),) = ((s, _x),): (PairUncoupled<_>,);
y // OK
}

fn coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
let ((y, _z),) = ((s, _x),): (PairCoupledTypes<_>,);
y //~ ERROR lifetime may not live long enough
}

fn coupled_regions_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
let ((y, _z),) = ((s, _x),): (PairCoupledRegions<_>,);
y //~ ERROR lifetime may not live long enough
}

fn cast_uncoupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
let ((y, _z),) = ((s, _x),) as (PairUncoupled<_>,);
y // OK
}

fn cast_coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
let ((y, _z),) = ((s, _x),) as (PairCoupledTypes<_>,);
y //~ ERROR lifetime may not live long enough
}

fn cast_coupled_regions_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
let ((y, _z),) = ((s, _x),) as (PairCoupledRegions<_>,);
y //~ ERROR lifetime may not live long enough
}

fn main() {}
@@ -0,0 +1,38 @@
error: lifetime may not live long enough
--> $DIR/issue-57731-ascibed-coupled-types.rs:17:5
|
LL | fn coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
| -- lifetime `'a` defined here
LL | let ((y, _z),) = ((s, _x),): (PairCoupledTypes<_>,);
LL | y //~ ERROR lifetime may not live long enough
| ^ returning this value requires that `'a` must outlive `'static`

error: lifetime may not live long enough
--> $DIR/issue-57731-ascibed-coupled-types.rs:22:5
|
LL | fn coupled_regions_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
| -- lifetime `'a` defined here
LL | let ((y, _z),) = ((s, _x),): (PairCoupledRegions<_>,);
LL | y //~ ERROR lifetime may not live long enough
| ^ returning this value requires that `'a` must outlive `'static`

error: lifetime may not live long enough
--> $DIR/issue-57731-ascibed-coupled-types.rs:32:5
|
LL | fn cast_coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
| -- lifetime `'a` defined here
LL | let ((y, _z),) = ((s, _x),) as (PairCoupledTypes<_>,);
LL | y //~ ERROR lifetime may not live long enough
| ^ returning this value requires that `'a` must outlive `'static`

error: lifetime may not live long enough
--> $DIR/issue-57731-ascibed-coupled-types.rs:37:5
|
LL | fn cast_coupled_regions_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
| -- lifetime `'a` defined here
LL | let ((y, _z),) = ((s, _x),) as (PairCoupledRegions<_>,);
LL | y //~ ERROR lifetime may not live long enough
| ^ returning this value requires that `'a` must outlive `'static`

error: aborting due to 4 previous errors

0 comments on commit 1593ac9

Please sign in to comment.