Skip to content

Commit

Permalink
Auto merge of rust-lang#82235 - GuillaumeGomez:rollup-oflxc08, r=Guil…
Browse files Browse the repository at this point in the history
…laumeGomez

Rollup of 11 pull requests

Successful merges:

 - rust-lang#79981 (Add 'consider using' message to overflowing_literals)
 - rust-lang#82094 (To digit simplification)
 - rust-lang#82105 (Don't fail to remove files if they are missing)
 - rust-lang#82136 (Fix ICE: Use delay_span_bug for mismatched subst/hir arg)
 - rust-lang#82169 (Document that `assert!` format arguments are evaluated lazily)
 - rust-lang#82174 (Replace File::create and write_all with fs::write)
 - rust-lang#82196 (Add caveat to Path::display() about lossiness)
 - rust-lang#82198 (Use internal iteration in Iterator::is_sorted_by)
 - rust-lang#82204 (Update books)
 - rust-lang#82207 (rustdoc: treat edition 2021 as unstable)
 - rust-lang#82231 (Add long explanation for E0543)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 17, 2021
2 parents 5ef2106 + 03477e9 commit 152f660
Show file tree
Hide file tree
Showing 34 changed files with 280 additions and 105 deletions.
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::llvm_util;
use crate::type_::Type;
use crate::LlvmCodegenBackend;
use crate::ModuleLlvm;
use rustc_codegen_ssa::back::link::ensure_removed;
use rustc_codegen_ssa::back::write::{
BitcodeSection, CodegenContext, EmitObj, ModuleConfig, TargetMachineFactoryConfig,
TargetMachineFactoryFn,
Expand Down Expand Up @@ -879,9 +880,7 @@ pub(crate) unsafe fn codegen(

if !config.emit_bc {
debug!("removing_bitcode {:?}", bc_out);
if let Err(e) = fs::remove_file(&bc_out) {
diag_handler.err(&format!("failed to remove bitcode: {}", e));
}
ensure_removed(diag_handler, &bc_out);
}
}

Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::temp_dir::MaybeTempDir;
use rustc_errors::Handler;
use rustc_fs_util::fix_windows_verbatim_for_gcc;
use rustc_hir::def_id::CrateNum;
use rustc_middle::middle::cstore::{EncodedMetadata, LibSource};
Expand Down Expand Up @@ -34,9 +35,11 @@ use std::path::{Path, PathBuf};
use std::process::{ExitStatus, Output, Stdio};
use std::{ascii, char, env, fmt, fs, io, mem, str};

pub fn remove(sess: &Session, path: &Path) {
pub fn ensure_removed(diag_handler: &Handler, path: &Path) {
if let Err(e) = fs::remove_file(path) {
sess.err(&format!("failed to remove {}: {}", path.display(), e));
if e.kind() != io::ErrorKind::NotFound {
diag_handler.err(&format!("failed to remove {}: {}", path.display(), e));
}
}
}

Expand Down Expand Up @@ -112,11 +115,11 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
if !sess.opts.cg.save_temps {
let remove_temps_from_module = |module: &CompiledModule| {
if let Some(ref obj) = module.object {
remove(sess, obj);
ensure_removed(sess.diagnostic(), obj);
}

if let Some(ref obj) = module.dwarf_object {
remove(sess, obj);
ensure_removed(sess.diagnostic(), obj);
}
};

Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::link::{self, remove};
use super::link::{self, ensure_removed};
use super::linker::LinkerInfo;
use super::lto::{self, SerializedModule};
use super::symbol_export::symbol_name_for_instance_in_crate;
Expand Down Expand Up @@ -543,7 +543,7 @@ fn produce_final_output_artifacts(
copy_gracefully(&path, &crate_output.path(output_type));
if !sess.opts.cg.save_temps && !keep_numbered {
// The user just wants `foo.x`, not `foo.#module-name#.x`.
remove(sess, &path);
ensure_removed(sess.diagnostic(), &path);
}
} else {
let ext = crate_output
Expand Down Expand Up @@ -642,33 +642,33 @@ fn produce_final_output_artifacts(
for module in compiled_modules.modules.iter() {
if let Some(ref path) = module.object {
if !keep_numbered_objects {
remove(sess, path);
ensure_removed(sess.diagnostic(), path);
}
}

if let Some(ref path) = module.dwarf_object {
if !keep_numbered_objects {
remove(sess, path);
ensure_removed(sess.diagnostic(), path);
}
}

if let Some(ref path) = module.bytecode {
if !keep_numbered_bitcode {
remove(sess, path);
ensure_removed(sess.diagnostic(), path);
}
}
}

if !user_wants_bitcode {
if let Some(ref metadata_module) = compiled_modules.metadata_module {
if let Some(ref path) = metadata_module.bytecode {
remove(sess, &path);
ensure_removed(sess.diagnostic(), &path);
}
}

if let Some(ref allocator_module) = compiled_modules.allocator_module {
if let Some(ref path) = allocator_module.bytecode {
remove(sess, path);
ensure_removed(sess.diagnostic(), path);
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions compiler/rustc_driver/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use rustc_span::symbol::Ident;
use rustc_span::FileName;

use std::cell::Cell;
use std::fs::File;
use std::io::Write;
use std::path::Path;

pub use self::PpMode::*;
Expand Down Expand Up @@ -375,13 +373,14 @@ fn get_source(input: &Input, sess: &Session) -> (String, FileName) {
(src, src_name)
}

fn write_output(out: Vec<u8>, ofile: Option<&Path>) {
fn write_or_print(out: &str, ofile: Option<&Path>) {
match ofile {
None => print!("{}", String::from_utf8(out).unwrap()),
Some(p) => match File::create(p) {
Ok(mut w) => w.write_all(&out).unwrap(),
Err(e) => panic!("print-print failed to open {} due to {}", p.display(), e),
},
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);
}
}
}
}

Expand Down Expand Up @@ -417,7 +416,7 @@ pub fn print_after_parsing(
unreachable!();
};

write_output(out.into_bytes(), ofile);
write_or_print(&out, ofile);
}

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

write_output(out.into_bytes(), ofile);
write_or_print(&out, ofile);
}

// In an ideal world, this would be a public function called by the driver after
Expand All @@ -503,7 +502,8 @@ fn print_with_analysis(
}
.unwrap();

write_output(out, ofile);
let out = std::str::from_utf8(&out).unwrap();
write_or_print(out, ofile);

Ok(())
}
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ E0538: include_str!("./error_codes/E0538.md"),
E0539: include_str!("./error_codes/E0539.md"),
E0541: include_str!("./error_codes/E0541.md"),
E0542: include_str!("./error_codes/E0542.md"),
E0543: include_str!("./error_codes/E0543.md"),
E0545: include_str!("./error_codes/E0545.md"),
E0546: include_str!("./error_codes/E0546.md"),
E0547: include_str!("./error_codes/E0547.md"),
Expand Down Expand Up @@ -605,7 +606,6 @@ E0781: include_str!("./error_codes/E0781.md"),
E0523,
// E0526, // shuffle indices are not constant
// E0540, // multiple rustc_deprecated attributes
E0543, // missing 'reason'
E0544, // multiple stability levels
// E0548, // replaced with a generic attribute input check
// rustc_deprecated attribute must be paired with either stable or unstable
Expand Down
35 changes: 35 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0543.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
The `reason` value is missing in a stability attribute.

Erroneous code example:

```compile_fail,E0543
#![feature(staged_api)]
#![stable(since = "1.0.0", feature = "test")]
#[stable(since = "0.1.0", feature = "_deprecated_fn")]
#[rustc_deprecated(
since = "1.0.0"
)] // invalid
fn _deprecated_fn() {}
```

To fix this issue, you need to provide the `reason` field. Example:

```
#![feature(staged_api)]
#![stable(since = "1.0.0", feature = "test")]
#[stable(since = "0.1.0", feature = "_deprecated_fn")]
#[rustc_deprecated(
since = "1.0.0",
reason = "explanation for deprecation"
)] // ok!
fn _deprecated_fn() {}
```

See the [How Rust is Made and “Nightly Rust”][how-rust-made-nightly] appendix
of the Book and the [Stability attributes][stability-attributes] section of the
Rustc Dev Guide for more details.

[how-rust-made-nightly]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
[stability-attributes]: https://rustc-dev-guide.rust-lang.org/stability.html
35 changes: 20 additions & 15 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ fn report_bin_hex_error(
(t.name_str(), actually.to_string())
}
};
let mut err = lint.build(&format!("literal out of range for {}", t));
let mut err = lint.build(&format!("literal out of range for `{}`", t));
err.note(&format!(
"the literal `{}` (decimal `{}`) does not fit into \
the type `{}` and will become `{}{}`",
Expand All @@ -238,12 +238,12 @@ fn report_bin_hex_error(
let (sans_suffix, _) = repr_str.split_at(pos);
err.span_suggestion(
expr.span,
&format!("consider using `{}` instead", sugg_ty),
&format!("consider using the type `{}` instead", sugg_ty),
format!("{}{}", sans_suffix, sugg_ty),
Applicability::MachineApplicable,
);
} else {
err.help(&format!("consider using `{}` instead", sugg_ty));
err.help(&format!("consider using the type `{}` instead", sugg_ty));
}
}
err.emit();
Expand Down Expand Up @@ -338,18 +338,23 @@ fn lint_int_literal<'tcx>(
}

cx.struct_span_lint(OVERFLOWING_LITERALS, e.span, |lint| {
lint.build(&format!("literal out of range for `{}`", t.name_str()))
.note(&format!(
"the literal `{}` does not fit into the type `{}` whose range is `{}..={}`",
cx.sess()
.source_map()
.span_to_snippet(lit.span)
.expect("must get snippet from literal"),
t.name_str(),
min,
max,
))
.emit();
let mut err = lint.build(&format!("literal out of range for `{}`", t.name_str()));
err.note(&format!(
"the literal `{}` does not fit into the type `{}` whose range is `{}..={}`",
cx.sess()
.source_map()
.span_to_snippet(lit.span)
.expect("must get snippet from literal"),
t.name_str(),
min,
max,
));
if let Some(sugg_ty) =
get_type_suggestion(&cx.typeck_results().node_type(e.hir_id), v, negative)
{
err.help(&format!("consider using the type `{}` instead", sugg_ty));
}
err.emit();
});
}
}
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,14 +634,11 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
| GenericArgKind::Const(_),
_,
) => {
// I *think* that HIR lowering should ensure this
// doesn't happen, even in erroneous
// programs. Else we should use delay-span-bug.
span_bug!(
// HIR lowering sometimes doesn't catch this in erroneous
// programs, so we need to use delay_span_bug here. See #82126.
self.infcx.tcx.sess.delay_span_bug(
hir_arg.span(),
"unmatched subst and hir arg: found {:?} vs {:?}",
kind,
hir_arg,
&format!("unmatched subst and hir arg: found {:?} vs {:?}", kind, hir_arg),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ pub fn parse_error_format(
error_format
}

fn parse_crate_edition(matches: &getopts::Matches) -> Edition {
pub fn parse_crate_edition(matches: &getopts::Matches) -> Edition {
let edition = match matches.opt_str("edition") {
Some(arg) => Edition::from_str(&arg).unwrap_or_else(|_| {
early_error(
Expand Down
12 changes: 5 additions & 7 deletions library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! impl char {}

use crate::intrinsics::likely;
use crate::slice;
use crate::str::from_utf8_unchecked_mut;
use crate::unicode::printable::is_printable;
Expand Down Expand Up @@ -330,16 +331,13 @@ impl char {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn to_digit(self, radix: u32) -> Option<u32> {
assert!(radix <= 36, "to_digit: radix is too high (maximum 36)");
// the code is split up here to improve execution speed for cases where
// the `radix` is constant and 10 or smaller
let val = if radix <= 10 {
match self {
'0'..='9' => self as u32 - '0' as u32,
_ => return None,
}
let val = if likely(radix <= 10) {
// If not a digit, a number greater than radix will be created.
(self as u32).wrapping_sub('0' as u32)
} else {
assert!(radix <= 36, "to_digit: radix is too high (maximum 36)");

match self {
'0'..='9' => self as u32 - '0' as u32,
'a'..='z' => self as u32 - 'a' as u32 + 10,
Expand Down
25 changes: 16 additions & 9 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3327,24 +3327,31 @@ pub trait Iterator {
///
/// [`is_sorted`]: Iterator::is_sorted
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
fn is_sorted_by<F>(mut self, mut compare: F) -> bool
fn is_sorted_by<F>(mut self, compare: F) -> bool
where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
{
#[inline]
fn check<'a, T>(
last: &'a mut T,
mut compare: impl FnMut(&T, &T) -> Option<Ordering> + 'a,
) -> impl FnMut(T) -> bool + 'a {
move |curr| {
if let Some(Ordering::Greater) | None = compare(&last, &curr) {
return false;
}
*last = curr;
true
}
}

let mut last = match self.next() {
Some(e) => e,
None => return true,
};

while let Some(curr) = self.next() {
if let Some(Ordering::Greater) | None = compare(&last, &curr) {
return false;
}
last = curr;
}

true
self.all(check(&mut last, compare))
}

/// Checks if the elements of this iterator are sorted using the given key extraction
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,8 @@ pub(crate) mod builtin {
///
/// This macro has a second form, where a custom panic message can
/// be provided with or without arguments for formatting. See [`std::fmt`]
/// for syntax for this form.
/// for syntax for this form. Expressions used as format arguments will only
/// be evaluated if the assertion fails.
///
/// [`std::fmt`]: ../std/fmt/index.html
///
Expand Down

0 comments on commit 152f660

Please sign in to comment.