1
Fork 0

Use generic NonZero internally.

This commit is contained in:
Markus Reiter 2024-01-29 23:59:09 +01:00
parent ee9c7c940c
commit 746a58d435
No known key found for this signature in database
GPG key ID: 245293B51702655B
144 changed files with 653 additions and 604 deletions

View file

@ -3226,7 +3226,7 @@ pub(crate) mod dep_tracking {
};
use std::collections::BTreeMap;
use std::hash::{DefaultHasher, Hash};
use std::num::NonZeroUsize;
use std::num::NonZero;
use std::path::PathBuf;
pub trait DepTrackingHash {
@ -3268,7 +3268,7 @@ pub(crate) mod dep_tracking {
impl_dep_tracking_hash_via_hash!(
bool,
usize,
NonZeroUsize,
NonZero<usize>,
u64,
Hash64,
String,

View file

@ -1,4 +1,4 @@
use std::num::NonZeroU32;
use std::num::NonZero;
use rustc_ast::token;
use rustc_ast::util::literal::LitError;
@ -26,7 +26,7 @@ impl<'a> IntoDiagnostic<'a> for FeatureGateError {
#[derive(Subdiagnostic)]
#[note(session_feature_diagnostic_for_issue)]
pub struct FeatureDiagnosticForIssue {
pub n: NonZeroU32,
pub n: NonZero<u32>,
}
#[derive(Subdiagnostic)]

View file

@ -1,3 +1,4 @@
#![feature(generic_nonzero)]
#![feature(let_chains)]
#![feature(lazy_cell)]
#![feature(option_get_or_insert_default)]

View file

@ -21,7 +21,7 @@ use rustc_span::SourceFileHashAlgorithm;
use std::collections::BTreeMap;
use std::hash::{DefaultHasher, Hasher};
use std::num::{IntErrorKind, NonZeroUsize};
use std::num::{IntErrorKind, NonZero};
use std::path::PathBuf;
use std::str;
@ -617,7 +617,7 @@ mod parse {
pub(crate) fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
match v.and_then(|s| s.parse().ok()) {
Some(0) => {
*slot = std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get);
*slot = std::thread::available_parallelism().map_or(1, NonZero::<usize>::get);
true
}
Some(i) => {
@ -991,7 +991,10 @@ mod parse {
true
}
pub(crate) fn parse_treat_err_as_bug(slot: &mut Option<NonZeroUsize>, v: Option<&str>) -> bool {
pub(crate) fn parse_treat_err_as_bug(
slot: &mut Option<NonZero<usize>>,
v: Option<&str>,
) -> bool {
match v {
Some(s) => match s.parse() {
Ok(val) => {
@ -1004,7 +1007,7 @@ mod parse {
}
},
None => {
*slot = NonZeroUsize::new(1);
*slot = NonZero::<usize>::new(1);
true
}
}
@ -1950,7 +1953,7 @@ written to standard error output)"),
"translate remapped paths into local paths when possible (default: yes)"),
trap_unreachable: Option<bool> = (None, parse_opt_bool, [TRACKED],
"generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)"),
treat_err_as_bug: Option<NonZeroUsize> = (None, parse_treat_err_as_bug, [TRACKED],
treat_err_as_bug: Option<NonZero<usize>> = (None, parse_treat_err_as_bug, [TRACKED],
"treat the `val`th error that occurs as bug (default if not specified: 0 - don't treat errors as bugs. \
default if specified without a value: 1 - treat the first error as bug)"),
trim_diagnostic_paths: bool = (true, parse_bool, [UNTRACKED],