Skip to content

Commit e9ac440

Browse files
committed
Auto merge of #29383 - petrochenkov:empstr, r=pnkfelix
Fixes #28692 Fixes #28992 Fixes some other similar issues (see the tests) [breaking-change], needs crater run (cc @brson or @alexcrichton ) The pattern with parens `UnitVariant(..)` for unit variants seems to be popular in rustc (see the second commit), but mostly used by one person (@nikomatsakis), according to git blame. If it causes breakage on crates.io I'll add an exceptional case for it.
2 parents bac2b13 + af96402 commit e9ac440

33 files changed

+192
-127
lines changed

src/librustc/middle/intrinsicck.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IntrinsicCheckingVisitor<'a, 'tcx> {
225225
intravisit::walk_fn(self, fk, fd, b, s);
226226
self.param_envs.pop();
227227
}
228-
FnKind::Closure(..) => {
228+
FnKind::Closure => {
229229
intravisit::walk_fn(self, fk, fd, b, s);
230230
}
231231
}
232-
233232
}
234233

235234
fn visit_expr(&mut self, expr: &hir::Expr) {

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ impl<'tcx> cmt_<'tcx> {
14241424
NonAliasable
14251425
}
14261426

1427-
Categorization::StaticItem(..) => {
1427+
Categorization::StaticItem => {
14281428
if self.mutbl.is_mutable() {
14291429
FreelyAliasable(AliasableStaticMut)
14301430
} else {

src/librustc/middle/resolve_lifetime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
184184
this.walk_fn(fk, fd, b, s)
185185
})
186186
}
187-
FnKind::Closure(..) => {
187+
FnKind::Closure => {
188188
self.walk_fn(fk, fd, b, s)
189189
}
190190
}
@@ -479,7 +479,7 @@ impl<'a> LifetimeContext<'a> {
479479
self.visit_generics(&sig.generics);
480480
self.visit_explicit_self(&sig.explicit_self);
481481
}
482-
FnKind::Closure(..) => {
482+
FnKind::Closure => {
483483
intravisit::walk_fn_decl(self, fd);
484484
}
485485
}

src/librustc/middle/traits/coherence.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ fn ty_is_local_constructor<'tcx>(tcx: &ty::ctxt<'tcx>,
300300
ty::TyInt(..) |
301301
ty::TyUint(..) |
302302
ty::TyFloat(..) |
303-
ty::TyStr(..) |
303+
ty::TyStr |
304304
ty::TyBareFn(..) |
305305
ty::TyArray(..) |
306306
ty::TySlice(..) |

src/librustc/middle/traits/select.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15631563
}
15641564

