Remove rust_v_1_46
We just bumped the MSRV to 1.48.0 so we know that we have all features from 1.46, no need for `rust_v_1_46` check anymore.
This commit is contained in:
parent
71fa9e81e7
commit
1dc04fe10f
|
@ -23,7 +23,7 @@ fn main() {
|
|||
.parse::<u64>()
|
||||
.expect("invalid Rust minor version");
|
||||
|
||||
for activate_version in &[46, 53, 60] {
|
||||
for activate_version in &[53, 60] {
|
||||
if minor >= *activate_version {
|
||||
println!("cargo:rustc-cfg=rust_v_1_{}", activate_version);
|
||||
}
|
||||
|
|
|
@ -1953,13 +1953,13 @@ mod tests {
|
|||
assert_eq!(Amount::from_str("5BTC BTC"), Err(E::InvalidCharacter('B')));
|
||||
assert_eq!(Amount::from_str("5 5 BTC"), Err(E::UnknownDenomination("5 BTC".into())));
|
||||
|
||||
#[cfg_attr(rust_v_1_46, track_caller)]
|
||||
#[track_caller]
|
||||
fn case(s: &str, expected: Result<Amount, ParseAmountError>) {
|
||||
assert_eq!(Amount::from_str(s), expected);
|
||||
assert_eq!(Amount::from_str(&s.replace(' ', "")), expected);
|
||||
}
|
||||
|
||||
#[cfg_attr(rust_v_1_46, track_caller)]
|
||||
#[track_caller]
|
||||
fn scase(s: &str, expected: Result<SignedAmount, ParseAmountError>) {
|
||||
assert_eq!(SignedAmount::from_str(s), expected);
|
||||
assert_eq!(SignedAmount::from_str(&s.replace(' ', "")), expected);
|
||||
|
|
|
@ -83,7 +83,7 @@ mod primitive {
|
|||
type Output = Self;
|
||||
|
||||
#[inline]
|
||||
#[cfg_attr(rust_v_1_46, track_caller)]
|
||||
#[track_caller]
|
||||
fn index(&self, index: $type) -> &Self::Output {
|
||||
// Slicing can not make slices longer
|
||||
unsafe {
|
||||
|
@ -111,7 +111,7 @@ mod primitive {
|
|||
type Output = u8;
|
||||
|
||||
#[inline]
|
||||
#[cfg_attr(rust_v_1_46, track_caller)]
|
||||
#[track_caller]
|
||||
fn index(&self, index: usize) -> &Self::Output { &self.0[index] }
|
||||
}
|
||||
|
||||
|
@ -239,7 +239,7 @@ mod primitive {
|
|||
/// ## Panics
|
||||
///
|
||||
/// This method panics if `index` is out of bounds.
|
||||
#[cfg_attr(rust_v_1_46, track_caller)]
|
||||
#[track_caller]
|
||||
pub fn remove(&mut self, index: usize) -> u8 { self.0.remove(index) }
|
||||
|
||||
/// Remove all bytes from buffer without affecting capacity.
|
||||
|
|
|
@ -1245,26 +1245,30 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
crate::internal_macros::maybe_const_fn! {
|
||||
fn predict_weight_internal(input_count: usize, partial_input_weight: usize, inputs_with_witnesses: usize, output_count: usize, output_scripts_size: usize) -> Weight {
|
||||
let input_weight = partial_input_weight + input_count * 4 * (32 + 4 + 4);
|
||||
let output_size = 8 * output_count + output_scripts_size;
|
||||
let non_input_size =
|
||||
// version:
|
||||
4 +
|
||||
// count varints:
|
||||
VarInt(input_count as u64).len() +
|
||||
VarInt(output_count as u64).len() +
|
||||
output_size +
|
||||
// lock_time
|
||||
4;
|
||||
let weight = if inputs_with_witnesses == 0 {
|
||||
non_input_size * 4 + input_weight
|
||||
} else {
|
||||
non_input_size * 4 + input_weight + input_count - inputs_with_witnesses + 2
|
||||
};
|
||||
Weight::from_wu(weight as u64)
|
||||
}
|
||||
const fn predict_weight_internal(
|
||||
input_count: usize,
|
||||
partial_input_weight: usize,
|
||||
inputs_with_witnesses: usize,
|
||||
output_count: usize,
|
||||
output_scripts_size: usize,
|
||||
) -> Weight {
|
||||
let input_weight = partial_input_weight + input_count * 4 * (32 + 4 + 4);
|
||||
let output_size = 8 * output_count + output_scripts_size;
|
||||
let non_input_size =
|
||||
// version:
|
||||
4 +
|
||||
// count varints:
|
||||
VarInt(input_count as u64).len() +
|
||||
VarInt(output_count as u64).len() +
|
||||
output_size +
|
||||
// lock_time
|
||||
4;
|
||||
let weight = if inputs_with_witnesses == 0 {
|
||||
non_input_size * 4 + input_weight
|
||||
} else {
|
||||
non_input_size * 4 + input_weight + input_count - inputs_with_witnesses + 2
|
||||
};
|
||||
Weight::from_wu(weight as u64)
|
||||
}
|
||||
|
||||
/// Predicts the weight of a to-be-constructed transaction in const context.
|
||||
|
@ -1276,7 +1280,6 @@ crate::internal_macros::maybe_const_fn! {
|
|||
/// `predict_weight` and thus is intended to be only used in `const` context.
|
||||
///
|
||||
/// Please see the documentation of `predict_weight` to learn more about this function.
|
||||
#[cfg(rust_v_1_46)]
|
||||
pub const fn predict_weight_from_slices(
|
||||
inputs: &[InputWeightPrediction],
|
||||
output_script_lens: &[usize],
|
||||
|
@ -1402,7 +1405,6 @@ impl InputWeightPrediction {
|
|||
/// This is a `const` version of [`new`](Self::new) which only allows slices due to current Rust
|
||||
/// limitations around `const fn`. Because of these limitations it may be less efficient than
|
||||
/// `new` and thus is intended to be only used in `const` context.
|
||||
#[cfg(rust_v_1_46)]
|
||||
pub const fn from_slice(input_script_len: usize, witness_element_lengths: &[usize]) -> Self {
|
||||
let mut i = 0;
|
||||
let mut total_size = 0;
|
||||
|
|
|
@ -365,21 +365,19 @@ impl_int_encodable!(i64, read_i64, emit_i64);
|
|||
|
||||
#[allow(clippy::len_without_is_empty)] // VarInt has on concept of 'is_empty'.
|
||||
impl VarInt {
|
||||
crate::internal_macros::maybe_const_fn! {
|
||||
/// Gets the length of this VarInt when encoded.
|
||||
///
|
||||
/// *Important: this method is only `const` in Rust 1.46 or higher!*
|
||||
///
|
||||
/// Returns 1 for 0..=0xFC, 3 for 0xFD..=(2^16-1), 5 for 0x10000..=(2^32-1),
|
||||
/// and 9 otherwise.
|
||||
#[inline]
|
||||
pub fn len(&self) -> usize {
|
||||
match self.0 {
|
||||
0..=0xFC => { 1 }
|
||||
0xFD..=0xFFFF => { 3 }
|
||||
0x10000..=0xFFFFFFFF => { 5 }
|
||||
_ => { 9 }
|
||||
}
|
||||
/// Gets the length of this VarInt when encoded.
|
||||
///
|
||||
/// *Important: this method is only `const` in Rust 1.46 or higher!*
|
||||
///
|
||||
/// Returns 1 for 0..=0xFC, 3 for 0xFD..=(2^16-1), 5 for 0x10000..=(2^32-1),
|
||||
/// and 9 otherwise.
|
||||
#[inline]
|
||||
pub const fn len(&self) -> usize {
|
||||
match self.0 {
|
||||
0..=0xFC => 1,
|
||||
0xFD..=0xFFFF => 3,
|
||||
0x10000..=0xFFFFFFFF => 5,
|
||||
_ => 9,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ impl<W: fmt::Write> ErrorTrackingWriter<W> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(rust_v_1_46, track_caller)]
|
||||
#[track_caller]
|
||||
fn assert_no_error(&self, fun: &str) {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
|
|
|
@ -45,20 +45,6 @@ macro_rules! impl_consensus_encoding {
|
|||
);
|
||||
}
|
||||
pub(crate) use impl_consensus_encoding;
|
||||
|
||||
/// Marks the function const in Rust 1.46.0
|
||||
macro_rules! maybe_const_fn {
|
||||
($(#[$attr:meta])* $vis:vis fn $name:ident($($args:tt)*) -> $ret:ty $body:block) => {
|
||||
#[cfg(rust_v_1_46)]
|
||||
$(#[$attr])*
|
||||
$vis const fn $name($($args)*) -> $ret $body
|
||||
|
||||
#[cfg(not(rust_v_1_46))]
|
||||
$(#[$attr])*
|
||||
$vis fn $name($($args)*) -> $ret $body
|
||||
}
|
||||
}
|
||||
pub(crate) use maybe_const_fn;
|
||||
// We use test_macros module to keep things organised, re-export everything for ease of use.
|
||||
#[cfg(test)]
|
||||
pub(crate) use test_macros::*;
|
||||
|
|
|
@ -68,7 +68,7 @@ mod out_bytes {
|
|||
/// ## Panics
|
||||
///
|
||||
/// The method panics if `len` is out of bounds.
|
||||
#[cfg_attr(rust_v_1_46, track_caller)]
|
||||
#[track_caller]
|
||||
pub(crate) fn assume_init(&self, len: usize) -> &[u8] { &self.0[..len] }
|
||||
|
||||
/// Writes given bytes into the buffer.
|
||||
|
@ -76,7 +76,7 @@ mod out_bytes {
|
|||
/// ## Panics
|
||||
///
|
||||
/// The method panics if pos is out of bounds or `bytes` don't fit into the buffer.
|
||||
#[cfg_attr(rust_v_1_46, track_caller)]
|
||||
#[track_caller]
|
||||
pub(crate) fn write(&mut self, pos: usize, bytes: &[u8]) {
|
||||
self.0[pos..(pos + bytes.len())].copy_from_slice(bytes);
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ impl<T: AsOutBytes> BufEncoder<T> {
|
|||
///
|
||||
/// The method panics if the buffer is full.
|
||||
#[inline]
|
||||
#[cfg_attr(rust_v_1_46, track_caller)]
|
||||
#[track_caller]
|
||||
pub fn put_byte(&mut self, byte: u8, case: Case) {
|
||||
self.buf.as_mut_out_bytes().write(self.pos, &super::byte_to_hex(byte, case.table()));
|
||||
self.pos += 2;
|
||||
|
@ -205,7 +205,7 @@ impl<T: AsOutBytes> BufEncoder<T> {
|
|||
///
|
||||
/// The method panics if the bytes wouldn't fit the buffer.
|
||||
#[inline]
|
||||
#[cfg_attr(rust_v_1_46, track_caller)]
|
||||
#[track_caller]
|
||||
pub fn put_bytes<I>(&mut self, bytes: I, case: Case)
|
||||
where
|
||||
I: IntoIterator,
|
||||
|
@ -215,7 +215,7 @@ impl<T: AsOutBytes> BufEncoder<T> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg_attr(rust_v_1_46, track_caller)]
|
||||
#[track_caller]
|
||||
fn put_bytes_inner<I>(&mut self, bytes: I, case: Case)
|
||||
where
|
||||
I: Iterator,
|
||||
|
@ -236,7 +236,7 @@ impl<T: AsOutBytes> BufEncoder<T> {
|
|||
/// bytes. The method returns an empty slice if all bytes were written
|
||||
#[must_use = "this may write only part of the input buffer"]
|
||||
#[inline]
|
||||
#[cfg_attr(rust_v_1_46, track_caller)]
|
||||
#[track_caller]
|
||||
pub fn put_bytes_min<'a>(&mut self, bytes: &'a [u8], case: Case) -> &'a [u8] {
|
||||
let to_write = self.space_remaining().min(bytes.len());
|
||||
self.put_bytes(&bytes[..to_write], case);
|
||||
|
|
Loading…
Reference in New Issue