Skip to content

Commit 1593ac9

Browse files
committed
Don't ignore _ in type casts and ascriptions
1 parent c76e557 commit 1593ac9

File tree

4 files changed

+89
-10
lines changed

4 files changed

+89
-10
lines changed

src/librustc_typeck/check/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2437,9 +2437,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
24372437
// types that involve projections, since those can resolve to
24382438
// `'static` bounds (modulo #54940, which hopefully will be
24392439
// fixed by the time you see this comment, dear reader,
2440-
// although I have my doubts). Other sorts of things are
2441-
// already sufficiently enforced with erased regions. =)
2442-
if ty.has_free_regions() || ty.has_projections() {
2440+
// although I have my doubts). Also pass in types with inference
2441+
// types, because they may be repeated. Other sorts of things
2442+
// are already sufficiently enforced with erased regions. =)
2443+
if ty.has_free_regions() || ty.has_projections() || ty.has_infer_types() {
24432444
let c_ty = self.infcx.canonicalize_response(&UserType::Ty(ty));
24442445
debug!("to_ty_saving_user_provided_ty: c_ty={:?}", c_ty);
24452446
self.tables.borrow_mut().user_provided_types_mut().insert(ast_ty.hir_id, c_ty);

src/test/mir-opt/retag.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ fn main() {
7575
// _10 = move _8;
7676
// Retag(_10);
7777
// ...
78-
// _14 = &mut (*_10);
79-
// Retag(_14);
80-
// _13 = move _14 as *mut i32 (Misc);
81-
// Retag([raw] _13);
78+
// _15 = &mut (*_10);
79+
// Retag(_15);
80+
// _14 = move _15 as *mut i32 (Misc);
81+
// Retag([raw] _14);
8282
// ...
83-
// _17 = move _18(move _19) -> bb2;
83+
// _18 = move _19(move _20) -> bb2;
8484
// }
8585
//
8686
// bb2: {
87-
// Retag(_17);
87+
// Retag(_18);
8888
// ...
89-
// _21 = const Test::foo_shr(move _22, move _24) -> bb3;
89+
// _22 = const Test::foo_shr(move _23, move _25) -> bb3;
9090
// }
9191
//
9292
// bb3: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Check that repeated type variables are correctly handled
2+
3+
#![allow(unused)]
4+
#![feature(nll, type_ascription)]
5+
6+
type PairUncoupled<'a, 'b, T> = (&'a T, &'b T);
7+
type PairCoupledTypes<T> = (T, T);
8+
type PairCoupledRegions<'a, T> = (&'a T, &'a T);
9+
10+
fn uncoupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
11+
let ((y, _z),) = ((s, _x),): (PairUncoupled<_>,);
12+
y // OK
13+
}
14+
15+
fn coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
16+
let ((y, _z),) = ((s, _x),): (PairCoupledTypes<_>,);
17+
y //~ ERROR lifetime may not live long enough
18+
}
19+
20+
fn coupled_regions_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
21+
let ((y, _z),) = ((s, _x),): (PairCoupledRegions<_>,);
22+
y //~ ERROR lifetime may not live long enough
23+
}
24+
25+
fn cast_uncoupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
26+
let ((y, _z),) = ((s, _x),) as (PairUncoupled<_>,);
27+
y // OK
28+
}
29+
30+
fn cast_coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
31+
let ((y, _z),) = ((s, _x),) as (PairCoupledTypes<_>,);
32+
y //~ ERROR lifetime may not live long enough
33+
}
34+
35+
fn cast_coupled_regions_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
36+
let ((y, _z),) = ((s, _x),) as (PairCoupledRegions<_>,);
37+
y //~ ERROR lifetime may not live long enough
38+
}
39+
40+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/issue-57731-ascibed-coupled-types.rs:17:5
3+
|
4+
LL | fn coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
5+
| -- lifetime `'a` defined here
6+
LL | let ((y, _z),) = ((s, _x),): (PairCoupledTypes<_>,);
7+
LL | y //~ ERROR lifetime may not live long enough
8+
| ^ returning this value requires that `'a` must outlive `'static`
9+
10+
error: lifetime may not live long enough
11+
--> $DIR/issue-57731-ascibed-coupled-types.rs:22:5
12+
|
13+
LL | fn coupled_regions_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
14+
| -- lifetime `'a` defined here
15+
LL | let ((y, _z),) = ((s, _x),): (PairCoupledRegions<_>,);
16+
LL | y //~ ERROR lifetime may not live long enough
17+
| ^ returning this value requires that `'a` must outlive `'static`
18+
19+
error: lifetime may not live long enough
20+
--> $DIR/issue-57731-ascibed-coupled-types.rs:32:5
21+
|
22+
LL | fn cast_coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
23+
| -- lifetime `'a` defined here
24+
LL | let ((y, _z),) = ((s, _x),) as (PairCoupledTypes<_>,);
25+
LL | y //~ ERROR lifetime may not live long enough
26+
| ^ returning this value requires that `'a` must outlive `'static`
27+
28+
error: lifetime may not live long enough
29+
--> $DIR/issue-57731-ascibed-coupled-types.rs:37:5
30+
|
31+
LL | fn cast_coupled_regions_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
32+
| -- lifetime `'a` defined here
33+
LL | let ((y, _z),) = ((s, _x),) as (PairCoupledRegions<_>,);
34+
LL | y //~ ERROR lifetime may not live long enough
35+
| ^ returning this value requires that `'a` must outlive `'static`
36+
37+
error: aborting due to 4 previous errors
38+

0 commit comments

Comments
 (0)