15651565
match other {
1566-
&ObjectCandidate(..) |
1566+
&ObjectCandidate |
15671567
&ParamCandidate(_) | &ProjectionCandidate => match victim {
15681568
&DefaultImplCandidate(..) => {
15691569
self.tcx().sess.bug(
@@ -1572,16 +1572,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15721572
}
15731573
&ImplCandidate(..) |
15741574
&ClosureCandidate(..) |
1575-
&FnPointerCandidate(..) |
1576-
&BuiltinObjectCandidate(..) |
1577-
&BuiltinUnsizeCandidate(..) |
1575+
&FnPointerCandidate |
1576+
&BuiltinObjectCandidate |
1577+
&BuiltinUnsizeCandidate |
15781578
&DefaultImplObjectCandidate(..) |
15791579
&BuiltinCandidate(..) => {
15801580
// We have a where-clause so don't go around looking
15811581
// for impls.
15821582
true
15831583
}
1584-
&ObjectCandidate(..) |
1584+
&ObjectCandidate |
15851585
&ProjectionCandidate => {
15861586
// Arbitrarily give param candidates priority
15871587
// over projection and object candidates.

src/librustc/middle/ty/outlives.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,21 @@ fn compute_components<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
188188
// the type and then visits the types that are lexically
189189
// contained within. (The comments refer to relevant rules
190190
// from RFC1214.)
191-
ty::TyBool(..) | // OutlivesScalar
192-
ty::TyChar(..) | // OutlivesScalar
191+
ty::TyBool | // OutlivesScalar
192+
ty::TyChar | // OutlivesScalar
193193
ty::TyInt(..) | // OutlivesScalar
194194
ty::TyUint(..) | // OutlivesScalar
195195
ty::TyFloat(..) | // OutlivesScalar
196196
ty::TyEnum(..) | // OutlivesNominalType
197197
ty::TyStruct(..) | // OutlivesNominalType
198198
ty::TyBox(..) | // OutlivesNominalType (ish)
199-
ty::TyStr(..) | // OutlivesScalar (ish)
199+
ty::TyStr | // OutlivesScalar (ish)
200200
ty::TyArray(..) | // ...
201201
ty::TySlice(..) | // ...
202202
ty::TyRawPtr(..) | // ...
203203
ty::TyRef(..) | // OutlivesReference
204204
ty::TyTuple(..) | // ...
205-
ty::TyError(..) => {
205+
ty::TyError => {
206206
push_region_constraints(out, ty.regions());
207207
for subty in ty.walk_shallow() {
208208
compute_components(infcx, subty, out);

src/librustc_borrowck/borrowck/check_loans.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -540,14 +540,14 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
540540
ol, old_loan_msg)
541541
}
542542

543-
euv::OverloadedOperator(..) |
544-
euv::AddrOf(..) |
545-
euv::AutoRef(..) |
546-
euv::AutoUnsafe(..) |
547-
euv::ClosureInvocation(..) |
548-
euv::ForLoop(..) |
549-
euv::RefBinding(..) |
550-
euv::MatchDiscriminant(..) => {
543+
euv::OverloadedOperator |
544+
euv::AddrOf |
545+
euv::AutoRef |
546+
euv::AutoUnsafe |
547+
euv::ClosureInvocation |
548+
euv::ForLoop |
549+
euv::RefBinding |
550+
euv::MatchDiscriminant => {
551551
format!("previous borrow of `{}` occurs here{}",
552552
ol, old_loan_msg)
553553
}

src/librustc_borrowck/borrowck/gather_loans/restrictions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
101101
self.extend(result, &cmt, LpInterior(i.cleaned()))
102102
}
103103

104-
Categorization::StaticItem(..) => {
104+
Categorization::StaticItem => {
105105
Safe
106106
}
107107

src/librustc_borrowck/borrowck/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
942942
"consider changing this closure to take self by mutable reference");
943943
}
944944
}
945-
mc::AliasableStatic(..) |
946-
mc::AliasableStaticMut(..) => {
945+
mc::AliasableStatic |
946+
mc::AliasableStaticMut => {
947947
span_err!(
948948
self.tcx.sess, span, E0388,
949949
"{} in a static location", prefix);
@@ -998,7 +998,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
998998
pub fn note_and_explain_bckerr(&self, err: BckError<'tcx>) {
999999
let code = err.code;
10001000
match code {
1001-
err_mutbl(..) => {
1001+
err_mutbl => {
10021002
match err.cmt.note {
10031003
mc::NoteClosureEnv(upvar_id) | mc::NoteUpvarRef(upvar_id) => {
10041004
// If this is an `Fn` closure, it simply can't mutate upvars.

src/librustc_mir/build/matches/simplify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
6666
candidate: &mut Candidate<'pat, 'tcx>)
6767
-> Result<BasicBlock, MatchPair<'pat, 'tcx>> {
6868
match *match_pair.pattern.kind {
69-
PatternKind::Wild(..) => {
69+
PatternKind::Wild => {
7070
// nothing left to do
7171
Ok(block)
7272
}

src/librustc_mir/hair/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
178178
}
179179
ty::TyEnum(adt, substs) => {
180180
match cx.tcx.def_map.borrow()[&self.id].full_def() {
181-
def::DefVariant(enum_id, variant_id, true) => {
181+
def::DefVariant(enum_id, variant_id, _) => {
182182
debug_assert!(adt.did == enum_id);
183183
let index = adt.variant_index_with_id(variant_id);
184184
let field_refs = field_refs(&adt.variants[index], fields);

src/librustc_resolve/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> {
619619
self.visit_explicit_self(&sig.explicit_self);
620620
MethodRibKind
621621
}
622-
FnKind::Closure(..) => ClosureRibKind(node_id),
622+
FnKind::Closure => ClosureRibKind(node_id),
623623
};
624624
self.resolve_function(rib_kind, declaration, block);
625625
}

src/librustc_trans/trans/type_of.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub fn sizing_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Typ
247247
}
248248
}
249249

250-
ty::TyProjection(..) | ty::TyInfer(..) | ty::TyParam(..) | ty::TyError(..) => {
250+
ty::TyProjection(..) | ty::TyInfer(..) | ty::TyParam(..) | ty::TyError => {
251251
cx.sess().bug(&format!("fictitious type {:?} in sizing_type_of()",
252252
t))
253253
}
@@ -451,7 +451,7 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
451451
ty::TyInfer(..) => cx.sess().bug("type_of with TyInfer"),
452452
ty::TyProjection(..) => cx.sess().bug("type_of with TyProjection"),
453453
ty::TyParam(..) => cx.sess().bug("type_of with ty_param"),
454-
ty::TyError(..) => cx.sess().bug("type_of with TyError"),
454+
ty::TyError => cx.sess().bug("type_of with TyError"),
455455
};
456456

457457
debug!("--> mapped t={:?} to llty={}",

src/librustc_typeck/check/_match.rs

+61-23
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use check::{check_expr_with_lvalue_pref};
2121
use check::{instantiate_path, resolve_ty_and_def_ufcs, structurally_resolved_type};
2222
use require_same_types;
2323
use util::nodemap::FnvHashMap;
24+
use session::Session;
2425

2526
use std::cmp;
2627
use std::collections::hash_map::Entry::{Occupied, Vacant};
@@ -136,6 +137,12 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
136137
}
137138
hir::PatEnum(..) | hir::PatIdent(..)
138139
if pat_is_resolved_const(&tcx.def_map.borrow(), pat) => {
140+
if let hir::PatEnum(ref path, ref subpats) = pat.node {
141+
if !(subpats.is_some() && subpats.as_ref().unwrap().is_empty()) {
142+
bad_struct_kind_err(tcx.sess, pat.span, path, false);
143+
return;
144+
}
145+
}
139146
let const_did = tcx.def_map.borrow().get(&pat.id).unwrap().def_id();
140147
let const_scheme = tcx.lookup_item_type(const_did);
141148
assert!(const_scheme.generics.is_empty());
@@ -192,11 +199,12 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
192199
}
193200
hir::PatIdent(_, ref path, _) => {
194201
let path = hir_util::ident_to_path(path.span, path.node);
195-
check_pat_enum(pcx, pat, &path, Some(&[]), expected);
202+
check_pat_enum(pcx, pat, &path, Some(&[]), expected, false);
196203
}
197204
hir::PatEnum(ref path, ref subpats) => {
198205
let subpats = subpats.as_ref().map(|v| &v[..]);
199-
check_pat_enum(pcx, pat, path, subpats, expected);
206+
let is_tuple_struct_pat = !(subpats.is_some() && subpats.unwrap().is_empty());
207+
check_pat_enum(pcx, pat, path, subpats, expected, is_tuple_struct_pat);
200208
}
201209
hir::PatQPath(ref qself, ref path) => {
202210
let self_ty = fcx.to_ty(&qself.ty);
@@ -572,11 +580,19 @@ pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx hir::Pat,
572580
fcx.write_substs(pat.id, ty::ItemSubsts { substs: item_substs.clone() });
573581
}
574582

583+
// This function exists due to the warning "diagnostic code E0164 already used"
584+
fn bad_struct_kind_err(sess: &Session, span: Span, path: &hir::Path, is_warning: bool) {
585+
let name = pprust::path_to_string(path);
586+
span_err_or_warn!(is_warning, sess, span, E0164,
587+
"`{}` does not name a tuple variant or a tuple struct", name);
588+
}
589+
575590
pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
576591
pat: &hir::Pat,
577592
path: &hir::Path,
578593
subpats: Option<&'tcx [P<hir::Pat>]>,
579-
expected: Ty<'tcx>)
594+
expected: Ty<'tcx>,
595+
is_tuple_struct_pat: bool)
580596
{
581597
// Typecheck the path.
582598
let fcx = pcx.fcx;
@@ -618,25 +634,52 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
618634
path_scheme, &ctor_predicates,
619635
opt_ty, def, pat.span, pat.id);
620636

637+
let report_bad_struct_kind = |is_warning| {
638+
bad_struct_kind_err(tcx.sess, pat.span, path, is_warning);
639+
fcx.write_error(pat.id);
640+
641+
if let Some(subpats) = subpats {
642+
for pat in subpats {
643+
check_pat(pcx, &**pat, tcx.types.err);
644+
}
645+
}
646+
};
647+
621648
// If we didn't have a fully resolved path to start with, we had an
622649
// associated const, and we should quit now, since the rest of this
623650
// function uses checks specific to structs and enums.
624651
if path_res.depth != 0 {
625-
let pat_ty = fcx.node_ty(pat.id);
626-
demand::suptype(fcx, pat.span, expected, pat_ty);
652+
if is_tuple_struct_pat {
653+
report_bad_struct_kind(false);
654+
} else {
655+
let pat_ty = fcx.node_ty(pat.id);
656+
demand::suptype(fcx, pat.span, expected, pat_ty);
657+
}
627658
return;
628659
}
629660

630661
let pat_ty = fcx.node_ty(pat.id);
631662
demand::eqtype(fcx, pat.span, expected, pat_ty);
632663

633-
634664
let real_path_ty = fcx.node_ty(pat.id);
635665
let (arg_tys, kind_name): (Vec<_>, &'static str) = match real_path_ty.sty {
636666
ty::TyEnum(enum_def, expected_substs)
637667
if def == def::DefVariant(enum_def.did, def.def_id(), false) =>
638668
{
639669
let variant = enum_def.variant_of_def(def);
670+
if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple {
671+
// Matching unit variants with tuple variant patterns (`UnitVariant(..)`)
672+
// is allowed for backward compatibility.
673+
let is_special_case = variant.kind() == ty::VariantKind::Unit;
674+
report_bad_struct_kind(is_special_case);
675+
if !is_special_case {
676+
return
677+
} else {
678+
span_note!(tcx.sess, pat.span,
679+
"this warning will become a HARD ERROR in a future release. \
680+
See RFC 218 for details.");
681+
}
682+
}
640683
(variant.fields
641684
.iter()
642685
.map(|f| fcx.instantiate_type_scheme(pat.span,
@@ -646,26 +689,21 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
646689
"variant")
647690
}
648691
ty::TyStruct(struct_def, expected_substs) => {
649-
(struct_def.struct_variant()
650-
.fields
651-
.iter()
652-
.map(|f| fcx.instantiate_type_scheme(pat.span,
653-
expected_substs,
654-
&f.unsubst_ty()))
655-
.collect(),
692+
let variant = struct_def.struct_variant();
693+
if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple {
694+
report_bad_struct_kind(false);
695+
return;
696+
}
697+
(variant.fields
698+
.iter()
699+
.map(|f| fcx.instantiate_type_scheme(pat.span,
700+
expected_substs,
701+
&f.unsubst_ty()))
702+
.collect(),
656703
"struct")
657704
}
658705
_ => {
659-
let name = pprust::path_to_string(path);
660-
span_err!(tcx.sess, pat.span, E0164,
661-
"`{}` does not name a non-struct variant or a tuple struct", name);
662-
fcx.write_error(pat.id);
663-
664-
if let Some(subpats) = subpats {
665-
for pat in subpats {
666-
check_pat(pcx, &**pat, tcx.types.err);
667-
}
668-
}
706+
report_bad_struct_kind(false);
669707
return;
670708
}
671709
};

src/librustc_typeck/check/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
10521052
(impl_def_id, substs, ref_obligations)
10531053
}
10541054

1055-
ObjectCandidate(..) |
1055+
ObjectCandidate |
10561056
TraitCandidate |
10571057
WhereClauseCandidate(..) => {
10581058
// These have no additional conditions to check.

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14461446
-> Option<(ty::AdtDef<'tcx>, ty::VariantDef<'tcx>)>
14471447
{
14481448
let (adt, variant) = match def {
1449-
def::DefVariant(enum_id, variant_id, true) => {
1449+
def::DefVariant(enum_id, variant_id, _) => {
14501450
let adt = self.tcx().lookup_adt_def(enum_id);
14511451
(adt, adt.variant_with_id(variant_id))
14521452
}

src/librustc_typeck/coherence/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn get_base_type_def_id<'a, 'tcx>(inference_context: &InferCtxt<'a, 'tcx>,
6969
}
7070

7171
TyBool | TyChar | TyInt(..) | TyUint(..) | TyFloat(..) |
72-
TyStr(..) | TyArray(..) | TySlice(..) | TyBareFn(..) | TyTuple(..) |
72+
TyStr | TyArray(..) | TySlice(..) | TyBareFn(..) | TyTuple(..) |
7373
TyParam(..) | TyError |
7474
TyRawPtr(_) | TyRef(_, _) | TyProjection(..) => {
7575
None

src/librustdoc/clean/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ impl Clean<Option<Lifetime>> for ty::Region {
774774
ty::ReScope(..) |
775775
ty::ReVar(..) |
776776
ty::ReSkolemized(..) |
777-
ty::ReEmpty(..) => None
777+
ty::ReEmpty => None
778778
}
779779
}
780780
}
@@ -1607,7 +1607,7 @@ impl Clean<Type> for hir::Ty {
16071607
TyPolyTraitRef(ref bounds) => {
16081608
PolyTraitRef(bounds.clean(cx))
16091609
},
1610-
TyInfer(..) => {
1610+
TyInfer => {
16111611
Infer
16121612
},
16131613
TyTypeof(..) => {

0 commit comments

Comments
 (0)