Skip to content

Commit 9b15ddb

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 fab632f commit 9b15ddb

Some content is hidden

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

57 files changed

+107
-243
lines changed

src/librustc/ich/impls_ty.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -886,9 +886,8 @@ for ty::TypeVariants<'gcx>
886886
TyGeneratorWitness(types) => {
887887
types.hash_stable(hcx, hasher)
888888
}
889-
TyTuple(inner_tys, from_diverging_type_var) => {
889+
TyTuple(inner_tys) => {
890890
inner_tys.hash_stable(hcx, hasher);
891-
from_diverging_type_var.hash_stable(hcx, hasher);
892891
}
893892
TyProjection(ref projection_ty) => {
894893
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
@@ -151,13 +151,6 @@ declare_lint! {
151151
"lints that have been renamed or removed"
152152
}
153153

154-
declare_lint! {
155-
pub RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
156-
Deny,
157-
"attempt to resolve a trait on an expression whose type cannot be inferred but which \
158-
currently defaults to ()"
159-
}
160-
161154
declare_lint! {
162155
pub SAFE_EXTERN_STATICS,
163156
Deny,
@@ -304,7 +297,6 @@ impl LintPass for HardwiredLints {
304297
INVALID_TYPE_PARAM_DEFAULT,
305298
CONST_ERR,
306299
RENAMED_AND_REMOVED_LINTS,
307-
RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
308300
SAFE_EXTERN_STATICS,
309301
SAFE_PACKED_BORROWS,
310302
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
@@ -155,7 +155,7 @@ impl<'tcx> Rvalue<'tcx> {
155155
let lhs_ty = lhs.ty(local_decls, tcx);
156156
let rhs_ty = rhs.ty(local_decls, tcx);
157157
let ty = op.ty(tcx, lhs_ty, rhs_ty);
158-
tcx.intern_tup(&[ty, tcx.types.bool], false)
158+
tcx.intern_tup(&[ty, tcx.types.bool])
159159
}
160160
Rvalue::UnaryOp(UnOp::Not, ref operand) |
161161
Rvalue::UnaryOp(UnOp::Neg, ref operand) => {
@@ -178,10 +178,7 @@ impl<'tcx> Rvalue<'tcx> {
178178
tcx.mk_array(ty, ops.len() as u64)
179179
}
180180
AggregateKind::Tuple => {
181-
tcx.mk_tup(
182-
ops.iter().map(|op| op.ty(local_decls, tcx)),
183-
false
184-
)
181+
tcx.mk_tup(ops.iter().map(|op| op.ty(local_decls, tcx)))
185182
}
186183
AggregateKind::Adt(def, _, substs, _) => {
187184
tcx.type_of(def.did).subst(tcx, substs)

src/librustc/traits/error_reporting.rs

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

731731
let found = match found_trait_ref.skip_binder().substs.type_at(1).sty {
732-
ty::TyTuple(ref tys, _) => tys.iter()
732+
ty::TyTuple(ref tys) => tys.iter()
733733
.map(|_| ArgKind::empty()).collect::<Vec<_>>(),
734734
_ => vec![ArgKind::empty()],
735735
};
736736
let expected = match expected_trait_ref.skip_binder().substs.type_at(1).sty {
737-
ty::TyTuple(ref tys, _) => tys.iter()
737+
ty::TyTuple(ref tys) => tys.iter()
738738
.map(|t| match t.sty {
739-
ty::TypeVariants::TyTuple(ref tys, _) => ArgKind::Tuple(
739+
ty::TypeVariants::TyTuple(ref tys) => ArgKind::Tuple(
740740
Some(span),
741741
tys.iter()
742742
.map(|ty| ("_".to_owned(), format!("{}", ty.sty)))
@@ -986,7 +986,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
986986
fn build_fn_sig_string<'a, 'gcx, 'tcx>(tcx: ty::TyCtxt<'a, 'gcx, 'tcx>,
987987
trait_ref: &ty::TraitRef<'tcx>) -> String {
988988
let inputs = trait_ref.substs.type_at(1);
989-
let sig = if let ty::TyTuple(inputs, _) = inputs.sty {
989+
let sig = if let ty::TyTuple(inputs) = inputs.sty {
990990
tcx.mk_fn_sig(
991991
inputs.iter().map(|&x| x),
992992
tcx.mk_infer(ty::TyVar(ty::TyVid { index: 0 })),
@@ -1422,7 +1422,7 @@ impl ArgKind {
14221422
/// argument. This has no name (`_`) and no source spans..
14231423
pub fn from_expected_ty(t: Ty<'_>) -> ArgKind {
14241424
match t.sty {
1425-
ty::TyTuple(ref tys, _) => ArgKind::Tuple(
1425+
ty::TyTuple(ref tys) => ArgKind::Tuple(
14261426
None,
14271427
tys.iter()
14281428
.map(|ty| ("_".to_owned(), format!("{}", ty.sty)))

src/librustc/traits/fulfill.rs

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

src/librustc/traits/select.rs

+6-49
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ use std::mem;
5353
use std::rc::Rc;
5454
use syntax::abi::Abi;
5555
use hir;
56-
use lint;
5756
use util::nodemap::{FxHashMap, FxHashSet};
5857

5958

@@ -526,54 +525,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
526525
debug!("select({:?})", obligation);
527526
assert!(!obligation.predicate.has_escaping_regions());
528527

529-
let tcx = self.tcx();
530-
531528
let stack = self.push_stack(TraitObligationStackList::empty(), obligation);
532529
let ret = match self.candidate_from_obligation(&stack)? {
533530
None => None,
534531
Some(candidate) => Some(self.confirm_candidate(obligation, candidate)?)
535532
};
536533

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

@@ -1929,7 +1886,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
19291886
}
19301887

19311888
// (.., T) -> (.., U).
1932-
(&ty::TyTuple(tys_a, _), &ty::TyTuple(tys_b, _)) => {
1889+
(&ty::TyTuple(tys_a), &ty::TyTuple(tys_b)) => {
19331890
tys_a.len() == tys_b.len()
19341891
}
19351892

@@ -2068,7 +2025,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
20682025

20692026
ty::TyStr | ty::TySlice(_) | ty::TyDynamic(..) | ty::TyForeign(..) => Never,
20702027

2071-
ty::TyTuple(tys, _) => {
2028+
ty::TyTuple(tys) => {
20722029
Where(ty::Binder(tys.last().into_iter().cloned().collect()))
20732030
}
20742031

@@ -2122,7 +2079,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21222079
Where(ty::Binder(vec![element_ty]))
21232080
}
21242081

2125-
ty::TyTuple(tys, _) => {
2082+
ty::TyTuple(tys) => {
21262083
// (*) binder moved here
21272084
Where(ty::Binder(tys.to_vec()))
21282085
}
@@ -2215,7 +2172,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
22152172
vec![element_ty]
22162173
}
22172174

2218-
ty::TyTuple(ref tys, _) => {
2175+
ty::TyTuple(ref tys) => {
22192176
// (T1, ..., Tn) -- meets any bound that all of T1...Tn meet
22202177
tys.to_vec()
22212178
}
@@ -3004,7 +2961,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
30042961
}
30052962

30062963
// (.., T) -> (.., U).
3007-
(&ty::TyTuple(tys_a, _), &ty::TyTuple(tys_b, _)) => {
2964+
(&ty::TyTuple(tys_a), &ty::TyTuple(tys_b)) => {
30082965
assert_eq!(tys_a.len(), tys_b.len());
30092966

30102967
// The last field of the tuple has to exist.
@@ -3017,7 +2974,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
30172974

30182975
// Check that the source tuple with the target's
30192976
// last element is equal to the target.
3020-
let new_tuple = tcx.mk_tup(a_mid.iter().chain(Some(b_last)), false);
2977+
let new_tuple = tcx.mk_tup(a_mid.iter().chain(Some(b_last)));
30212978
let InferOk { obligations, .. } =
30222979
self.infcx.at(&obligation.cause, obligation.param_env)
30232980
.eq(target, new_tuple)

src/librustc/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
503503
let arguments_tuple = match tuple_arguments {
504504
TupleArgumentsFlag::No => sig.skip_binder().inputs()[0],
505505
TupleArgumentsFlag::Yes =>
506-
self.intern_tup(sig.skip_binder().inputs(), false),
506+
self.intern_tup(sig.skip_binder().inputs()),
507507
};
508508
let trait_ref = ty::TraitRef {
509509
def_id: fn_trait_def_id,

src/librustc/ty/context.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
20142014
pub fn coerce_closure_fn_ty(self, sig: PolyFnSig<'tcx>) -> Ty<'tcx> {
20152015
let converted_sig = sig.map_bound(|s| {
20162016
let params_iter = match s.inputs()[0].sty {
2017-
ty::TyTuple(params, _) => {
2017+
ty::TyTuple(params) => {
20182018
params.into_iter().cloned()
20192019
}
20202020
_ => bug!(),
@@ -2134,25 +2134,16 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
21342134
self.mk_ty(TySlice(ty))
21352135
}
21362136

2137-
pub fn intern_tup(self, ts: &[Ty<'tcx>], defaulted: bool) -> Ty<'tcx> {
2138-
self.mk_ty(TyTuple(self.intern_type_list(ts), defaulted))
2137+
pub fn intern_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> {
2138+
self.mk_ty(TyTuple(self.intern_type_list(ts)))
21392139
}
21402140

2141-
pub fn mk_tup<I: InternAs<[Ty<'tcx>], Ty<'tcx>>>(self, iter: I,
2142-
defaulted: bool) -> I::Output {
2143-
iter.intern_with(|ts| self.mk_ty(TyTuple(self.intern_type_list(ts), defaulted)))
2141+
pub fn mk_tup<I: InternAs<[Ty<'tcx>], Ty<'tcx>>>(self, iter: I) -> I::Output {
2142+
iter.intern_with(|ts| self.mk_ty(TyTuple(self.intern_type_list(ts))))
21442143
}
21452144

21462145
pub fn mk_nil(self) -> Ty<'tcx> {
2147-
self.intern_tup(&[], false)
2148-
}
2149-
2150-
pub fn mk_diverging_default(self) -> Ty<'tcx> {
2151-
if self.features().never_type {
2152-
self.types.never
2153-
} else {
2154-
self.intern_tup(&[], true)
2155-
}
2146+
self.intern_tup(&[])
21562147
}
21572148

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

src/librustc/ty/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
177177
match self.sty {
178178
ty::TyBool | ty::TyChar | ty::TyInt(_) |
179179
ty::TyUint(_) | ty::TyFloat(_) | ty::TyStr | ty::TyNever => self.to_string(),
180-
ty::TyTuple(ref tys, _) if tys.is_empty() => self.to_string(),
180+
ty::TyTuple(ref tys) if tys.is_empty() => self.to_string(),
181181

182182
ty::TyAdt(def, _) => format!("{} `{}`", def.descr(), tcx.item_path_str(def.did)),
183183
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
@@ -97,7 +97,7 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
9797
Some(GeneratorWitnessSimplifiedType(tys.skip_binder().len()))
9898
}
9999
ty::TyNever => Some(NeverSimplifiedType),
100-
ty::TyTuple(ref tys, _) => {
100+
ty::TyTuple(ref tys) => {
101101
Some(TupleSimplifiedType(tys.len()))
102102
}
103103
ty::TyFnPtr(ref f) => {

src/librustc/ty/flags.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ impl FlagComputation {
179179
self.add_ty(m.ty);
180180
}
181181

182-
&ty::TyTuple(ref ts, is_default) => {
183-
if is_default {
184-
self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX);
185-
}
182+
&ty::TyTuple(ref ts) => {
186183
self.add_tys(&ts[..]);
187184
}
188185

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
@@ -1318,7 +1318,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
13181318
StructKind::AlwaysSized)?
13191319
}
13201320

1321-
ty::TyTuple(tys, _) => {
1321+
ty::TyTuple(tys) => {
13221322
let kind = if tys.len() == 0 {
13231323
StructKind::AlwaysSized
13241324
} else {
@@ -2243,7 +2243,7 @@ impl<'a, 'tcx> TyLayout<'tcx> {
22432243
substs.field_tys(def_id, tcx).nth(i).unwrap()
22442244
}
22452245

2246-
ty::TyTuple(tys, _) => tys[i],
2246+
ty::TyTuple(tys) => tys[i],
22472247

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

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
20462046
vec![ty]
20472047
}
20482048

2049-
TyTuple(ref tys, _) => {
2049+
TyTuple(ref tys) => {
20502050
match tys.last() {
20512051
None => vec![],
20522052
Some(ty) => self.sized_constraint_for_ty(tcx, ty)

src/librustc/ty/relate.rs

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

532-
(&ty::TyTuple(as_, a_defaulted), &ty::TyTuple(bs, b_defaulted)) =>
532+
(&ty::TyTuple(as_), &ty::TyTuple(bs)) =>
533533
{
534534
if as_.len() == bs.len() {
535-
let defaulted = a_defaulted || b_defaulted;
536-
Ok(tcx.mk_tup(as_.iter().zip(bs).map(|(a, b)| relation.relate(a, b)), defaulted)?)
535+
Ok(tcx.mk_tup(as_.iter().zip(bs).map(|(a, b)| relation.relate(a, b)))?)
537536
} else if !(as_.is_empty() || bs.is_empty()) {
538537
Err(TypeError::TupleSize(
539538
expected_found(relation, &as_.len(), &bs.len())))

0 commit comments

Comments
 (0)