Skip to content

Commit a3a06b1

Browse files
committed
remove the "defaulted unit" type bit during writeback
The defaulted unit bit is only relevant for the surrounding inference context, and can cause trouble, including spurious lints and ICEs, outside of it. Fixes rust-lang#43853.
1 parent adbce60 commit a3a06b1

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

src/librustc/infer/resolve.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for FullTypeResolver<'a, 'gcx, 'tcx>
111111
}
112112

113113
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
114-
if !t.needs_infer() {
114+
if !t.needs_infer() && !ty::keep_local(&t) {
115115
t // micro-optimize -- if there is nothing in this type that this fold affects...
116+
// ^ we need to have the `keep_local` check to un-default
117+
// defaulted tuples.
116118
} else {
117119
let t = self.infcx.shallow_resolve(t);
118120
match t.sty {
@@ -131,6 +133,12 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for FullTypeResolver<'a, 'gcx, 'tcx>
131133
ty::TyInfer(_) => {
132134
bug!("Unexpected type in full type resolver: {:?}", t);
133135
}
136+
ty::TyTuple(tys, true) => {
137+
// Un-default defaulted tuples - we are going to a
138+
// different infcx, and the default will just cause
139+
// pollution.
140+
self.tcx().intern_tup(tys, false)
141+
}
134142
_ => {
135143
t.super_fold_with(self)
136144
}

src/librustc/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ macro_rules! direct_interners {
11951195
}
11961196
}
11971197

1198-
fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool {
1198+
pub fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool {
11991199
x.has_type_flags(ty::TypeFlags::KEEP_IN_LOCAL_TCX)
12001200
}
12011201

src/librustc/ty/flags.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ impl FlagComputation {
151151
self.add_ty(m.ty);
152152
}
153153

154-
&ty::TyTuple(ref ts, _) => {
154+
&ty::TyTuple(ref ts, is_default) => {
155+
if is_default {
156+
self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX);
157+
}
155158
self.add_tys(&ts[..]);
156159
}
157160

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub use self::sty::TypeVariants::*;
7676
pub use self::binding::BindingMode;
7777
pub use self::binding::BindingMode::*;
7878

79-
pub use self::context::{TyCtxt, GlobalArenas, tls};
79+
pub use self::context::{TyCtxt, GlobalArenas, tls, keep_local};
8080
pub use self::context::{Lift, TypeckTables};
8181

8282
pub use self::instance::{Instance, InstanceDef};

src/test/run-pass/issue-43853.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2017 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+
use std::panic;
12+
13+
fn test() {
14+
wait(|| panic!());
15+
}
16+
17+
fn wait<T, F: FnOnce() -> T>(f: F) -> F::Output {
18+
From::from(f())
19+
}
20+
21+
fn main() {
22+
let result = panic::catch_unwind(move || test());
23+
assert!(result.is_err());
24+
}

0 commit comments

Comments
 (0)