Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #82235

Merged
merged 28 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d00ca11
Add 'consider using' message to overflowing_literals
camelid Dec 12, 2020
a9b16c6
Improve error and help messages
camelid Feb 14, 2021
fa3621b
Don't fail to remove files if they are missing
nagisa Feb 14, 2021
845c14d
Simpler way to convert to digit
gilescope Feb 14, 2021
a491f51
Use delay_span_bug for mismatched subst/hir arg
edward-shen Feb 15, 2021
f856224
Fix test issue reference
edward-shen Feb 15, 2021
a4b2faf
Revise HIR lowering comment
edward-shen Feb 15, 2021
17e238d
Use wrapping sub
gilescope Feb 15, 2021
d2ba68b
Update methods.rs
gilescope Feb 15, 2021
cb653b1
Document that `assert!` format arguments are evaluated lazily
not-an-aardvark Feb 16, 2021
e527def
Replace File::create and write_all with fs::write
est31 Feb 16, 2021
a98b22c
Add caveat to Path::display() about lossiness
Manishearth Feb 16, 2021
61bb183
Optimize Iterator::is_sorted_by by using Iterator::all for internal i…
SkiFire13 Feb 16, 2021
15197cb
Ensure debug_assert! tests get run
not-an-aardvark Feb 17, 2021
5715f79
Update books
ehuss Feb 17, 2021
ee0e841
rustdoc: treat edition 2021 as unstable
ehuss Feb 17, 2021
c80b737
Add long explanation for E0543
jesusprubio Feb 17, 2021
ec00784
Rollup merge of #79981 - camelid:overflowing_literals-inference-error…
GuillaumeGomez Feb 17, 2021
253631d
Rollup merge of #82094 - gilescope:to_digit_speedup2, r=m-ou-se
GuillaumeGomez Feb 17, 2021
7292d5f
Rollup merge of #82105 - nagisa:nagisa/ensure-removed, r=petrochenkov
GuillaumeGomez Feb 17, 2021
13730e9
Rollup merge of #82136 - edward-shen:mismatched-subst-and-hir, r=lcnr
GuillaumeGomez Feb 17, 2021
16481a2
Rollup merge of #82169 - not-an-aardvark:assert-lazy-format-expressio…
GuillaumeGomez Feb 17, 2021
d382771
Rollup merge of #82174 - est31:master, r=oli-obk
GuillaumeGomez Feb 17, 2021
8e6bc14
Rollup merge of #82196 - Manishearth:display-caveat, r=m-ou-se
GuillaumeGomez Feb 17, 2021
f46bd72
Rollup merge of #82198 - SkiFire13:optimize-iter-is-sorted, r=sfackler
GuillaumeGomez Feb 17, 2021
086342c
Rollup merge of #82204 - ehuss:update-books, r=ehuss
GuillaumeGomez Feb 17, 2021
f97e112
Rollup merge of #82207 - ehuss:rustdoc-2021, r=jyn514
GuillaumeGomez Feb 17, 2021
03477e9
Rollup merge of #82231 - jesusprubio:add-long-explanation-e0543, r=Gu…
GuillaumeGomez Feb 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading