]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #87769 - m-ou-se:alloc-features-cleanup, r=yaahc,dtolnay
authorYuki Okushi <jtitor@2k36.org>
Tue, 19 Oct 2021 19:35:12 +0000 (04:35 +0900)
committerGitHub <noreply@github.com>
Tue, 19 Oct 2021 19:35:12 +0000 (04:35 +0900)
Alloc features cleanup

This sorts and categorizes the `#![features]` in `alloc` and removes unused ones.

This is part of #87766

The following feature attributes were unnecessary and are removed:

```diff
// Library features:
-#![feature(cow_is_borrowed)]
-#![feature(maybe_uninit_uninit_array)]
-#![feature(slice_partition_dedup)]

// Language features:
-#![feature(arbitrary_self_types)]
-#![feature(auto_traits)]
-#![feature(box_patterns)]
-#![feature(decl_macro)]
-#![feature(nll)]
```

66 files changed:
Cargo.lock
compiler/rustc_borrowck/src/borrow_set.rs
compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs
compiler/rustc_borrowck/src/lib.rs
compiler/rustc_codegen_llvm/Cargo.toml
compiler/rustc_codegen_ssa/src/back/link.rs
compiler/rustc_codegen_ssa/src/lib.rs
compiler/rustc_codegen_ssa/src/mir/operand.rs
compiler/rustc_const_eval/src/lib.rs
compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
compiler/rustc_data_structures/Cargo.toml
compiler/rustc_data_structures/src/profiling.rs
compiler/rustc_errors/src/emitter.rs
compiler/rustc_errors/src/lib.rs
compiler/rustc_expand/src/expand.rs
compiler/rustc_expand/src/lib.rs
compiler/rustc_expand/src/mbe/transcribe.rs
compiler/rustc_incremental/src/lib.rs
compiler/rustc_incremental/src/persist/file_format.rs
compiler/rustc_incremental/src/persist/fs.rs
compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs
compiler/rustc_infer/src/lib.rs
compiler/rustc_metadata/src/lib.rs
compiler/rustc_metadata/src/rmeta/decoder.rs
compiler/rustc_middle/src/lib.rs
compiler/rustc_middle/src/ty/diagnostics.rs
compiler/rustc_middle/src/ty/layout.rs
compiler/rustc_mir_build/src/build/expr/as_place.rs
compiler/rustc_mir_build/src/build/scope.rs
compiler/rustc_mir_build/src/lib.rs
compiler/rustc_mir_dataflow/src/lib.rs
compiler/rustc_mir_dataflow/src/rustc_peek.rs
compiler/rustc_mir_transform/src/inline.rs
compiler/rustc_mir_transform/src/lib.rs
compiler/rustc_mir_transform/src/lower_slice_len.rs
compiler/rustc_mir_transform/src/normalize_array_len.rs
compiler/rustc_mir_transform/src/uninhabited_enum_branching.rs
compiler/rustc_monomorphize/src/lib.rs
compiler/rustc_monomorphize/src/partitioning/default.rs
compiler/rustc_query_impl/Cargo.toml
compiler/rustc_query_system/src/dep_graph/serialized.rs
compiler/rustc_query_system/src/lib.rs
compiler/rustc_query_system/src/query/job.rs
compiler/rustc_query_system/src/query/plumbing.rs
compiler/rustc_resolve/src/diagnostics.rs
compiler/rustc_resolve/src/late/lifetimes.rs
compiler/rustc_resolve/src/lib.rs
compiler/rustc_session/src/options.rs
compiler/rustc_trait_selection/src/lib.rs
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
compiler/rustc_trait_selection/src/traits/object_safety.rs
compiler/rustc_trait_selection/src/traits/on_unimplemented.rs
compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
compiler/rustc_typeck/src/astconv/mod.rs
compiler/rustc_typeck/src/check/coercion.rs
compiler/rustc_typeck/src/check/demand.rs
compiler/rustc_typeck/src/check/op.rs
compiler/rustc_typeck/src/check/pat.rs
compiler/rustc_typeck/src/check/place_op.rs
compiler/rustc_typeck/src/check/upvar.rs
compiler/rustc_typeck/src/lib.rs
library/core/src/fmt/float.rs
library/core/src/num/f32.rs
library/core/src/num/f64.rs
library/core/tests/fmt/float.rs
src/tools/cargo

index 6bd09931aecbfb6b30448b7af7d26c854fd75eb0..aaa709e50f60dd088ad9f123f0989650da96b08c 100644 (file)
@@ -2143,6 +2143,20 @@ dependencies = [
  "smallvec",
 ]
 
+[[package]]
+name = "measureme"
+version = "10.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bd460fad6e55ca82fa0cd9dab0d315294188fd9ec6efbf4105e5635d4872ef9c"
+dependencies = [
+ "log",
+ "memmap2",
+ "parking_lot",
+ "perf-event-open-sys",
+ "rustc-hash",
+ "smallvec",
+]
+
 [[package]]
 name = "memchr"
 version = "2.4.1"
