Skip to content

Commit 61f8e2c

Browse files
committed
remove defaulting to unit
Types will no longer default to `()`, instead always defaulting to `!`. This disables the associated warning and removes the flag from TyTuple
1 parent 8d3e93b commit 61f8e2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+111
-246
lines changed

src/librustc/ich/impls_ty.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,8 @@ for ty::TypeVariants<'gcx>
635635
closure_substs.hash_stable(hcx, hasher);
636636
interior.hash_stable(hcx, hasher);
637637
}
638-
TyTuple(inner_tys, from_diverging_type_var) => {
638+
TyTuple(inner_tys) => {
639639
inner_tys.hash_stable(hcx, hasher);
640-
from_diverging_type_var.hash_stable(hcx, hasher);
641640
}
642641
TyProjection(ref projection_ty) => {
643642
projection_ty.hash_stable(hcx, hasher);

src/librustc/infer/resolve.rs

-6
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,6 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for FullTypeResolver<'a, 'gcx, 'tcx>
173173
ty::TyInfer(_) => {
174174
bug!("Unexpected type in full type resolver: {:?}", t);
175175
}
176-
ty::TyTuple(tys, true) => {
177-
// Un-default defaulted tuples - we are going to a
178-
// different infcx, and the default will just cause
179-
// pollution.
180-
self.tcx().intern_tup(tys, false)
181-
}
182176
_ => {
183177
t.super_fold_with(self)
184178
}

src/librustc/lint/builtin.rs

-8
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,6 @@ declare_lint! {
142142
"lints that have been renamed or removed"
143143
}
144144

145-
declare_lint! {
146-
pub RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
147-
Deny,
148-
"attempt to resolve a trait on an expression whose type cannot be inferred but which \
149-
currently defaults to ()"
150-
}
151-
152145
declare_lint! {
153146
pub SAFE_EXTERN_STATICS,
154147
Deny,
@@ -275,7 +268,6 @@ impl LintPass for HardwiredLints {
275268
INVALID_TYPE_PARAM_DEFAULT,
276269
CONST_ERR,
277270
RENAMED_AND_REMOVED_LINTS,
278-
RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
279271
SAFE_EXTERN_STATICS,
280272
SAFE_PACKED_BORROWS,
281273
PATTERNS_IN_FNS_WITHOUT_BODY,

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12981298
PatKind::Tuple(ref subpats, ddpos) => {
12991299
// (p1, ..., pN)
13001300
let expected_len = match self.pat_ty(&pat)?.sty {
1301-
ty::TyTuple(ref tys, _) => tys.len(),
1301+
ty::TyTuple(ref tys) => tys.len(),
13021302
ref ty => span_bug!(pat.span, "tuple pattern unexpected type {:?}", ty),
13031303
};
13041304
for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) {

src/librustc/mir/tcx.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<'tcx> Rvalue<'tcx> {
171171
let lhs_ty = lhs.ty(local_decls, tcx);
172172
let rhs_ty = rhs.ty(local_decls, tcx);
173173
let ty = op.ty(tcx, lhs_ty, rhs_ty);
174-
tcx.intern_tup(&[ty, tcx.types.bool], false)
174+
tcx.intern_tup(&[ty, tcx.types.bool])
175175
}
176176
Rvalue::UnaryOp(UnOp::Not, ref operand) |
177177
Rvalue::UnaryOp(UnOp::Neg, ref operand) => {
@@ -195,10 +195,7 @@ impl<'tcx> Rvalue<'tcx> {
195195
tcx.mk_array(ty, ops.len() as u64)
196196
}
197197
AggregateKind::Tuple => {
198-
tcx.mk_tup(
199-
ops.iter().map(|op| op.ty(local_decls, tcx)),
200-
false
201-
)
198+
tcx.mk_tup(ops.iter().map(|op| op.ty(local_decls, tcx)))
202199
}
203200
AggregateKind::Adt(def, _, substs, _) => {
204201
tcx.type_of(def.did).subst(tcx, substs)

src/librustc/traits/error_reporting.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -718,14 +718,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
718718
}).map(|sp| self.tcx.sess.codemap().def_span(sp)); // the sp could be an fn def
719719

720720
let found = match found_trait_ref.skip_binder().substs.type_at(1).sty {
721-
ty::TyTuple(ref tys, _) => tys.iter()
721+
ty::TyTuple(ref tys) => tys.iter()
722722
.map(|_| ArgKind::empty()).collect::<Vec<_>>(),
723723
_ => vec![ArgKind::empty()],
724724
};
725725
let expected = match expected_trait_ref.skip_binder().substs.type_at(1).sty {
726-
ty::TyTuple(ref tys, _) => tys.iter()
726+
ty::TyTuple(ref tys) => tys.iter()
727727
.map(|t| match t.sty {
728-
ty::TypeVariants::TyTuple(ref tys, _) => ArgKind::Tuple(
728+
ty::TypeVariants::TyTuple(ref tys) => ArgKind::Tuple(
729729
span,
730730
tys.iter()
731731
.map(|ty| ("_".to_owned(), format!("{}", ty.sty)))
@@ -937,7 +937,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
937937
fn build_fn_sig_string<'a, 'gcx, 'tcx>(tcx: ty::TyCtxt<'a, 'gcx, 'tcx>,
938938
trait_ref: &ty::TraitRef<'tcx>) -> String {
939939
let inputs = trait_ref.substs.type_at(1);
940-
let sig = if let ty::TyTuple(inputs, _) = inputs.sty {
940+
let sig = if let ty::TyTuple(inputs) = inputs.sty {
941941
tcx.mk_fn_sig(
942942
inputs.iter().map(|&x| x),
943943
tcx.mk_infer(ty::TyVar(ty::TyVid { index: 0 })),

src/librustc/traits/fulfill.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,7 @@ fn process_predicate<'a, 'gcx, 'tcx>(
328328
if data.is_global() {
329329
// no type variables present, can use evaluation for better caching.
330330
// FIXME: consider caching errors too.
331-
if
332-
// make defaulted unit go through the slow path for better warnings,
333-
// please remove this when the warnings are removed.
334-
!trait_obligation.predicate.skip_binder().self_ty().is_defaulted_unit() &&
335-
selcx.evaluate_obligation_conservatively(&obligation) {
331+
if selcx.evaluate_obligation_conservatively(&obligation) {
336332
debug!("selecting trait `{:?}` at depth {} evaluated to holds",
337333
data, obligation.recursion_depth);
338334
return Ok(Some(vec![]))

src/librustc/traits/select.rs

+6-49
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ use std::mem;
5252
use std::rc::Rc;
5353
use syntax::abi::Abi;
5454
use hir;
55-
use lint;
5655
use util::nodemap::FxHashMap;
5756

5857
struct InferredObligationsSnapshotVecDelegate<'tcx> {
@@ -517,8 +516,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
517516
debug!("select({:?})", obligation);
518517
assert!(!obligation.predicate.has_escaping_regions());
519518

520-
let tcx = self.tcx();
521-
522519
let stack = self.push_stack(TraitObligationStackList::empty(), obligation);
523520
let ret = match self.candidate_from_obligation(&stack)? {
524521
None => None,
@@ -530,46 +527,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
530527
},
531528
};
532529

533-
// Test whether this is a `()` which was produced by defaulting a
534-
// diverging type variable with `!` disabled. If so, we may need
535-
// to raise a warning.
536-
if obligation.predicate.skip_binder().self_ty().is_defaulted_unit() {
537-
let mut raise_warning = true;
538-
// Don't raise a warning if the trait is implemented for ! and only
539-
// permits a trivial implementation for !. This stops us warning
540-
// about (for example) `(): Clone` becoming `!: Clone` because such
541-
// a switch can't cause code to stop compiling or execute
542-
// differently.
543-
let mut never_obligation = obligation.clone();
544-
let def_id = never_obligation.predicate.skip_binder().trait_ref.def_id;
545-
never_obligation.predicate = never_obligation.predicate.map_bound(|mut trait_pred| {
546-
// Swap out () with ! so we can check if the trait is impld for !
547-
{
548-
let trait_ref = &mut trait_pred.trait_ref;
549-
let unit_substs = trait_ref.substs;
550-
let mut never_substs = Vec::with_capacity(unit_substs.len());
551-
never_substs.push(From::from(tcx.types.never));
552-
never_substs.extend(&unit_substs[1..]);
553-
trait_ref.substs = tcx.intern_substs(&never_substs);
554-
}
555-
trait_pred
556-
});
557-
if let Ok(Some(..)) = self.select(&never_obligation) {
558-
if !tcx.trait_relevant_for_never(def_id) {
559-
// The trait is also implemented for ! and the resulting
560-
// implementation cannot actually be invoked in any way.
561-
raise_warning = false;
562-
}
563-
}
564-
565-
if raise_warning {
566-
tcx.lint_node(lint::builtin::RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
567-
obligation.cause.body_id,
568-
obligation.cause.span,
569-
&format!("code relies on type inference rules which are likely \
570-
to change"));
571-
}
572-
}
573530
Ok(ret)
574531
}
575532

@@ -1913,7 +1870,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
19131870
}
19141871

19151872
// (.., T) -> (.., U).
1916-
(&ty::TyTuple(tys_a, _), &ty::TyTuple(tys_b, _)) => {
1873+
(&ty::TyTuple(tys_a), &ty::TyTuple(tys_b)) => {
19171874
tys_a.len() == tys_b.len()
19181875
}
19191876

@@ -2052,7 +2009,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
20522009

20532010
ty::TyStr | ty::TySlice(_) | ty::TyDynamic(..) | ty::TyForeign(..) => Never,
20542011

2055-
ty::TyTuple(tys, _) => {
2012+
ty::TyTuple(tys) => {
20562013
Where(ty::Binder(tys.last().into_iter().cloned().collect()))
20572014
}
20582015

@@ -2105,7 +2062,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21052062
Where(ty::Binder(vec![element_ty]))
21062063
}
21072064

2108-
ty::TyTuple(tys, _) => {
2065+
ty::TyTuple(tys) => {
21092066
// (*) binder moved here
21102067
Where(ty::Binder(tys.to_vec()))
21112068
}
@@ -2196,7 +2153,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21962153
vec![element_ty]
21972154
}
21982155

2199-
ty::TyTuple(ref tys, _) => {
2156+
ty::TyTuple(ref tys) => {
22002157
// (T1, ..., Tn) -- meets any bound that all of T1...Tn meet
22012158
tys.to_vec()
22022159
}
@@ -2969,7 +2926,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
29692926
}
29702927

29712928
// (.., T) -> (.., U).
2972-
(&ty::TyTuple(tys_a, _), &ty::TyTuple(tys_b, _)) => {
2929+
(&ty::TyTuple(tys_a), &ty::TyTuple(tys_b)) => {
29732930
assert_eq!(tys_a.len(), tys_b.len());
29742931

29752932
// The last field of the tuple has to exist.
@@ -2982,7 +2939,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
29822939

29832940
// Check that the source tuple with the target's
29842941
// last element is equal to the target.
2985-
let new_tuple = tcx.mk_tup(a_mid.iter().chain(Some(b_last)), false);
2942+
let new_tuple = tcx.mk_tup(a_mid.iter().chain(Some(b_last)));
29862943
let InferOk { obligations, .. } =
29872944
self.infcx.at(&obligation.cause, obligation.param_env)
29882945
.eq(target, new_tuple)

src/librustc/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
511511
let arguments_tuple = match tuple_arguments {
512512
TupleArgumentsFlag::No => sig.skip_binder().inputs()[0],
513513
TupleArgumentsFlag::Yes =>
514-
self.intern_tup(sig.skip_binder().inputs(), false),
514+
self.intern_tup(sig.skip_binder().inputs()),
515515
};
516516
let trait_ref = ty::TraitRef {
517517
def_id: fn_trait_def_id,

src/librustc/ty/context.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
18801880
pub fn coerce_closure_fn_ty(self, sig: PolyFnSig<'tcx>) -> Ty<'tcx> {
18811881
let converted_sig = sig.map_bound(|s| {
18821882
let params_iter = match s.inputs()[0].sty {
1883-
ty::TyTuple(params, _) => {
1883+
ty::TyTuple(params) => {
18841884
params.into_iter().cloned()
18851885
}
18861886
_ => bug!(),
@@ -2005,25 +2005,16 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
20052005
self.mk_ty(TySlice(ty))
20062006
}
20072007

2008-
pub fn intern_tup(self, ts: &[Ty<'tcx>], defaulted: bool) -> Ty<'tcx> {
2009-
self.mk_ty(TyTuple(self.intern_type_list(ts), defaulted))
2008+
pub fn intern_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> {
2009+
self.mk_ty(TyTuple(self.intern_type_list(ts)))
20102010
}
20112011

2012-
pub fn mk_tup<I: InternAs<[Ty<'tcx>], Ty<'tcx>>>(self, iter: I,
2013-
defaulted: bool) -> I::Output {
2014-
iter.intern_with(|ts| self.mk_ty(TyTuple(self.intern_type_list(ts), defaulted)))
2012+
pub fn mk_tup<I: InternAs<[Ty<'tcx>], Ty<'tcx>>>(self, iter: I) -> I::Output {
2013+
iter.intern_with(|ts| self.mk_ty(TyTuple(self.intern_type_list(ts))))
20152014
}
20162015

20172016
pub fn mk_nil(self) -> Ty<'tcx> {
2018-
self.intern_tup(&[], false)
2019-
}
2020-
2021-
pub fn mk_diverging_default(self) -> Ty<'tcx> {
2022-
if self.sess.features.borrow().never_type {
2023-
self.types.never
2024-
} else {
2025-
self.intern_tup(&[], true)
2026-
}
2017+
self.intern_tup(&[])
20272018
}
20282019

20292020
pub fn mk_bool(self) -> Ty<'tcx> {

src/librustc/ty/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
188188
match self.sty {
189189
ty::TyBool | ty::TyChar | ty::TyInt(_) |
190190
ty::TyUint(_) | ty::TyFloat(_) | ty::TyStr | ty::TyNever => self.to_string(),
191-
ty::TyTuple(ref tys, _) if tys.is_empty() => self.to_string(),
191+
ty::TyTuple(ref tys) if tys.is_empty() => self.to_string(),
192192

193193
ty::TyAdt(def, _) => format!("{} `{}`", def.descr(), tcx.item_path_str(def.did)),
194194
ty::TyForeign(def_id) => format!("extern type `{}`", tcx.item_path_str(def_id)),

src/librustc/ty/fast_reject.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
9393
Some(GeneratorSimplifiedType(def_id))
9494
}
9595
ty::TyNever => Some(NeverSimplifiedType),
96-
ty::TyTuple(ref tys, _) => {
96+
ty::TyTuple(ref tys) => {
9797
Some(TupleSimplifiedType(tys.len()))
9898
}
9999
ty::TyFnPtr(ref f) => {

src/librustc/ty/flags.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,7 @@ impl FlagComputation {
165165
self.add_ty(m.ty);
166166
}
167167

168-
&ty::TyTuple(ref ts, is_default) => {
169-
if is_default {
170-
self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX);
171-
}
168+
&ty::TyTuple(ref ts) => {
172169
self.add_tys(&ts[..]);
173170
}
174171

src/librustc/ty/inhabitedness/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
256256
},
257257

258258
TyNever => DefIdForest::full(tcx),
259-
TyTuple(ref tys, _) => {
259+
TyTuple(ref tys) => {
260260
DefIdForest::union(tcx, tys.iter().map(|ty| {
261261
ty.uninhabited_from(visited, tcx)
262262
}))

src/librustc/ty/item_path.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,9 @@ pub fn characteristic_def_id_of_type(ty: Ty) -> Option<DefId> {
355355
ty::TyRawPtr(mt) |
356356
ty::TyRef(_, mt) => characteristic_def_id_of_type(mt.ty),
357357

358-
ty::TyTuple(ref tys, _) => tys.iter()
359-
.filter_map(|ty| characteristic_def_id_of_type(ty))
360-
.next(),
358+
ty::TyTuple(ref tys) => tys.iter()
359+
.filter_map(|ty| characteristic_def_id_of_type(ty))
360+
.next(),
361361

362362
ty::TyFnDef(def_id, _) |
363363
ty::TyClosure(def_id, _) |

src/librustc/ty/layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ impl<'a, 'tcx> LayoutDetails {
13011301
StructKind::AlwaysSized)?
13021302
}
13031303

1304-
ty::TyTuple(tys, _) => {
1304+
ty::TyTuple(tys) => {
13051305
let kind = if tys.len() == 0 {
13061306
StructKind::AlwaysSized
13071307
} else {
@@ -2204,7 +2204,7 @@ impl<'a, 'tcx> TyLayout<'tcx> {
22042204
substs.field_tys(def_id, tcx).nth(i).unwrap()
22052205
}
22062206

2207-
ty::TyTuple(tys, _) => tys[i],
2207+
ty::TyTuple(tys) => tys[i],
22082208

22092209
// SIMD vector types.
22102210
ty::TyAdt(def, ..) if def.repr.simd() => {

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
18641864
vec![ty]
18651865
}
18661866

1867-
TyTuple(ref tys, _) => {
1867+
TyTuple(ref tys) => {
18681868
match tys.last() {
18691869
None => vec![],
18701870
Some(ty) => self.sized_constraint_for_ty(tcx, ty)

src/librustc/ty/relate.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,10 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
485485
Ok(tcx.mk_slice(t))
486486
}
487487

488-
(&ty::TyTuple(as_, a_defaulted), &ty::TyTuple(bs, b_defaulted)) =>
488+
(&ty::TyTuple(as_), &ty::TyTuple(bs)) =>
489489
{
490490
if as_.len() == bs.len() {
491-
let defaulted = a_defaulted || b_defaulted;
492-
Ok(tcx.mk_tup(as_.iter().zip(bs).map(|(a, b)| relation.relate(a, b)), defaulted)?)
491+
Ok(tcx.mk_tup(as_.iter().zip(bs).map(|(a, b)| relation.relate(a, b)))?)
493492
} else if !(as_.is_empty() || bs.is_empty()) {
494493
Err(TypeError::TupleSize(
495494
expected_found(relation, &as_.len(), &bs.len())))

src/librustc/ty/structural_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
787787
ty::TyAdt(tid, substs) => ty::TyAdt(tid, substs.fold_with(folder)),
788788
ty::TyDynamic(ref trait_ty, ref region) =>
789789
ty::TyDynamic(trait_ty.fold_with(folder), region.fold_with(folder)),
790-
ty::TyTuple(ts, defaulted) => ty::TyTuple(ts.fold_with(folder), defaulted),
790+
ty::TyTuple(ts) => ty::TyTuple(ts.fold_with(folder)),
791791
ty::TyFnDef(def_id, substs) => {
792792
ty::TyFnDef(def_id, substs.fold_with(folder))
793793
}
@@ -825,7 +825,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
825825
ty::TyAdt(_, substs) => substs.visit_with(visitor),
826826
ty::TyDynamic(ref trait_ty, ref reg) =>
827827
trait_ty.visit_with(visitor) || reg.visit_with(visitor),
828-
ty::TyTuple(ts, _) => ts.visit_with(visitor),
828+
ty::TyTuple(ts) => ts.visit_with(visitor),
829829
ty::TyFnDef(_, substs) => substs.visit_with(visitor),
830830
ty::TyFnPtr(ref f) => f.visit_with(visitor),
831831
ty::TyRef(r, ref tm) => r.visit_with(visitor) || tm.visit_with(visitor),

0 commit comments

Comments
 (0)