Skip to content

Commit e5b150e

Browse files
committed
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
2 parents 13db650 + 87bb0c4 commit e5b150e

File tree

17 files changed

+159
-29
lines changed

17 files changed

+159
-29
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ is a bug or not, feel free to file a bug anyway.
5050
**If you believe reporting your bug publicly represents a security risk to Rust users,
5151
please follow our [instructions for reporting security vulnerabilities](https://www.rust-lang.org/policies/security)**.
5252

53+
If you're using the nightly channel, please check if the bug exists in the
54+
latest toolchain before filing your bug. It might be fixed already.
55+
5356
If you have the chance, before reporting a bug, please [search existing
5457
issues](https://github.com/rust-lang/rust/search?q=&type=Issues&utf8=%E2%9C%93),
5558
as it's possible that someone else has already reported your error. This doesn't

rustfmt.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ merge_derives = false
66
# by default we ignore everything in the repository
77
# tidy only checks files which are not ignored, each entry follows gitignore style
88
ignore = [
9+
"build",
10+
911
# tests for now are not formatted, as they are sometimes pretty-printing constrained
1012
# (and generally rustfmt can move around comments in UI-testing incompatible ways)
1113
"src/test",

src/libcore/alloc.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,10 +1227,3 @@ pub unsafe trait AllocRef {
12271227
}
12281228
}
12291229
}
1230-
1231-
// In order to rename `Alloc` to `AllocRef`, some submoduleshas to be updated as well. The CI fails
1232-
// if either of the submodules fails to compile. The submodules have their own CI depending on a
1233-
// specific Rust version, which don't have `AllocRef` yet. This alias is used to make the submodules
1234-
// compile and pass the CI.
1235-
#[unstable(feature = "allocator_api", issue = "32838")]
1236-
pub use self::AllocRef as Alloc;

src/librustc_data_structures/obligation_forest/graphviz.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::obligation_forest::{ForestObligation, ObligationForest};
22
use graphviz as dot;
33
use std::env::var_os;
44
use std::fs::File;
5+
use std::io::BufWriter;
56
use std::path::Path;
67
use std::sync::atomic::AtomicUsize;
78
use std::sync::atomic::Ordering;
@@ -31,7 +32,7 @@ impl<O: ForestObligation> ObligationForest<O> {
3132

3233
let file_path = dir.as_ref().join(format!("{:010}_{}.gv", counter, description));
3334

34-
let mut gv_file = File::create(file_path).unwrap();
35+
let mut gv_file = BufWriter::new(File::create(file_path).unwrap());
3536

3637
dot::render(&self, &mut gv_file).unwrap();
3738
}

src/librustc_incremental/assert_dep_graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use syntax::ast;
4949

5050
use std::env;
5151
use std::fs::{self, File};
52-
use std::io::Write;
52+
use std::io::{BufWriter, Write};
5353

5454
pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
5555
tcx.dep_graph.with_ignore(|| {
@@ -235,7 +235,7 @@ fn dump_graph(tcx: TyCtxt<'_>) {
235235
{
236236
// dump a .txt file with just the edges:
237237
let txt_path = format!("{}.txt", path);
238-
let mut file = File::create(&txt_path).unwrap();
238+
let mut file = BufWriter::new(File::create(&txt_path).unwrap());
239239
for &(ref source, ref target) in &edges {
240240
write!(file, "{:?} -> {:?}\n", source, target).unwrap();
241241
}

src/librustc_interface/passes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use tempfile::Builder as TempFileBuilder;
4848
use std::any::Any;
4949
use std::cell::RefCell;
5050
use std::ffi::OsString;
51-
use std::io::{self, Write};
51+
use std::io::{self, BufWriter, Write};
5252
use std::path::PathBuf;
5353
use std::rc::Rc;
5454
use std::{env, fs, iter, mem};
@@ -574,7 +574,7 @@ fn write_out_deps(
574574
});
575575
}
576576

577-
let mut file = fs::File::create(&deps_filename)?;
577+
let mut file = BufWriter::new(fs::File::create(&deps_filename)?);
578578
for path in out_filenames {
579579
writeln!(file, "{}: {}\n", path.display(), files.join(" "))?;
580580
}

src/librustc_mir/borrow_check/facts.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_index::vec::Idx;
88
use std::error::Error;
99
use std::fmt::Debug;
1010
use std::fs::{self, File};
11-
use std::io::Write;
11+
use std::io::{BufWriter, Write};
1212
use std::path::Path;
1313

1414
#[derive(Copy, Clone, Debug)]
@@ -117,7 +117,7 @@ impl<'w> FactWriter<'w> {
117117
T: FactRow,
118118
{
119119
let file = &self.dir.join(file_name);
120-
let mut file = File::create(file)?;
120+
let mut file = BufWriter::new(File::create(file)?);
121121
for row in rows {
122122
row.write(&mut file, self.location_table)?;
123123
}
@@ -126,11 +126,19 @@ impl<'w> FactWriter<'w> {
126126
}
127127

128128
trait FactRow {
129-
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>>;
129+
fn write(
130+
&self,
131+
out: &mut dyn Write,
132+
location_table: &LocationTable,
133+
) -> Result<(), Box<dyn Error>>;
130134
}
131135

132136
impl FactRow for RegionVid {
133-
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
137+
fn write(
138+
&self,
139+
out: &mut dyn Write,
140+
location_table: &LocationTable,
141+
) -> Result<(), Box<dyn Error>> {
134142
write_row(out, location_table, &[self])
135143
}
136144
}
@@ -140,7 +148,11 @@ where
140148
A: FactCell,
141149
B: FactCell,
142150
{
143-
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
151+
fn write(
152+
&self,
153+
out: &mut dyn Write,
154+
location_table: &LocationTable,
155+
) -> Result<(), Box<dyn Error>> {
144156
write_row(out, location_table, &[&self.0, &self.1])
145157
}
146158
}
@@ -151,7 +163,11 @@ where
151163
B: FactCell,
152164
C: FactCell,
153165
{
154-
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
166+
fn write(
167+
&self,
168+
out: &mut dyn Write,
169+
location_table: &LocationTable,
170+
) -> Result<(), Box<dyn Error>> {
155171
write_row(out, location_table, &[&self.0, &self.1, &self.2])
156172
}
157173
}
@@ -163,7 +179,11 @@ where
163179
C: FactCell,
164180
D: FactCell,
165181
{
166-
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
182+
fn write(
183+
&self,
184+
out: &mut dyn Write,
185+
location_table: &LocationTable,
186+
) -> Result<(), Box<dyn Error>> {
167187
write_row(out, location_table, &[&self.0, &self.1, &self.2, &self.3])
168188
}
169189
}

src/librustc_mir/transform/dump_mir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn on_mir_pass<'tcx>(
6161

6262
pub fn emit_mir(tcx: TyCtxt<'_>, outputs: &OutputFilenames) -> io::Result<()> {
6363
let path = outputs.path(OutputType::Mir);
64-
let mut f = File::create(&path)?;
64+
let mut f = io::BufWriter::new(File::create(&path)?);
6565
mir_util::write_mir_pretty(tcx, None, &mut f)?;
6666
Ok(())
6767
}

src/librustc_mir/util/liveness.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_data_structures::work_queue::WorkQueue;
3636
use rustc_index::bit_set::BitSet;
3737
use rustc_index::vec::{Idx, IndexVec};
3838
use std::fs;
39-
use std::io::{self, Write};
39+
use std::io::{self, BufWriter, Write};
4040
use std::path::{Path, PathBuf};
4141

4242
pub type LiveVarSet = BitSet<Local>;
@@ -288,7 +288,8 @@ fn dump_matched_mir_node<'tcx>(
288288
let item_id = tcx.hir().as_local_hir_id(source.def_id()).unwrap();
289289
let file_name = format!("rustc.node{}{}-liveness.mir", item_id, pass_name);
290290
file_path.push(&file_name);
291-
let _ = fs::File::create(&file_path).and_then(|mut file| {
291+
let _ = fs::File::create(&file_path).and_then(|file| {
292+
let mut file = BufWriter::new(file);
292293
writeln!(file, "// MIR local liveness analysis for `{}`", node_path)?;
293294
writeln!(file, "// source = {:?}", source)?;
294295
writeln!(file, "// pass_name = {}", pass_name)?;

src/librustc_parse/parser/path.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,49 @@ impl<'a> Parser<'a> {
7171
debug!("parse_qpath: (decrement) count={:?}", self.unmatched_angle_bracket_count);
7272
}
7373

74-
self.expect(&token::ModSep)?;
74+
if !self.recover_colon_before_qpath_proj() {
75+
self.expect(&token::ModSep)?;
76+
}
7577

7678
let qself = QSelf { ty, path_span, position: path.segments.len() };
7779
self.parse_path_segments(&mut path.segments, style)?;
7880

7981
Ok((qself, Path { segments: path.segments, span: lo.to(self.prev_span) }))
8082
}
8183

84+
/// Recover from an invalid single colon, when the user likely meant a qualified path.
85+
/// We avoid emitting this if not followed by an identifier, as our assumption that the user
86+
/// intended this to be a qualified path may not be correct.
87+
///
88+
/// ```ignore (diagnostics)
89+
/// <Bar as Baz<T>>:Qux
90+
/// ^ help: use double colon
91+
/// ```
92+
fn recover_colon_before_qpath_proj(&mut self) -> bool {
93+
if self.token.kind != token::Colon
94+
|| self.look_ahead(1, |t| !t.is_ident() || t.is_reserved_ident())
95+
{
96+
return false;
97+
}
98+
99+
self.bump(); // colon
100+
101+
self.diagnostic()
102+
.struct_span_err(
103+
self.prev_span,
104+
"found single colon before projection in qualified path",
105+
)
106+
.span_suggestion(
107+
self.prev_span,
108+
"use double colon",
109+
"::".to_string(),
110+
Applicability::MachineApplicable,
111+
)
112+
.emit();
113+
114+
true
115+
}
116+
82117
/// Parses simple paths.
83118
///
84119
/// `path = [::] segment+`

0 commit comments

Comments
 (0)