@@ -2247,7 +2261,7 @@ dependencies = [
  "hex 0.4.2",
  "libc",
  "log",
- "measureme",
+ "measureme 9.1.2",
  "rand 0.8.4",
  "rustc-workspace-hack",
  "rustc_version 0.4.0",
@@ -2728,9 +2742,9 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086"
 
 [[package]]
 name = "proc-macro2"
-version = "1.0.24"
+version = "1.0.30"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
+checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70"
 dependencies = [
  "unicode-xid",
 ]
@@ -3235,7 +3249,7 @@ dependencies = [
  "indexmap",
  "jobserver",
  "libc",
- "measureme",
+ "measureme 9.1.2",
  "memmap2",
  "parking_lot",
  "rustc-ap-rustc_graphviz",
@@ -3674,7 +3688,7 @@ dependencies = [
  "bitflags",
  "cstr",
  "libc",
- "measureme",
+ "measureme 10.0.0",
  "rustc-demangle",
  "rustc_arena",
  "rustc_ast",
@@ -3767,7 +3781,7 @@ dependencies = [
  "indexmap",
  "jobserver",
  "libc",
- "measureme",
+ "measureme 10.0.0",
  "memmap2",
  "parking_lot",
  "rustc-hash",
@@ -4292,7 +4306,7 @@ dependencies = [
 name = "rustc_query_impl"
 version = "0.0.0"
 dependencies = [
- "measureme",
+ "measureme 10.0.0",
  "rustc-rayon-core",
  "rustc_ast",
  "rustc_data_structures",
@@ -5093,9 +5107,9 @@ dependencies = [
 
 [[package]]
 name = "syn"
-version = "1.0.65"
+version = "1.0.80"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f3a1d708c221c5a612956ef9f75b37e454e88d1f7b899fbd3a18d4252012d663"
+checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194"
 dependencies = [
  "proc-macro2",
  "quote",
index ee2ce1d3f74c3035129f153692dcbafeb12740f7..e30d6c7fca73191a66468303cacbbf94d9396d70 100644 (file)
@@ -315,9 +315,7 @@ fn insert_as_pending_if_two_phase(
         //    TEMP = &foo
         //
         // so extract `temp`.
-        let temp = if let Some(temp) = assigned_place.as_local() {
-            temp
-        } else {
+        let Some(temp) = assigned_place.as_local() else {
             span_bug!(
                 self.body.source_info(start_location).span,
                 "expected 2-phase borrow to assign to a local, not `{:?}`",
index b15e55cd6675e786be24d4fabb6a5362717f6c49..723b57ed970ad6bb16bac57787f39029e9ea4f4f 100644 (file)
@@ -90,9 +90,7 @@ fn compile_all_suggestions(
         let mut unified_already = FxHashSet::default();
 
         for (fr, outlived) in &self.constraints_to_add {
-            let fr_name = if let Some(fr_name) = self.region_vid_to_name(mbcx, *fr) {
-                fr_name
-            } else {
+            let Some(fr_name) = self.region_vid_to_name(mbcx, *fr) else {
                 continue;
             };
 
index e6260157d11a752bda23d4f6b0022fff47477b7d..08df87e0488b8c0006d633be3dc45ba3771dddd0 100644 (file)
@@ -7,6 +7,7 @@
 #![feature(format_args_capture)]
 #![feature(in_band_lifetimes)]
 #![feature(iter_zip)]
+#![feature(let_else)]
 #![feature(min_specialization)]
 #![feature(stmt_expr_attributes)]
 #![feature(trusted_step)]
index a6a553b31a3262b8eb25676f707c02dcdf089029..5f3f533447532c5ffcac8a4b0964dd25356c3f6b 100644 (file)
@@ -11,7 +11,7 @@ doctest = false
 bitflags = "1.0"
 cstr = "0.2"
 libc = "0.2"
-measureme = "9.1.0"
+measureme = "10.0.0"
 snap = "1"
 tracing = "0.1"
 rustc_middle = { path = "../rustc_middle" }
index cf1c60588978c33085d32337045a460ec8e4e3a0..be50911f4e143a8b5cb91fc4e0c8d344c9600982 100644 (file)
@@ -174,9 +174,8 @@ pub fn each_linked_rlib(
             _ => {}
         }
     }
-    let fmts = match fmts {
-        Some(f) => f,
-        None => return Err("could not find formats for rlibs".to_string()),
+    let Some(fmts) = fmts else {
+        return Err("could not find formats for rlibs".to_string());
     };
     for &cnum in crates {
         match fmts.get(cnum.as_usize() - 1) {
index b759e3a7a7a33d72b946bfa2f69e4b7e245ad764..f78196d7ec58e25bc00797df2308c7709288cad8 100644 (file)
@@ -3,6 +3,7 @@
 #![feature(box_patterns)]
 #![feature(try_blocks)]
 #![feature(in_band_lifetimes)]
+#![feature(let_else)]
 #![feature(once_cell)]
 #![feature(nll)]
 #![feature(associated_type_bounds)]
index ce6cec67ad41ef7b17f7f73bf31925d3671c6c2b..bea55bbc87965a37e12acf89ea8b3e66a0cf754f 100644 (file)
@@ -343,9 +343,7 @@ pub fn store_unsized<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
             .unwrap_or_else(|| bug!("indirect_dest has non-pointer type: {:?}", indirect_dest))
             .ty;
 
-        let (llptr, llextra) = if let OperandValue::Ref(llptr, Some(llextra), _) = self {
-            (llptr, llextra)
-        } else {
+        let OperandValue::Ref(llptr, Some(llextra), _) = self else {
             bug!("store_unsized called with a sized value")
         };
 
index 7ce40b319a1e59dcb7c4d27bb917355d41e188b1..f308e764e861d0422e76464c39014aea20b59d09 100644 (file)
@@ -13,6 +13,7 @@
 #![feature(exact_size_is_empty)]
 #![feature(in_band_lifetimes)]
 #![feature(iter_zip)]
+#![feature(let_else)]
 #![feature(map_try_insert)]
 #![feature(min_specialization)]
 #![feature(slice_ptr_get)]
index dd2980d40ade7aec66ecd253784f37c679bc1405..5418f6fc007ca12050d8baa7eb117e8842267c46 100644 (file)
@@ -145,9 +145,7 @@ fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, mut ty: Ty<'tcx>) -> bool {
             Ok([..]) => {}
         }
 
-        let drop_trait = if let Some(did) = cx.tcx.lang_items().drop_trait() {
-            did
-        } else {
+        let Some(drop_trait) = cx.tcx.lang_items().drop_trait() else {
             // there is no way to define a type that needs non-const drop
             // without having the lang item present.
             return false;
index 49962570129704a91392ec7117e379e53d0aa040..e3395df35908c847c1c83f6fa5501483a828ece0 100644 (file)
@@ -23,7 +23,7 @@ rustc-hash = "1.1.0"
 smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
 rustc_index = { path = "../rustc_index", package = "rustc_index" }
 bitflags = "1.2.1"
-measureme = "9.1.0"
+measureme = "10.0.0"
 libc = "0.2"
 stacker = "0.1.14"
 tempfile = "3.2"
index 0bbd0eda0c6e1cdd0130013c598eb0c83a395b6b..c21939209fc3bfecb7fcea268f8d0900273402ea 100644 (file)
@@ -110,12 +110,14 @@ struct EventFilter: u32 {
         const FUNCTION_ARGS       = 1 << 6;
         const LLVM                = 1 << 7;
         const INCR_RESULT_HASHING = 1 << 8;
+        const ARTIFACT_SIZES = 1 << 9;
 
         const DEFAULT = Self::GENERIC_ACTIVITIES.bits |
                         Self::QUERY_PROVIDERS.bits |
                         Self::QUERY_BLOCKED.bits |
                         Self::INCR_CACHE_LOADS.bits |
-                        Self::INCR_RESULT_HASHING.bits;
+                        Self::INCR_RESULT_HASHING.bits |
+                        Self::ARTIFACT_SIZES.bits;
 
         const ARGS = Self::QUERY_KEYS.bits | Self::FUNCTION_ARGS.bits;
     }
@@ -136,6 +138,7 @@ struct EventFilter: u32 {
     ("args", EventFilter::ARGS),
     ("llvm", EventFilter::LLVM),
     ("incr-result-hashing", EventFilter::INCR_RESULT_HASHING),
+    ("artifact-sizes", EventFilter::ARTIFACT_SIZES),
 ];
 
 /// Something that uniquely identifies a query invocation.
@@ -285,6 +288,33 @@ pub fn generic_activity_with_arg<A>(
         })
     }
 
+    /// Record the size of an artifact that the compiler produces
+    ///
+    /// `artifact_kind` is the class of artifact (e.g., query_cache, object_file, etc.)
+    /// `artifact_name` is an identifier to the specific artifact being stored (usually a filename)
+    #[inline(always)]
+    pub fn artifact_size<A>(&self, artifact_kind: &str, artifact_name: A, size: u64)
+    where
+        A: Borrow<str> + Into<String>,
+    {
+        drop(self.exec(EventFilter::ARTIFACT_SIZES, |profiler| {
+            let builder = EventIdBuilder::new(&profiler.profiler);
+            let event_label = profiler.get_or_alloc_cached_string(artifact_kind);
+            let event_arg = profiler.get_or_alloc_cached_string(artifact_name);
+            let event_id = builder.from_label_and_arg(event_label, event_arg);
+            let thread_id = get_thread_id();
+
+            profiler.profiler.record_integer_event(
+                profiler.artifact_size_event_kind,
+                event_id,
+                thread_id,
+                size,
+            );
+
+            TimingGuard::none()
+        }))
+    }
+
     #[inline(always)]
     pub fn generic_activity_with_args(
         &self,
@@ -372,7 +402,7 @@ fn instant_query_event(
     ) {
         drop(self.exec(event_filter, |profiler| {
             let event_id = StringId::new_virtual(query_invocation_id.0);
-            let thread_id = std::thread::current().id().as_u64().get() as u32;
+            let thread_id = get_thread_id();
 
             profiler.profiler.record_instant_event(
                 event_kind(profiler),
@@ -425,6 +455,7 @@ pub struct SelfProfiler {
     incremental_result_hashing_event_kind: StringId,
     query_blocked_event_kind: StringId,
     query_cache_hit_event_kind: StringId,
+    artifact_size_event_kind: StringId,
 }
 
 impl SelfProfiler {
@@ -447,6 +478,7 @@ pub fn new(
             profiler.alloc_string("IncrementalResultHashing");
         let query_blocked_event_kind = profiler.alloc_string("QueryBlocked");
         let query_cache_hit_event_kind = profiler.alloc_string("QueryCacheHit");
+        let artifact_size_event_kind = profiler.alloc_string("ArtifactSize");
 
         let mut event_filter_mask = EventFilter::empty();
 
@@ -491,6 +523,7 @@ pub fn new(
             incremental_result_hashing_event_kind,
             query_blocked_event_kind,
             query_cache_hit_event_kind,
+            artifact_size_event_kind,
         })
     }
 
@@ -561,7 +594,7 @@ pub fn start(
         event_kind: StringId,
         event_id: EventId,
     ) -> TimingGuard<'a> {
-        let thread_id = std::thread::current().id().as_u64().get() as u32;
+        let thread_id = get_thread_id();
         let raw_profiler = &profiler.profiler;
         let timing_guard =
             raw_profiler.start_recording_interval_event(event_kind, event_id, thread_id);
@@ -655,6 +688,10 @@ pub fn duration_to_secs_str(dur: std::time::Duration) -> String {
     format!("{:.3}", dur.as_secs_f64())
 }
 
+fn get_thread_id() -> u32 {
+    std::thread::current().id().as_u64().get() as u32
+}
+
 // Memory reporting
 cfg_if! {
     if #[cfg(windows)] {
index 778d58eeadcf0344ae3ec63c72c9c661259b6988..849ffa881df7d72c238cb34d15046ebf94402a54 100644 (file)
@@ -449,11 +449,7 @@ fn fix_multispans_in_extern_macros(
         span: &mut MultiSpan,
         children: &mut Vec<SubDiagnostic>,
     ) {
-        let source_map = if let Some(ref sm) = source_map {
-            sm
-        } else {
-            return;
-        };
+        let Some(source_map) = source_map else { return };
         debug!("fix_multispans_in_extern_macros: before: span={:?} children={:?}", span, children);
         self.fix_multispan_in_extern_macros(source_map, span);
         for child in children.iter_mut() {
index 9b2094adb150c1a0dd62a2ae975c56afaff6bc21..b6cf332f511ec2fe39e4eda5fbbd5982d92539a6 100644 (file)
@@ -8,6 +8,7 @@
 #![feature(if_let_guard)]
 #![feature(format_args_capture)]
 #![feature(iter_zip)]
+#![feature(let_else)]
 #![feature(nll)]
 
 #[macro_use]
index 65f0719ba99c246334f1d3252c5ca25e5804dff8..89dbd64ed8168171e82b3577e8c440b865e4a17d 100644 (file)
@@ -447,9 +447,7 @@ pub fn fully_expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragm
         let mut undetermined_invocations = Vec::new();
         let (mut progress, mut force) = (false, !self.monotonic);
         loop {
-            let (invoc, ext) = if let Some(invoc) = invocations.pop() {
-                invoc
-            } else {
+            let Some((invoc, ext)) = invocations.pop() else {
                 self.resolve_imports();
                 if undetermined_invocations.is_empty() {
                     break;
index 6dfeb047ec94cf26d38e6bd12cb8b0fc72e60d95..521ca2135c6f217ad573c1ffbf437ade2652c08b 100644 (file)
@@ -4,6 +4,7 @@
 #![feature(format_args_capture)]
 #![feature(if_let_guard)]
 #![feature(iter_zip)]
+#![feature(let_else)]
 #![feature(proc_macro_diagnostic)]
 #![feature(proc_macro_internals)]
 #![feature(proc_macro_span)]
index 9ed5c8b8ffba5c814d4177fe50772285d1f36ec8..4663dd80fa8bbed095b1203feebf4e02bc94a7cf 100644 (file)
@@ -116,10 +116,8 @@ pub(super) fn transcribe<'a>(
 
     loop {
         // Look at the last frame on the stack.
-        let tree = if let Some(tree) = stack.last_mut().unwrap().next() {
-            // If it still has a TokenTree we have not looked at yet, use that tree.
-            tree
-        } else {
+        // If it still has a TokenTree we have not looked at yet, use that tree.
+        let Some(tree) = stack.last_mut().unwrap().next() else {
             // This else-case never produces a value for `tree` (it `continue`s or `return`s).
 
             // Otherwise, if we have just reached the end of a sequence and we can keep repeating,
@@ -190,9 +188,7 @@ pub(super) fn transcribe<'a>(
                     LockstepIterSize::Constraint(len, _) => {
                         // We do this to avoid an extra clone above. We know that this is a
                         // sequence already.
-                        let (sp, seq) = if let mbe::TokenTree::Sequence(sp, seq) = seq {
-                            (sp, seq)
-                        } else {
+                        let mbe::TokenTree::Sequence(sp, seq) = seq else {
                             unreachable!()
                         };
 
index f089cbcfca6e5f150a2bdc40776eb3ab0d1bbc6f..dd3f8c937f81abd400017a7885e74a02990ada60 100644 (file)
@@ -2,6 +2,7 @@
 
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![feature(in_band_lifetimes)]
+#![feature(let_else)]
 #![feature(nll)]
 #![recursion_limit = "256"]
 
index 572a4fc69717380aa6a8867a175425fd270da670..392c5bdc15ad204472ec07f3d6cced7028d3bf53 100644 (file)
@@ -95,6 +95,12 @@ pub(crate) fn save_in<F>(sess: &Session, path_buf: PathBuf, name: &str, encode:
         return;
     }
 
+    sess.prof.artifact_size(
+        &name.replace(' ', "_"),
+        path_buf.file_name().unwrap().to_string_lossy(),
+        encoder.position() as u64,
+    );
+
     debug!("save: data written to disk successfully");
 }
 
index 2ed0539841aa30b42f896132fbf02779b70354c6..38cbf5314ef314361e3bf869a9a99a9ebf37c1c5 100644 (file)
@@ -241,9 +241,7 @@ pub fn prepare_session_directory(
         // have already tried before.
         let source_directory = find_source_directory(&crate_dir, &source_directories_already_tried);
 
-        let source_directory = if let Some(dir) = source_directory {
-            dir
-        } else {
+        let Some(source_directory) = source_directory else {
             // There's nowhere to copy from, we're done
             debug!(
                 "no source directory found. Continuing with empty session \
@@ -397,15 +395,14 @@ fn copy_files(sess: &Session, target_dir: &Path, source_dir: &Path) -> Result<bo
     // We acquire a shared lock on the lock file of the directory, so that
     // nobody deletes it out from under us while we are reading from it.
     let lock_file_path = lock_file_path(source_dir);
-    let _lock = if let Ok(lock) = flock::Lock::new(
+
+    // not exclusive
+    let Ok(_lock) = flock::Lock::new(
         &lock_file_path,
         false, // don't wait,
         false, // don't create
         false,
-    ) {
-        // not exclusive
-        lock
-    } else {
+    ) else {
         // Could not acquire the lock, don't try to copy from here
         return Err(());
     };
index 7fba6a823d75ee4e40a62365a655dee1aed4c99e..c6ccd9b60a9c44ba0a788cc067c95ca7aae116b4 100644 (file)
@@ -263,9 +263,7 @@ pub fn suggest_new_region_bound(
         match fn_return.kind {
             TyKind::OpaqueDef(item_id, _) => {
                 let item = tcx.hir().item(item_id);
-                let opaque = if let ItemKind::OpaqueTy(opaque) = &item.kind {
-                    opaque
-                } else {
+                let ItemKind::OpaqueTy(opaque) = &item.kind else {
                     return;
                 };
 
index a4cfaddeeb96f40cce76d3b1cb6f9d098348edca..d0f1ff649d058a0558f80ef9258234fac1fd165a 100644 (file)
@@ -17,6 +17,7 @@
 #![feature(box_patterns)]
 #![feature(extend_one)]
 #![feature(iter_zip)]
+#![feature(let_else)]
 #![feature(never_type)]
 #![feature(in_band_lifetimes)]
 #![feature(control_flow_enum)]
index 644b849a9f899e17bb81ccfec572c1591cc64489..6cf0dd8b1addbee40c76b377e7c05bb52c39455e 100644 (file)
@@ -2,6 +2,7 @@
 #![feature(crate_visibility_modifier)]
 #![feature(drain_filter)]
 #![feature(in_band_lifetimes)]
+#![feature(let_else)]
 #![feature(nll)]
 #![feature(once_cell)]
 #![feature(proc_macro_internals)]
index 89bb5797a828f3770d78f02ad1ba0c96dc10e62e..ca9daa49aa2d2115d4e522d23ef38996af7f7a80 100644 (file)
@@ -472,9 +472,7 @@ fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> Result<Span, String> {
         let len = BytePos::decode(decoder)?;
         let hi = lo + len;
 
-        let sess = if let Some(sess) = decoder.sess {
-            sess
-        } else {
+        let Some(sess) = decoder.sess else {
             bug!("Cannot decode Span without Session.")
         };
 
index e41f5add457fb2782fa9536781d1c2b7e853fb69..0894b80507581458cb006426ed59e7b33158347e 100644 (file)
@@ -39,6 +39,7 @@
 #![feature(new_uninit)]
 #![feature(nll)]
 #![feature(once_cell)]
+#![feature(let_else)]
 #![feature(min_specialization)]
 #![feature(trusted_len)]
 #![feature(in_band_lifetimes)]
index 092eae0fc5c236bbd3bb91ed99b767a7f2994a72..1b32c8a66989f7b8ded38db6a847e1170b292616 100644 (file)
@@ -221,9 +221,7 @@ pub fn suggest_constraining_type_param(
 ) -> bool {
     let param = generics.params.iter().find(|p| p.name.ident().as_str() == param_name);
 
-    let param = if let Some(param) = param {
-        param
-    } else {
+    let Some(param) = param else {
         return false;
     };
 
index d0c7379c2d94d5aab856d8fb9ffbda0c6f795008..8ec5f4c79781f34902df49db679edbcfc574a8a6 100644 (file)
@@ -755,17 +755,14 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<'
                     }
 
                     // Extract the number of elements from the layout of the array field:
-                    let len = if let Ok(TyAndLayout {
+                    let Ok(TyAndLayout {
                         layout: Layout { fields: FieldsShape::Array { count, .. }, .. },
                         ..
-                    }) = self.layout_of(f0_ty)
-                    {
-                        count
-                    } else {
+                    }) = self.layout_of(f0_ty) else {
                         return Err(LayoutError::Unknown(ty));
                     };
 
-                    (*e_ty, *len, true)
+                    (*e_ty, *count, true)
                 } else {
                     // First ADT field is not an array:
                     (f0_ty, def.non_enum_variant().fields.len() as _, false)
@@ -787,9 +784,7 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<'
 
                 // Compute the ABI of the element type:
                 let e_ly = self.layout_of(e_ty)?;
-                let e_abi = if let Abi::Scalar(scalar) = e_ly.abi {
-                    scalar
-                } else {
+                let Abi::Scalar(e_abi) = e_ly.abi else {
                     // This error isn't caught in typeck, e.g., if
                     // the element type of the vector is generic.
                     tcx.sess.fatal(&format!(
index 05995ddcc00513398e1036cb0b7aa9ed0d8518e4..c6a34ece24576e51aa85e42b2d179aa26943dcd1 100644 (file)
@@ -221,15 +221,13 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
             let closure_hir_id = tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local());
             let closure_span = tcx.hir().span(closure_hir_id);
 
-            let (capture_index, capture) = if let Some(capture_details) =
+            let Some((capture_index, capture)) =
                 find_capture_matching_projections(
                     typeck_results,
                     var_hir_id,
                     closure_def_id,
                     &from_builder.projection,
-                ) {
-                capture_details
-            } else {
+                ) else {
                 if !enable_precise_capture(tcx, closure_span) {
                     bug!(
                         "No associated capture found for {:?}[{:#?}] even though \
index b74208edafea6172643d9c02f41a5a8cfb7679d2..8dadbf5f02bd1bd2a6a5a339cb56730867d30f08 100644 (file)
@@ -362,11 +362,7 @@ fn link_blocks<'tcx>(
         blocks: &IndexVec<DropIdx, Option<BasicBlock>>,
     ) {
         for (drop_idx, drop_data) in self.drops.iter_enumerated().rev() {
-            let block = if let Some(block) = blocks[drop_idx] {
-                block
-            } else {
-                continue;
-            };
+            let Some(block) = blocks[drop_idx] else { continue };
             match drop_data.0.kind {
                 DropKind::Value => {
                     let terminator = TerminatorKind::Drop {
index 02023c48a6c98d0371666340c32fff6bb2d1c21a..b0f1e08562c1609b4d91ef91d0b9333478f2d59c 100644 (file)
@@ -6,6 +6,7 @@
 #![feature(crate_visibility_modifier)]
 #![feature(bool_to_option)]
 #![feature(iter_zip)]
+#![feature(let_else)]
 #![feature(once_cell)]
 #![feature(min_specialization)]
 #![recursion_limit = "256"]
index 402391b87eaa93e177dee350192a0beacc64e7ea..2f3de52965db1dbe6d3f70bae30a9b3c54115ca4 100644 (file)
@@ -6,6 +6,7 @@
 #![feature(exact_size_is_empty)]
 #![feature(in_band_lifetimes)]
 #![feature(iter_zip)]
+#![feature(let_else)]
 #![feature(min_specialization)]
 #![feature(once_cell)]
 #![feature(stmt_expr_attributes)]
index c0bf4b659aa9674c12fa61201d51571afe3decaf..2d27d085b489398440fb2e4a3640624b469063ad 100644 (file)
@@ -290,9 +290,7 @@ fn peek_at(
         call: PeekCall,
     ) {
         info!(?place, "peek_at");
-        let local = if let Some(l) = place.as_local() {
-            l
-        } else {
+        let Some(local) = place.as_local() else {
             tcx.sess.span_err(call.span, "rustc_peek: argument was not a local");
             return;
         };
@@ -312,9 +310,7 @@ fn peek_at(
         call: PeekCall,
     ) {
         info!(?place, "peek_at");
-        let local = if let Some(l) = place.as_local() {
-            l
-        } else {
+        let Some(local) = place.as_local() else {
             tcx.sess.span_err(call.span, "rustc_peek: argument was not a local");
             return;
         };
index ee4e91ecb62b036451e7a48c3e2c3635f6f30f7a..84a1e3fb600fdb42d9d4283be8cab5642577e4e1 100644 (file)
@@ -673,9 +673,7 @@ fn make_call_args(
             assert!(args.next().is_none());
 
             let tuple = Place::from(tuple);
-            let tuple_tys = if let ty::Tuple(s) = tuple.ty(caller_body, tcx).ty.kind() {
-                s
-            } else {
+            let ty::Tuple(tuple_tys) = tuple.ty(caller_body, tcx).ty.kind() else {
                 bug!("Closure arguments are not passed as a tuple");
             };
 
index 9b11c8f0b24c0836fb96b3d31f82236d26e10b85..60135ef2d85717f4cf3765096b205f2fae9c0b68 100644 (file)
@@ -4,6 +4,7 @@
 #![cfg_attr(bootstrap, feature(const_panic))]
 #![feature(in_band_lifetimes)]
 #![feature(iter_zip)]
+#![feature(let_else)]
 #![feature(map_try_insert)]
 #![feature(min_specialization)]
 #![feature(option_get_or_insert_default)]
index a2cce9f1eda076e12fc6f2f43b0465a5c4e62507..822a372d8ce90fa1a11d043fe96da70e1072f750 100644 (file)
@@ -17,9 +17,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
 
 pub fn lower_slice_len_calls<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
     let language_items = tcx.lang_items();
-    let slice_len_fn_item_def_id = if let Some(slice_len_fn_item) = language_items.slice_len_fn() {
-        slice_len_fn_item
-    } else {
+    let Some(slice_len_fn_item_def_id) = language_items.slice_len_fn() else {
         // there is no language item to compare to :)
         return;
     };
index 76f0e83c8c3d5c8a63c6f65c9d01d8323ac48117..a04a0b51531509bf5ad7d3e16a9437b90cccb4e8 100644 (file)
@@ -208,7 +208,7 @@ fn normalize_array_len_call<'tcx>(
                         operand,
                         cast_ty,
                     ) => {
-                        let local = if let Some(local) = place.as_local() { local } else { return };
+                        let Some(local) = place.as_local() else { return };
                         match operand {
                             Operand::Copy(place) | Operand::Move(place) => {
                                 let operand_local =
@@ -255,9 +255,7 @@ fn normalize_array_len_call<'tcx>(
                         }
                     }
                     Rvalue::Len(place) => {
-                        let local = if let Some(local) = place.local_or_deref_local() {
-                            local
-                        } else {
+                        let Some(local) = place.local_or_deref_local() else {
                             return;
                         };
                         if let Some(cast_statement_idx) = state.get(&local).copied() {
index 5cef64d7786b3b965e9b9bd0471cddb562be8fe8..2aa506112909d6241cdc6840d94cad79c3509031 100644 (file)
@@ -83,12 +83,9 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
             let bb = BasicBlock::from_usize(bb);
             trace!("processing block {:?}", bb);
 
-            let discriminant_ty =
-                if let Some(ty) = get_switched_on_type(&body.basic_blocks()[bb], tcx, body) {
-                    ty
-                } else {
-                    continue;
-                };
+            let Some(discriminant_ty) = get_switched_on_type(&body.basic_blocks()[bb], tcx, body) else {
+                continue;
+            };
 
             let layout = tcx.layout_of(tcx.param_env(body.source.def_id()).and(discriminant_ty));
 
index 08b1d7b7fabd7314f2487935b555bf2fe1c7001c..f4082153b684048d1310b9a1990ee6b721dd128b 100644 (file)
@@ -2,6 +2,7 @@
 #![feature(bool_to_option)]
 #![feature(crate_visibility_modifier)]
 #![feature(control_flow_enum)]
+#![feature(let_else)]
 #![feature(in_band_lifetimes)]
 #![recursion_limit = "256"]
 
index be6820822586d82dc04be49b08c09ce80edbc7ea..b41906111b938598ba89cc32804dc462e5c75226 100644 (file)
@@ -458,9 +458,7 @@ fn mono_item_visibility(
     let is_generic = instance.substs.non_erasable_generics().next().is_some();
 
     // Upstream `DefId` instances get different handling than local ones.
-    let def_id = if let Some(def_id) = def_id.as_local() {
-        def_id
-    } else {
+    let Some(def_id) = def_id.as_local() else {
         return if export_generics && is_generic {
             // If it is an upstream monomorphization and we export generics, we must make
             // it available to downstream crates.
index 89df3d4674b6b363cc471fe89329292966f3329d..814581563896e3663f6347f391457bcf057819fb 100644 (file)
@@ -7,7 +7,7 @@ edition = "2021"
 doctest = false
 
 [dependencies]
-measureme = "9.0.0"
+measureme = "10.0.0"
 rustc-rayon-core = "0.3.1"
 tracing = "0.1"
 rustc_ast = { path = "../rustc_ast" }
index f5f67fcd0a08c322d3daca93e7ac299ef55a8ed4..47197a1e492a3d5901105c3894beeddac96cf6d5 100644 (file)
@@ -222,7 +222,7 @@ fn encode_node(
         index
     }
 
-    fn finish(self) -> FileEncodeResult {
+    fn finish(self, profiler: &SelfProfilerRef) -> FileEncodeResult {
         let Self { mut encoder, total_node_count, total_edge_count, result, stats: _ } = self;
         let () = result?;
 
@@ -235,7 +235,11 @@ fn finish(self) -> FileEncodeResult {
         IntEncodedWithFixedSize(edge_count).encode(&mut encoder)?;
         debug!("position: {:?}", encoder.position());
         // Drop the encoder so that nothing is written after the counts.
-        encoder.flush()
+        let result = encoder.flush();
+        // FIXME(rylev): we hardcode the dep graph file name so we don't need a dependency on
+        // rustc_incremental just for that.
+        profiler.artifact_size("dep_graph", "dep-graph.bin", encoder.position() as u64);
+        result
     }
 }
 
@@ -332,6 +336,6 @@ pub(crate) fn send(
 
     pub fn finish(self, profiler: &SelfProfilerRef) -> FileEncodeResult {
         let _prof_timer = profiler.generic_activity("incr_comp_encode_dep_graph");
-        self.status.into_inner().finish()
+        self.status.into_inner().finish(profiler)
     }
 }
index bc23de069b0d9fdbccf830ce8736ed644b0b84ed..1b992cdb0c94b2f0a3fbc7c491aa3bfc2fecff08 100644 (file)
@@ -3,6 +3,7 @@
 #![feature(core_intrinsics)]
 #![feature(hash_raw_entry)]
 #![feature(iter_zip)]
+#![feature(let_else)]
 #![feature(min_specialization)]
 #![feature(thread_local_const_init)]
 
index 98b2a450b19df73ff34e53d5e0078d580ea19b04..bd67303099220e39ee508d2e855ad8cdc1ea7ab3 100644 (file)
@@ -644,9 +644,7 @@ pub fn print_query_stack<CTX: QueryContext>(
         if Some(i) == num_frames {
             break;
         }
-        let query_info = if let Some(info) = query_map.as_ref().and_then(|map| map.get(&query)) {
-            info
-        } else {
+        let Some(query_info) = query_map.as_ref().and_then(|map| map.get(&query)) else {
             break;
         };
         let mut diag = Diagnostic::new(
index 07d720599759607a25ee5f4c68df663f00c6fc39..d3c75635783fa774e1fb42005bddf6b32e0b7cda 100644 (file)
@@ -761,11 +761,9 @@ pub fn force_query<Q, CTX>(tcx: CTX, dep_node: &DepNode<CTX::DepKind>) -> bool
         return false;
     }
 
-    let key = if let Some(key) =
+    let Some(key) =
         <Q::Key as DepNodeParams<CTX::DepContext>>::recover(*tcx.dep_context(), &dep_node)
-    {
-        key
-    } else {
+    else {
         return false;
     };
 
index 38fb1c760bd4e5fd9f30d62dcc941d4bd580aef5..63000a9d13d412eb2920c7d894dbb1c2008b450a 100644 (file)
@@ -1471,9 +1471,7 @@ pub(crate) fn check_for_module_export_macro(
         module: ModuleOrUniformRoot<'b>,
         ident: Ident,
     ) -> Option<(Option<Suggestion>, Vec<String>)> {
-        let mut crate_module = if let ModuleOrUniformRoot::Module(module) = module {
-            module
-        } else {
+        let ModuleOrUniformRoot::Module(mut crate_module) = module else {
             return None;
         };
 
index eb6f302a11da825aa195388a3bc29df9333c4f20..94563400a8b53580578424ca2251b4169e3c4391 100644 (file)
@@ -1057,9 +1057,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
                     match param.kind {
                         GenericParamKind::Lifetime { .. } => {
                             let (name, reg) = Region::early(&self.tcx.hir(), &mut index, &param);
-                            let def_id = if let Region::EarlyBound(_, def_id, _) = reg {
-                                def_id
-                            } else {
+                            let Region::EarlyBound(_, def_id, _) = reg else {
                                 bug!();
                             };
                             // We cannot predict what lifetimes are unused in opaque type.
index 4b6585f55436acf4642625a8a245ffd531373687..98c1355d05b25a16317b0f5b815e0ecd7131a28d 100644 (file)
@@ -15,6 +15,7 @@
 #![feature(crate_visibility_modifier)]
 #![feature(format_args_capture)]
 #![feature(iter_zip)]
+#![feature(let_else)]
 #![feature(never_type)]
 #![feature(nll)]
 #![recursion_limit = "256"]
index b3d36b396c51cafe80e657ec51e1202831b41af4..059b5dc51756ec4cefbf240d1169a8f2604f5e38 100644 (file)
@@ -1283,7 +1283,7 @@ mod parse {
         "specify the events recorded by the self profiler;
         for example: `-Z self-profile-events=default,query-keys`
         all options: none, all, default, generic-activity, query-provider, query-cache-hit
-                     query-blocked, incr-cache-load, incr-result-hashing, query-keys, function-args, args, llvm"),
+                     query-blocked, incr-cache-load, incr-result-hashing, query-keys, function-args, args, llvm, artifact-sizes"),
     share_generics: Option<bool> = (None, parse_opt_bool, [TRACKED],
         "make the current crate share its generic instantiations"),
     show_span: Option<String> = (None, parse_opt_string, [TRACKED],
index 017a7c45bbf9d21fd8d6c49dad2264a9a6beac92..1a049e6ec649da4bcd0c63408e40b7e5106f6d0a 100644 (file)
@@ -17,6 +17,7 @@
 #![feature(hash_drain_filter)]
 #![feature(in_band_lifetimes)]
 #![feature(iter_zip)]
+#![feature(let_else)]
 #![feature(never_type)]
 #![feature(crate_visibility_modifier)]
 #![feature(control_flow_enum)]
index 1a8f863952e6ad5cddaabc3247c5864edac6b354..970fb30487963bb7854e362fc1a825d14a2ff536 100644 (file)
@@ -1038,13 +1038,11 @@ fn suggest_impl_trait(
         let hir = self.tcx.hir();
         let parent_node = hir.get_parent_node(obligation.cause.body_id);
         let node = hir.find(parent_node);
-        let (sig, body_id) = if let Some(hir::Node::Item(hir::Item {
+        let Some(hir::Node::Item(hir::Item {
             kind: hir::ItemKind::Fn(sig, _, body_id),
             ..
         })) = node
-        {
-            (sig, body_id)
-        } else {
+        else {
             return false;
         };
         let body = hir.body(*body_id);
index 0bb00dfeb43ad92fd54f6d035dd4d545403df7f7..ad9fd0ca62cfac03e1da8c730af0805a366f28cc 100644 (file)
@@ -647,9 +647,7 @@ fn receiver_is_dispatchable<'tcx>(
     debug!("receiver_is_dispatchable: method = {:?}, receiver_ty = {:?}", method, receiver_ty);
 
     let traits = (tcx.lang_items().unsize_trait(), tcx.lang_items().dispatch_from_dyn_trait());
-    let (unsize_did, dispatch_from_dyn_did) = if let (Some(u), Some(cu)) = traits {
-        (u, cu)
-    } else {
+    let (Some(unsize_did), Some(dispatch_from_dyn_did)) = traits else {
         debug!("receiver_is_dispatchable: Missing Unsize or DispatchFromDyn traits");
         return false;
     };
index 209fd83b3ab3467caf30665072f510088acf139d..85ca4db7d747d1fbd98bad87763259bf923189e2 100644 (file)
@@ -164,9 +164,7 @@ pub fn of_item(
     ) -> Result<Option<Self>, ErrorReported> {
         let attrs = tcx.get_attrs(impl_def_id);
 
-        let attr = if let Some(item) = tcx.sess.find_by_name(&attrs, sym::rustc_on_unimplemented) {
-            item
-        } else {
+        let Some(attr) = tcx.sess.find_by_name(&attrs, sym::rustc_on_unimplemented) else {
             return Ok(None);
         };
 
index 856ea43b1ff4e5508cedd2d1927967e39502b69e..74e132097cc5588b11e33080841332d525cce521 100644 (file)
@@ -716,9 +716,7 @@ fn need_migrate_deref_output_trait_object(
             cause.clone(),
         );
 
-        let data = if let ty::Dynamic(ref data, ..) = normalized_ty.kind() {
-            data
-        } else {
+        let ty::Dynamic(data, ..) = normalized_ty.kind() else {
             return None;
         };
 
index 889b68773c27b1eaeba74e462ea02d7fc4cc2bd9..da751f2075399cef877e49ae73c661a34c2a03a6 100644 (file)
@@ -1916,9 +1916,7 @@ fn qpath_to_ty(
 
         debug!("qpath_to_ty: trait_def_id={:?}", trait_def_id);
 
-        let self_ty = if let Some(ty) = opt_self_ty {
-            ty
-        } else {
+        let Some(self_ty) = opt_self_ty else {
             let path_str = tcx.def_path_str(trait_def_id);
 
             let def_id = self.item_def_id();
index a87318ff34e6dc0a20d1e8718e6d262350a15c94..40f456de18332bf736ef0285fa1db0ee52e70695 100644 (file)
@@ -521,9 +521,7 @@ fn coerce_unsized(&self, mut source: Ty<'tcx>, mut target: Ty<'tcx>) -> CoerceRe
 
         let traits =
             (self.tcx.lang_items().unsize_trait(), self.tcx.lang_items().coerce_unsized_trait());
-        let (unsize_did, coerce_unsized_did) = if let (Some(u), Some(cu)) = traits {
-            (u, cu)
-        } else {
+        let (Some(unsize_did), Some(coerce_unsized_did)) = traits else {
             debug!("missing Unsize or CoerceUnsized traits");
             return Err(TypeError::Mismatch);
         };
index 540365956a8fb793ef5bc39380463c2f9eaf25c6..2b3672211e4f582e951922e2ff2c555c4b36866f 100644 (file)
@@ -743,9 +743,7 @@ pub fn check_for_cast(
             return false;
         }
 
-        let src = if let Ok(src) = self.tcx.sess.source_map().span_to_snippet(expr.span) {
-            src
-        } else {
+        let Ok(src) = self.tcx.sess.source_map().span_to_snippet(expr.span) else {
             return false;
         };
 
index 1bbdf910e420a55cf318c488851e60e4cf272c0e..aea1bcd95df21a63504981b9e25075a54882d89f 100644 (file)
@@ -502,9 +502,7 @@ fn add_type_neq_err_label(
             // FIXME: Instead of exiting early when encountering bound vars in
             // the function signature, consider keeping the binder here and
             // propagating it downwards.
-            let fn_sig = if let Some(fn_sig) = self.tcx.fn_sig(def_id).no_bound_vars() {
-                fn_sig
-            } else {
+            let Some(fn_sig) = self.tcx.fn_sig(def_id).no_bound_vars() else {
                 return false;
             };
 
index 635219146d0f5ee344670b467e1f76a97ecc7f79..5aa11cce25fb6d5247d38f9757f3bea37c5d6487 100644 (file)
@@ -718,10 +718,7 @@ fn check_pat_struct(
         ti: TopInfo<'tcx>,
     ) -> Ty<'tcx> {
         // Resolve the path and check the definition for errors.
-        let (variant, pat_ty) = if let Some(variant_ty) = self.check_struct_path(qpath, pat.hir_id)
-        {
-            variant_ty
-        } else {
+        let Some((variant, pat_ty)) = self.check_struct_path(qpath, pat.hir_id) else {
             let err = self.tcx.ty_error();
             for field in fields {
                 let ti = TopInfo { parent_pat: Some(pat), ..ti };
index 849bf1e455cbf3153ac2a9f5085b57c52de45c3a..5d9e6ebd50c85582c32eee27843c66753503d55b 100644 (file)
@@ -411,9 +411,7 @@ fn convert_place_op_to_mutable(
         debug!("convert_place_op_to_mutable: method={:?}", method);
         self.write_method_call(expr.hir_id, method);
 
-        let region = if let ty::Ref(r, _, hir::Mutability::Mut) = method.sig.inputs()[0].kind() {
-            r
-        } else {
+        let ty::Ref(region, _, hir::Mutability::Mut) = method.sig.inputs()[0].kind() else {
             span_bug!(expr.span, "input to mutable place op is not a mut ref?");
         };
 
index 3a10988bba0b9db381587f40fcd0bd39cb33f91d..caad28ff2b21fa90e0ca728b3f401e7e0a4aafdd 100644 (file)
@@ -1000,11 +1000,7 @@ fn compute_2229_migrations_for_drop(
             return None;
         }
 
-        let root_var_min_capture_list = if let Some(root_var_min_capture_list) =
-            min_captures.and_then(|m| m.get(&var_hir_id))
-        {
-            root_var_min_capture_list
-        } else {
+        let Some(root_var_min_capture_list) = min_captures.and_then(|m| m.get(&var_hir_id)) else {
             // The upvar is mentioned within the closure but no path starting from it is
             // used.
 
@@ -1077,9 +1073,7 @@ fn compute_2229_migrations(
         closure_clause: hir::CaptureBy,
         min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>,
     ) -> (Vec<MigrationDiagnosticInfo>, String) {
-        let upvars = if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
-            upvars
-        } else {
+        let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) else {
             return (Vec::new(), format!(""));
         };
 
@@ -1684,9 +1678,7 @@ fn adjust_upvar_borrow_kind_for_consume(
         diag_expr_id: hir::HirId,
     ) {
         let tcx = self.fcx.tcx;
-        let upvar_id = if let PlaceBase::Upvar(upvar_id) = place_with_id.place.base {
-            upvar_id
-        } else {
+        let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else {
             return;
         };
 
index 971776c882a157e4946fbe714bb2a54cafb375fd..017e7ad8ca74a83f6620b2f31a2df6b43c3471b3 100644 (file)
@@ -63,6 +63,7 @@
 #![feature(in_band_lifetimes)]
 #![feature(is_sorted)]
 #![feature(iter_zip)]
+#![feature(let_else)]
 #![feature(min_specialization)]
 #![feature(nll)]
 #![feature(try_blocks)]
index ba65f0fadbd9d88a38ff35fb8c4fa2e1d5154b74..89d5fac30d3576bc347c25a2e73f2a578b54aec1 100644 (file)
@@ -3,6 +3,26 @@
 use crate::num::flt2dec;
 use crate::num::fmt as numfmt;
 
+#[doc(hidden)]
+trait GeneralFormat: PartialOrd {
+    /// Determines if a value should use exponential based on its magnitude, given the precondition
+    /// that it will not be rounded any further before it is displayed.
+    fn already_rounded_value_should_use_exponential(&self) -> bool;
+}
+
+macro_rules! impl_general_format {
+    ($($t:ident)*) => {
+        $(impl GeneralFormat for $t {
+            fn already_rounded_value_should_use_exponential(&self) -> bool {
+                let abs = $t::abs_private(*self);
+                (abs != 0.0 && abs < 1e-4) || abs >= 1e+16
+            }
+        })*
+    }
+}
+
+impl_general_format! { f32 f64 }
+
 // Don't inline this so callers don't use the stack space this function
 // requires unless they have to.
 #[inline(never)]
@@ -54,8 +74,7 @@ fn float_to_decimal_common_shortest<T>(
     fmt.pad_formatted_parts(&formatted)
 }
 
-// Common code of floating point Debug and Display.
-fn float_to_decimal_common<T>(fmt: &mut Formatter<'_>, num: &T, min_precision: usize) -> Result
+fn float_to_decimal_display<T>(fmt: &mut Formatter<'_>, num: &T) -> Result
 where
     T: flt2dec::DecodableFloat,
 {
@@ -68,6 +87,7 @@ fn float_to_decimal_common<T>(fmt: &mut Formatter<'_>, num: &T, min_precision: u
     if let Some(precision) = fmt.precision {
         float_to_decimal_common_exact(fmt, num, sign, precision)
     } else {
+        let min_precision = 0;
         float_to_decimal_common_shortest(fmt, num, sign, min_precision)
     }
 }
@@ -145,19 +165,44 @@ fn float_to_exponential_common<T>(fmt: &mut Formatter<'_>, num: &T, upper: bool)
     }
 }
 
+fn float_to_general_debug<T>(fmt: &mut Formatter<'_>, num: &T) -> Result
+where
+    T: flt2dec::DecodableFloat + GeneralFormat,
+{
+    let force_sign = fmt.sign_plus();
+    let sign = match force_sign {
+        false => flt2dec::Sign::Minus,
+        true => flt2dec::Sign::MinusPlus,
+    };
+
+    if let Some(precision) = fmt.precision {
+        // this behavior of {:.PREC?} predates exponential formatting for {:?}
+        float_to_decimal_common_exact(fmt, num, sign, precision)
+    } else {
+        // since there is no precision, there will be no rounding
+        if num.already_rounded_value_should_use_exponential() {
+            let upper = false;
+            float_to_exponential_common_shortest(fmt, num, sign, upper)
+        } else {
+            let min_precision = 1;
+            float_to_decimal_common_shortest(fmt, num, sign, min_precision)
+        }
+    }
+}
+
 macro_rules! floating {
     ($ty:ident) => {
         #[stable(feature = "rust1", since = "1.0.0")]
         impl Debug for $ty {
             fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
-                float_to_decimal_common(fmt, self, 1)
+                float_to_general_debug(fmt, self)
             }
         }
 
         #[stable(feature = "rust1", since = "1.0.0")]
         impl Display for $ty {
             fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
-                float_to_decimal_common(fmt, self, 0)
+                float_to_decimal_display(fmt, self)
             }
         }
 
index ad8106df198da3005c3b4e0692aef6e259b86213..83a922ae34891b969d5616ce1ed20d30e60bae2a 100644 (file)
@@ -449,7 +449,7 @@ pub const fn is_nan(self) -> bool {
     // private use internally.
     #[inline]
     #[rustc_const_unstable(feature = "const_float_classify", issue = "72505")]
-    const fn abs_private(self) -> f32 {
+    pub(crate) const fn abs_private(self) -> f32 {
         f32::from_bits(self.to_bits() & 0x7fff_ffff)
     }
 
index 6a48101e04fdac695166d174e2484cbc73d60946..4267260eea38cbbb6cc294da4fd7692ffc68344f 100644 (file)
@@ -448,7 +448,7 @@ pub const fn is_nan(self) -> bool {
     // private use internally.
     #[inline]
     #[rustc_const_unstable(feature = "const_float_classify", issue = "72505")]
-    const fn abs_private(self) -> f64 {
+    pub(crate) const fn abs_private(self) -> f64 {
         f64::from_bits(self.to_bits() & 0x7fff_ffff_ffff_ffff)
     }
 
index bd0daf7a8eb8487b1ce795cc4ae6f7fde055719d..47a7400f76ef95ecfb73146e2f295aa649ac3907 100644 (file)
@@ -12,6 +12,16 @@ fn test_format_f64() {
     assert_eq!("1.23456789E3", format!("{:E}", 1234.56789f64));
     assert_eq!("0.0", format!("{:?}", 0.0f64));
     assert_eq!("1.01", format!("{:?}", 1.01f64));
+
+    let high_cutoff = 1e16_f64;
+    assert_eq!("1e16", format!("{:?}", high_cutoff));
+    assert_eq!("-1e16", format!("{:?}", -high_cutoff));
+    assert!(!is_exponential(&format!("{:?}", high_cutoff * (1.0 - 2.0 * f64::EPSILON))));
+    assert_eq!("-3.0", format!("{:?}", -3f64));
+    assert_eq!("0.0001", format!("{:?}", 0.0001f64));
+    assert_eq!("9e-5", format!("{:?}", 0.00009f64));
+    assert_eq!("1234567.9", format!("{:.1?}", 1234567.89f64));
+    assert_eq!("1234.6", format!("{:.1?}", 1234.56789f64));
 }
 
 #[test]
@@ -28,4 +38,18 @@ fn test_format_f32() {
     assert_eq!("1.2345679E3", format!("{:E}", 1234.56789f32));
     assert_eq!("0.0", format!("{:?}", 0.0f32));
     assert_eq!("1.01", format!("{:?}", 1.01f32));
+
+    let high_cutoff = 1e16_f32;
+    assert_eq!("1e16", format!("{:?}", high_cutoff));
+    assert_eq!("-1e16", format!("{:?}", -high_cutoff));
+    assert!(!is_exponential(&format!("{:?}", high_cutoff * (1.0 - 2.0 * f32::EPSILON))));
+    assert_eq!("-3.0", format!("{:?}", -3f32));
+    assert_eq!("0.0001", format!("{:?}", 0.0001f32));
+    assert_eq!("9e-5", format!("{:?}", 0.00009f32));
+    assert_eq!("1234567.9", format!("{:.1?}", 1234567.89f32));
+    assert_eq!("1234.6", format!("{:.1?}", 1234.56789f32));
+}
+
+fn is_exponential(s: &str) -> bool {
+    s.contains("e") || s.contains("E")
 }
index c7957a74bdcf3b11e7154c1a9401735f23ebd484..7fbbf4e8f23e3c24b8afff541dcb17e53eb5ff88 160000 (submodule)
@@ -1 +1 @@
-Subproject commit c7957a74bdcf3b11e7154c1a9401735f23ebd484
+Subproject commit 7fbbf4e8f23e3c24b8afff541dcb17e53eb5ff88