From 4d3cf5bd9b6c48e5116fb8d9747a7a2dbde09d1d Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 26 Apr 2020 19:07:13 +0200 Subject: [PATCH 01/12] use new interface to create threads on HermitCore - the new interface allows to define the stack size --- Cargo.lock | 4 ++-- src/libstd/Cargo.toml | 2 +- src/libstd/sys/hermit/thread.rs | 13 ++++++------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 816d65cb2ce23..0f9f2c6b4fb07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1366,9 +1366,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" +checksum = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4" dependencies = [ "compiler_builtins", "libc", diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index ceb39c01c6723..923d5fa8cacdb 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -41,7 +41,7 @@ dlmalloc = { version = "0.1", features = ['rustc-dep-of-std'] } fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] } [target.'cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), target_os = "hermit"))'.dependencies] -hermit-abi = { version = "0.1.10", features = ['rustc-dep-of-std'] } +hermit-abi = { version = "0.1.12", features = ['rustc-dep-of-std'] } [target.wasm32-wasi.dependencies] wasi = { version = "0.9.0", features = ['rustc-dep-of-std'], default-features = false } diff --git a/src/libstd/sys/hermit/thread.rs b/src/libstd/sys/hermit/thread.rs index 7e3fb4c6d2052..55924ee0e6885 100644 --- a/src/libstd/sys/hermit/thread.rs +++ b/src/libstd/sys/hermit/thread.rs @@ -16,25 +16,24 @@ pub struct Thread { unsafe impl Send for Thread {} unsafe impl Sync for Thread {} -pub const DEFAULT_MIN_STACK_SIZE: usize = 262144; +pub const DEFAULT_MIN_STACK_SIZE: usize = 1_048_576; impl Thread { pub unsafe fn new_with_coreid( - _stack: usize, + stack: usize, p: Box, core_id: isize, ) -> io::Result { let p = Box::into_raw(box p); - let mut tid: Tid = u32::MAX; - let ret = abi::spawn( - &mut tid as *mut Tid, + let tid = abi::spawn2( thread_start, - &*p as *const _ as *const u8 as usize, + p as usize, abi::Priority::into(abi::NORMAL_PRIO), + stack, core_id, ); - return if ret != 0 { + return if tid == 0 { // The thread failed to start and as a result p was not consumed. Therefore, it is // safe to reconstruct the box so that it gets deallocated. drop(Box::from_raw(p)); From 2c43746758f4bc60bd4dda30a761cf48d1f60635 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 27 Apr 2020 13:18:33 +0200 Subject: [PATCH 02/12] use nicer code style to define DEFAULT_MIN_STACK_SIZE --- src/libstd/sys/hermit/thread.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sys/hermit/thread.rs b/src/libstd/sys/hermit/thread.rs index 55924ee0e6885..e11afed668728 100644 --- a/src/libstd/sys/hermit/thread.rs +++ b/src/libstd/sys/hermit/thread.rs @@ -16,7 +16,7 @@ pub struct Thread { unsafe impl Send for Thread {} unsafe impl Sync for Thread {} -pub const DEFAULT_MIN_STACK_SIZE: usize = 1_048_576; +pub const DEFAULT_MIN_STACK_SIZE: usize = 1 << 20; impl Thread { pub unsafe fn new_with_coreid( From 9bcf4097e33d8982b57c063f6481f7dd453bb0aa Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 2 May 2020 20:54:28 -0400 Subject: [PATCH 03/12] x.py: Give a more helpful error message if curl isn't installed This also abstracts checking for a command into `require`. Before: ``` Updating only changed submodules Submodules updated in 0.01 seconds Traceback (most recent call last): File "./x.py", line 11, in bootstrap.main() ... File "/home/joshua/src/rust/src/bootstrap/bootstrap.py", line 137, in run ret = subprocess.Popen(args, **kwargs) File "/usr/lib/python2.7/subprocess.py", line 394, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory ``` After: ``` error: unable to run `curl --version`: [Errno 2] No such file or directory Please make sure it's installed and in the path. ``` --- src/bootstrap/bootstrap.py | 48 ++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 2aa3f9c7ec04b..9e56dd3770d46 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -79,6 +79,7 @@ def _download(path, url, probably_big, verbose, exception): option = "-#" else: option = "-s" + require(["curl", "--version"]) run(["curl", option, "-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds "--connect-timeout", "30", # timeout if cannot connect within 30 seconds @@ -143,6 +144,21 @@ def run(args, verbose=False, exception=False, **kwargs): sys.exit(err) +def require(cmd, exit=True): + '''Run a command, returning its output. + On error, + If `exit` is `True`, exit the process. + Otherwise, return None.''' + try: + return subprocess.check_output(cmd).strip() + except (subprocess.CalledProcessError, OSError) as exc: + if not exit: + return None + print("error: unable to run `{}`: {}".format(' '.join(cmd), exc)) + print("Please make sure it's installed and in the path.") + sys.exit(1) + + def stage0_data(rust_root): """Build a dictionary from stage0.txt""" nightlies = os.path.join(rust_root, "src/stage0.txt") @@ -164,16 +180,12 @@ def format_build_time(duration): def default_build_triple(): """Build triple as in LLVM""" default_encoding = sys.getdefaultencoding() - try: - ostype = subprocess.check_output( - ['uname', '-s']).strip().decode(default_encoding) - cputype = subprocess.check_output( - ['uname', '-m']).strip().decode(default_encoding) - except (subprocess.CalledProcessError, OSError): - if sys.platform == 'win32': - return 'x86_64-pc-windows-msvc' - err = "uname not found" - sys.exit(err) + required = not sys.platform == 'win32' + ostype = require(["uname", "-s"], exit=required).decode(default_encoding) + cputype = require(['uname', '-m'], exit=required).decode(default_encoding) + + if ostype is None or cputype is None: + return 'x86_64-pc-windows-msvc' # The goal here is to come up with the same triple as LLVM would, # at least for the subset of platforms we're willing to target. @@ -203,12 +215,7 @@ def default_build_triple(): # output from that option is too generic for our purposes (it will # always emit 'i386' on x86/amd64 systems). As such, isainfo -k # must be used instead. - try: - cputype = subprocess.check_output( - ['isainfo', '-k']).strip().decode(default_encoding) - except (subprocess.CalledProcessError, OSError): - err = "isainfo not found" - sys.exit(err) + cputype = require(['isainfo', '-k']).decode(default_encoding) elif ostype.startswith('MINGW'): # msys' `uname` does not print gcc configuration, but prints msys # configuration. so we cannot believe `uname -m`: @@ -766,13 +773,8 @@ def update_submodules(self): default_encoding = sys.getdefaultencoding() # check the existence and version of 'git' command - try: - git_version_output = subprocess.check_output(['git', '--version']) - git_version_str = git_version_output.strip().split()[2].decode(default_encoding) - self.git_version = distutils.version.LooseVersion(git_version_str) - except (subprocess.CalledProcessError, OSError): - print("error: `git` is not found, please make sure it's installed and in the path.") - sys.exit(1) + git_version_str = require(['git', '--version']).split()[2].decode(default_encoding) + self.git_version = distutils.version.LooseVersion(git_version_str) slow_submodules = self.get_toml('fast-submodules') == "false" start_time = time() From 9c93b883d186008d6ccb96993299a0dd4c90084c Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Mon, 4 May 2020 12:49:10 -0700 Subject: [PATCH 04/12] Export dataflow impls by name --- src/librustc_mir/dataflow/impls/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/dataflow/impls/mod.rs b/src/librustc_mir/dataflow/impls/mod.rs index 222ae137d96e2..e199a174efbc3 100644 --- a/src/librustc_mir/dataflow/impls/mod.rs +++ b/src/librustc_mir/dataflow/impls/mod.rs @@ -21,14 +21,14 @@ use super::on_lookup_result_bits; use crate::dataflow::drop_flag_effects; mod borrowed_locals; +pub(super) mod borrows; mod liveness; mod storage_liveness; -pub use self::borrowed_locals::*; +pub use self::borrowed_locals::{MaybeBorrowedLocals, MaybeMutBorrowedLocals}; +pub use self::borrows::Borrows; pub use self::liveness::MaybeLiveLocals; -pub use self::storage_liveness::*; - -pub(super) mod borrows; +pub use self::storage_liveness::{MaybeRequiresStorage, MaybeStorageLive}; /// `MaybeInitializedPlaces` tracks all places that might be /// initialized upon reaching a particular point in the control flow From 095d1fdf1649c36967515310a5deedc5d46d11b5 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Mon, 4 May 2020 12:50:36 -0700 Subject: [PATCH 05/12] Import dataflow impls via the `impls` submodule --- src/librustc_mir/borrow_check/mod.rs | 6 +++--- src/librustc_mir/borrow_check/nll.rs | 2 +- src/librustc_mir/borrow_check/type_check/liveness/mod.rs | 2 +- .../borrow_check/type_check/liveness/trace.rs | 2 +- src/librustc_mir/borrow_check/type_check/mod.rs | 2 +- src/librustc_mir/dataflow/mod.rs | 7 +------ src/librustc_mir/transform/check_consts/validation.rs | 2 +- src/librustc_mir/transform/elaborate_drops.rs | 2 +- src/librustc_mir/transform/generator.rs | 4 ++-- src/librustc_mir/transform/rustc_peek.rs | 8 ++++---- 10 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 7d8a2b540a944..0df12d553aec0 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -32,13 +32,13 @@ use std::mem; use std::rc::Rc; use crate::dataflow; +use crate::dataflow::impls::{ + Borrows, EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces, +}; use crate::dataflow::indexes::{BorrowIndex, InitIndex, MoveOutIndex, MovePathIndex}; use crate::dataflow::move_paths::{InitLocation, LookupResult, MoveData, MoveError}; -use crate::dataflow::Borrows; -use crate::dataflow::EverInitializedPlaces; use crate::dataflow::MoveDataParamEnv; use crate::dataflow::{Analysis, BorrowckFlowState as Flows, BorrowckResults}; -use crate::dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces}; use crate::transform::MirSource; use self::diagnostics::{AccessKind, RegionName}; diff --git a/src/librustc_mir/borrow_check/nll.rs b/src/librustc_mir/borrow_check/nll.rs index e0cfcdb87a5a9..29636a067092b 100644 --- a/src/librustc_mir/borrow_check/nll.rs +++ b/src/librustc_mir/borrow_check/nll.rs @@ -21,8 +21,8 @@ use std::str::FromStr; use self::mir_util::PassWhere; use polonius_engine::{Algorithm, Output}; +use crate::dataflow::impls::MaybeInitializedPlaces; use crate::dataflow::move_paths::{InitKind, InitLocation, MoveData}; -use crate::dataflow::MaybeInitializedPlaces; use crate::dataflow::ResultsCursor; use crate::transform::MirSource; use crate::util as mir_util; diff --git a/src/librustc_mir/borrow_check/type_check/liveness/mod.rs b/src/librustc_mir/borrow_check/type_check/liveness/mod.rs index 717bfb8fe7de0..bddcd34ed3e47 100644 --- a/src/librustc_mir/borrow_check/type_check/liveness/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/liveness/mod.rs @@ -3,8 +3,8 @@ use rustc_middle::mir::{Body, Local}; use rustc_middle::ty::{RegionVid, TyCtxt}; use std::rc::Rc; +use crate::dataflow::impls::MaybeInitializedPlaces; use crate::dataflow::move_paths::MoveData; -use crate::dataflow::MaybeInitializedPlaces; use crate::dataflow::ResultsCursor; use crate::borrow_check::{ diff --git a/src/librustc_mir/borrow_check/type_check/liveness/trace.rs b/src/librustc_mir/borrow_check/type_check/liveness/trace.rs index 41c77cf21a76f..f04736e04a053 100644 --- a/src/librustc_mir/borrow_check/type_check/liveness/trace.rs +++ b/src/librustc_mir/borrow_check/type_check/liveness/trace.rs @@ -8,9 +8,9 @@ use rustc_trait_selection::traits::query::type_op::outlives::DropckOutlives; use rustc_trait_selection::traits::query::type_op::TypeOp; use std::rc::Rc; +use crate::dataflow::impls::MaybeInitializedPlaces; use crate::dataflow::indexes::MovePathIndex; use crate::dataflow::move_paths::{HasMoveData, MoveData}; -use crate::dataflow::MaybeInitializedPlaces; use crate::dataflow::ResultsCursor; use crate::borrow_check::{ diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 36ccc0aaa8bb4..7533bdfbd8d60 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -39,8 +39,8 @@ use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp; use rustc_trait_selection::traits::query::{Fallible, NoSolution}; use rustc_trait_selection::traits::{self, ObligationCause, PredicateObligations}; +use crate::dataflow::impls::MaybeInitializedPlaces; use crate::dataflow::move_paths::MoveData; -use crate::dataflow::MaybeInitializedPlaces; use crate::dataflow::ResultsCursor; use crate::transform::{ check_consts::ConstCx, diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index a05b4a5385d9c..ae1328dbd12c7 100644 --- a/src/librustc_mir/dataflow/mod.rs +++ b/src/librustc_mir/dataflow/mod.rs @@ -8,17 +8,12 @@ pub use self::framework::{ BottomValue, Engine, Forward, GenKill, GenKillAnalysis, Results, ResultsCursor, ResultsRefCursor, ResultsVisitor, }; -pub use self::impls::{ - borrows::Borrows, DefinitelyInitializedPlaces, EverInitializedPlaces, MaybeBorrowedLocals, - MaybeInitializedPlaces, MaybeLiveLocals, MaybeMutBorrowedLocals, MaybeRequiresStorage, - MaybeStorageLive, MaybeUninitializedPlaces, -}; use self::move_paths::MoveData; pub mod drop_flag_effects; mod framework; -mod impls; +pub mod impls; pub mod move_paths; pub(crate) mod indexes { diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index 3fd9131d5db76..1d03606f2537e 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -20,7 +20,7 @@ use super::qualifs::{self, CustomEq, HasMutInterior, NeedsDrop}; use super::resolver::FlowSensitiveAnalysis; use super::{is_lang_panic_fn, ConstCx, ConstKind, Qualif}; use crate::const_eval::{is_const_fn, is_unstable_const_fn}; -use crate::dataflow::MaybeMutBorrowedLocals; +use crate::dataflow::impls::MaybeMutBorrowedLocals; use crate::dataflow::{self, Analysis}; // We are using `MaybeMutBorrowedLocals` as a proxy for whether an item may have been mutated diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index a1becf062eea6..e379e5ee656b7 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -1,10 +1,10 @@ use crate::dataflow; +use crate::dataflow::impls::{MaybeInitializedPlaces, MaybeUninitializedPlaces}; use crate::dataflow::move_paths::{LookupResult, MoveData, MovePathIndex}; use crate::dataflow::on_lookup_result_bits; use crate::dataflow::MoveDataParamEnv; use crate::dataflow::{on_all_children_bits, on_all_drop_children_bits}; use crate::dataflow::{Analysis, ResultsCursor}; -use crate::dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces}; use crate::transform::{MirPass, MirSource}; use crate::util::elaborate_drops::{elaborate_drop, DropFlagState, Unwind}; use crate::util::elaborate_drops::{DropElaborator, DropFlagMode, DropStyle}; diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 25804c2a62cfe..b5e691ef029dd 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -49,10 +49,10 @@ //! For generators with state 1 (returned) and state 2 (poisoned) it does nothing. //! Otherwise it drops all the values in scope at the last suspension point. -use crate::dataflow::{self, Analysis}; -use crate::dataflow::{ +use crate::dataflow::impls::{ MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive, }; +use crate::dataflow::{self, Analysis}; use crate::transform::no_landing_pads::no_landing_pads; use crate::transform::simplify; use crate::transform::{MirPass, MirSource}; diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs index 43ddc0c914c03..5eb374e7ee2f1 100644 --- a/src/librustc_mir/transform/rustc_peek.rs +++ b/src/librustc_mir/transform/rustc_peek.rs @@ -9,14 +9,14 @@ use rustc_index::bit_set::BitSet; use rustc_middle::mir::{self, Body, Local, Location}; use rustc_middle::ty::{self, Ty, TyCtxt}; +use crate::dataflow::impls::{ + DefinitelyInitializedPlaces, MaybeInitializedPlaces, MaybeLiveLocals, MaybeMutBorrowedLocals, + MaybeUninitializedPlaces, +}; use crate::dataflow::move_paths::{HasMoveData, MoveData}; use crate::dataflow::move_paths::{LookupResult, MovePathIndex}; -use crate::dataflow::MaybeMutBorrowedLocals; use crate::dataflow::MoveDataParamEnv; use crate::dataflow::{Analysis, Results, ResultsCursor}; -use crate::dataflow::{ - DefinitelyInitializedPlaces, MaybeInitializedPlaces, MaybeLiveLocals, MaybeUninitializedPlaces, -}; pub struct SanityCheck; From 32d1a4b025716727bb9b350fcbddaad16ee1ab17 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Tue, 5 May 2020 12:41:23 -0700 Subject: [PATCH 06/12] Use -fvisibility=hidden for libunwind We don't want to export any symbols from Rust's version of libunwind as these may collide with other copies of libunwind e.g. when linking Rust staticlib together C/C++ libraries that have their own version. --- src/libunwind/build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libunwind/build.rs b/src/libunwind/build.rs index c8d2419ab4514..1462639259cb8 100644 --- a/src/libunwind/build.rs +++ b/src/libunwind/build.rs @@ -89,6 +89,7 @@ mod llvm_libunwind { cfg.flag("-fno-rtti"); cfg.flag("-fstrict-aliasing"); cfg.flag("-funwind-tables"); + cfg.flag("-fvisibility=hidden"); } let mut unwind_sources = vec![ From 7db74beaecc2cb51c76b08311cf68df1c92a5ae5 Mon Sep 17 00:00:00 2001 From: Mohsen Zohrevandi Date: Tue, 5 May 2020 18:12:50 -0700 Subject: [PATCH 07/12] Ignore SGX on a few ui tests --- src/test/ui/eprint-on-tls-drop.rs | 1 + src/test/ui/issues/issue-15487.rs | 1 + src/test/ui/issues/issue-17546.rs | 2 + src/test/ui/issues/issue-17546.stderr | 8 +- src/test/ui/lint/use_suggestion_json.rs | 1 + src/test/ui/lint/use_suggestion_json.stderr | 106 +++++++++--------- src/test/ui/proc-macro/crt-static.rs | 1 + src/test/ui/resolve/issue-16058.rs | 2 + src/test/ui/resolve/issue-16058.stderr | 2 +- src/test/ui/test-panic-abort-nocapture.rs | 1 + .../ui/test-panic-abort-nocapture.run.stderr | 4 +- src/test/ui/test-panic-abort.rs | 1 + src/test/ui/test-panic-abort.run.stdout | 2 +- 13 files changed, 71 insertions(+), 61 deletions(-) diff --git a/src/test/ui/eprint-on-tls-drop.rs b/src/test/ui/eprint-on-tls-drop.rs index 9c4800c1a3fa1..f5243077384ac 100644 --- a/src/test/ui/eprint-on-tls-drop.rs +++ b/src/test/ui/eprint-on-tls-drop.rs @@ -1,5 +1,6 @@ // run-pass // ignore-emscripten no processes +// ignore-sgx no processes use std::cell::RefCell; use std::env; diff --git a/src/test/ui/issues/issue-15487.rs b/src/test/ui/issues/issue-15487.rs index 98714cba0e42d..17b16a62a74e7 100644 --- a/src/test/ui/issues/issue-15487.rs +++ b/src/test/ui/issues/issue-15487.rs @@ -2,6 +2,7 @@ #![allow(unused_attributes)] // ignore-windows // ignore-wasm32-bare no libs to link +// ignore-sgx no libs to link #![feature(link_args)] diff --git a/src/test/ui/issues/issue-17546.rs b/src/test/ui/issues/issue-17546.rs index dbfdad25e5be8..6c62010f1762b 100644 --- a/src/test/ui/issues/issue-17546.rs +++ b/src/test/ui/issues/issue-17546.rs @@ -1,3 +1,5 @@ +// ignore-sgx std::os::fortanix_sgx::usercalls::raw::Result changes compiler suggestions + use foo::MyEnum::Result; use foo::NoResult; // Through a re-export diff --git a/src/test/ui/issues/issue-17546.stderr b/src/test/ui/issues/issue-17546.stderr index 5bbe6d3b17176..1236bbcdbf6ee 100644 --- a/src/test/ui/issues/issue-17546.stderr +++ b/src/test/ui/issues/issue-17546.stderr @@ -1,5 +1,5 @@ error[E0573]: expected type, found variant `NoResult` - --> $DIR/issue-17546.rs:12:17 + --> $DIR/issue-17546.rs:14:17 | LL | fn new() -> NoResult { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | fn new() -> Result { | ^^^^^^ error[E0573]: expected type, found variant `Result` - --> $DIR/issue-17546.rs:22:17 + --> $DIR/issue-17546.rs:24:17 | LL | fn new() -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a type @@ -37,7 +37,7 @@ LL | use std::result::Result; and 1 other candidate error[E0573]: expected type, found variant `Result` - --> $DIR/issue-17546.rs:28:13 + --> $DIR/issue-17546.rs:30:13 | LL | fn new() -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a type @@ -55,7 +55,7 @@ LL | use std::result::Result; and 1 other candidate error[E0573]: expected type, found variant `NoResult` - --> $DIR/issue-17546.rs:33:15 + --> $DIR/issue-17546.rs:35:15 | LL | fn newer() -> NoResult { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/lint/use_suggestion_json.rs b/src/test/ui/lint/use_suggestion_json.rs index 1828b8c2dc735..d7efa4aac6516 100644 --- a/src/test/ui/lint/use_suggestion_json.rs +++ b/src/test/ui/lint/use_suggestion_json.rs @@ -1,5 +1,6 @@ // ignore-cloudabi // ignore-windows +// ignore-sgx std::os::fortanix_sgx::usercalls::alloc::Iter changes compiler suggestions // compile-flags: --error-format pretty-json --json=diagnostic-rendered-ansi // The output for humans should just highlight the whole span without showing diff --git a/src/test/ui/lint/use_suggestion_json.stderr b/src/test/ui/lint/use_suggestion_json.stderr index 7176f17bc3fab..1d0b2a554f19a 100644 --- a/src/test/ui/lint/use_suggestion_json.stderr +++ b/src/test/ui/lint/use_suggestion_json.stderr @@ -72,10 +72,10 @@ mod foo { "spans": [ { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 471, - "byte_end": 475, - "line_start": 12, - "line_end": 12, + "byte_start": 560, + "byte_end": 564, + "line_start": 13, + "line_end": 13, "column_start": 12, "column_end": 16, "is_primary": true, @@ -100,10 +100,10 @@ mod foo { "spans": [ { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 448, - "byte_end": 448, - "line_start": 11, - "line_end": 11, + "byte_start": 537, + "byte_end": 537, + "line_start": 12, + "line_end": 12, "column_start": 1, "column_end": 1, "is_primary": true, @@ -123,10 +123,10 @@ mod foo { }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 448, - "byte_end": 448, - "line_start": 11, - "line_end": 11, + "byte_start": 537, + "byte_end": 537, + "line_start": 12, + "line_end": 12, "column_start": 1, "column_end": 1, "is_primary": true, @@ -146,10 +146,10 @@ mod foo { }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 448, - "byte_end": 448, - "line_start": 11, - "line_end": 11, + "byte_start": 537, + "byte_end": 537, + "line_start": 12, + "line_end": 12, "column_start": 1, "column_end": 1, "is_primary": true, @@ -169,10 +169,10 @@ mod foo { }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 448, - "byte_end": 448, - "line_start": 11, - "line_end": 11, + "byte_start": 537, + "byte_end": 537, + "line_start": 12, + "line_end": 12, "column_start": 1, "column_end": 1, "is_primary": true, @@ -192,10 +192,10 @@ mod foo { }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 448, - "byte_end": 448, - "line_start": 11, - "line_end": 11, + "byte_start": 537, + "byte_end": 537, + "line_start": 12, + "line_end": 12, "column_start": 1, "column_end": 1, "is_primary": true, @@ -215,10 +215,10 @@ mod foo { }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 448, - "byte_end": 448, - "line_start": 11, - "line_end": 11, + "byte_start": 537, + "byte_end": 537, + "line_start": 12, + "line_end": 12, "column_start": 1, "column_end": 1, "is_primary": true, @@ -238,10 +238,10 @@ mod foo { }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 448, - "byte_end": 448, - "line_start": 11, - "line_end": 11, + "byte_start": 537, + "byte_end": 537, + "line_start": 12, + "line_end": 12, "column_start": 1, "column_end": 1, "is_primary": true, @@ -261,10 +261,10 @@ mod foo { }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 448, - "byte_end": 448, - "line_start": 11, - "line_end": 11, + "byte_start": 537, + "byte_end": 537, + "line_start": 12, + "line_end": 12, "column_start": 1, "column_end": 1, "is_primary": true, @@ -284,10 +284,10 @@ mod foo { }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 448, - "byte_end": 448, - "line_start": 11, - "line_end": 11, + "byte_start": 537, + "byte_end": 537, + "line_start": 12, + "line_end": 12, "column_start": 1, "column_end": 1, "is_primary": true, @@ -307,10 +307,10 @@ mod foo { }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 448, - "byte_end": 448, - "line_start": 11, - "line_end": 11, + "byte_start": 537, + "byte_end": 537, + "line_start": 12, + "line_end": 12, "column_start": 1, "column_end": 1, "is_primary": true, @@ -330,10 +330,10 @@ mod foo { }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 448, - "byte_end": 448, - "line_start": 11, - "line_end": 11, + "byte_start": 537, + "byte_end": 537, + "line_start": 12, + "line_end": 12, "column_start": 1, "column_end": 1, "is_primary": true, @@ -353,10 +353,10 @@ mod foo { }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 448, - "byte_end": 448, - "line_start": 11, - "line_end": 11, + "byte_start": 537, + "byte_end": 537, + "line_start": 12, + "line_end": 12, "column_start": 1, "column_end": 1, "is_primary": true, @@ -380,7 +380,7 @@ mod foo { } ], "rendered": "\u001b[0m\u001b[1m\u001b[38;5;9merror[E0412]\u001b[0m\u001b[0m\u001b[1m: cannot find type `Iter` in this scope\u001b[0m -\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0m$DIR/use_suggestion_json.rs:12:12\u001b[0m +\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0m$DIR/use_suggestion_json.rs:13:12\u001b[0m \u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m \u001b[0m\u001b[1m\u001b[38;5;12mLL\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m let x: Iter;\u001b[0m \u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;9m^^^^\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;9mnot found in this scope\u001b[0m diff --git a/src/test/ui/proc-macro/crt-static.rs b/src/test/ui/proc-macro/crt-static.rs index 90e3d422b3cbc..97f6265e3089b 100644 --- a/src/test/ui/proc-macro/crt-static.rs +++ b/src/test/ui/proc-macro/crt-static.rs @@ -3,6 +3,7 @@ // override -Ctarget-feature=-crt-static from compiletest // compile-flags: -Ctarget-feature= // ignore-wasm32 +// ignore-sgx no support for proc-macro crate type // build-pass #![crate_type = "proc-macro"] diff --git a/src/test/ui/resolve/issue-16058.rs b/src/test/ui/resolve/issue-16058.rs index d41023e82c00c..048aaf65fbfa8 100644 --- a/src/test/ui/resolve/issue-16058.rs +++ b/src/test/ui/resolve/issue-16058.rs @@ -1,3 +1,5 @@ +// ignore-sgx std::os::fortanix_sgx::usercalls::raw::Result changes compiler suggestions + pub struct GslResult { pub val: f64, pub err: f64 diff --git a/src/test/ui/resolve/issue-16058.stderr b/src/test/ui/resolve/issue-16058.stderr index 31f4998bd83b6..913009ce51c1a 100644 --- a/src/test/ui/resolve/issue-16058.stderr +++ b/src/test/ui/resolve/issue-16058.stderr @@ -1,5 +1,5 @@ error[E0574]: expected struct, variant or union type, found enum `Result` - --> $DIR/issue-16058.rs:8:9 + --> $DIR/issue-16058.rs:10:9 | LL | Result { | ^^^^^^ not a struct, variant or union type diff --git a/src/test/ui/test-panic-abort-nocapture.rs b/src/test/ui/test-panic-abort-nocapture.rs index 75f7983865020..978732a9ec374 100644 --- a/src/test/ui/test-panic-abort-nocapture.rs +++ b/src/test/ui/test-panic-abort-nocapture.rs @@ -7,6 +7,7 @@ // ignore-wasm no panic or subprocess support // ignore-emscripten no panic or subprocess support +// ignore-sgx no subprocess support #![cfg(test)] diff --git a/src/test/ui/test-panic-abort-nocapture.run.stderr b/src/test/ui/test-panic-abort-nocapture.run.stderr index 37fbe3d3ff21f..3388813d5a0bd 100644 --- a/src/test/ui/test-panic-abort-nocapture.run.stderr +++ b/src/test/ui/test-panic-abort-nocapture.run.stderr @@ -1,9 +1,9 @@ thread 'main' panicked at 'assertion failed: `(left == right)` left: `2`, - right: `4`', $DIR/test-panic-abort-nocapture.rs:31:5 + right: `4`', $DIR/test-panic-abort-nocapture.rs:32:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread 'main' panicked at 'assertion failed: `(left == right)` left: `2`, - right: `4`', $DIR/test-panic-abort-nocapture.rs:25:5 + right: `4`', $DIR/test-panic-abort-nocapture.rs:26:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace testing321 diff --git a/src/test/ui/test-panic-abort.rs b/src/test/ui/test-panic-abort.rs index b7bf5a150ea8b..21e7dc393f512 100644 --- a/src/test/ui/test-panic-abort.rs +++ b/src/test/ui/test-panic-abort.rs @@ -7,6 +7,7 @@ // ignore-wasm no panic or subprocess support // ignore-emscripten no panic or subprocess support +// ignore-sgx no subprocess support #![cfg(test)] diff --git a/src/test/ui/test-panic-abort.run.stdout b/src/test/ui/test-panic-abort.run.stdout index 2f4bc32ed6a1f..33ddd519030ff 100644 --- a/src/test/ui/test-panic-abort.run.stdout +++ b/src/test/ui/test-panic-abort.run.stdout @@ -18,7 +18,7 @@ testing123 testing321 thread 'main' panicked at 'assertion failed: `(left == right)` left: `2`, - right: `5`', $DIR/test-panic-abort.rs:32:5 + right: `5`', $DIR/test-panic-abort.rs:33:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace From 5087c1ad2bdcf478d62cbe90fc20dd9ff0ffd207 Mon Sep 17 00:00:00 2001 From: Donough Liu Date: Wed, 6 May 2020 17:02:53 +0800 Subject: [PATCH 08/12] Add comment for `Ord` implementation for array --- src/libcore/array/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcore/array/mod.rs b/src/libcore/array/mod.rs index 937451274cfc2..549228ffffaa4 100644 --- a/src/libcore/array/mod.rs +++ b/src/libcore/array/mod.rs @@ -375,6 +375,7 @@ where } } +/// Implements comparison of arrays lexicographically. #[stable(feature = "rust1", since = "1.0.0")] impl Ord for [T; N] where From 9907ad6ed9fde5ccdb58a7d59d652a4c8a98a346 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 17 Apr 2020 21:42:22 -0400 Subject: [PATCH 09/12] Define UB in float-to-int casts to saturate - Round to zero, and representable values cast directly. - `NaN` goes to 0 - Values beyond the limits of the type are saturated to the "nearest value" (essentially rounding to zero, in some sense) in the integral type, so e.g. `f32::INFINITY` would go to `{u,i}N::MAX.` --- src/librustc_codegen_ssa/mir/rvalue.rs | 2 +- src/librustc_interface/tests.rs | 2 +- src/librustc_session/options.rs | 4 ++-- src/test/codegen/unchecked-float-casts.rs | 12 ++++++------ .../ui/numbers-arithmetic/saturating-float-casts.rs | 1 - 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index 19a0138d9cb6d..bb532abd84bde 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -768,7 +768,7 @@ fn cast_float_to_int<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( ) -> Bx::Value { let fptosui_result = if signed { bx.fptosi(x, int_ty) } else { bx.fptoui(x, int_ty) }; - if !bx.cx().sess().opts.debugging_opts.saturating_float_casts { + if let Some(false) = bx.cx().sess().opts.debugging_opts.saturating_float_casts { return fptosui_result; } diff --git a/src/librustc_interface/tests.rs b/src/librustc_interface/tests.rs index 0a200426e38ea..ad1934c97865e 100644 --- a/src/librustc_interface/tests.rs +++ b/src/librustc_interface/tests.rs @@ -558,7 +558,7 @@ fn test_debugging_options_tracking_hash() { tracked!(sanitizer, Some(Sanitizer::Address)); tracked!(sanitizer_memory_track_origins, 2); tracked!(sanitizer_recover, vec![Sanitizer::Address]); - tracked!(saturating_float_casts, true); + tracked!(saturating_float_casts, Some(true)); tracked!(share_generics, Some(true)); tracked!(show_span, Some(String::from("abc"))); tracked!(src_hash_algorithm, Some(SourceFileHashAlgorithm::Sha1)); diff --git a/src/librustc_session/options.rs b/src/librustc_session/options.rs index b03fc00d93db2..7fcf6d1385060 100644 --- a/src/librustc_session/options.rs +++ b/src/librustc_session/options.rs @@ -936,9 +936,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "enable origins tracking in MemorySanitizer"), sanitizer_recover: Vec = (vec![], parse_sanitizer_list, [TRACKED], "enable recovery for selected sanitizers"), - saturating_float_casts: bool = (false, parse_bool, [TRACKED], + saturating_float_casts: Option = (None, parse_opt_bool, [TRACKED], "make float->int casts UB-free: numbers outside the integer type's range are clipped to \ - the max/min integer respectively, and NaN is mapped to 0 (default: no)"), + the max/min integer respectively, and NaN is mapped to 0 (default: yes)"), save_analysis: bool = (false, parse_bool, [UNTRACKED], "write syntax and type analysis (in JSON format) information, in \ addition to normal output (default: no)"), diff --git a/src/test/codegen/unchecked-float-casts.rs b/src/test/codegen/unchecked-float-casts.rs index 34e9612222309..789feea12d6d7 100644 --- a/src/test/codegen/unchecked-float-casts.rs +++ b/src/test/codegen/unchecked-float-casts.rs @@ -1,7 +1,7 @@ -// compile-flags: -C no-prepopulate-passes +// This file tests that we don't generate any code for saturation when using the +// unchecked intrinsics. -// This file tests that we don't generate any code for saturation if -// -Z saturating-float-casts is not enabled. +// compile-flags: -C opt-level=3 #![crate_type = "lib"] @@ -12,7 +12,7 @@ pub fn f32_to_u32(x: f32) -> u32 { // CHECK-NOT: fcmp // CHECK-NOT: icmp // CHECK-NOT: select - x as u32 + unsafe { x.to_int_unchecked() } } // CHECK-LABEL: @f32_to_i32 @@ -22,7 +22,7 @@ pub fn f32_to_i32(x: f32) -> i32 { // CHECK-NOT: fcmp // CHECK-NOT: icmp // CHECK-NOT: select - x as i32 + unsafe { x.to_int_unchecked() } } #[no_mangle] @@ -31,5 +31,5 @@ pub fn f64_to_u16(x: f64) -> u16 { // CHECK-NOT: fcmp // CHECK-NOT: icmp // CHECK-NOT: select - x as u16 + unsafe { x.to_int_unchecked() } } diff --git a/src/test/ui/numbers-arithmetic/saturating-float-casts.rs b/src/test/ui/numbers-arithmetic/saturating-float-casts.rs index f13964fb38665..811efaefbb5bd 100644 --- a/src/test/ui/numbers-arithmetic/saturating-float-casts.rs +++ b/src/test/ui/numbers-arithmetic/saturating-float-casts.rs @@ -1,6 +1,5 @@ // run-pass // Tests saturating float->int casts. See u128-as-f32.rs for the opposite direction. -// compile-flags: -Z saturating-float-casts #![feature(test, stmt_expr_attributes)] #![deny(overflowing_literals)] From 0dbce10bcd611b97db390282f1239bd67d69f6bd Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 18 Apr 2020 18:43:08 -0400 Subject: [PATCH 10/12] Pull in miri test cases --- .../saturating-float-casts.rs | 463 +++++++++++++++++- 1 file changed, 458 insertions(+), 5 deletions(-) diff --git a/src/test/ui/numbers-arithmetic/saturating-float-casts.rs b/src/test/ui/numbers-arithmetic/saturating-float-casts.rs index 811efaefbb5bd..09c044a1b7a98 100644 --- a/src/test/ui/numbers-arithmetic/saturating-float-casts.rs +++ b/src/test/ui/numbers-arithmetic/saturating-float-casts.rs @@ -1,14 +1,19 @@ // run-pass // Tests saturating float->int casts. See u128-as-f32.rs for the opposite direction. +// +// Some of these tests come from a similar file in miri, +// tests/run-pass/float.rs. They're just duplicated currently but we may want +// to merge this in the future. #![feature(test, stmt_expr_attributes)] +#![feature(track_caller)] #![deny(overflowing_literals)] extern crate test; use std::{f32, f64}; -use std::{u8, i8, u16, i16, u32, i32, u64, i64}; -#[cfg(not(target_os="emscripten"))] -use std::{u128, i128}; +#[cfg(not(target_os = "emscripten"))] +use std::{i128, u128}; +use std::{i16, i32, i64, i8, u16, u32, u64, u8}; use test::black_box; macro_rules! test { @@ -84,11 +89,459 @@ macro_rules! fptoui_tests { }) } +use std::fmt::Debug; + +// Helper function to avoid promotion so that this tests "run-time" casts, not CTFE. +#[track_caller] +#[inline(never)] +fn assert_eq(x: T, y: T) { + assert_eq!(x, y); +} + +trait FloatToInt: Copy { + fn cast(self) -> Int; + unsafe fn cast_unchecked(self) -> Int; +} + +impl FloatToInt for f32 { + fn cast(self) -> i8 { + self as _ + } + unsafe fn cast_unchecked(self) -> i8 { + self.to_int_unchecked() + } +} +impl FloatToInt for f32 { + fn cast(self) -> i32 { + self as _ + } + unsafe fn cast_unchecked(self) -> i32 { + self.to_int_unchecked() + } +} +impl FloatToInt for f32 { + fn cast(self) -> u32 { + self as _ + } + unsafe fn cast_unchecked(self) -> u32 { + self.to_int_unchecked() + } +} +impl FloatToInt for f32 { + fn cast(self) -> i64 { + self as _ + } + unsafe fn cast_unchecked(self) -> i64 { + self.to_int_unchecked() + } +} +impl FloatToInt for f32 { + fn cast(self) -> u64 { + self as _ + } + unsafe fn cast_unchecked(self) -> u64 { + self.to_int_unchecked() + } +} + +impl FloatToInt for f64 { + fn cast(self) -> i8 { + self as _ + } + unsafe fn cast_unchecked(self) -> i8 { + self.to_int_unchecked() + } +} +impl FloatToInt for f64 { + fn cast(self) -> i32 { + self as _ + } + unsafe fn cast_unchecked(self) -> i32 { + self.to_int_unchecked() + } +} +impl FloatToInt for f64 { + fn cast(self) -> u32 { + self as _ + } + unsafe fn cast_unchecked(self) -> u32 { + self.to_int_unchecked() + } +} +impl FloatToInt for f64 { + fn cast(self) -> i64 { + self as _ + } + unsafe fn cast_unchecked(self) -> i64 { + self.to_int_unchecked() + } +} +impl FloatToInt for f64 { + fn cast(self) -> u64 { + self as _ + } + unsafe fn cast_unchecked(self) -> u64 { + self.to_int_unchecked() + } +} +// FIXME emscripten does not support i128 +#[cfg(not(target_os = "emscripten"))] +impl FloatToInt for f64 { + fn cast(self) -> i128 { + self as _ + } + unsafe fn cast_unchecked(self) -> i128 { + self.to_int_unchecked() + } +} +// FIXME emscripten does not support i128 +#[cfg(not(target_os = "emscripten"))] +impl FloatToInt for f64 { + fn cast(self) -> u128 { + self as _ + } + unsafe fn cast_unchecked(self) -> u128 { + self.to_int_unchecked() + } +} + +/// Test this cast both via `as` and via `to_int_unchecked` (i.e., it must not saturate). +#[track_caller] +#[inline(never)] +fn test_both_cast(x: F, y: I) +where + F: FloatToInt, + I: PartialEq + Debug, +{ + assert_eq!(x.cast(), y); + assert_eq!(unsafe { x.cast_unchecked() }, y); +} + +fn basic() { + // basic arithmetic + assert_eq(6.0_f32 * 6.0_f32, 36.0_f32); + assert_eq(6.0_f64 * 6.0_f64, 36.0_f64); + assert_eq(-{ 5.0_f32 }, -5.0_f32); + assert_eq(-{ 5.0_f64 }, -5.0_f64); + // infinities, NaN + assert!((5.0_f32 / 0.0).is_infinite()); + assert_ne!({ 5.0_f32 / 0.0 }, { -5.0_f32 / 0.0 }); + assert!((5.0_f64 / 0.0).is_infinite()); + assert_ne!({ 5.0_f64 / 0.0 }, { 5.0_f64 / -0.0 }); + assert!((-5.0_f32).sqrt().is_nan()); + assert!((-5.0_f64).sqrt().is_nan()); + assert_ne!(f32::NAN, f32::NAN); + assert_ne!(f64::NAN, f64::NAN); + // negative zero + let posz = 0.0f32; + let negz = -0.0f32; + assert_eq(posz, negz); + assert_ne!(posz.to_bits(), negz.to_bits()); + let posz = 0.0f64; + let negz = -0.0f64; + assert_eq(posz, negz); + assert_ne!(posz.to_bits(), negz.to_bits()); + // byte-level transmute + let x: u64 = unsafe { std::mem::transmute(42.0_f64) }; + let y: f64 = unsafe { std::mem::transmute(x) }; + assert_eq(y, 42.0_f64); + let x: u32 = unsafe { std::mem::transmute(42.0_f32) }; + let y: f32 = unsafe { std::mem::transmute(x) }; + assert_eq(y, 42.0_f32); +} + +fn casts() { + // f32 -> i8 + test_both_cast::(127.99, 127); + test_both_cast::(-128.99, -128); + + // f32 -> i32 + test_both_cast::(0.0, 0); + test_both_cast::(-0.0, 0); + test_both_cast::(/*0x1p-149*/ f32::from_bits(0x00000001), 0); + test_both_cast::(/*-0x1p-149*/ f32::from_bits(0x80000001), 0); + test_both_cast::(/*0x1.19999ap+0*/ f32::from_bits(0x3f8ccccd), 1); + test_both_cast::(/*-0x1.19999ap+0*/ f32::from_bits(0xbf8ccccd), -1); + test_both_cast::(1.9, 1); + test_both_cast::(-1.9, -1); + test_both_cast::(5.0, 5); + test_both_cast::(-5.0, -5); + test_both_cast::(2147483520.0, 2147483520); + test_both_cast::(-2147483648.0, -2147483648); + // unrepresentable casts + assert_eq::(2147483648.0f32 as i32, i32::MAX); + assert_eq::(-2147483904.0f32 as i32, i32::MIN); + assert_eq::(f32::MAX as i32, i32::MAX); + assert_eq::(f32::MIN as i32, i32::MIN); + assert_eq::(f32::INFINITY as i32, i32::MAX); + assert_eq::(f32::NEG_INFINITY as i32, i32::MIN); + assert_eq::(f32::NAN as i32, 0); + assert_eq::((-f32::NAN) as i32, 0); + + // f32 -> u32 + test_both_cast::(0.0, 0); + test_both_cast::(-0.0, 0); + test_both_cast::(-0.9999999, 0); + test_both_cast::(/*0x1p-149*/ f32::from_bits(0x1), 0); + test_both_cast::(/*-0x1p-149*/ f32::from_bits(0x80000001), 0); + test_both_cast::(/*0x1.19999ap+0*/ f32::from_bits(0x3f8ccccd), 1); + test_both_cast::(1.9, 1); + test_both_cast::(5.0, 5); + test_both_cast::(2147483648.0, 0x8000_0000); + test_both_cast::(4294967040.0, 0u32.wrapping_sub(256)); + test_both_cast::(/*-0x1.ccccccp-1*/ f32::from_bits(0xbf666666), 0); + test_both_cast::(/*-0x1.fffffep-1*/ f32::from_bits(0xbf7fffff), 0); + test_both_cast::((u32::MAX - 128) as f32, u32::MAX - 255); // rounding loss + + // unrepresentable casts: + + // rounds up and then becomes unrepresentable + assert_eq::((u32::MAX - 127) as f32 as u32, u32::MAX); + + assert_eq::(4294967296.0f32 as u32, u32::MAX); + assert_eq::(-5.0f32 as u32, 0); + assert_eq::(f32::MAX as u32, u32::MAX); + assert_eq::(f32::MIN as u32, 0); + assert_eq::(f32::INFINITY as u32, u32::MAX); + assert_eq::(f32::NEG_INFINITY as u32, 0); + assert_eq::(f32::NAN as u32, 0); + assert_eq::((-f32::NAN) as u32, 0); + + // f32 -> i64 + test_both_cast::(4294967296.0, 4294967296); + test_both_cast::(-4294967296.0, -4294967296); + test_both_cast::(9223371487098961920.0, 9223371487098961920); + test_both_cast::(-9223372036854775808.0, -9223372036854775808); + + // f64 -> i8 + test_both_cast::(127.99, 127); + test_both_cast::(-128.99, -128); + + // f64 -> i32 + test_both_cast::(0.0, 0); + test_both_cast::(-0.0, 0); + test_both_cast::(/*0x1.199999999999ap+0*/ f64::from_bits(0x3ff199999999999a), 1); + test_both_cast::( + /*-0x1.199999999999ap+0*/ f64::from_bits(0xbff199999999999a), + -1, + ); + test_both_cast::(1.9, 1); + test_both_cast::(-1.9, -1); + test_both_cast::(1e8, 100_000_000); + test_both_cast::(2147483647.0, 2147483647); + test_both_cast::(-2147483648.0, -2147483648); + // unrepresentable casts + assert_eq::(2147483648.0f64 as i32, i32::MAX); + assert_eq::(-2147483649.0f64 as i32, i32::MIN); + + // f64 -> i64 + test_both_cast::(0.0, 0); + test_both_cast::(-0.0, 0); + test_both_cast::(/*0x0.0000000000001p-1022*/ f64::from_bits(0x1), 0); + test_both_cast::( + /*-0x0.0000000000001p-1022*/ f64::from_bits(0x8000000000000001), + 0, + ); + test_both_cast::(/*0x1.199999999999ap+0*/ f64::from_bits(0x3ff199999999999a), 1); + test_both_cast::( + /*-0x1.199999999999ap+0*/ f64::from_bits(0xbff199999999999a), + -1, + ); + test_both_cast::(5.0, 5); + test_both_cast::(5.9, 5); + test_both_cast::(-5.0, -5); + test_both_cast::(-5.9, -5); + test_both_cast::(4294967296.0, 4294967296); + test_both_cast::(-4294967296.0, -4294967296); + test_both_cast::(9223372036854774784.0, 9223372036854774784); + test_both_cast::(-9223372036854775808.0, -9223372036854775808); + // unrepresentable casts + assert_eq::(9223372036854775808.0f64 as i64, i64::MAX); + assert_eq::(-9223372036854777856.0f64 as i64, i64::MIN); + assert_eq::(f64::MAX as i64, i64::MAX); + assert_eq::(f64::MIN as i64, i64::MIN); + assert_eq::(f64::INFINITY as i64, i64::MAX); + assert_eq::(f64::NEG_INFINITY as i64, i64::MIN); + assert_eq::(f64::NAN as i64, 0); + assert_eq::((-f64::NAN) as i64, 0); + + // f64 -> u64 + test_both_cast::(0.0, 0); + test_both_cast::(-0.0, 0); + test_both_cast::(-0.99999999999, 0); + test_both_cast::(5.0, 5); + test_both_cast::(1e16, 10000000000000000); + test_both_cast::((u64::MAX - 1024) as f64, u64::MAX - 2047); // rounding loss + test_both_cast::(9223372036854775808.0, 9223372036854775808); + // unrepresentable casts + assert_eq::(-5.0f64 as u64, 0); + // rounds up and then becomes unrepresentable + assert_eq::((u64::MAX - 1023) as f64 as u64, u64::MAX); + assert_eq::(18446744073709551616.0f64 as u64, u64::MAX); + assert_eq::(f64::MAX as u64, u64::MAX); + assert_eq::(f64::MIN as u64, 0); + assert_eq::(f64::INFINITY as u64, u64::MAX); + assert_eq::(f64::NEG_INFINITY as u64, 0); + assert_eq::(f64::NAN as u64, 0); + assert_eq::((-f64::NAN) as u64, 0); + + // FIXME emscripten does not support i128 + #[cfg(not(target_os = "emscripten"))] + { + // f64 -> i128 + assert_eq::(f64::MAX as i128, i128::MAX); + assert_eq::(f64::MIN as i128, i128::MIN); + + // f64 -> u128 + assert_eq::(f64::MAX as u128, u128::MAX); + assert_eq::(f64::MIN as u128, 0); + } + + // int -> f32 + assert_eq::(127i8 as f32, 127.0); + assert_eq::(2147483647i32 as f32, 2147483648.0); + assert_eq::((-2147483648i32) as f32, -2147483648.0); + assert_eq::(1234567890i32 as f32, /*0x1.26580cp+30*/ f32::from_bits(0x4e932c06)); + assert_eq::(16777217i32 as f32, 16777216.0); + assert_eq::((-16777217i32) as f32, -16777216.0); + assert_eq::(16777219i32 as f32, 16777220.0); + assert_eq::((-16777219i32) as f32, -16777220.0); + assert_eq::( + 0x7fffff4000000001i64 as f32, + /*0x1.fffffep+62*/ f32::from_bits(0x5effffff), + ); + assert_eq::( + 0x8000004000000001u64 as i64 as f32, + /*-0x1.fffffep+62*/ f32::from_bits(0xdeffffff), + ); + assert_eq::( + 0x0020000020000001i64 as f32, + /*0x1.000002p+53*/ f32::from_bits(0x5a000001), + ); + assert_eq::( + 0xffdfffffdfffffffu64 as i64 as f32, + /*-0x1.000002p+53*/ f32::from_bits(0xda000001), + ); + // FIXME emscripten does not support i128 + #[cfg(not(target_os = "emscripten"))] + { + assert_eq::(i128::MIN as f32, -170141183460469231731687303715884105728.0f32); + assert_eq::(u128::MAX as f32, f32::INFINITY); // saturation + } + + // int -> f64 + assert_eq::(127i8 as f64, 127.0); + assert_eq::(i16::MIN as f64, -32768.0f64); + assert_eq::(2147483647i32 as f64, 2147483647.0); + assert_eq::(-2147483648i32 as f64, -2147483648.0); + assert_eq::(987654321i32 as f64, 987654321.0); + assert_eq::(9223372036854775807i64 as f64, 9223372036854775807.0); + assert_eq::(-9223372036854775808i64 as f64, -9223372036854775808.0); + assert_eq::(4669201609102990i64 as f64, 4669201609102990.0); // Feigenbaum (?) + assert_eq::(9007199254740993i64 as f64, 9007199254740992.0); + assert_eq::(-9007199254740993i64 as f64, -9007199254740992.0); + assert_eq::(9007199254740995i64 as f64, 9007199254740996.0); + assert_eq::(-9007199254740995i64 as f64, -9007199254740996.0); + // FIXME emscripten does not support i128 + #[cfg(not(target_os = "emscripten"))] + { + // even that fits... + assert_eq::(u128::MAX as f64, 340282366920938463463374607431768211455.0f64); + } + + // f32 -> f64 + assert_eq::((0.0f32 as f64).to_bits(), 0.0f64.to_bits()); + assert_eq::(((-0.0f32) as f64).to_bits(), (-0.0f64).to_bits()); + assert_eq::(5.0f32 as f64, 5.0f64); + assert_eq::( + /*0x1p-149*/ f32::from_bits(0x1) as f64, + /*0x1p-149*/ f64::from_bits(0x36a0000000000000), + ); + assert_eq::( + /*-0x1p-149*/ f32::from_bits(0x80000001) as f64, + /*-0x1p-149*/ f64::from_bits(0xb6a0000000000000), + ); + assert_eq::( + /*0x1.fffffep+127*/ f32::from_bits(0x7f7fffff) as f64, + /*0x1.fffffep+127*/ f64::from_bits(0x47efffffe0000000), + ); + assert_eq::( + /*-0x1.fffffep+127*/ (-f32::from_bits(0x7f7fffff)) as f64, + /*-0x1.fffffep+127*/ -f64::from_bits(0x47efffffe0000000), + ); + assert_eq::( + /*0x1p-119*/ f32::from_bits(0x4000000) as f64, + /*0x1p-119*/ f64::from_bits(0x3880000000000000), + ); + assert_eq::( + /*0x1.8f867ep+125*/ f32::from_bits(0x7e47c33f) as f64, + 6.6382536710104395e+37, + ); + assert_eq::(f32::INFINITY as f64, f64::INFINITY); + assert_eq::(f32::NEG_INFINITY as f64, f64::NEG_INFINITY); + + // f64 -> f32 + assert_eq::((0.0f64 as f32).to_bits(), 0.0f32.to_bits()); + assert_eq::(((-0.0f64) as f32).to_bits(), (-0.0f32).to_bits()); + assert_eq::(5.0f64 as f32, 5.0f32); + assert_eq::(/*0x0.0000000000001p-1022*/ f64::from_bits(0x1) as f32, 0.0); + assert_eq::(/*-0x0.0000000000001p-1022*/ (-f64::from_bits(0x1)) as f32, -0.0); + assert_eq::( + /*0x1.fffffe0000000p-127*/ f64::from_bits(0x380fffffe0000000) as f32, + /*0x1p-149*/ f32::from_bits(0x800000), + ); + assert_eq::( + /*0x1.4eae4f7024c7p+108*/ f64::from_bits(0x46b4eae4f7024c70) as f32, + /*0x1.4eae5p+108*/ f32::from_bits(0x75a75728), + ); + assert_eq::(f64::MAX as f32, f32::INFINITY); + assert_eq::(f64::MIN as f32, f32::NEG_INFINITY); + assert_eq::(f64::INFINITY as f32, f32::INFINITY); + assert_eq::(f64::NEG_INFINITY as f32, f32::NEG_INFINITY); +} + +fn ops() { + // f32 min/max + assert_eq((1.0 as f32).max(-1.0), 1.0); + assert_eq((1.0 as f32).min(-1.0), -1.0); + assert_eq(f32::NAN.min(9.0), 9.0); + assert_eq(f32::NAN.max(-9.0), -9.0); + assert_eq((9.0 as f32).min(f32::NAN), 9.0); + assert_eq((-9.0 as f32).max(f32::NAN), -9.0); + + // f64 min/max + assert_eq((1.0 as f64).max(-1.0), 1.0); + assert_eq((1.0 as f64).min(-1.0), -1.0); + assert_eq(f64::NAN.min(9.0), 9.0); + assert_eq(f64::NAN.max(-9.0), -9.0); + assert_eq((9.0 as f64).min(f64::NAN), 9.0); + assert_eq((-9.0 as f64).max(f64::NAN), -9.0); + + // f32 copysign + assert_eq(3.5_f32.copysign(0.42), 3.5_f32); + assert_eq(3.5_f32.copysign(-0.42), -3.5_f32); + assert_eq((-3.5_f32).copysign(0.42), 3.5_f32); + assert_eq((-3.5_f32).copysign(-0.42), -3.5_f32); + assert!(f32::NAN.copysign(1.0).is_nan()); + + // f64 copysign + assert_eq(3.5_f64.copysign(0.42), 3.5_f64); + assert_eq(3.5_f64.copysign(-0.42), -3.5_f64); + assert_eq((-3.5_f64).copysign(0.42), 3.5_f64); + assert_eq((-3.5_f64).copysign(-0.42), -3.5_f64); + assert!(f64::NAN.copysign(1.0).is_nan()); +} + pub fn main() { + basic(); + casts(); + ops(); + common_fptoi_tests!(f* -> i8 i16 i32 i64 u8 u16 u32 u64); fptoui_tests!(f* -> u8 u16 u32 u64); // FIXME emscripten does not support i128 - #[cfg(not(target_os="emscripten"))] { + #[cfg(not(target_os = "emscripten"))] + { common_fptoi_tests!(f* -> i128 u128); fptoui_tests!(f* -> u128); } @@ -123,7 +576,7 @@ pub fn main() { test!(4294967296., f* -> u32, 4294967295); // # u128 - #[cfg(not(target_os="emscripten"))] + #[cfg(not(target_os = "emscripten"))] { // float->int: test_c!(f32::MAX, f32 -> u128, 0xffffff00000000000000000000000000); From d4f31b4687e52b5d4e8aa3775a347e0bcbf366cc Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 19 Apr 2020 11:53:51 -0400 Subject: [PATCH 11/12] Fixup tests to test both const-eval and runtime --- .../saturating-float-casts.rs | 121 ++++-------------- 1 file changed, 22 insertions(+), 99 deletions(-) diff --git a/src/test/ui/numbers-arithmetic/saturating-float-casts.rs b/src/test/ui/numbers-arithmetic/saturating-float-casts.rs index 09c044a1b7a98..e6d0c94a02fac 100644 --- a/src/test/ui/numbers-arithmetic/saturating-float-casts.rs +++ b/src/test/ui/numbers-arithmetic/saturating-float-casts.rs @@ -1,9 +1,12 @@ // run-pass +// compile-flags:-Zmir-opt-level=0 // Tests saturating float->int casts. See u128-as-f32.rs for the opposite direction. // // Some of these tests come from a similar file in miri, -// tests/run-pass/float.rs. They're just duplicated currently but we may want -// to merge this in the future. +// tests/run-pass/float.rs. Individual test cases are potentially duplicated +// with the previously existing tests, but since this runs so quickly anyway, +// we're not spending the time to figure out exactly which ones should be +// merged. #![feature(test, stmt_expr_attributes)] #![feature(track_caller)] @@ -21,31 +24,18 @@ macro_rules! test { // black_box disables constant evaluation to test run-time conversions: assert_eq!(black_box::<$src_ty>($val) as $dest_ty, $expected, "run-time {} -> {}", stringify!($src_ty), stringify!($dest_ty)); - ); - - ($fval:expr, f* -> $ity:ident, $ival:expr) => ( - test!($fval, f32 -> $ity, $ival); - test!($fval, f64 -> $ity, $ival); - ) -} -// This macro tests const eval in addition to run-time evaluation. -// If and when saturating casts are adopted, this macro should be merged with test!() to ensure -// that run-time and const eval agree on inputs that currently trigger a const eval error. -macro_rules! test_c { - ($val:expr, $src_ty:ident -> $dest_ty:ident, $expected:expr) => ({ - test!($val, $src_ty -> $dest_ty, $expected); { const X: $src_ty = $val; const Y: $dest_ty = X as $dest_ty; assert_eq!(Y, $expected, "const eval {} -> {}", stringify!($src_ty), stringify!($dest_ty)); } - }); + ); ($fval:expr, f* -> $ity:ident, $ival:expr) => ( - test_c!($fval, f32 -> $ity, $ival); - test_c!($fval, f64 -> $ity, $ival); + test!($fval, f32 -> $ity, $ival); + test!($fval, f64 -> $ity, $ival); ) } @@ -59,11 +49,11 @@ macro_rules! common_fptoi_tests { // as well, the test is just slightly misplaced. test!($ity::MIN as $fty, $fty -> $ity, $ity::MIN); test!($ity::MAX as $fty, $fty -> $ity, $ity::MAX); - test_c!(0., $fty -> $ity, 0); - test_c!($fty::MIN_POSITIVE, $fty -> $ity, 0); + test!(0., $fty -> $ity, 0); + test!($fty::MIN_POSITIVE, $fty -> $ity, 0); test!(-0.9, $fty -> $ity, 0); - test_c!(1., $fty -> $ity, 1); - test_c!(42., $fty -> $ity, 42); + test!(1., $fty -> $ity, 1); + test!(42., $fty -> $ity, 42); )+ }); (f* -> $($ity:ident)+) => ({ @@ -217,39 +207,6 @@ where assert_eq!(unsafe { x.cast_unchecked() }, y); } -fn basic() { - // basic arithmetic - assert_eq(6.0_f32 * 6.0_f32, 36.0_f32); - assert_eq(6.0_f64 * 6.0_f64, 36.0_f64); - assert_eq(-{ 5.0_f32 }, -5.0_f32); - assert_eq(-{ 5.0_f64 }, -5.0_f64); - // infinities, NaN - assert!((5.0_f32 / 0.0).is_infinite()); - assert_ne!({ 5.0_f32 / 0.0 }, { -5.0_f32 / 0.0 }); - assert!((5.0_f64 / 0.0).is_infinite()); - assert_ne!({ 5.0_f64 / 0.0 }, { 5.0_f64 / -0.0 }); - assert!((-5.0_f32).sqrt().is_nan()); - assert!((-5.0_f64).sqrt().is_nan()); - assert_ne!(f32::NAN, f32::NAN); - assert_ne!(f64::NAN, f64::NAN); - // negative zero - let posz = 0.0f32; - let negz = -0.0f32; - assert_eq(posz, negz); - assert_ne!(posz.to_bits(), negz.to_bits()); - let posz = 0.0f64; - let negz = -0.0f64; - assert_eq(posz, negz); - assert_ne!(posz.to_bits(), negz.to_bits()); - // byte-level transmute - let x: u64 = unsafe { std::mem::transmute(42.0_f64) }; - let y: f64 = unsafe { std::mem::transmute(x) }; - assert_eq(y, 42.0_f64); - let x: u32 = unsafe { std::mem::transmute(42.0_f32) }; - let y: f32 = unsafe { std::mem::transmute(x) }; - assert_eq(y, 42.0_f32); -} - fn casts() { // f32 -> i8 test_both_cast::(127.99, 127); @@ -500,42 +457,8 @@ fn casts() { assert_eq::(f64::NEG_INFINITY as f32, f32::NEG_INFINITY); } -fn ops() { - // f32 min/max - assert_eq((1.0 as f32).max(-1.0), 1.0); - assert_eq((1.0 as f32).min(-1.0), -1.0); - assert_eq(f32::NAN.min(9.0), 9.0); - assert_eq(f32::NAN.max(-9.0), -9.0); - assert_eq((9.0 as f32).min(f32::NAN), 9.0); - assert_eq((-9.0 as f32).max(f32::NAN), -9.0); - - // f64 min/max - assert_eq((1.0 as f64).max(-1.0), 1.0); - assert_eq((1.0 as f64).min(-1.0), -1.0); - assert_eq(f64::NAN.min(9.0), 9.0); - assert_eq(f64::NAN.max(-9.0), -9.0); - assert_eq((9.0 as f64).min(f64::NAN), 9.0); - assert_eq((-9.0 as f64).max(f64::NAN), -9.0); - - // f32 copysign - assert_eq(3.5_f32.copysign(0.42), 3.5_f32); - assert_eq(3.5_f32.copysign(-0.42), -3.5_f32); - assert_eq((-3.5_f32).copysign(0.42), 3.5_f32); - assert_eq((-3.5_f32).copysign(-0.42), -3.5_f32); - assert!(f32::NAN.copysign(1.0).is_nan()); - - // f64 copysign - assert_eq(3.5_f64.copysign(0.42), 3.5_f64); - assert_eq(3.5_f64.copysign(-0.42), -3.5_f64); - assert_eq((-3.5_f64).copysign(0.42), 3.5_f64); - assert_eq((-3.5_f64).copysign(-0.42), -3.5_f64); - assert!(f64::NAN.copysign(1.0).is_nan()); -} - pub fn main() { - basic(); - casts(); - ops(); + casts(); // from miri's tests common_fptoi_tests!(f* -> i8 i16 i32 i64 u8 u16 u32 u64); fptoui_tests!(f* -> u8 u16 u32 u64); @@ -549,39 +472,39 @@ pub fn main() { // The following tests cover edge cases for some integer types. // # u8 - test_c!(254., f* -> u8, 254); + test!(254., f* -> u8, 254); test!(256., f* -> u8, 255); // # i8 - test_c!(-127., f* -> i8, -127); + test!(-127., f* -> i8, -127); test!(-129., f* -> i8, -128); - test_c!(126., f* -> i8, 126); + test!(126., f* -> i8, 126); test!(128., f* -> i8, 127); // # i32 // -2147483648. is i32::MIN (exactly) - test_c!(-2147483648., f* -> i32, i32::MIN); + test!(-2147483648., f* -> i32, i32::MIN); // 2147483648. is i32::MAX rounded up test!(2147483648., f32 -> i32, 2147483647); // With 24 significand bits, floats with magnitude in [2^30 + 1, 2^31] are rounded to // multiples of 2^7. Therefore, nextDown(round(i32::MAX)) is 2^31 - 128: - test_c!(2147483520., f32 -> i32, 2147483520); + test!(2147483520., f32 -> i32, 2147483520); // Similarly, nextUp(i32::MIN) is i32::MIN + 2^8 and nextDown(i32::MIN) is i32::MIN - 2^7 test!(-2147483904., f* -> i32, i32::MIN); - test_c!(-2147483520., f* -> i32, -2147483520); + test!(-2147483520., f* -> i32, -2147483520); // # u32 // round(MAX) and nextUp(round(MAX)) - test_c!(4294967040., f* -> u32, 4294967040); + test!(4294967040., f* -> u32, 4294967040); test!(4294967296., f* -> u32, 4294967295); // # u128 #[cfg(not(target_os = "emscripten"))] { // float->int: - test_c!(f32::MAX, f32 -> u128, 0xffffff00000000000000000000000000); + test!(f32::MAX, f32 -> u128, 0xffffff00000000000000000000000000); // nextDown(f32::MAX) = 2^128 - 2 * 2^104 const SECOND_LARGEST_F32: f32 = 340282326356119256160033759537265639424.; - test_c!(SECOND_LARGEST_F32, f32 -> u128, 0xfffffe00000000000000000000000000); + test!(SECOND_LARGEST_F32, f32 -> u128, 0xfffffe00000000000000000000000000); } } From f63b8bffefb0f652dc164859f4c8a10329c9117a Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 21 Apr 2020 09:00:36 -0400 Subject: [PATCH 12/12] Remove warning about UB --- src/librustc_typeck/check/demand.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 9e14efb67a94c..8ae5ee4c3f971 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -909,13 +909,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { cast_suggestion, Applicability::MaybeIncorrect, // lossy conversion ); - err.warn( - "if the rounded value cannot be represented by the target \ - integer type, including `Inf` and `NaN`, casting will cause \ - undefined behavior \ - (see issue #10184 \ - for more information)", - ); } true }