diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fc8ca5d07b212..d6840b20c89ac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,6 +50,9 @@ is a bug or not, feel free to file a bug anyway. **If you believe reporting your bug publicly represents a security risk to Rust users, please follow our [instructions for reporting security vulnerabilities](https://www.rust-lang.org/policies/security)**. +If you're using the nightly channel, please check if the bug exists in the +latest toolchain before filing your bug. It might be fixed already. + If you have the chance, before reporting a bug, please [search existing issues](https://github.com/rust-lang/rust/search?q=&type=Issues&utf8=%E2%9C%93), as it's possible that someone else has already reported your error. This doesn't diff --git a/rustfmt.toml b/rustfmt.toml index 73f8cc1ff68c6..2a034845c6e0b 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -6,6 +6,8 @@ merge_derives = false # by default we ignore everything in the repository # tidy only checks files which are not ignored, each entry follows gitignore style ignore = [ + "build", + # tests for now are not formatted, as they are sometimes pretty-printing constrained # (and generally rustfmt can move around comments in UI-testing incompatible ways) "src/test", diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index 1b7dfafbd704c..38df843d258d3 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 ddf89d99621ca..0fd83dad56b1a 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 ObligationForest { 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 9490128e32d6a..51cc091b6c0af 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 c22c00e9154e7..0be73e55e9c1d 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 a16c36d749f0d..827ccb1c85733 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>; + fn write( + &self, + out: &mut dyn Write, + location_table: &LocationTable, + ) -> Result<(), Box>; } impl FactRow for RegionVid { - fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box> { + fn write( + &self, + out: &mut dyn Write, + location_table: &LocationTable, + ) -> Result<(), Box> { 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> { + fn write( + &self, + out: &mut dyn Write, + location_table: &LocationTable, + ) -> Result<(), Box> { 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> { + fn write( + &self, + out: &mut dyn Write, + location_table: &LocationTable, + ) -> Result<(), Box> { 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> { + fn write( + &self, + out: &mut dyn Write, + location_table: &LocationTable, + ) -> Result<(), Box> { 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 2cbda33ad2db1..5dec2c6df99dc 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 1488bfe4d627a..b12ad1e4c15cc 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; @@ -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 0358458c0991d..a09eb42dcfe6a 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) + /// >: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 f8e963192c99f..a612ad9e783f4 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 1a070843cc446..27ab3d6b7abff 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 0000000000000..404d2f7762df4 --- /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() -> i64 { + 3 +} + +fn main() { + template::<::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 0000000000000..2f4b2ed348b9c --- /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() -> i64 { + 3 +} + +fn main() { + template::<: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 0000000000000..8857d2ef30cfc --- /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::<: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 0000000000000..a2b05db035150 --- /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(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 0000000000000..65d1b084a3a7b --- /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(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`.