Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #68752

Merged
merged 18 commits into from
Feb 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3c91bdc
Suggest path separator for single-colon typos
bobrippling Jan 29, 2020
2a79ed0
[docs] remind bug reporters to update nightly
jbr Jan 31, 2020
08e85aa
Ignore `build` dir formatting
jonas-schievink Jan 31, 2020
482c761
Use BufWriter
sinkuu Jan 22, 2020
cad0cfd
Remove a comment about pretty printer in formatting tests
KamilaBorowska Feb 1, 2020
8bbaeb7
Remove `Alloc` in favor of `AllocRef`
TimDiekmann Feb 1, 2020
88d64a0
Simplify span usage and avoid .eat()
bobrippling Feb 1, 2020
45fb723
Move colon-check to recover_colon_before_qpath_proj()
bobrippling Feb 1, 2020
991d2ee
Improve wording and docs for qualified path recovery
bobrippling Feb 1, 2020
07ee472
Avoid qualified path recovery when not followed by identifier
bobrippling Feb 1, 2020
726568b
Do not suggest things named underscore
JohnTitor Feb 1, 2020
bf68a05
Rollup merge of #68460 - sinkuu:emit_mir_buffered, r=Mark-Simulacrum
JohnTitor Feb 1, 2020
b18b269
Rollup merge of #68681 - bobrippling:fix-matched-angle-brackets, r=Ce…
JohnTitor Feb 1, 2020
518ed67
Rollup merge of #68688 - jbr:remind-bug-reporters-to-update-if-on-nig…
JohnTitor Feb 1, 2020
44dc4c2
Rollup merge of #68704 - jonas-schievink:ignore-build-fmt, r=Mark-Sim…
JohnTitor Feb 1, 2020
1529126
Rollup merge of #68727 - xfix:remove-comment-about-pretty-printer-in-…
JohnTitor Feb 1, 2020
c7332ab
Rollup merge of #68736 - TimDiekmann:remove-alloc, r=Amanieu
JohnTitor Feb 1, 2020
87bb0c4
Rollup merge of #68740 - JohnTitor:do-not-sugg-underscore, r=Centril
JohnTitor Feb 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 0 additions & 7 deletions src/libcore/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 2 additions & 1 deletion src/librustc_data_structures/obligation_forest/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_incremental/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(" "))?;
}
Expand Down
34 changes: 27 additions & 7 deletions src/librustc_mir/borrow_check/facts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)?;
}
Expand All @@ -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])
}
}
Expand All @@ -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])
}
}
Expand All @@ -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])
}
}
Expand All @@ -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])
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/dump_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
5 changes: 3 additions & 2 deletions src/librustc_mir/util/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -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)?;
Expand Down
37 changes: 36 additions & 1 deletion src/librustc_parse/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,49 @@ 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)?;

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+`
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 0 additions & 6 deletions src/test/ui/ifmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ");
Expand Down Expand Up @@ -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");

Expand All @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/parser/qualified-path-in-turbofish.fixed
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions src/test/ui/parser/qualified-path-in-turbofish.rs
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions src/test/ui/parser/qualified-path-in-turbofish.stderr
Original file line number Diff line number Diff line change
@@ -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

14 changes: 14 additions & 0 deletions src/test/ui/resolve/typo-suggestion-named-underscore.rs
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions src/test/ui/resolve/typo-suggestion-named-underscore.stderr
Original file line number Diff line number Diff line change
@@ -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`.