Skip to content

Commit

Permalink
Auto merge of #101249 - matthiaskrgr:rollup-wahnoz8, r=matthiaskrgr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Aug 31, 2022
2 parents 9243168 + 14d216d commit db00199
Show file tree
Hide file tree
Showing 280 changed files with 10,129 additions and 4,856 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ version = "0.1.65"
dependencies = [
"arrayvec",
"if_chain",
"itertools",
"rustc-semver",
]

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl TokenStreamBuilder {

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

// Append the subsequent elements to the result stream, after
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_data_structures/src/sorted_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl<K: Ord, V> SortedMap<K, V> {
/// It is up to the caller to make sure that the elements are sorted by key
/// and that there are no duplicates.
#[inline]
pub fn insert_presorted(&mut self, mut elements: Vec<(K, V)>) {
pub fn insert_presorted(&mut self, elements: Vec<(K, V)>) {
if elements.is_empty() {
return;
}
Expand All @@ -173,28 +173,28 @@ impl<K: Ord, V> SortedMap<K, V> {

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

let drain = match start_index {
let elements = match start_index {
Ok(index) => {
let mut drain = elements.drain(..);
self.data[index] = drain.next().unwrap();
drain
let mut elements = elements.into_iter();
self.data[index] = elements.next().unwrap();
elements
}
Err(index) => {
if index == self.data.len() || elements.last().unwrap().0 < self.data[index].0 {
// We can copy the whole range without having to mix with
// existing elements.
self.data.splice(index..index, elements.drain(..));
self.data.splice(index..index, elements.into_iter());
return;
}

let mut drain = elements.drain(..);
self.data.insert(index, drain.next().unwrap());
drain
let mut elements = elements.into_iter();
self.data.insert(index, elements.next().unwrap());
elements
}
};

// Insert the rest
for (k, v) in drain {
for (k, v) in elements {
self.insert(k, v);
}
}
Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_driver/src/pretty.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! The various pretty-printing routines.
use crate::session_diagnostics::UnprettyDumpFail;
use rustc_ast as ast;
use rustc_ast_pretty::pprust;
use rustc_errors::ErrorGuaranteed;
Expand Down Expand Up @@ -357,12 +358,15 @@ fn get_source(input: &Input, sess: &Session) -> (String, FileName) {
(src, src_name)
}

fn write_or_print(out: &str, ofile: Option<&Path>) {
fn write_or_print(out: &str, ofile: Option<&Path>, sess: &Session) {
match ofile {
None => print!("{}", out),
Some(p) => {
if let Err(e) = std::fs::write(p, out) {
panic!("print-print failed to write {} due to {}", p.display(), e);
sess.emit_fatal(UnprettyDumpFail {
path: p.display().to_string(),
err: e.to_string(),
});
}
}
}
Expand Down Expand Up @@ -402,7 +406,7 @@ pub fn print_after_parsing(
_ => unreachable!(),
};

write_or_print(&out, ofile);
write_or_print(&out, ofile, sess);
}

pub fn print_after_hir_lowering<'tcx>(
Expand Down Expand Up @@ -468,7 +472,7 @@ pub fn print_after_hir_lowering<'tcx>(
_ => unreachable!(),
};

write_or_print(&out, ofile);
write_or_print(&out, ofile, tcx.sess);
}

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

write_or_print(&out, ofile);
write_or_print(&out, ofile, tcx.sess);

Ok(())
}
7 changes: 7 additions & 0 deletions compiler/rustc_driver/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ pub(crate) struct RLinkRustcVersionMismatch<'a> {
#[derive(SessionDiagnostic)]
#[diag(driver::rlink_no_a_file)]
pub(crate) struct RlinkNotAFile;

#[derive(SessionDiagnostic)]
#[diag(driver::unpretty_dump_fail)]
pub(crate) struct UnprettyDumpFail {
pub path: String,
pub err: String,
}
2 changes: 2 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/driver.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ driver_rlink_encoding_version_mismatch = .rlink file was produced with encoding
driver_rlink_rustc_version_mismatch = .rlink file was produced by rustc version `{$rustc_version}`, but the current version is `{$current_version}`
driver_rlink_no_a_file = rlink must be a file
driver_unpretty_dump_fail = pretty-print failed to write `{$path}` due to error `{$err}`
25 changes: 25 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/query_system.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
query_system_reentrant = internal compiler error: re-entrant incremental verify failure, suppressing message
query_system_increment_compilation = internal compiler error: encountered incremental compilation error with {$dep_node}
.help = This is a known issue with the compiler. Run {$run_cmd} to allow your project to compile
query_system_increment_compilation_note1 = Please follow the instructions below to create a bug report with the provided information
query_system_increment_compilation_note2 = See <https://github.com/rust-lang/rust/issues/84970> for more information
query_system_cycle = cycle detected when {$stack_bottom}
query_system_cycle_usage = cycle used when {$usage}
query_system_cycle_stack_single = ...which immediately requires {$stack_bottom} again
query_system_cycle_stack_multiple = ...which again requires {$stack_bottom}, completing the cycle
query_system_cycle_recursive_ty_alias = type aliases cannot be recursive
query_system_cycle_recursive_ty_alias_help1 = consider using a struct, enum, or union instead to break the cycle
query_system_cycle_recursive_ty_alias_help2 = see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information
query_system_cycle_recursive_trait_alias = trait aliases cannot be recursive
query_system_cycle_which_requires = ...which requires {$desc}...
query_system_query_overflow = queries overflow the depth limit!
1 change: 1 addition & 0 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fluent_messages! {
passes => "../locales/en-US/passes.ftl",
plugin_impl => "../locales/en-US/plugin_impl.ftl",
privacy => "../locales/en-US/privacy.ftl",
query_system => "../locales/en-US/query_system.ftl",
save_analysis => "../locales/en-US/save_analysis.ftl",
ty_utils => "../locales/en-US/ty_utils.ftl",
typeck => "../locales/en-US/typeck.ftl",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,12 +974,12 @@ impl Diagnostic {
fn sub_with_highlights<M: Into<SubdiagnosticMessage>>(
&mut self,
level: Level,
mut message: Vec<(M, Style)>,
message: Vec<(M, Style)>,
span: MultiSpan,
render_span: Option<MultiSpan>,
) {
let message = message
.drain(..)
.into_iter()
.map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.0), m.1))
.collect();
let sub = SubDiagnostic { level, message, span, render_span };
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait Translate {
/// Typically performed once for each diagnostic at the start of `emit_diagnostic` and then
/// passed around as a reference thereafter.
fn to_fluent_args<'arg>(&self, args: &[DiagnosticArg<'arg>]) -> FluentArgs<'arg> {
FromIterator::from_iter(args.to_vec().drain(..))
FromIterator::from_iter(args.iter().cloned())
}

/// Convert `DiagnosticMessage`s to a string, performing translation if necessary.
Expand Down
12 changes: 9 additions & 3 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,14 @@ impl LateLintPass<'_> for Diagnostics {
return;
}

let mut found_parent_with_attr = false;
let mut found_impl = false;
for (_, parent) in cx.tcx.hir().parent_iter(expr.hir_id) {
for (hir_id, parent) in cx.tcx.hir().parent_iter(expr.hir_id) {
if let Some(owner_did) = hir_id.as_owner() {
found_parent_with_attr = found_parent_with_attr
|| cx.tcx.has_attr(owner_did.to_def_id(), sym::rustc_lint_diagnostics);
}

debug!(?parent);
if let Node::Item(Item { kind: ItemKind::Impl(impl_), .. }) = parent &&
let Impl { of_trait: Some(of_trait), .. } = impl_ &&
Expand All @@ -407,7 +413,7 @@ impl LateLintPass<'_> for Diagnostics {
}
}
debug!(?found_impl);
if !found_impl {
if !found_parent_with_attr && !found_impl {
cx.struct_span_lint(DIAGNOSTIC_OUTSIDE_OF_IMPL, span, |lint| {
lint.build(fluent::lint::diag_out_of_impl).emit();
})
Expand All @@ -425,7 +431,7 @@ impl LateLintPass<'_> for Diagnostics {
}
}
debug!(?found_diagnostic_message);
if !found_diagnostic_message {
if !found_parent_with_attr && !found_diagnostic_message {
cx.struct_span_lint(UNTRANSLATABLE_DIAGNOSTIC, span, |lint| {
lint.build(fluent::lint::untranslatable_diag).emit();
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl DiagnosticDeriveBuilder {
}
}

Ok(tokens.drain(..).collect())
Ok(tokens.into_iter().collect())
}

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

0 comments on commit db00199

Please sign in to comment.