Auto merge of #82235 - GuillaumeGomez:rollup-oflxc08, r=GuillaumeGomez

Rollup of 11 pull requests

Successful merges:

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

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2021-02-17 19:39:58 +00:00
commit 152f660924
34 changed files with 280 additions and 105 deletions

View File

@ -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);
}
}

View File

@ -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);
}
};

View File

@ -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);
}
}
}

View File

@ -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<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);
}
}
}
}
@ -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(())
}

View File

@ -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

View File

@ -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

View File

@ -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();
});
}
}

View File

@ -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),
);
}
}

View File

@ -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(

View File

@ -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<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,

View File

@ -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

View File

@ -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
///

View File

@ -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
///

@ -1 +1 @@
Subproject commit e724bd826580ff95df48a8533af7dec1080693d4
Subproject commit db5e8a5105aa22979490dce30e33b68d8645761d

@ -1 +1 @@
Subproject commit b91a9a881ee007c12e74e844460ec407cf07a50f
Subproject commit 1da3c411f17adb1ba5de1683bb6acee83362b54a

@ -1 +1 @@
Subproject commit ceec19e873be87c6ee5666b030c6bb612f889a96
Subproject commit 4cf7981696a85c3e633076c6401611bd3f6346c4

@ -1 +1 @@
Subproject commit bbf06ad39d1f45654047e9596b750cc6e6d1b693
Subproject commit adca786547d08fe676b2fc7a6f08c2ed5280ca38

@ -1 +1 @@
Subproject commit f02b09eb6e8af340ad1256a54adb7aae2ff3163e
Subproject commit 361367c126290ac17cb4089f8d38fd8b2ac43f98

@ -1 +1 @@
Subproject commit f633769acef68574427a6fae6c06f13bc2199573
Subproject commit 551cc4bc8394feccea6acd21f86d9a4e1d2271a0

View File

@ -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);

View File

@ -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<MarketMultiplier>) -> 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>(T);
fn main() {}

View File

@ -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<MarketMultiplier>) -> 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>(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<MarketMultiplier>) -> 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>(T);
| ^^^^^^^^^^^^ -
help: add missing type argument
|
LL | async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> 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`.

View File

@ -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"]

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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`
}

View File

@ -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`

View File

@ -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"));
}

View File

@ -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`.