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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 0 additions & 6 deletions
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

Lines changed: 0 additions & 8 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 6 additions & 49 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 15 deletions
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> {

0 commit comments

Comments
 (0)