diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 8b737c9a2e5..5f8a11ab94e 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -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, @@ -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); } } diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 6c58417590e..972b9bbfe1c 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -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}; @@ -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)); + } } } @@ -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); } }; diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 6aef5cb535a..b0aed812460 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -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; @@ -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 @@ -642,19 +642,19 @@ 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); } } } @@ -662,13 +662,13 @@ fn produce_final_output_artifacts( 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); } } } diff --git a/compiler/rustc_driver/src/pretty.rs b/compiler/rustc_driver/src/pretty.rs index b2e201c5ff2..17d2b3386f5 100644 --- a/compiler/rustc_driver/src/pretty.rs +++ b/compiler/rustc_driver/src/pretty.rs @@ -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::*; @@ -375,13 +373,14 @@ fn get_source(input: &Input, sess: &Session) -> (String, FileName) { (src, src_name) } -fn write_output(out: Vec, 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); + } + } } } @@ -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>( @@ -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 @@ -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(()) } diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index cccc0e05600..8944711f38f 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -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"), @@ -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 diff --git a/compiler/rustc_error_codes/src/error_codes/E0543.md b/compiler/rustc_error_codes/src/error_codes/E0543.md new file mode 100644 index 00000000000..ba26f92e89f --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0543.md @@ -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 diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 4d70e33c607..792655ff35a 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -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 `{}{}`", @@ -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(); @@ -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(); }); } } diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs index 63a3e269d61..03738f1b40a 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs @@ -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), ); } } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 210dbb0ee99..4533b37f10b 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -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( diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index e450240527a..64ae7db0d9b 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -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; @@ -330,16 +331,13 @@ impl char { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn to_digit(self, radix: u32) -> Option { + 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, diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 5faa4b82560..a38b35a5b5c 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -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(mut self, mut compare: F) -> bool + fn is_sorted_by(mut self, compare: F) -> bool where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Option, { + #[inline] + fn check<'a, T>( + last: &'a mut T, + mut compare: impl FnMut(&T, &T) -> Option + '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 diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index b3802c1abde..97315769957 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -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 /// diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 1889e549338..581c09e23df 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2321,7 +2321,9 @@ impl Path { } /// Returns an object that implements [`Display`] for safely printing paths - /// that may contain non-Unicode data. + /// that may contain non-Unicode data. This may perform lossy conversion, + /// depending on the platform. If you would like an implementation which + /// escapes the path please use [`Debug`] instead. /// /// [`Display`]: fmt::Display /// @@ -2555,7 +2557,9 @@ impl fmt::Debug for Path { /// /// A [`Path`] might contain non-Unicode data. This `struct` implements the /// [`Display`] trait in a way that mitigates that. It is created by the -/// [`display`](Path::display) method on [`Path`]. +/// [`display`](Path::display) method on [`Path`]. This may perform lossy +/// conversion, depending on the platform. If you would like an implementation +/// which escapes the path please use [`Debug`] instead. /// /// # Examples /// diff --git a/src/doc/book b/src/doc/book index e724bd82658..db5e8a5105a 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit e724bd826580ff95df48a8533af7dec1080693d4 +Subproject commit db5e8a5105aa22979490dce30e33b68d8645761d diff --git a/src/doc/edition-guide b/src/doc/edition-guide index b91a9a881ee..1da3c411f17 160000 --- a/src/doc/edition-guide +++ b/src/doc/edition-guide @@ -1 +1 @@ -Subproject commit b91a9a881ee007c12e74e844460ec407cf07a50f +Subproject commit 1da3c411f17adb1ba5de1683bb6acee83362b54a diff --git a/src/doc/embedded-book b/src/doc/embedded-book index ceec19e873b..4cf7981696a 160000 --- a/src/doc/embedded-book +++ b/src/doc/embedded-book @@ -1 +1 @@ -Subproject commit ceec19e873be87c6ee5666b030c6bb612f889a96 +Subproject commit 4cf7981696a85c3e633076c6401611bd3f6346c4 diff --git a/src/doc/nomicon b/src/doc/nomicon index bbf06ad39d1..adca786547d 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit bbf06ad39d1f45654047e9596b750cc6e6d1b693 +Subproject commit adca786547d08fe676b2fc7a6f08c2ed5280ca38 diff --git a/src/doc/reference b/src/doc/reference index f02b09eb6e8..361367c1262 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit f02b09eb6e8af340ad1256a54adb7aae2ff3163e +Subproject commit 361367c126290ac17cb4089f8d38fd8b2ac43f98 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index f633769acef..551cc4bc839 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit f633769acef68574427a6fae6c06f13bc2199573 +Subproject commit 551cc4bc8394feccea6acd21f86d9a4e1d2271a0 diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 63a25e5dbfb..1478437cefa 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -16,7 +16,7 @@ use rustc_session::config::{CodegenOptions, DebuggingOptions, ErrorOutputType, E use rustc_session::getopts; use rustc_session::lint::Level; use rustc_session::search_paths::SearchPath; -use rustc_span::edition::{Edition, DEFAULT_EDITION}; +use rustc_span::edition::Edition; use rustc_target::spec::TargetTriple; use crate::core::new_handler; @@ -469,17 +469,7 @@ impl Options { } } - let edition = if let Some(e) = matches.opt_str("edition") { - match e.parse() { - Ok(e) => e, - Err(_) => { - diag.struct_err("could not parse edition").emit(); - return Err(1); - } - } - } else { - DEFAULT_EDITION - }; + let edition = config::parse_crate_edition(&matches); let mut id_map = html::markdown::IdMap::new(); id_map.populate(&html::render::INITIAL_IDS); diff --git a/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs b/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs new file mode 100644 index 00000000000..2e6b88a4beb --- /dev/null +++ b/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs @@ -0,0 +1,25 @@ +// Regression test for #82126. Checks that mismatched lifetimes and types are +// properly handled. + +// edition:2018 + +use std::sync::Mutex; + +struct MarketMultiplier {} + +impl MarketMultiplier { + fn buy(&mut self) -> &mut usize { + todo!() + } +} + +async fn buy_lock(generator: &Mutex) -> LockedMarket<'_> { + //~^ ERROR this struct takes 0 lifetime arguments but 1 lifetime argument was supplied + //~^^ ERROR this struct takes 1 type argument but 0 type arguments were supplied + LockedMarket(generator.lock().unwrap().buy()) + //~^ ERROR cannot return value referencing temporary value +} + +struct LockedMarket(T); + +fn main() {} diff --git a/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr b/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr new file mode 100644 index 00000000000..b6844f50488 --- /dev/null +++ b/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr @@ -0,0 +1,43 @@ +error[E0107]: this struct takes 0 lifetime arguments but 1 lifetime argument was supplied + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 + | +LL | async fn buy_lock(generator: &Mutex) -> LockedMarket<'_> { + | ^^^^^^^^^^^^---- help: remove these generics + | | + | expected 0 lifetime arguments + | +note: struct defined here, with 0 lifetime parameters + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:23:8 + | +LL | struct LockedMarket(T); + | ^^^^^^^^^^^^ + +error[E0107]: this struct takes 1 type argument but 0 type arguments were supplied + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 + | +LL | async fn buy_lock(generator: &Mutex) -> LockedMarket<'_> { + | ^^^^^^^^^^^^ expected 1 type argument + | +note: struct defined here, with 1 type parameter: `T` + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:23:8 + | +LL | struct LockedMarket(T); + | ^^^^^^^^^^^^ - +help: add missing type argument + | +LL | async fn buy_lock(generator: &Mutex) -> LockedMarket<'_, T> { + | ^^^ + +error[E0515]: cannot return value referencing temporary value + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:19:5 + | +LL | LockedMarket(generator.lock().unwrap().buy()) + | ^^^^^^^^^^^^^-------------------------^^^^^^^ + | | | + | | temporary value created here + | returns a value referencing data owned by the current function + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0107, E0515. +For more information about an error, try `rustc --explain E0107`. diff --git a/src/test/ui/debuginfo-emit-llvm-ir-and-split-debuginfo.rs b/src/test/ui/debuginfo-emit-llvm-ir-and-split-debuginfo.rs new file mode 100644 index 00000000000..043011b3316 --- /dev/null +++ b/src/test/ui/debuginfo-emit-llvm-ir-and-split-debuginfo.rs @@ -0,0 +1,7 @@ +// build-pass +// +// compile-flags: -g --emit=llvm-ir -Zunstable-options -Csplit-debuginfo=unpacked +// +// Make sure that we don't explode with an error if we don't actually end up emitting any `dwo`s, +// as would be the case if we don't actually codegen anything. +#![crate_type="rlib"] diff --git a/src/test/ui/enum/enum-discrim-too-small2.stderr b/src/test/ui/enum/enum-discrim-too-small2.stderr index fadf6ab86b4..43830679535 100644 --- a/src/test/ui/enum/enum-discrim-too-small2.stderr +++ b/src/test/ui/enum/enum-discrim-too-small2.stderr @@ -10,6 +10,7 @@ note: the lint level is defined here LL | #![deny(overflowing_literals)] | ^^^^^^^^^^^^^^^^^^^^ = note: the literal `223` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `u8` instead error: literal out of range for `i16` --> $DIR/enum-discrim-too-small2.rs:15:12 @@ -18,6 +19,7 @@ LL | Ci16 = 55555, | ^^^^^ | = note: the literal `55555` does not fit into the type `i16` whose range is `-32768..=32767` + = help: consider using the type `u16` instead error: literal out of range for `i32` --> $DIR/enum-discrim-too-small2.rs:22:12 @@ -26,6 +28,7 @@ LL | Ci32 = 3_000_000_000, | ^^^^^^^^^^^^^ | = note: the literal `3_000_000_000` does not fit into the type `i32` whose range is `-2147483648..=2147483647` + = help: consider using the type `u32` instead error: literal out of range for `i64` --> $DIR/enum-discrim-too-small2.rs:29:12 @@ -34,6 +37,7 @@ LL | Ci64 = 9223372036854775809, | ^^^^^^^^^^^^^^^^^^^ | = note: the literal `9223372036854775809` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807` + = help: consider using the type `u64` instead error: aborting due to 4 previous errors diff --git a/src/test/ui/issues/issue-79744.rs b/src/test/ui/issues/issue-79744.rs new file mode 100644 index 00000000000..e9725a027d3 --- /dev/null +++ b/src/test/ui/issues/issue-79744.rs @@ -0,0 +1,13 @@ +fn main() { + let elem = 6i8; + let e2 = 230; + //~^ ERROR literal out of range for `i8` + //~| HELP consider using the type `u8` instead + + let mut vec = Vec::new(); + + vec.push(e2); + vec.push(elem); + + println!("{:?}", vec); +} diff --git a/src/test/ui/issues/issue-79744.stderr b/src/test/ui/issues/issue-79744.stderr new file mode 100644 index 00000000000..6f6dd44d236 --- /dev/null +++ b/src/test/ui/issues/issue-79744.stderr @@ -0,0 +1,12 @@ +error: literal out of range for `i8` + --> $DIR/issue-79744.rs:3:14 + | +LL | let e2 = 230; + | ^^^ + | + = note: `#[deny(overflowing_literals)]` on by default + = note: the literal `230` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `u8` instead + +error: aborting due to previous error + diff --git a/src/test/ui/lint/lint-type-limits2.stderr b/src/test/ui/lint/lint-type-limits2.stderr index e8746ce980a..3562cb440a6 100644 --- a/src/test/ui/lint/lint-type-limits2.stderr +++ b/src/test/ui/lint/lint-type-limits2.stderr @@ -18,6 +18,7 @@ note: the lint level is defined here LL | #![warn(overflowing_literals)] | ^^^^^^^^^^^^^^^^^^^^ = note: the literal `128` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `u8` instead error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/lint/lint-type-limits3.stderr b/src/test/ui/lint/lint-type-limits3.stderr index 0e8a6451069..823d1a4c76f 100644 --- a/src/test/ui/lint/lint-type-limits3.stderr +++ b/src/test/ui/lint/lint-type-limits3.stderr @@ -18,6 +18,7 @@ note: the lint level is defined here LL | #![warn(overflowing_literals)] | ^^^^^^^^^^^^^^^^^^^^ = note: the literal `200` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `u8` instead error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/lint/lint-type-overflow.stderr b/src/test/ui/lint/lint-type-overflow.stderr index 7715c0d3a4d..1bb1ec54776 100644 --- a/src/test/ui/lint/lint-type-overflow.stderr +++ b/src/test/ui/lint/lint-type-overflow.stderr @@ -26,6 +26,7 @@ LL | let x1: i8 = 128; | ^^^ | = note: the literal `128` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `u8` instead error: literal out of range for `i8` --> $DIR/lint-type-overflow.rs:18:19 @@ -34,6 +35,7 @@ LL | let x3: i8 = -129; | ^^^ | = note: the literal `129` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `i16` instead error: literal out of range for `i8` --> $DIR/lint-type-overflow.rs:19:19 @@ -42,6 +44,7 @@ LL | let x3: i8 = -(129); | ^^^^^ | = note: the literal `129` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `i16` instead error: literal out of range for `i8` --> $DIR/lint-type-overflow.rs:20:20 @@ -50,6 +53,7 @@ LL | let x3: i8 = -{129}; | ^^^ | = note: the literal `129` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `u8` instead error: literal out of range for `i8` --> $DIR/lint-type-overflow.rs:22:10 @@ -58,6 +62,7 @@ LL | test(1000); | ^^^^ | = note: the literal `1000` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `i16` instead error: literal out of range for `i8` --> $DIR/lint-type-overflow.rs:24:13 @@ -66,6 +71,7 @@ LL | let x = 128_i8; | ^^^^^^ | = note: the literal `128_i8` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `u8` instead error: literal out of range for `i8` --> $DIR/lint-type-overflow.rs:28:14 @@ -74,6 +80,7 @@ LL | let x = -129_i8; | ^^^^^^ | = note: the literal `129_i8` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `i16` instead error: literal out of range for `i32` --> $DIR/lint-type-overflow.rs:32:18 @@ -82,6 +89,7 @@ LL | let x: i32 = 2147483648; | ^^^^^^^^^^ | = note: the literal `2147483648` does not fit into the type `i32` whose range is `-2147483648..=2147483647` + = help: consider using the type `u32` instead error: literal out of range for `i32` --> $DIR/lint-type-overflow.rs:33:13 @@ -90,6 +98,7 @@ LL | let x = 2147483648_i32; | ^^^^^^^^^^^^^^ | = note: the literal `2147483648_i32` does not fit into the type `i32` whose range is `-2147483648..=2147483647` + = help: consider using the type `u32` instead error: literal out of range for `i32` --> $DIR/lint-type-overflow.rs:36:19 @@ -98,6 +107,7 @@ LL | let x: i32 = -2147483649; | ^^^^^^^^^^ | = note: the literal `2147483649` does not fit into the type `i32` whose range is `-2147483648..=2147483647` + = help: consider using the type `i64` instead error: literal out of range for `i32` --> $DIR/lint-type-overflow.rs:37:14 @@ -106,6 +116,7 @@ LL | let x = -2147483649_i32; | ^^^^^^^^^^^^^^ | = note: the literal `2147483649_i32` does not fit into the type `i32` whose range is `-2147483648..=2147483647` + = help: consider using the type `i64` instead error: literal out of range for `i32` --> $DIR/lint-type-overflow.rs:38:13 @@ -114,6 +125,7 @@ LL | let x = 2147483648; | ^^^^^^^^^^ | = note: the literal `2147483648` does not fit into the type `i32` whose range is `-2147483648..=2147483647` + = help: consider using the type `u32` instead error: literal out of range for `i64` --> $DIR/lint-type-overflow.rs:40:13 @@ -122,6 +134,7 @@ LL | let x = 9223372036854775808_i64; | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: the literal `9223372036854775808_i64` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807` + = help: consider using the type `u64` instead error: literal out of range for `i64` --> $DIR/lint-type-overflow.rs:42:13 @@ -130,6 +143,7 @@ LL | let x = 18446744073709551615_i64; | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the literal `18446744073709551615_i64` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807` + = help: consider using the type `u64` instead error: literal out of range for `i64` --> $DIR/lint-type-overflow.rs:43:19 @@ -138,6 +152,7 @@ LL | let x: i64 = -9223372036854775809; | ^^^^^^^^^^^^^^^^^^^ | = note: the literal `9223372036854775809` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807` + = help: consider using the type `i128` instead error: literal out of range for `i64` --> $DIR/lint-type-overflow.rs:44:14 @@ -146,6 +161,7 @@ LL | let x = -9223372036854775809_i64; | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: the literal `9223372036854775809_i64` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807` + = help: consider using the type `i128` instead error: aborting due to 18 previous errors diff --git a/src/test/ui/lint/lint-type-overflow2.stderr b/src/test/ui/lint/lint-type-overflow2.stderr index 0f16229a291..3d40cdf96ef 100644 --- a/src/test/ui/lint/lint-type-overflow2.stderr +++ b/src/test/ui/lint/lint-type-overflow2.stderr @@ -10,6 +10,7 @@ note: the lint level is defined here LL | #![deny(overflowing_literals)] | ^^^^^^^^^^^^^^^^^^^^ = note: the literal `128` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `u8` instead error: literal out of range for `f32` --> $DIR/lint-type-overflow2.rs:9:14 diff --git a/src/test/ui/lint/type-overflow.rs b/src/test/ui/lint/type-overflow.rs index e40321e56bf..6234b794c1f 100644 --- a/src/test/ui/lint/type-overflow.rs +++ b/src/test/ui/lint/type-overflow.rs @@ -7,16 +7,16 @@ fn main() { let ok = 0b1000_0001; // should be ok -> i32 let ok = 0b0111_1111i8; // should be ok -> 127i8 - let fail = 0b1000_0001i8; //~WARNING literal out of range for i8 + let fail = 0b1000_0001i8; //~WARNING literal out of range for `i8` - let fail = 0x8000_0000_0000_0000i64; //~WARNING literal out of range for i64 + let fail = 0x8000_0000_0000_0000i64; //~WARNING literal out of range for `i64` - let fail = 0x1_FFFF_FFFFu32; //~WARNING literal out of range for u32 + let fail = 0x1_FFFF_FFFFu32; //~WARNING literal out of range for `u32` let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000; - //~^ WARNING literal out of range for i128 + //~^ WARNING literal out of range for `i128` - let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for i32 + let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for `i32` - let fail = -0b1111_1111i8; //~WARNING literal out of range for i8 + let fail = -0b1111_1111i8; //~WARNING literal out of range for `i8` } diff --git a/src/test/ui/lint/type-overflow.stderr b/src/test/ui/lint/type-overflow.stderr index 6ba8b43954d..521223e3256 100644 --- a/src/test/ui/lint/type-overflow.stderr +++ b/src/test/ui/lint/type-overflow.stderr @@ -10,54 +10,55 @@ note: the lint level is defined here LL | #![warn(overflowing_literals)] | ^^^^^^^^^^^^^^^^^^^^ = note: the literal `255i8` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `u8` instead -warning: literal out of range for i8 +warning: literal out of range for `i8` --> $DIR/type-overflow.rs:10:16 | LL | let fail = 0b1000_0001i8; - | ^^^^^^^^^^^^^ help: consider using `u8` instead: `0b1000_0001u8` + | ^^^^^^^^^^^^^ help: consider using the type `u8` instead: `0b1000_0001u8` | = note: the literal `0b1000_0001i8` (decimal `129`) does not fit into the type `i8` and will become `-127i8` -warning: literal out of range for i64 +warning: literal out of range for `i64` --> $DIR/type-overflow.rs:12:16 | LL | let fail = 0x8000_0000_0000_0000i64; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `u64` instead: `0x8000_0000_0000_0000u64` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the type `u64` instead: `0x8000_0000_0000_0000u64` | = note: the literal `0x8000_0000_0000_0000i64` (decimal `9223372036854775808`) does not fit into the type `i64` and will become `-9223372036854775808i64` -warning: literal out of range for u32 +warning: literal out of range for `u32` --> $DIR/type-overflow.rs:14:16 | LL | let fail = 0x1_FFFF_FFFFu32; - | ^^^^^^^^^^^^^^^^ help: consider using `u64` instead: `0x1_FFFF_FFFFu64` + | ^^^^^^^^^^^^^^^^ help: consider using the type `u64` instead: `0x1_FFFF_FFFFu64` | = note: the literal `0x1_FFFF_FFFFu32` (decimal `8589934591`) does not fit into the type `u32` and will become `4294967295u32` -warning: literal out of range for i128 +warning: literal out of range for `i128` --> $DIR/type-overflow.rs:16:22 | LL | let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the literal `0x8000_0000_0000_0000_0000_0000_0000_0000` (decimal `170141183460469231731687303715884105728`) does not fit into the type `i128` and will become `-170141183460469231731687303715884105728i128` - = help: consider using `u128` instead + = help: consider using the type `u128` instead -warning: literal out of range for i32 +warning: literal out of range for `i32` --> $DIR/type-overflow.rs:19:16 | LL | let fail = 0x8FFF_FFFF_FFFF_FFFE; | ^^^^^^^^^^^^^^^^^^^^^ | = note: the literal `0x8FFF_FFFF_FFFF_FFFE` (decimal `10376293541461622782`) does not fit into the type `i32` and will become `-2i32` - = help: consider using `i128` instead + = help: consider using the type `i128` instead -warning: literal out of range for i8 +warning: literal out of range for `i8` --> $DIR/type-overflow.rs:21:17 | LL | let fail = -0b1111_1111i8; - | ^^^^^^^^^^^^^ help: consider using `i16` instead: `0b1111_1111i16` + | ^^^^^^^^^^^^^ help: consider using the type `i16` instead: `0b1111_1111i16` | = note: the literal `0b1111_1111i8` (decimal `255`) does not fit into the type `i8` and will become `-1i8` diff --git a/src/test/ui/macros/assert-format-lazy.rs b/src/test/ui/macros/assert-format-lazy.rs new file mode 100644 index 00000000000..c7f05d763b7 --- /dev/null +++ b/src/test/ui/macros/assert-format-lazy.rs @@ -0,0 +1,12 @@ +// run-pass +// compile-flags: -C debug_assertions=yes + +#[allow(unreachable_code)] +fn main() { + assert!(true, "Failed: {:?}", panic!("assert! evaluated format expressions")); + debug_assert!(true, "Failed: {:?}", panic!("debug_assert! evaluated format expressions")); + assert_eq!(1, 1, "Failed: {:?}", panic!("assert_eq! evaluated format expressions")); + debug_assert_eq!(1, 1, "Failed: {:?}", panic!("debug_assert_eq! evaluated format expressions")); + assert_ne!(1, 2, "Failed: {:?}", panic!("assert_ne! evaluated format expressions")); + debug_assert_ne!(1, 2, "Failed: {:?}", panic!("debug_assert_ne! evaluated format expressions")); +} diff --git a/src/test/ui/stability-attribute/stability-attribute-sanity.stderr b/src/test/ui/stability-attribute/stability-attribute-sanity.stderr index 674139f4afc..715eb00974e 100644 --- a/src/test/ui/stability-attribute/stability-attribute-sanity.stderr +++ b/src/test/ui/stability-attribute/stability-attribute-sanity.stderr @@ -116,5 +116,5 @@ LL | #[rustc_deprecated(since = "a", reason = "text")] error: aborting due to 19 previous errors -Some errors have detailed explanations: E0539, E0541, E0542, E0546, E0547, E0550. +Some errors have detailed explanations: E0539, E0541, E0542, E0543, E0546, E0547, E0550. For more information about an error, try `rustc --explain E0539`.