about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-02-01 23:31:51 +0000
committerbors <bors@rust-lang.org>2020-02-01 23:31:51 +0000
commite5b150edafc0e72cd7f5f3f67a4e8b417d515b01 (patch)
treef29b6c6172ad7b834afac0155d93036c028cfc63 /src
parent13db6501c7273cd1997ce20e15106f362e5613c4 (diff)
parent87bb0c4389b09bfa86780eb014a4a2de95a3840b (diff)
downloadrust-e5b150edafc0e72cd7f5f3f67a4e8b417d515b01.tar.gz
rust-e5b150edafc0e72cd7f5f3f67a4e8b417d515b01.zip
Auto merge of #68752 - JohnTitor:rollup-zz3u4xl, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #68460 (Use BufWriter for emitting MIR)
 - #68681 (Suggest path separator for single-colon typos)
 - #68688 ([docs] remind bug reporters to update nightly)
 - #68704 (Ignore `build` dir formatting)
 - #68727 (Remove a comment about pretty printer in formatting tests)
 - #68736 (Remove `Alloc` in favor of `AllocRef`)
 - #68740 (Do not suggest things named underscore)

Failed merges:

r? @ghost
Diffstat (limited to 'src')
-rw-r--r--src/libcore/alloc.rs7
-rw-r--r--src/librustc_data_structures/obligation_forest/graphviz.rs3
-rw-r--r--src/librustc_incremental/assert_dep_graph.rs4
-rw-r--r--src/librustc_interface/passes.rs4
-rw-r--r--src/librustc_mir/borrow_check/facts.rs34
-rw-r--r--src/librustc_mir/transform/dump_mir.rs2
-rw-r--r--src/librustc_mir/util/liveness.rs5
-rw-r--r--src/librustc_parse/parser/path.rs37
-rw-r--r--src/librustc_resolve/diagnostics.rs5
-rw-r--r--src/test/ui/ifmt.rs6
-rw-r--r--src/test/ui/parser/qualified-path-in-turbofish.fixed19
-rw-r--r--src/test/ui/parser/qualified-path-in-turbofish.rs19
-rw-r--r--src/test/ui/parser/qualified-path-in-turbofish.stderr8
-rw-r--r--src/test/ui/resolve/typo-suggestion-named-underscore.rs14
-rw-r--r--src/test/ui/resolve/typo-suggestion-named-underscore.stderr16
15 files changed, 154 insertions, 29 deletions
diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs
index 1b7dfafbd70..38df843d258 100644
--- a/src/libcore/alloc.rs
+++ b/src/libcore/alloc.rs
@@ -1227,10 +1227,3 @@ pub unsafe trait AllocRef {
         }
     }
 }
-
-// In order to rename `Alloc` to `AllocRef`, some submoduleshas to be updated as well. The CI fails
-// if either of the submodules fails to compile. The submodules have their own CI depending on a
-// specific Rust version, which don't have `AllocRef` yet. This alias is used to make the submodules
-// compile and pass the CI.
-#[unstable(feature = "allocator_api", issue = "32838")]
-pub use self::AllocRef as Alloc;
diff --git a/src/librustc_data_structures/obligation_forest/graphviz.rs b/src/librustc_data_structures/obligation_forest/graphviz.rs
index ddf89d99621..0fd83dad56b 100644
--- a/src/librustc_data_structures/obligation_forest/graphviz.rs
+++ b/src/librustc_data_structures/obligation_forest/graphviz.rs
@@ -2,6 +2,7 @@ use crate::obligation_forest::{ForestObligation, ObligationForest};
 use graphviz as dot;
 use std::env::var_os;
 use std::fs::File;
+use std::io::BufWriter;
 use std::path::Path;
 use std::sync::atomic::AtomicUsize;
 use std::sync::atomic::Ordering;
@@ -31,7 +32,7 @@ impl<O: ForestObligation> ObligationForest<O> {
 
         let file_path = dir.as_ref().join(format!("{:010}_{}.gv", counter, description));
 
-        let mut gv_file = File::create(file_path).unwrap();
+        let mut gv_file = BufWriter::new(File::create(file_path).unwrap());
 
         dot::render(&self, &mut gv_file).unwrap();
     }
diff --git a/src/librustc_incremental/assert_dep_graph.rs b/src/librustc_incremental/assert_dep_graph.rs
index 9490128e32d..51cc091b6c0 100644
--- a/src/librustc_incremental/assert_dep_graph.rs
+++ b/src/librustc_incremental/assert_dep_graph.rs
@@ -49,7 +49,7 @@ use syntax::ast;
 
 use std::env;
 use std::fs::{self, File};
