Skip to content

Commit 2879d94

Browse files
committed
Merge pull request #32291 from alexcrichton/beta-next
Merge in beta-accepted into beta
2 parents facbfdd + 48313e8 commit 2879d94

File tree

9 files changed

+156
-63
lines changed

9 files changed

+156
-63
lines changed

mk/main.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CFG_RELEASE_NUM=1.8.0
1818
# An optional number to put after the label, e.g. '.2' -> '-beta.2'
1919
# NB Make sure it starts with a dot to conform to semver pre-release
2020
# versions (section 9)
21-
CFG_PRERELEASE_VERSION=.1
21+
CFG_PRERELEASE_VERSION=.2
2222

2323
# Append a version-dependent hash to each library, so we can install different
2424
# versions in the same place

src/librustc/middle/check_match.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1047,10 +1047,7 @@ fn is_refutable<A, F>(cx: &MatchCheckCtxt, pat: &Pat, refutable: F) -> Option<A>
10471047
{
10481048
let pats = Matrix(vec!(vec!(pat)));
10491049
match is_useful(cx, &pats, &[DUMMY_WILD_PAT], ConstructWitness) {
1050-
UsefulWithWitness(pats) => {
1051-
assert_eq!(pats.len(), 1);
1052-
Some(refutable(&pats[0]))
1053-
},
1050+
UsefulWithWitness(pats) => Some(refutable(&pats[0])),
10541051
NotUseful => None,
10551052
Useful => unreachable!()
10561053
}

src/librustc/middle/infer/mod.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1107,11 +1107,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11071107
.map(|method| resolve_ty(method.ty)))
11081108
}
11091109

