Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit af2aa22

Browse files
authoredNov 4, 2024
Unrolled build for rust-lang#132521
Rollup merge of rust-lang#132521 - klensy:times, r=compiler-errors replace manual time convertions with std ones, comptime time format parsing First commit replaces few manual time conversions with std ones, second makes parsing of time format at compiletime.
2 parents 42188c3 + bc1d8e7 commit af2aa22

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed
 

‎compiler/rustc_driver_impl/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ rustc_trait_selection = { path = "../rustc_trait_selection" }
4949
rustc_ty_utils = { path = "../rustc_ty_utils" }
5050
serde_json = "1.0.59"
5151
shlex = "1.0"
52-
time = { version = "0.3.36", default-features = false, features = ["alloc", "formatting", "parsing", "macros"] }
52+
time = { version = "0.3.36", default-features = false, features = ["alloc", "formatting", "macros"] }
5353
tracing = { version = "0.1.35" }
5454
# tidy-alphabetical-end
5555

‎compiler/rustc_driver_impl/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ use rustc_span::source_map::FileLoader;
6464
use rustc_target::json::ToJson;
6565
use rustc_target::spec::{Target, TargetTuple};
6666
use time::OffsetDateTime;
67+
use time::macros::format_description;
6768
use tracing::trace;
6869

6970
#[allow(unused_macros)]
@@ -1356,8 +1357,7 @@ fn ice_path_with_config(config: Option<&UnstableOptions>) -> &'static Option<Pat
13561357
let file_now = now
13571358
.format(
13581359
// Don't use a standard datetime format because Windows doesn't support `:` in paths
1359-
&time::format_description::parse("[year]-[month]-[day]T[hour]_[minute]_[second]")
1360-
.unwrap(),
1360+
&format_description!("[year]-[month]-[day]T[hour]_[minute]_[second]"),
13611361
)
13621362
.unwrap_or_default();
13631363
let pid = std::process::id();

‎compiler/rustc_incremental/src/persist/fs.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -585,23 +585,17 @@ fn extract_timestamp_from_session_dir(directory_name: &str) -> Result<SystemTime
585585

586586
fn timestamp_to_string(timestamp: SystemTime) -> BaseNString {
587587
let duration = timestamp.duration_since(UNIX_EPOCH).unwrap();
588-
let micros = duration.as_secs() * 1_000_000 + (duration.subsec_nanos() as u64) / 1000;
588+
let micros: u64 = duration.as_micros().try_into().unwrap();
589589
micros.to_base_fixed_len(CASE_INSENSITIVE)
590590
}
591591

592592
fn string_to_timestamp(s: &str) -> Result<SystemTime, &'static str> {
593-
let micros_since_unix_epoch = u64::from_str_radix(s, INT_ENCODE_BASE as u32);
594-
595-
if micros_since_unix_epoch.is_err() {
596-
return Err("timestamp not an int");
597-
}
598-
599-
let micros_since_unix_epoch = micros_since_unix_epoch.unwrap();
593+
let micros_since_unix_epoch = match u64::from_str_radix(s, INT_ENCODE_BASE as u32) {
594+
Ok(micros) => micros,
595+
Err(_) => return Err("timestamp not an int"),
596+
};
600597

601-
let duration = Duration::new(
602-
micros_since_unix_epoch / 1_000_000,
603-
1000 * (micros_since_unix_epoch % 1_000_000) as u32,
604-
);
598+
let duration = Duration::from_micros(micros_since_unix_epoch);
605599
Ok(UNIX_EPOCH + duration)
606600
}
607601

‎compiler/rustc_query_system/src/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ impl<D: Deps> CurrentDepGraph<D> {
10981098
use std::time::{SystemTime, UNIX_EPOCH};
10991099

11001100
let duration = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
1101-
let nanos = duration.as_secs() * 1_000_000_000 + duration.subsec_nanos() as u64;
1101+
let nanos = duration.as_nanos();
11021102
let mut stable_hasher = StableHasher::new();
11031103
nanos.hash(&mut stable_hasher);
11041104
let anon_id_seed = stable_hasher.finish();

0 commit comments

Comments
 (0)
Failed to load comments.