Skip to content

Commit

Permalink
Merge pull request #32291 from alexcrichton/beta-next
Browse files Browse the repository at this point in the history
Merge in beta-accepted into beta
  • Loading branch information
brson committed Mar 22, 2016
2 parents facbfdd + 48313e8 commit 2879d94
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 63 deletions.
2 changes: 1 addition & 1 deletion mk/main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CFG_RELEASE_NUM=1.8.0
# An optional number to put after the label, e.g. '.2' -> '-beta.2'
# NB Make sure it starts with a dot to conform to semver pre-release
# versions (section 9)
CFG_PRERELEASE_VERSION=.1
CFG_PRERELEASE_VERSION=.2

# Append a version-dependent hash to each library, so we can install different
# versions in the same place
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,7 @@ fn is_refutable<A, F>(cx: &MatchCheckCtxt, pat: &Pat, refutable: F) -> Option<A>
{
let pats = Matrix(vec!(vec!(pat)));
match is_useful(cx, &pats, &[DUMMY_WILD_PAT], ConstructWitness) {
UsefulWithWitness(pats) => {
assert_eq!(pats.len(), 1);
Some(refutable(&pats[0]))
},
UsefulWithWitness(pats) => Some(refutable(&pats[0])),
NotUseful => None,
Useful => unreachable!()
}
Expand Down
15 changes: 13 additions & 2 deletions src/librustc/middle/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,11 +1107,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
.map(|method| resolve_ty(method.ty)))
}

pub fn errors_since_creation(&self) -> bool {
self.tcx.sess.err_count() - self.err_count_on_creation != 0
}

