From 59279b5abbb8c7780f44c82bb8a8bdb0fbacbecd Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 9 Mar 2016 16:53:19 -0500 Subject: [PATCH 1/5] Do not report errors from regionck if other errors were already reported during the lifetime of this inferencer. Fixes #30580. --- src/librustc/middle/infer/mod.rs | 15 +++++++++++++-- src/test/compile-fail/issue-30580.rs | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/issue-30580.rs diff --git a/src/librustc/middle/infer/mod.rs b/src/librustc/middle/infer/mod.rs index b9a5b32b71d82..dc0076e59f8c4 100644 --- a/src/librustc/middle/infer/mod.rs +++ b/src/librustc/middle/infer/mod.rs @@ -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( @@ -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 { diff --git a/src/test/compile-fail/issue-30580.rs b/src/test/compile-fail/issue-30580.rs new file mode 100644 index 0000000000000..908a2d47401e5 --- /dev/null +++ b/src/test/compile-fail/issue-30580.rs @@ -0,0 +1,24 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +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() {} From 0ddc17d5bb6757dc49136c0de3168d9cdb00f6e3 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 10 Mar 2016 05:21:00 -0500 Subject: [PATCH 2/5] Add comment explaining purpose of test --- src/test/compile-fail/issue-30580.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/compile-fail/issue-30580.rs b/src/test/compile-fail/issue-30580.rs index 908a2d47401e5..88d4aef6d9ddc 100644 --- a/src/test/compile-fail/issue-30580.rs +++ b/src/test/compile-fail/issue-30580.rs @@ -8,6 +8,9 @@ // 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 ()); From b308ed06846460150eb2a5f67c89ff4e63e7e665 Mon Sep 17 00:00:00 2001 From: srinivasreddy Date: Fri, 11 Mar 2016 00:05:53 +0530 Subject: [PATCH 3/5] Removed integer suffixes in libsyntax crate --- src/libsyntax/ast.rs | 6 +++--- src/libsyntax/print/pp.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a8bea2da83349..f7621b0131ad4 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -927,7 +927,7 @@ pub enum ExprKind { Binary(BinOp, P, P), /// A unary operation (For example: `!x`, `*x`) Unary(UnOp, P), - /// A literal (For example: `1u8`, `"foo"`) + /// A literal (For example: `1`, `"foo"`) Lit(P), /// A cast (`foo as f64`) Cast(P, P), @@ -1016,7 +1016,7 @@ pub enum ExprKind { /// An array literal constructed from one repeated element. /// - /// For example, `[1u8; 5]`. The first expression is the element + /// For example, `[1; 5]`. The first expression is the element /// to be repeated; the second is the number of times to repeat it. Repeat(P, P), @@ -1288,7 +1288,7 @@ pub enum LitKind { Byte(u8), /// A character literal (`'a'`) Char(char), - /// An integer literal (`1u8`) + /// An integer literal (`1`) Int(u64, LitIntType), /// A float literal (`1f64` or `1E10f64`) Float(InternedString, FloatTy), diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index cbbd5289a5a2d..c1d922ea665b1 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -168,8 +168,8 @@ pub fn mk_printer<'a>(out: Box, linewidth: usize) -> Printer<'a> { let n: usize = 3 * linewidth; debug!("mk_printer {}", linewidth); let token = vec![Token::Eof; n]; - let size = vec![0_isize; n]; - let scan_stack = vec![0_usize; n]; + let size = vec![0; n]; + let scan_stack = vec![0; n]; Printer { out: out, buf_len: n, From 8e3ccd9c9bce2830581596d496e130cb43c179d0 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 12 Mar 2016 16:01:34 +0530 Subject: [PATCH 4/5] Don't allow values for codegen-units less than 1 (fixes #32191) --- src/librustc/session/config.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 679da4abf5f9f..dba0bcf19be13 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1095,6 +1095,10 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { } } + if cg.codegen_units < 1 { + early_error(error_format, "Value for codegen units must be a positive nonzero integer"); + } + let cg = cg; let sysroot_opt = matches.opt_str("sysroot").map(|m| PathBuf::from(&m)); From 56ab2a1cdefec1ddee00ee99d3fb710906714d1b Mon Sep 17 00:00:00 2001 From: Andrew Cantino Date: Sat, 12 Mar 2016 12:35:34 -0800 Subject: [PATCH 5/5] Fix minor typos in doc.rust-lang.org/book --- src/doc/book/getting-started.md | 2 +- src/doc/book/if.md | 2 +- src/doc/book/strings.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/book/getting-started.md b/src/doc/book/getting-started.md index 31ee385a928d6..042c9710645df 100644 --- a/src/doc/book/getting-started.md +++ b/src/doc/book/getting-started.md @@ -513,7 +513,7 @@ Cargo checks to see if any of your project’s files have been modified, and onl rebuilds your project if they’ve changed since the last time you built it. With simple projects, Cargo doesn't bring a whole lot over just using `rustc`, -but it will become useful in future. This is especially true when you start +but it will become useful in the future. This is especially true when you start using crates; these are synonymous with a ‘library’ or ‘package’ in other programming languages. For complex projects composed of multiple crates, it’s much easier to let Cargo coordinate the build. Using Cargo, you can run `cargo diff --git a/src/doc/book/if.md b/src/doc/book/if.md index a532dabf8d12d..52d0dd888efef 100644 --- a/src/doc/book/if.md +++ b/src/doc/book/if.md @@ -4,7 +4,7 @@ Rust’s take on `if` is not particularly complex, but it’s much more like the `if` you’ll find in a dynamically typed language than in a more traditional systems language. So let’s talk about it, to make sure you grasp the nuances. -`if` is a specific form of a more general concept, the ‘branch’. The name comes +`if` is a specific form of a more general concept, the ‘branch’, whose name comes from a branch in a tree: a decision point, where depending on a choice, multiple paths can be taken. diff --git a/src/doc/book/strings.md b/src/doc/book/strings.md index 68c7235975e8c..5ed1f3de06249 100644 --- a/src/doc/book/strings.md +++ b/src/doc/book/strings.md @@ -44,7 +44,7 @@ let s = "foo\ assert_eq!("foobar", s); ``` -Rust has more than only `&str`s though. A `String`, is a heap-allocated string. +Rust has more than only `&str`s though. A `String` is a heap-allocated string. This string is growable, and is also guaranteed to be UTF-8. `String`s are commonly created by converting from a string slice using the `to_string` method. @@ -89,7 +89,7 @@ Viewing a `String` as a `&str` is cheap, but converting the `&str` to a ## Indexing -Because strings are valid UTF-8, strings do not support indexing: +Because strings are valid UTF-8, they do not support indexing: ```rust,ignore let s = "hello";