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

+3
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

+2
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

-7
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

+2-1
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

+2-2
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

+2-2
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

+27-7
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

+1-1
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

+3-2
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

+36-1
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+`

src/librustc_resolve/diagnostics.rs

+5
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,11 @@ impl<'a> Resolver<'a> {
769769
span: Span,
770770
) -> bool {
771771
if let Some(suggestion) = suggestion {
772+
// We shouldn't suggest underscore.
773+
if suggestion.candidate == kw::Underscore {
774+
return false;
775+
}
776+
772777
let msg = format!(
773778
"{} {} with a similar name exists",
774779
suggestion.res.article(),

src/test/ui/ifmt.rs

-6
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ pub fn main() {
9999
let a: &dyn fmt::Debug = &1;
100100
t!(format!("{:?}", a), "1");
101101

102-
103102
// Formatting strings and their arguments
104103
t!(format!("{}", "a"), "a");
105104
t!(format!("{:4}", "a"), "a ");
@@ -187,10 +186,6 @@ pub fn main() {
187186
// Ergonomic format_args!
188187
t!(format!("{0:x} {0:X}", 15), "f F");
189188
t!(format!("{0:x} {0:X} {}", 15), "f F 15");
190-
// NOTE: For now the longer test cases must not be followed immediately by
191-
// >1 empty lines, or the pretty printer will break. Since no one wants to
192-
// touch the current pretty printer (#751), we have no choice but to work
193-
// around it. Some of the following test cases are also affected.
194189
t!(format!("{:x}{0:X}{a:x}{:X}{1:x}{a:X}", 13, 14, a=15), "dDfEeF");
195190
t!(format!("{a:x} {a:X}", a=15), "f F");
196191

@@ -201,7 +196,6 @@ pub fn main() {
201196
t!(format!("{a:.*} {0} {:.*}", 4, 3, "efgh", a="abcdef"), "abcd 4 efg");
202197
t!(format!("{:.a$} {a} {a:#x}", "aaaaaa", a=2), "aa 2 0x2");
203198

204-
205199
// Test that pointers don't get truncated.
206200
{
207201
let val = usize::MAX;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-rustfix
2+
trait T {
3+
type Ty;
4+
}
5+
6+
struct Impl;
7+
8+
impl T for Impl {
9+
type Ty = u32;
10+
}
11+
12+
fn template<T>() -> i64 {
13+
3
14+
}
15+
16+
fn main() {
17+
template::<<Impl as T>::Ty>();
18+
//~^ ERROR found single colon before projection in qualified path
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-rustfix
2+
trait T {
3+
type Ty;
4+
}
5+
6+
struct Impl;
7+
8+
impl T for Impl {
9+
type Ty = u32;
10+
}
11+
12+
fn template<T>() -> i64 {
13+
3
14+
}
15+
16+
fn main() {
17+
template::<<Impl as T>:Ty>();
18+
//~^ ERROR found single colon before projection in qualified path
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: found single colon before projection in qualified path
2+
--> $DIR/qualified-path-in-turbofish.rs:17:27
3+
|
4+
LL | template::<<Impl as T>:Ty>();
5+
| ^ help: use double colon: `::`
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const _: () = ();
2+
3+
fn main() {
4+
a // Shouldn't suggest underscore
5+
//~^ ERROR: cannot find value `a` in this scope
6+
}
7+
8+
trait Unknown {}
9+
10+
#[allow(unused_imports)]
11+
use Unknown as _;
12+
13+
fn foo<T: A>(x: T) {} // Shouldn't suggest underscore
14+
//~^ ERROR: cannot find trait `A` in this scope
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0425]: cannot find value `a` in this scope
2+
--> $DIR/typo-suggestion-named-underscore.rs:4:5
3+
|
4+
LL | a // Shouldn't suggest underscore
5+
| ^ not found in this scope
6+
7+
error[E0405]: cannot find trait `A` in this scope
8+
--> $DIR/typo-suggestion-named-underscore.rs:13:11
9+
|
10+
LL | fn foo<T: A>(x: T) {} // Shouldn't suggest underscore
11+
| ^ not found in this scope
12+
13+
error: aborting due to 2 previous errors
14+
15+
Some errors have detailed explanations: E0405, E0425.
16+
For more information about an error, try `rustc --explain E0405`.

0 commit comments

Comments
 (0)