-use std::io::Write;
+use std::io::{BufWriter, Write};
 
 pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
     tcx.dep_graph.with_ignore(|| {
@@ -235,7 +235,7 @@ fn dump_graph(tcx: TyCtxt<'_>) {
     {
         // dump a .txt file with just the edges:
         let txt_path = format!("{}.txt", path);
-        let mut file = File::create(&txt_path).unwrap();
+        let mut file = BufWriter::new(File::create(&txt_path).unwrap());
         for &(ref source, ref target) in &edges {
             write!(file, "{:?} -> {:?}\n", source, target).unwrap();
         }
diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs
index c22c00e9154..0be73e55e9c 100644
--- a/src/librustc_interface/passes.rs
+++ b/src/librustc_interface/passes.rs
@@ -48,7 +48,7 @@ use tempfile::Builder as TempFileBuilder;
 use std::any::Any;
 use std::cell::RefCell;
 use std::ffi::OsString;
-use std::io::{self, Write};
+use std::io::{self, BufWriter, Write};
 use std::path::PathBuf;
 use std::rc::Rc;
 use std::{env, fs, iter, mem};
@@ -574,7 +574,7 @@ fn write_out_deps(
             });
         }
 
-        let mut file = fs::File::create(&deps_filename)?;
+        let mut file = BufWriter::new(fs::File::create(&deps_filename)?);
         for path in out_filenames {
             writeln!(file, "{}: {}\n", path.display(), files.join(" "))?;
         }
diff --git a/src/librustc_mir/borrow_check/facts.rs b/src/librustc_mir/borrow_check/facts.rs
index a16c36d749f..827ccb1c857 100644
--- a/src/librustc_mir/borrow_check/facts.rs
+++ b/src/librustc_mir/borrow_check/facts.rs
@@ -8,7 +8,7 @@ use rustc_index::vec::Idx;
 use std::error::Error;
 use std::fmt::Debug;
 use std::fs::{self, File};
-use std::io::Write;
+use std::io::{BufWriter, Write};
 use std::path::Path;
 
 #[derive(Copy, Clone, Debug)]
@@ -117,7 +117,7 @@ impl<'w> FactWriter<'w> {
         T: FactRow,
     {
         let file = &self.dir.join(file_name);
-        let mut file = File::create(file)?;
+        let mut file = BufWriter::new(File::create(file)?);
         for row in rows {
             row.write(&mut file, self.location_table)?;
         }
@@ -126,11 +126,19 @@ impl<'w> FactWriter<'w> {
 }
 
 trait FactRow {
-    fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>>;
+    fn write(
+        &self,
+        out: &mut dyn Write,
+        location_table: &LocationTable,
+    ) -> Result<(), Box<dyn Error>>;
 }
 
 impl FactRow for RegionVid {
-    fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
+    fn write(
+        &self,
+        out: &mut dyn Write,
+        location_table: &LocationTable,
+    ) -> Result<(), Box<dyn Error>> {
         write_row(out, location_table, &[self])
     }
 }
@@ -140,7 +148,11 @@ where
     A: FactCell,
     B: FactCell,
 {
-    fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
+    fn write(
+        &self,
+        out: &mut dyn Write,
+        location_table: &LocationTable,
+    ) -> Result<(), Box<dyn Error>> {
         write_row(out, location_table, &[&self.0, &self.1])
     }
 }
@@ -151,7 +163,11 @@ where
     B: FactCell,
     C: FactCell,
 {
-    fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
+    fn write(
+        &self,
+        out: &mut dyn Write,
+        location_table: &LocationTable,
+    ) -> Result<(), Box<dyn Error>> {
         write_row(out, location_table, &[&self.0, &self.1, &self.2])
     }
 }
@@ -163,7 +179,11 @@ where
     C: FactCell,
     D: FactCell,
 {
-    fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
+    fn write(
+        &self,
+        out: &mut dyn Write,
+        location_table: &LocationTable,
+    ) -> Result<(), Box<dyn Error>> {
         write_row(out, location_table, &[&self.0, &self.1, &self.2, &self.3])
     }
 }
diff --git a/src/librustc_mir/transform/dump_mir.rs b/src/librustc_mir/transform/dump_mir.rs
index 2cbda33ad2d..5dec2c6df99 100644
--- a/src/librustc_mir/transform/dump_mir.rs
+++ b/src/librustc_mir/transform/dump_mir.rs
@@ -61,7 +61,7 @@ pub fn on_mir_pass<'tcx>(
 
 pub fn emit_mir(tcx: TyCtxt<'_>, outputs: &OutputFilenames) -> io::Result<()> {
     let path = outputs.path(OutputType::Mir);
-    let mut f = File::create(&path)?;
+    let mut f = io::BufWriter::new(File::create(&path)?);
     mir_util::write_mir_pretty(tcx, None, &mut f)?;
     Ok(())
 }
diff --git a/src/librustc_mir/util/liveness.rs b/src/librustc_mir/util/liveness.rs
index 1488bfe4d62..b12ad1e4c15 100644
--- a/src/librustc_mir/util/liveness.rs
+++ b/src/librustc_mir/util/liveness.rs
@@ -36,7 +36,7 @@ use rustc_data_structures::work_queue::WorkQueue;
 use rustc_index::bit_set::BitSet;
 use rustc_index::vec::{Idx, IndexVec};
 use std::fs;
-use std::io::{self, Write};
+use std::io::{self, BufWriter, Write};
 use std::path::{Path, PathBuf};
 
 pub type LiveVarSet = BitSet<Local>;
@@ -288,7 +288,8 @@ fn dump_matched_mir_node<'tcx>(
     let item_id = tcx.hir().as_local_hir_id(source.def_id()).unwrap();
     let file_name = format!("rustc.node{}{}-liveness.mir", item_id, pass_name);
     file_path.push(&file_name);
-    let _ = fs::File::create(&file_path).and_then(|mut file| {
+    let _ = fs::File::create(&file_path).and_then(|file| {
+        let mut file = BufWriter::new(file);
         writeln!(file, "// MIR local liveness analysis for `{}`", node_path)?;
         writeln!(file, "// source = {:?}", source)?;
         writeln!(file, "// pass_name = {}", pass_name)?;
diff --git a/src/librustc_parse/parser/path.rs b/src/librustc_parse/parser/path.rs
index 0358458c099..a09eb42dcfe 100644
--- a/src/librustc_parse/parser/path.rs
+++ b/src/librustc_parse/parser/path.rs
@@ -71,7 +71,9 @@ impl<'a> Parser<'a> {
             debug!("parse_qpath: (decrement) count={:?}", self.unmatched_angle_bracket_count);
         }
 
-        self.expect(&token::ModSep)?;
+        if !self.recover_colon_before_qpath_proj() {
+            self.expect(&token::ModSep)?;
+        }
 
         let qself = QSelf { ty, path_span, position: path.segments.len() };
         self.parse_path_segments(&mut path.segments, style)?;
@@ -79,6 +81,39 @@ impl<'a> Parser<'a> {
         Ok((qself, Path { segments: path.segments, span: lo.to(self.prev_span) }))
     }
 
+    /// Recover from an invalid single colon, when the user likely meant a qualified path.
+    /// We avoid emitting this if not followed by an identifier, as our assumption that the user
+    /// intended this to be a qualified path may not be correct.
+    ///
+    /// ```ignore (diagnostics)
+    /// <Bar as Baz<T>>:Qux
+    ///                ^ help: use double colon
+    /// ```
+    fn recover_colon_before_qpath_proj(&mut self) -> bool {
+        if self.token.kind != token::Colon
+            || self.look_ahead(1, |t| !t.is_ident() || t.is_reserved_ident())
+        {
+            return false;
+        }
+
+        self.bump(); // colon
+
+        self.diagnostic()
+            .struct_span_err(
+                self.prev_span,
+                "found single colon before projection in qualified path",
+            )
+            .span_suggestion(
+                self.prev_span,
+                "use double colon",
+                "::".to_string(),
+                Applicability::MachineApplicable,
+            )
+            .emit();
+
+        true
+    }
+
     /// Parses simple paths.
     ///
     /// `path = [::] segment+`
diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs
index f8e963192c9..a612ad9e783 100644
--- a/src/librustc_resolve/diagnostics.rs
+++ b/src/librustc_resolve/diagnostics.rs
@@ -769,6 +769,11 @@ impl<'a> Resolver<'a> {
         span: Span,
     ) -> bool {
         if let Some(suggestion) = suggestion {
+            // We shouldn't suggest underscore.
+            if suggestion.candidate == kw::Underscore {
+                return false;
+            }
+
             let msg = format!(
                 "{} {} with a similar name exists",
                 suggestion.res.article(),
diff --git a/src/test/ui/ifmt.rs b/src/test/ui/ifmt.rs
index 1a070843cc4..27ab3d6b7ab 100644
--- a/src/test/ui/ifmt.rs
+++ b/src/test/ui/ifmt.rs
@@ -99,7 +99,6 @@ pub fn main() {
     let a: &dyn fmt::Debug = &1;
     t!(format!("{:?}", a), "1");
 
-
     // Formatting strings and their arguments
     t!(format!("{}", "a"), "a");
     t!(format!("{:4}", "a"), "a   ");
@@ -187,10 +186,6 @@ pub fn main() {
     // Ergonomic format_args!
     t!(format!("{0:x} {0:X}", 15), "f F");
     t!(format!("{0:x} {0:X} {}", 15), "f F 15");
-    // NOTE: For now the longer test cases must not be followed immediately by
-    // >1 empty lines, or the pretty printer will break. Since no one wants to
-    // touch the current pretty printer (#751), we have no choice but to work
-    // around it. Some of the following test cases are also affected.
     t!(format!("{:x}{0:X}{a:x}{:X}{1:x}{a:X}", 13, 14, a=15), "dDfEeF");
     t!(format!("{a:x} {a:X}", a=15), "f F");
 
@@ -201,7 +196,6 @@ pub fn main() {
     t!(format!("{a:.*} {0} {:.*}", 4, 3, "efgh", a="abcdef"), "abcd 4 efg");
     t!(format!("{:.a$} {a} {a:#x}", "aaaaaa", a=2), "aa 2 0x2");
 
-
     // Test that pointers don't get truncated.
     {
         let val = usize::MAX;
diff --git a/src/test/ui/parser/qualified-path-in-turbofish.fixed b/src/test/ui/parser/qualified-path-in-turbofish.fixed
new file mode 100644
index 00000000000..404d2f7762d
--- /dev/null
+++ b/src/test/ui/parser/qualified-path-in-turbofish.fixed
@@ -0,0 +1,19 @@
+// run-rustfix
+trait T {
+    type Ty;
+}
+
+struct Impl;
+
+impl T for Impl {
+    type Ty = u32;
+}
+
+fn template<T>() -> i64 {
+    3
+}
+
+fn main() {
+    template::<<Impl as T>::Ty>();
+    //~^ ERROR found single colon before projection in qualified path
+}
diff --git a/src/test/ui/parser/qualified-path-in-turbofish.rs b/src/test/ui/parser/qualified-path-in-turbofish.rs
new file mode 100644
index 00000000000..2f4b2ed348b
--- /dev/null
+++ b/src/test/ui/parser/qualified-path-in-turbofish.rs
@@ -0,0 +1,19 @@
+// run-rustfix
+trait T {
+    type Ty;
+}
+
+struct Impl;
+
+impl T for Impl {
+    type Ty = u32;
+}
+
+fn template<T>() -> i64 {
+    3
+}
+
+fn main() {
+    template::<<Impl as T>:Ty>();
+    //~^ ERROR found single colon before projection in qualified path
+}
diff --git a/src/test/ui/parser/qualified-path-in-turbofish.stderr b/src/test/ui/parser/qualified-path-in-turbofish.stderr
new file mode 100644
index 00000000000..8857d2ef30c
--- /dev/null
+++ b/src/test/ui/parser/qualified-path-in-turbofish.stderr
@@ -0,0 +1,8 @@
+error: found single colon before projection in qualified path
+  --> $DIR/qualified-path-in-turbofish.rs:17:27
+   |
+LL |     template::<<Impl as T>:Ty>();
+   |                           ^ help: use double colon: `::`
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/resolve/typo-suggestion-named-underscore.rs b/src/test/ui/resolve/typo-suggestion-named-underscore.rs
new file mode 100644
index 00000000000..a2b05db0351
--- /dev/null
+++ b/src/test/ui/resolve/typo-suggestion-named-underscore.rs
@@ -0,0 +1,14 @@
+const _: () = ();
+
+fn main() {
+    a // Shouldn't suggest underscore
+    //~^ ERROR: cannot find value `a` in this scope
+}
+
+trait Unknown {}
+
+#[allow(unused_imports)]
+use Unknown as _;
+
+fn foo<T: A>(x: T) {} // Shouldn't suggest underscore
+//~^ ERROR: cannot find trait `A` in this scope
diff --git a/src/test/ui/resolve/typo-suggestion-named-underscore.stderr b/src/test/ui/resolve/typo-suggestion-named-underscore.stderr
new file mode 100644
index 00000000000..65d1b084a3a
--- /dev/null
+++ b/src/test/ui/resolve/typo-suggestion-named-underscore.stderr
@@ -0,0 +1,16 @@
+error[E0425]: cannot find value `a` in this scope
+  --> $DIR/typo-suggestion-named-underscore.rs:4:5
+   |
+LL |     a // Shouldn't suggest underscore
+   |     ^ not found in this scope
+
+error[E0405]: cannot find trait `A` in this scope
+  --> $DIR/typo-suggestion-named-underscore.rs:13:11
+   |
+LL | fn foo<T: A>(x: T) {} // Shouldn't suggest underscore
+   |           ^ not found in this scope
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0405, E0425.
+For more information about an error, try `rustc --explain E0405`.