pub fn node_type(&self, id: ast::NodeId) -> Ty<'tcx> {
match self.tables.borrow().node_types.get(&id) {
Some(&t) => t,
// FIXME
None if self.tcx.sess.err_count() - self.err_count_on_creation != 0 =>
None if self.errors_since_creation() =>
self.tcx.types.err,
None => {
self.tcx.sess.bug(
Expand All @@ -1134,7 +1138,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
free_regions: &FreeRegionMap,
subject_node_id: ast::NodeId) {
let errors = self.region_vars.resolve_regions(free_regions, subject_node_id);
self.report_region_errors(&errors); // see error_reporting.rs
if !self.errors_since_creation() {
// As a heuristic, just skip reporting region errors
// altogether if other errors have been reported while
// this infcx was in use. This is totally hokey but
// otherwise we have a hard time separating legit region
// errors from silly ones.
self.report_region_errors(&errors); // see error_reporting.rs
}
}

pub fn ty_to_string(&self, t: Ty<'tcx>) -> String {
Expand Down
26 changes: 17 additions & 9 deletions src/librustc_trans/trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,17 @@ pub fn addr_of(ccx: &CrateContext,
gv
}

fn const_deref_ptr(cx: &CrateContext, v: ValueRef) -> ValueRef {
/// Deref a constant pointer
fn load_const(cx: &CrateContext, v: ValueRef, t: Ty) -> ValueRef {
let v = match cx.const_unsized().borrow().get(&v) {
Some(&v) => v,
None => v
};
unsafe {
llvm::LLVMGetInitializer(v)
let d = unsafe { llvm::LLVMGetInitializer(v) };
if t.is_bool() {
unsafe { llvm::LLVMConstTrunc(d, Type::i1(cx).to_ref()) }
} else {
d
}
}

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

let (te2, _) = try!(const_expr(cx, &e2, param_substs, fn_args, trueconst));
let (te2, ty2) = try!(const_expr(cx, &e2, param_substs, fn_args, trueconst));
debug!("const_expr_unadjusted: te2={}, ty={:?}",
cx.tn().val_to_string(te2),
ty2);

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

Expand Down Expand Up @@ -671,13 +678,13 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
};
let (arr, len) = match bt.sty {
ty::TyArray(_, u) => (bv, C_uint(cx, u)),
ty::TySlice(_) | ty::TyStr => {
ty::TySlice(..) | ty::TyStr => {
let e1 = const_get_elt(cx, bv, &[0]);
(const_deref_ptr(cx, e1), const_get_elt(cx, bv, &[1]))
(load_const(cx, e1, bt), const_get_elt(cx, bv, &[1]))
},
ty::TyRef(_, mt) => match mt.ty.sty {
ty::TyArray(_, u) => {
(const_deref_ptr(cx, bv), C_uint(cx, u))
(load_const(cx, bv, mt.ty), C_uint(cx, u))
},
_ => cx.sess().span_bug(base.span,
&format!("index-expr base must be a vector \
Expand Down Expand Up @@ -891,7 +898,8 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
expr::trans_def_fn_unadjusted(cx, e, def, param_substs).val
}
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
const_deref_ptr(cx, try!(get_const_val(cx, def_id, e, param_substs)))
load_const(cx, try!(get_const_val(cx, def_id, e, param_substs)),
ety)
}
Def::Variant(enum_did, variant_did) => {
let vinfo = cx.tcx().lookup_adt_def(enum_did).variant_with_id(variant_did);
Expand Down
76 changes: 29 additions & 47 deletions src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
check_pat_enum(pcx, pat, path, subpats.as_ref().map(|v| &v[..]), expected, true);
}
PatKind::Path(ref path) => {
check_pat_enum(pcx, pat, path, None, expected, false);
check_pat_enum(pcx, pat, path, Some(&[]), expected, false);
}
PatKind::QPath(ref qself, ref path) => {
let self_ty = fcx.to_ty(&qself.ty);
Expand Down Expand Up @@ -599,12 +599,12 @@ fn bad_struct_kind_err(sess: &Session, pat: &hir::Pat, path: &hir::Path, lint: b
}
}

pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
pat: &hir::Pat,
path: &hir::Path,
subpats: Option<&'tcx [P<hir::Pat>]>,
expected: Ty<'tcx>,
is_tuple_struct_pat: bool)
fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
pat: &hir::Pat,
path: &hir::Path,
subpats: Option<&'tcx [P<hir::Pat>]>,
expected: Ty<'tcx>,
is_tuple_struct_pat: bool)
{
// Typecheck the path.
let fcx = pcx.fcx;
Expand Down Expand Up @@ -687,59 +687,41 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
demand::eqtype(fcx, pat.span, expected, pat_ty);

let real_path_ty = fcx.node_ty(pat.id);
let (arg_tys, kind_name): (Vec<_>, &'static str) = match real_path_ty.sty {
let (kind_name, variant, expected_substs) = match real_path_ty.sty {
ty::TyEnum(enum_def, expected_substs) => {
let variant = enum_def.variant_of_def(def);
if variant.kind() == ty::VariantKind::Struct {
report_bad_struct_kind(false);
return;
}
if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple {
// Matching unit variants with tuple variant patterns (`UnitVariant(..)`)
// is allowed for backward compatibility.
let is_special_case = variant.kind() == ty::VariantKind::Unit;
report_bad_struct_kind(is_special_case);
if !is_special_case {
return
}
}
(variant.fields
.iter()
.map(|f| fcx.instantiate_type_scheme(pat.span,
expected_substs,
&f.unsubst_ty()))
.collect(),
"variant")
("variant", variant, expected_substs)
}
ty::TyStruct(struct_def, expected_substs) => {
let variant = struct_def.struct_variant();
if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple {
// Matching unit structs with tuple variant patterns (`UnitVariant(..)`)
// is allowed for backward compatibility.
let is_special_case = variant.kind() == ty::VariantKind::Unit;
report_bad_struct_kind(is_special_case);
return;
}
(variant.fields
.iter()
.map(|f| fcx.instantiate_type_scheme(pat.span,
expected_substs,
&f.unsubst_ty()))
.collect(),
"struct")
("struct", variant, expected_substs)
}
_ => {
report_bad_struct_kind(false);
return;
}
};

match (is_tuple_struct_pat, variant.kind()) {
(true, ty::VariantKind::Unit) => {
// Matching unit structs with tuple variant patterns (`UnitVariant(..)`)
// is allowed for backward compatibility.
report_bad_struct_kind(true);
}
(_, ty::VariantKind::Struct) => {
report_bad_struct_kind(false);
return
}
_ => {}
}

if let Some(subpats) = subpats {
if subpats.len() == arg_tys.len() {
for (subpat, arg_ty) in subpats.iter().zip(arg_tys) {
check_pat(pcx, &subpat, arg_ty);
if subpats.len() == variant.fields.len() {
for (subpat, field) in subpats.iter().zip(&variant.fields) {
let field_ty = fcx.field_ty(subpat.span, field, expected_substs);
check_pat(pcx, &subpat, field_ty);
}
} else if arg_tys.is_empty() {
} else if variant.fields.is_empty() {
span_err!(tcx.sess, pat.span, E0024,
"this pattern has {} field{}, but the corresponding {} has no fields",
subpats.len(), if subpats.len() == 1 {""} else {"s"}, kind_name);
Expand All @@ -752,7 +734,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
"this pattern has {} field{}, but the corresponding {} has {} field{}",
subpats.len(), if subpats.len() == 1 {""} else {"s"},
kind_name,
arg_tys.len(), if arg_tys.len() == 1 {""} else {"s"});
variant.fields.len(), if variant.fields.len() == 1 {""} else {"s"});

for pat in subpats {
check_pat(pcx, &pat, tcx.types.err);
Expand Down
27 changes: 27 additions & 0 deletions src/test/compile-fail/issue-30580.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test that we do not see uninformative region-related errors
// when we get some basic type-checking failure. See #30580.

pub struct Foo { a: u32 }
pub struct Pass<'a, 'tcx: 'a>(&'a mut &'a (), &'a &'tcx ());

impl<'a, 'tcx> Pass<'a, 'tcx>
{
pub fn tcx(&self) -> &'a &'tcx () { self.1 }
fn lol(&mut self, b: &Foo)
{
b.c; //~ ERROR no field with that name was found
self.tcx();
}
}

fn main() {}
20 changes: 20 additions & 0 deletions src/test/compile-fail/issue-31561.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

enum Thing {
Foo(u8),
Bar,
Baz
}

fn main() {
let Thing::Foo(y) = Thing::Foo(1);
//~^ ERROR refutable pattern in local binding: `Bar` not covered
}
29 changes: 29 additions & 0 deletions src/test/compile-fail/issue-32004.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

enum Foo {
Bar(i32),
Baz
}

struct S;

fn main() {
match Foo::Baz {
Foo::Bar => {}
//~^ ERROR this pattern has 0 fields, but the corresponding variant
_ => {}
}

match S {
S(()) => {}
//~^ ERROR this pattern has 1 field, but the corresponding struct
}
}
19 changes: 19 additions & 0 deletions src/test/run-pass/issue-30891.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

const ERROR_CONST: bool = true;

fn get() -> bool {
false || ERROR_CONST
}

pub fn main() {
assert_eq!(get(), true);
}

0 comments on commit 2879d94

Please sign in to comment.