Skip to content

Commit 152f660

Browse files
committed
Auto merge of rust-lang#82235 - GuillaumeGomez:rollup-oflxc08, r=GuillaumeGomez
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
2 parents 5ef2106 + 03477e9 commit 152f660

34 files changed

+280
-105
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::llvm_util;
1111
use crate::type_::Type;
1212
use crate::LlvmCodegenBackend;
1313
use crate::ModuleLlvm;
14+
use rustc_codegen_ssa::back::link::ensure_removed;
1415
use rustc_codegen_ssa::back::write::{
1516
BitcodeSection, CodegenContext, EmitObj, ModuleConfig, TargetMachineFactoryConfig,
1617
TargetMachineFactoryFn,
@@ -879,9 +880,7 @@ pub(crate) unsafe fn codegen(
879880

880881
if !config.emit_bc {
881882
debug!("removing_bitcode {:?}", bc_out);
882-
if let Err(e) = fs::remove_file(&bc_out) {
883-
diag_handler.err(&format!("failed to remove bitcode: {}", e));
884-
}
883+
ensure_removed(diag_handler, &bc_out);
885884
}
886885
}
887886

compiler/rustc_codegen_ssa/src/back/link.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_data_structures::fx::FxHashSet;
22
use rustc_data_structures::temp_dir::MaybeTempDir;
3+
use rustc_errors::Handler;
34
use rustc_fs_util::fix_windows_verbatim_for_gcc;
45
use rustc_hir::def_id::CrateNum;
56
use rustc_middle::middle::cstore::{EncodedMetadata, LibSource};
@@ -34,9 +35,11 @@ use std::path::{Path, PathBuf};
3435
use std::process::{ExitStatus, Output, Stdio};
3536
use std::{ascii, char, env, fmt, fs, io, mem, str};
3637

37-
pub fn remove(sess: &Session, path: &Path) {
38+
pub fn ensure_removed(diag_handler: &Handler, path: &Path) {
3839
if let Err(e) = fs::remove_file(path) {
39-
sess.err(&format!("failed to remove {}: {}", path.display(), e));
40+
if e.kind() != io::ErrorKind::NotFound {
41+
diag_handler.err(&format!("failed to remove {}: {}", path.display(), e));
42+
}
4043
}
4144
}
4245

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

118121
if let Some(ref obj) = module.dwarf_object {
119-
remove(sess, obj);
122+
ensure_removed(sess.diagnostic(), obj);
120123
}
121124
};
122125

compiler/rustc_codegen_ssa/src/back/write.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::link::{self, remove};
1+
use super::link::{self, ensure_removed};
22
use super::linker::LinkerInfo;
33
use super::lto::{self, SerializedModule};
44
use super::symbol_export::symbol_name_for_instance_in_crate;
@@ -543,7 +543,7 @@ fn produce_final_output_artifacts(
543543
copy_gracefully(&path, &crate_output.path(output_type));
544544
if !sess.opts.cg.save_temps && !keep_numbered {
545545
// The user just wants `foo.x`, not `foo.#module-name#.x`.
546-
remove(sess, &path);
546+
ensure_removed(sess.diagnostic(), &path);
547547
}
548548
} else {
549549
let ext = crate_output
@@ -642,33 +642,33 @@ fn produce_final_output_artifacts(
642642
for module in compiled_modules.modules.iter() {
643643
if let Some(ref path) = module.object {
644644
if !keep_numbered_objects {
645-
remove(sess, path);
645+
ensure_removed(sess.diagnostic(), path);
646646
}
647647
}
648648

649649
if let Some(ref path) = module.dwarf_object {
650650
if !keep_numbered_objects {
651-
remove(sess, path);
651+
ensure_removed(sess.diagnostic(), path);
652652
}
653653
}
654654

655655
if let Some(ref path) = module.bytecode {
656656
if !keep_numbered_bitcode {
657-
remove(sess, path);
657+
ensure_removed(sess.diagnostic(), path);
658658
}
659659
}
660660
}
661661

662662
if !user_wants_bitcode {
663663
if let Some(ref metadata_module) = compiled_modules.metadata_module {
664664
if let Some(ref path) = metadata_module.bytecode {
665-
remove(sess, &path);
665+
ensure_removed(sess.diagnostic(), &path);
666666
}
667667
}
668668

669669
if let Some(ref allocator_module) = compiled_modules.allocator_module {
670670
if let Some(ref path) = allocator_module.bytecode {
671-
remove(sess, path);
671+
ensure_removed(sess.diagnostic(), path);
672672
}
673673
}
674674
}

compiler/rustc_driver/src/pretty.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ use rustc_span::symbol::Ident;
1515
use rustc_span::FileName;
1616

1717
use std::cell::Cell;
18-
use std::fs::File;
19-
use std::io::Write;
2018
use std::path::Path;
2119

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

378-
fn write_output(out: Vec<u8>, ofile: Option<&Path>) {
376+
fn write_or_print(out: &str, ofile: Option<&Path>) {
379377
match ofile {
380-
None => print!("{}", String::from_utf8(out).unwrap()),
381-
Some(p) => match File::create(p) {
382-
Ok(mut w) => w.write_all(&out).unwrap(),
383-
Err(e) => panic!("print-print failed to open {} due to {}", p.display(), e),
384-
},
378+
None => print!("{}", out),
379+
Some(p) => {
380+
if let Err(e) = std::fs::write(p, out) {
381+
panic!("print-print failed to write {} due to {}", p.display(), e);
382+
}
383+
}
385384
}
386385
}
387386

@@ -417,7 +416,7 @@ pub fn print_after_parsing(
417416
unreachable!();
418417
};
419418

420-
write_output(out.into_bytes(), ofile);
419+
write_or_print(&out, ofile);
421420
}
422421

423422
pub fn print_after_hir_lowering<'tcx>(
@@ -477,7 +476,7 @@ pub fn print_after_hir_lowering<'tcx>(
477476
_ => unreachable!(),
478477
}
479478

480-
write_output(out.into_bytes(), ofile);
479+
write_or_print(&out, ofile);
481480
}
482481

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

506-
write_output(out, ofile);
505+
let out = std::str::from_utf8(&out).unwrap();
506+
write_or_print(out, ofile);
507507

508508
Ok(())
509509
}

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ E0538: include_str!("./error_codes/E0538.md"),
286286
E0539: include_str!("./error_codes/E0539.md"),
287287
E0541: include_str!("./error_codes/E0541.md"),
288288
E0542: include_str!("./error_codes/E0542.md"),
289+
E0543: include_str!("./error_codes/E0543.md"),
289290
E0545: include_str!("./error_codes/E0545.md"),
290291
E0546: include_str!("./error_codes/E0546.md"),
291292
E0547: include_str!("./error_codes/E0547.md"),
@@ -605,7 +606,6 @@ E0781: include_str!("./error_codes/E0781.md"),
605606
E0523,
606607
// E0526, // shuffle indices are not constant
607608
// E0540, // multiple rustc_deprecated attributes
608-
E0543, // missing 'reason'
609609
E0544, // multiple stability levels
610610
// E0548, // replaced with a generic attribute input check
611611
// rustc_deprecated attribute must be paired with either stable or unstable
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
The `reason` value is missing in a stability attribute.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0543
6+
#![feature(staged_api)]
7+
#![stable(since = "1.0.0", feature = "test")]
8+
9+
#[stable(since = "0.1.0", feature = "_deprecated_fn")]
10+
#[rustc_deprecated(
11+
since = "1.0.0"
12+
)] // invalid
13+
fn _deprecated_fn() {}
14+
```
15+
16+
To fix this issue, you need to provide the `reason` field. Example:
17+
18+
```
19+
#![feature(staged_api)]
20+
#![stable(since = "1.0.0", feature = "test")]
21+
22+
#[stable(since = "0.1.0", feature = "_deprecated_fn")]
23+
#[rustc_deprecated(
24+
since = "1.0.0",
25+
reason = "explanation for deprecation"
26+
)] // ok!
27+
fn _deprecated_fn() {}
28+
```
29+
30+
See the [How Rust is Made and “Nightly Rust”][how-rust-made-nightly] appendix
31+
of the Book and the [Stability attributes][stability-attributes] section of the
32+
Rustc Dev Guide for more details.
33+
34+
[how-rust-made-nightly]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
35+
[stability-attributes]: https://rustc-dev-guide.rust-lang.org/stability.html

compiler/rustc_lint/src/types.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ fn report_bin_hex_error(
225225
(t.name_str(), actually.to_string())
226226
}
227227
};
228-
let mut err = lint.build(&format!("literal out of range for {}", t));
228+
let mut err = lint.build(&format!("literal out of range for `{}`", t));
229229
err.note(&format!(
230230
"the literal `{}` (decimal `{}`) does not fit into \
231231
the type `{}` and will become `{}{}`",
@@ -238,12 +238,12 @@ fn report_bin_hex_error(
238238
let (sans_suffix, _) = repr_str.split_at(pos);
239239
err.span_suggestion(
240240
expr.span,
241-
&format!("consider using `{}` instead", sugg_ty),
241+
&format!("consider using the type `{}` instead", sugg_ty),
242242
format!("{}{}", sans_suffix, sugg_ty),
243243
Applicability::MachineApplicable,
244244
);
245245
} else {
246-
err.help(&format!("consider using `{}` instead", sugg_ty));
246+
err.help(&format!("consider using the type `{}` instead", sugg_ty));
247247
}
248248
}
249249
err.emit();
@@ -338,18 +338,23 @@ fn lint_int_literal<'tcx>(
338338
}
339339

340340
cx.struct_span_lint(OVERFLOWING_LITERALS, e.span, |lint| {
341-
lint.build(&format!("literal out of range for `{}`", t.name_str()))
342-
.note(&format!(
343-
"the literal `{}` does not fit into the type `{}` whose range is `{}..={}`",
344-
cx.sess()
345-
.source_map()
346-
.span_to_snippet(lit.span)
347-
.expect("must get snippet from literal"),
348-
t.name_str(),
349-
min,
350-
max,
351-
))
352-
.emit();
341+
let mut err = lint.build(&format!("literal out of range for `{}`", t.name_str()));
342+
err.note(&format!(
343+
"the literal `{}` does not fit into the type `{}` whose range is `{}..={}`",
344+
cx.sess()
345+
.source_map()
346+
.span_to_snippet(lit.span)
347+
.expect("must get snippet from literal"),
348+
t.name_str(),
349+
min,
350+
max,
351+
));
352+
if let Some(sugg_ty) =
353+
get_type_suggestion(&cx.typeck_results().node_type(e.hir_id), v, negative)
354+
{
355+
err.help(&format!("consider using the type `{}` instead", sugg_ty));
356+
}
357+
err.emit();
353358
});
354359
}
355360
}

compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -634,14 +634,11 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
634634
| GenericArgKind::Const(_),
635635
_,
636636
) => {
637-
// I *think* that HIR lowering should ensure this
638-
// doesn't happen, even in erroneous
639-
// programs. Else we should use delay-span-bug.
640-
span_bug!(
637+
// HIR lowering sometimes doesn't catch this in erroneous
638+
// programs, so we need to use delay_span_bug here. See #82126.
639+
self.infcx.tcx.sess.delay_span_bug(
641640
hir_arg.span(),
642-
"unmatched subst and hir arg: found {:?} vs {:?}",
643-
kind,
644-
hir_arg,
641+
&format!("unmatched subst and hir arg: found {:?} vs {:?}", kind, hir_arg),
645642
);
646643
}
647644
}

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ pub fn parse_error_format(
13501350
error_format
13511351
}
13521352

1353-
fn parse_crate_edition(matches: &getopts::Matches) -> Edition {
1353+
pub fn parse_crate_edition(matches: &getopts::Matches) -> Edition {
13541354
let edition = match matches.opt_str("edition") {
13551355
Some(arg) => Edition::from_str(&arg).unwrap_or_else(|_| {
13561356
early_error(

library/core/src/char/methods.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! impl char {}
22
3+
use crate::intrinsics::likely;
34
use crate::slice;
45
use crate::str::from_utf8_unchecked_mut;
56
use crate::unicode::printable::is_printable;
@@ -330,16 +331,13 @@ impl char {
330331
#[stable(feature = "rust1", since = "1.0.0")]
331332
#[inline]
332333
pub fn to_digit(self, radix: u32) -> Option<u32> {
334+
assert!(radix <= 36, "to_digit: radix is too high (maximum 36)");
333335
// the code is split up here to improve execution speed for cases where
334336
// the `radix` is constant and 10 or smaller
335-
let val = if radix <= 10 {
336-
match self {
337-
'0'..='9' => self as u32 - '0' as u32,
338-
_ => return None,
339-
}
337+
let val = if likely(radix <= 10) {
338+
// If not a digit, a number greater than radix will be created.
339+
(self as u32).wrapping_sub('0' as u32)
340340
} else {
341-
assert!(radix <= 36, "to_digit: radix is too high (maximum 36)");
342-
343341
match self {
344342
'0'..='9' => self as u32 - '0' as u32,
345343
'a'..='z' => self as u32 - 'a' as u32 + 10,

library/core/src/iter/traits/iterator.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -3327,24 +3327,31 @@ pub trait Iterator {
33273327
///
33283328
/// [`is_sorted`]: Iterator::is_sorted
33293329
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
3330-
fn is_sorted_by<F>(mut self, mut compare: F) -> bool
3330+
fn is_sorted_by<F>(mut self, compare: F) -> bool
33313331
where
33323332
Self: Sized,
33333333
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
33343334
{
3335+
#[inline]
3336+
fn check<'a, T>(
3337+
last: &'a mut T,
3338+
mut compare: impl FnMut(&T, &T) -> Option<Ordering> + 'a,
3339+
) -> impl FnMut(T) -> bool + 'a {
3340+
move |curr| {
3341+
if let Some(Ordering::Greater) | None = compare(&last, &curr) {
3342+
return false;
3343+
}
3344+
*last = curr;
3345+
true
3346+
}
3347+
}
3348+
33353349
let mut last = match self.next() {
33363350
Some(e) => e,
33373351
None => return true,
33383352
};
33393353

3340-
while let Some(curr) = self.next() {
3341-
if let Some(Ordering::Greater) | None = compare(&last, &curr) {
3342-
return false;
3343-
}
3344-
last = curr;
3345-
}
3346-
3347-
true
3354+
self.all(check(&mut last, compare))
33483355
}
33493356

33503357
/// Checks if the elements of this iterator are sorted using the given key extraction

library/core/src/macros/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,8 @@ pub(crate) mod builtin {
12091209
///
12101210
/// This macro has a second form, where a custom panic message can
12111211
/// be provided with or without arguments for formatting. See [`std::fmt`]
1212-
/// for syntax for this form.
1212+
/// for syntax for this form. Expressions used as format arguments will only
1213+
/// be evaluated if the assertion fails.
12131214
///
12141215
/// [`std::fmt`]: ../std/fmt/index.html
12151216
///

0 commit comments

Comments
 (0)