1110+
pub fn errors_since_creation(&self) -> bool {
1111+
self.tcx.sess.err_count() - self.err_count_on_creation != 0
1112+
}
1113+
11101114
pub fn node_type(&self, id: ast::NodeId) -> Ty<'tcx> {
11111115
match self.tables.borrow().node_types.get(&id) {
11121116
Some(&t) => t,
11131117
// FIXME
1114-
None if self.tcx.sess.err_count() - self.err_count_on_creation != 0 =>
1118+
None if self.errors_since_creation() =>
11151119
self.tcx.types.err,
11161120
None => {
11171121
self.tcx.sess.bug(
@@ -1134,7 +1138,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11341138
free_regions: &FreeRegionMap,
11351139
subject_node_id: ast::NodeId) {
11361140
let errors = self.region_vars.resolve_regions(free_regions, subject_node_id);
1137-
self.report_region_errors(&errors); // see error_reporting.rs
1141+
if !self.errors_since_creation() {
1142+
// As a heuristic, just skip reporting region errors
1143+
// altogether if other errors have been reported while
1144+
// this infcx was in use. This is totally hokey but
1145+
// otherwise we have a hard time separating legit region
1146+
// errors from silly ones.
1147+
self.report_region_errors(&errors); // see error_reporting.rs
1148+
}
11381149
}
11391150

11401151
pub fn ty_to_string(&self, t: Ty<'tcx>) -> String {

src/librustc_trans/trans/consts.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,17 @@ pub fn addr_of(ccx: &CrateContext,
161161
gv
162162
}
163163

164-
fn const_deref_ptr(cx: &CrateContext, v: ValueRef) -> ValueRef {
164+
/// Deref a constant pointer
165+
fn load_const(cx: &CrateContext, v: ValueRef, t: Ty) -> ValueRef {
165166
let v = match cx.const_unsized().borrow().get(&v) {
166167
Some(&v) => v,
167168
None => v
168169
};
169-
unsafe {
170-
llvm::LLVMGetInitializer(v)
170+
let d = unsafe { llvm::LLVMGetInitializer(v) };
171+
if t.is_bool() {
172+
unsafe { llvm::LLVMConstTrunc(d, Type::i1(cx).to_ref()) }
173+
} else {
174+
d
171175
}
172176
}
173177

@@ -178,7 +182,7 @@ fn const_deref<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
178182
match ty.builtin_deref(true, ty::NoPreference) {
179183
Some(mt) => {
180184
if type_is_sized(cx.tcx(), mt.ty) {
181-
(const_deref_ptr(cx, v), mt.ty)
185+
(load_const(cx, v, mt.ty), mt.ty)
182186
} else {
183187
// Derefing a fat pointer does not change the representation,
184188
// just the type to the unsized contents.
@@ -588,7 +592,10 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
588592
let is_float = ty.is_fp();
589593
let signed = ty.is_signed();
590594

591-
let (te2, _) = try!(const_expr(cx, &e2, param_substs, fn_args, trueconst));
595+
let (te2, ty2) = try!(const_expr(cx, &e2, param_substs, fn_args, trueconst));
596+
debug!("const_expr_unadjusted: te2={}, ty={:?}",
597+
cx.tn().val_to_string(te2),
598+
ty2);
592599

593600
try!(check_binary_expr_validity(cx, e, ty, te1, te2, trueconst));
594601

@@ -671,13 +678,13 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
671678
};
672679
let (arr, len) = match bt.sty {
673680
ty::TyArray(_, u) => (bv, C_uint(cx, u)),
674-
ty::TySlice(_) | ty::TyStr => {
681+
ty::TySlice(..) | ty::TyStr => {
675682
let e1 = const_get_elt(cx, bv, &[0]);
676-
(const_deref_ptr(cx, e1), const_get_elt(cx, bv, &[1]))
683+
(load_const(cx, e1, bt), const_get_elt(cx, bv, &[1]))
677684
},
678685
ty::TyRef(_, mt) => match mt.ty.sty {
679686
ty::TyArray(_, u) => {
680-
(const_deref_ptr(cx, bv), C_uint(cx, u))
687+
(load_const(cx, bv, mt.ty), C_uint(cx, u))
681688
},
682689
_ => cx.sess().span_bug(base.span,
683690
&format!("index-expr base must be a vector \
@@ -891,7 +898,8 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
891898
expr::trans_def_fn_unadjusted(cx, e, def, param_substs).val
892899
}
893900
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
894-
const_deref_ptr(cx, try!(get_const_val(cx, def_id, e, param_substs)))
901+
load_const(cx, try!(get_const_val(cx, def_id, e, param_substs)),
902+
ety)
895903
}
896904
Def::Variant(enum_did, variant_did) => {
897905
let vinfo = cx.tcx().lookup_adt_def(enum_did).variant_with_id(variant_did);

src/librustc_typeck/check/_match.rs

+29-47
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
204204
check_pat_enum(pcx, pat, path, subpats.as_ref().map(|v| &v[..]), expected, true);
205205
}
206206
PatKind::Path(ref path) => {
207-
check_pat_enum(pcx, pat, path, None, expected, false);
207+
check_pat_enum(pcx, pat, path, Some(&[]), expected, false);
208208
}
209209
PatKind::QPath(ref qself, ref path) => {
210210
let self_ty = fcx.to_ty(&qself.ty);
@@ -599,12 +599,12 @@ fn bad_struct_kind_err(sess: &Session, pat: &hir::Pat, path: &hir::Path, lint: b
599599
}
600600
}
601601

602-
pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
603-
pat: &hir::Pat,
604-
path: &hir::Path,
605-
subpats: Option<&'tcx [P<hir::Pat>]>,
606-
expected: Ty<'tcx>,
607-
is_tuple_struct_pat: bool)
602+
fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
603+
pat: &hir::Pat,
604+
path: &hir::Path,
605+
subpats: Option<&'tcx [P<hir::Pat>]>,
606+
expected: Ty<'tcx>,
607+
is_tuple_struct_pat: bool)
608608
{
609609
// Typecheck the path.
610610
let fcx = pcx.fcx;
@@ -687,59 +687,41 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
687687
demand::eqtype(fcx, pat.span, expected, pat_ty);
688688

689689
let real_path_ty = fcx.node_ty(pat.id);
690-
let (arg_tys, kind_name): (Vec<_>, &'static str) = match real_path_ty.sty {
690+
let (kind_name, variant, expected_substs) = match real_path_ty.sty {
691691
ty::TyEnum(enum_def, expected_substs) => {
692692
let variant = enum_def.variant_of_def(def);
693-
if variant.kind() == ty::VariantKind::Struct {
694-
report_bad_struct_kind(false);
695-
return;
696-
}
697-
if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple {
698-
// Matching unit variants with tuple variant patterns (`UnitVariant(..)`)
699-
// is allowed for backward compatibility.
700-
let is_special_case = variant.kind() == ty::VariantKind::Unit;
701-
report_bad_struct_kind(is_special_case);
702-
if !is_special_case {
703-
return
704-
}
705-
}
706-
(variant.fields
707-
.iter()
708-
.map(|f| fcx.instantiate_type_scheme(pat.span,
709-
expected_substs,
710-
&f.unsubst_ty()))
711-
.collect(),
712-
"variant")
693+
("variant", variant, expected_substs)
713694
}
714695
ty::TyStruct(struct_def, expected_substs) => {
715696
let variant = struct_def.struct_variant();
716-
if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple {
717-
// Matching unit structs with tuple variant patterns (`UnitVariant(..)`)
718-
// is allowed for backward compatibility.
719-
let is_special_case = variant.kind() == ty::VariantKind::Unit;
720-
report_bad_struct_kind(is_special_case);
721-
return;
722-
}
723-
(variant.fields
724-
.iter()
725-
.map(|f| fcx.instantiate_type_scheme(pat.span,
726-
expected_substs,
727-
&f.unsubst_ty()))
728-
.collect(),
729-
"struct")
697+
("struct", variant, expected_substs)
730698
}
731699
_ => {
732700
report_bad_struct_kind(false);
733701
return;
734702
}
735703
};
736704

705+
match (is_tuple_struct_pat, variant.kind()) {
706+
(true, ty::VariantKind::Unit) => {
707+
// Matching unit structs with tuple variant patterns (`UnitVariant(..)`)
708+
// is allowed for backward compatibility.
709+
report_bad_struct_kind(true);
710+
}
711+
(_, ty::VariantKind::Struct) => {
712+
report_bad_struct_kind(false);
713+
return
714+
}
715+
_ => {}
716+
}
717+
737718
if let Some(subpats) = subpats {
738-
if subpats.len() == arg_tys.len() {
739-
for (subpat, arg_ty) in subpats.iter().zip(arg_tys) {
740-
check_pat(pcx, &subpat, arg_ty);
719+
if subpats.len() == variant.fields.len() {
720+
for (subpat, field) in subpats.iter().zip(&variant.fields) {
721+
let field_ty = fcx.field_ty(subpat.span, field, expected_substs);
722+
check_pat(pcx, &subpat, field_ty);
741723
}
742-
} else if arg_tys.is_empty() {
724+
} else if variant.fields.is_empty() {
743725
span_err!(tcx.sess, pat.span, E0024,
744726
"this pattern has {} field{}, but the corresponding {} has no fields",
745727
subpats.len(), if subpats.len() == 1 {""} else {"s"}, kind_name);
@@ -752,7 +734,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
752734
"this pattern has {} field{}, but the corresponding {} has {} field{}",
753735
subpats.len(), if subpats.len() == 1 {""} else {"s"},
754736
kind_name,
755-
arg_tys.len(), if arg_tys.len() == 1 {""} else {"s"});
737+
variant.fields.len(), if variant.fields.len() == 1 {""} else {"s"});
756738

757739
for pat in subpats {
758740
check_pat(pcx, &pat, tcx.types.err);

src/test/compile-fail/issue-30580.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2012 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+
// Test that we do not see uninformative region-related errors
12+
// when we get some basic type-checking failure. See #30580.
13+
14+
pub struct Foo { a: u32 }
15+
pub struct Pass<'a, 'tcx: 'a>(&'a mut &'a (), &'a &'tcx ());
16+
17+
impl<'a, 'tcx> Pass<'a, 'tcx>
18+
{
19+
pub fn tcx(&self) -> &'a &'tcx () { self.1 }
20+
fn lol(&mut self, b: &Foo)
21+
{
22+
b.c; //~ ERROR no field with that name was found
23+
self.tcx();
24+
}
25+
}
26+
27+
fn main() {}

src/test/compile-fail/issue-31561.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 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+
enum Thing {
12+
Foo(u8),
13+
Bar,
14+
Baz
15+
}
16+
17+
fn main() {
18+
let Thing::Foo(y) = Thing::Foo(1);
19+
//~^ ERROR refutable pattern in local binding: `Bar` not covered
20+
}

src/test/compile-fail/issue-32004.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2016 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+
enum Foo {
12+
Bar(i32),
13+
Baz
14+
}
15+
16+
struct S;
17+
18+
fn main() {
19+
match Foo::Baz {
20+
Foo::Bar => {}
21+
//~^ ERROR this pattern has 0 fields, but the corresponding variant
22+
_ => {}
23+
}
24+
25+
match S {
26+
S(()) => {}
27+
//~^ ERROR this pattern has 1 field, but the corresponding struct
28+
}
29+
}

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

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 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+
const ERROR_CONST: bool = true;
12+
13+
fn get() -> bool {
14+
false || ERROR_CONST
15+
}
16+
17+
pub fn main() {
18+
assert_eq!(get(), true);
19+
}

0 commit comments

Comments
 (0)