Skip to content

Commit db00199

Browse files
committed
Auto merge of #101249 - matthiaskrgr:rollup-wahnoz8, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #100787 (Pretty printing give proper error message without panic) - #100838 (Suggest moving redundant generic args of an assoc fn to its trait) - #100844 (migrate rustc_query_system to use SessionDiagnostic) - #101140 (Update Clippy) - #101161 (Fix uintended diagnostic caused by `drain(..)`) - #101165 (Use more `into_iter` rather than `drain(..)`) - #101229 (Link “? operator” to relevant chapter in The Book) - #101230 (lint: avoid linting diag functions with diag lints) - #101236 (Avoid needless buffer zeroing in `std::sys::windows::fs`) - #101240 (Fix a typo on `wasm64-unknown-unknown` doc) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9243168 + 14d216d commit db00199

File tree

280 files changed

+10129
-4856
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

280 files changed

+10129
-4856
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ version = "0.1.65"
727727
dependencies = [
728728
"arrayvec",
729729
"if_chain",
730+
"itertools",
730731
"rustc-semver",
731732
]
732733

compiler/rustc_ast/src/tokenstream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ impl TokenStreamBuilder {
555555

556556
// Get the first stream, which will become the result stream.
557557
// If it's `None`, create an empty stream.
558-
let mut iter = streams.drain(..);
558+
let mut iter = streams.into_iter();
559559
let mut res_stream_lrc = iter.next().unwrap().0;
560560

561561
// Append the subsequent elements to the result stream, after

compiler/rustc_data_structures/src/sorted_map.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<K: Ord, V> SortedMap<K, V> {
164164
/// It is up to the caller to make sure that the elements are sorted by key
165165
/// and that there are no duplicates.
166166
#[inline]
167-
pub fn insert_presorted(&mut self, mut elements: Vec<(K, V)>) {
167+
pub fn insert_presorted(&mut self, elements: Vec<(K, V)>) {
168168
if elements.is_empty() {
169169
return;
170170
}
@@ -173,28 +173,28 @@ impl<K: Ord, V> SortedMap<K, V> {
173173

174174
let start_index = self.lookup_index_for(&elements[0].0);
175175

176-
let drain = match start_index {
176+
let elements = match start_index {
177177
Ok(index) => {
178-
let mut drain = elements.drain(..);
179-
self.data[index] = drain.next().unwrap();
180-
drain
178+
let mut elements = elements.into_iter();
179+
self.data[index] = elements.next().unwrap();
180+
elements
181181
}
182182
Err(index) => {
183183
if index == self.data.len() || elements.last().unwrap().0 < self.data[index].0 {
184184
// We can copy the whole range without having to mix with
185185
// existing elements.
186-
self.data.splice(index..index, elements.drain(..));
186+
self.data.splice(index..index, elements.into_iter());
187187
return;
188188
}
189189

190-
let mut drain = elements.drain(..);
191-
self.data.insert(index, drain.next().unwrap());
192-
drain
190+
let mut elements = elements.into_iter();
191+
self.data.insert(index, elements.next().unwrap());
192+
elements
193193
}
194194
};
195195

196196
// Insert the rest
197-
for (k, v) in drain {
197+
for (k, v) in elements {
198198
self.insert(k, v);
199199
}
200200
}

compiler/rustc_driver/src/pretty.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! The various pretty-printing routines.
22
3+
use crate::session_diagnostics::UnprettyDumpFail;
34
use rustc_ast as ast;
45
use rustc_ast_pretty::pprust;
56
use rustc_errors::ErrorGuaranteed;
@@ -357,12 +358,15 @@ fn get_source(input: &Input, sess: &Session) -> (String, FileName) {
357358
(src, src_name)
358359
}
359360

360-
fn write_or_print(out: &str, ofile: Option<&Path>) {
361+
fn write_or_print(out: &str, ofile: Option<&Path>, sess: &Session) {
361362
match ofile {
362363
None => print!("{}", out),
363364
Some(p) => {
364365
if let Err(e) = std::fs::write(p, out) {
365-
panic!("print-print failed to write {} due to {}", p.display(), e);
366+
sess.emit_fatal(UnprettyDumpFail {
367+
path: p.display().to_string(),
368+
err: e.to_string(),
369+
});
366370
}
367371
}
368372
}
@@ -402,7 +406,7 @@ pub fn print_after_parsing(
402406
_ => unreachable!(),
403407
};
404408

405-
write_or_print(&out, ofile);
409+
write_or_print(&out, ofile, sess);
406410
}
407411

408412
pub fn print_after_hir_lowering<'tcx>(
@@ -468,7 +472,7 @@ pub fn print_after_hir_lowering<'tcx>(
468472
_ => unreachable!(),
469473
};
470474

471-
write_or_print(&out, ofile);
475+
write_or_print(&out, ofile, tcx.sess);
472476
}
473477

474478
// In an ideal world, this would be a public function called by the driver after
@@ -512,7 +516,7 @@ fn print_with_analysis(
512516
_ => unreachable!(),
513517
};
514518

515-
write_or_print(&out, ofile);
519+
write_or_print(&out, ofile, tcx.sess);
516520

517521
Ok(())
518522
}

compiler/rustc_driver/src/session_diagnostics.rs

+7
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ pub(crate) struct RLinkRustcVersionMismatch<'a> {
3131
#[derive(SessionDiagnostic)]
3232
#[diag(driver::rlink_no_a_file)]
3333
pub(crate) struct RlinkNotAFile;
34+
35+
#[derive(SessionDiagnostic)]
36+
#[diag(driver::unpretty_dump_fail)]
37+
pub(crate) struct UnprettyDumpFail {
38+
pub path: String,
39+
pub err: String,
40+
}

compiler/rustc_error_messages/locales/en-US/driver.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ driver_rlink_encoding_version_mismatch = .rlink file was produced with encoding
99
driver_rlink_rustc_version_mismatch = .rlink file was produced by rustc version `{$rustc_version}`, but the current version is `{$current_version}`
1010
1111
driver_rlink_no_a_file = rlink must be a file
12+
13+
driver_unpretty_dump_fail = pretty-print failed to write `{$path}` due to error `{$err}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
query_system_reentrant = internal compiler error: re-entrant incremental verify failure, suppressing message
2+
3+
query_system_increment_compilation = internal compiler error: encountered incremental compilation error with {$dep_node}
4+
.help = This is a known issue with the compiler. Run {$run_cmd} to allow your project to compile
5+
6+
query_system_increment_compilation_note1 = Please follow the instructions below to create a bug report with the provided information
7+
query_system_increment_compilation_note2 = See <https://github.com/rust-lang/rust/issues/84970> for more information
8+
9+
query_system_cycle = cycle detected when {$stack_bottom}
10+
11+
query_system_cycle_usage = cycle used when {$usage}
12+
13+
query_system_cycle_stack_single = ...which immediately requires {$stack_bottom} again
14+
15+
query_system_cycle_stack_multiple = ...which again requires {$stack_bottom}, completing the cycle
16+
17+
query_system_cycle_recursive_ty_alias = type aliases cannot be recursive
18+
query_system_cycle_recursive_ty_alias_help1 = consider using a struct, enum, or union instead to break the cycle
19+
query_system_cycle_recursive_ty_alias_help2 = see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information
20+
21+
query_system_cycle_recursive_trait_alias = trait aliases cannot be recursive
22+
23+
query_system_cycle_which_requires = ...which requires {$desc}...
24+
25+
query_system_query_overflow = queries overflow the depth limit!

compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ fluent_messages! {
5050
passes => "../locales/en-US/passes.ftl",
5151
plugin_impl => "../locales/en-US/plugin_impl.ftl",
5252
privacy => "../locales/en-US/privacy.ftl",
53+
query_system => "../locales/en-US/query_system.ftl",
5354
save_analysis => "../locales/en-US/save_analysis.ftl",
5455
ty_utils => "../locales/en-US/ty_utils.ftl",
5556
typeck => "../locales/en-US/typeck.ftl",

compiler/rustc_errors/src/diagnostic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -974,12 +974,12 @@ impl Diagnostic {
974974
fn sub_with_highlights<M: Into<SubdiagnosticMessage>>(
975975
&mut self,
976976
level: Level,
977-
mut message: Vec<(M, Style)>,
977+
message: Vec<(M, Style)>,
978978
span: MultiSpan,
979979
render_span: Option<MultiSpan>,
980980
) {
981981
let message = message
982-
.drain(..)
982+
.into_iter()
983983
.map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.0), m.1))
984984
.collect();
985985
let sub = SubDiagnostic { level, message, span, render_span };

compiler/rustc_errors/src/translation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub trait Translate {
2121
/// Typically performed once for each diagnostic at the start of `emit_diagnostic` and then
2222
/// passed around as a reference thereafter.
2323
fn to_fluent_args<'arg>(&self, args: &[DiagnosticArg<'arg>]) -> FluentArgs<'arg> {
24-
FromIterator::from_iter(args.to_vec().drain(..))
24+
FromIterator::from_iter(args.iter().cloned())
2525
}
2626

2727
/// Convert `DiagnosticMessage`s to a string, performing translation if necessary.

compiler/rustc_lint/src/internal.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,14 @@ impl LateLintPass<'_> for Diagnostics {
393393
return;
394394
}
395395

396+
let mut found_parent_with_attr = false;
396397
let mut found_impl = false;
397-
for (_, parent) in cx.tcx.hir().parent_iter(expr.hir_id) {
398+
for (hir_id, parent) in cx.tcx.hir().parent_iter(expr.hir_id) {
399+
if let Some(owner_did) = hir_id.as_owner() {
400+
found_parent_with_attr = found_parent_with_attr
401+
|| cx.tcx.has_attr(owner_did.to_def_id(), sym::rustc_lint_diagnostics);
402+
}
403+
398404
debug!(?parent);
399405
if let Node::Item(Item { kind: ItemKind::Impl(impl_), .. }) = parent &&
400406
let Impl { of_trait: Some(of_trait), .. } = impl_ &&
@@ -407,7 +413,7 @@ impl LateLintPass<'_> for Diagnostics {
407413
}
408414
}
409415
debug!(?found_impl);
410-
if !found_impl {
416+
if !found_parent_with_attr && !found_impl {
411417
cx.struct_span_lint(DIAGNOSTIC_OUTSIDE_OF_IMPL, span, |lint| {
412418
lint.build(fluent::lint::diag_out_of_impl).emit();
413419
})
@@ -425,7 +431,7 @@ impl LateLintPass<'_> for Diagnostics {
425431
}
426432
}
427433
debug!(?found_diagnostic_message);
428-
if !found_diagnostic_message {
434+
if !found_parent_with_attr && !found_diagnostic_message {
429435
cx.struct_span_lint(UNTRANSLATABLE_DIAGNOSTIC, span, |lint| {
430436
lint.build(fluent::lint::untranslatable_diag).emit();
431437
})

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl DiagnosticDeriveBuilder {
239239
}
240240
}
241241

242-
Ok(tokens.drain(..).collect())
242+
Ok(tokens.into_iter().collect())
243243
}
244244

245245
fn generate_field_attrs_code(&mut self, binding_info: &BindingInfo<'_>) -> TokenStream {

0 commit comments

Comments
 (0)