Skip to content

Commit 03d7ad7

Browse files
committed
Auto merge of #149750 - Zalathar:rollup-9qjiz5r, r=Zalathar
Rollup of 8 pull requests Successful merges: - #148935 (Fix division syntax in doc comments) - #149207 (Add `ilog10` result range hints) - #149676 (Tidying up tests/ui/issues tests [3/N]) - #149710 (Move ambient gdb discovery from compiletest to bootstrap) - #149714 (Check associated type where-clauses for lifetimes) - #149722 (contracts: fix lowering final declaration without trailing semicolon) - #149736 (contracts: clean up feature flag warning duplicated across tests) - #149739 (mailmap: add binarycat) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5549523 + 2aa4bdc commit 03d7ad7

File tree

121 files changed

+596
-763
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+596
-763
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Ben Sago <ogham@users.noreply.github.com> <ogham@bsago.me>
8383
Ben Striegel <ben.striegel@gmail.com>
8484
Benjamin Jackman <ben@jackman.biz>
8585
Benoît Cortier <benoit.cortier@fried-world.eu>
86+
binarycat <binarycat@envs.net> lolbinarycat <dogedoge61+github@gmail.com> <dogedoge61@gmail.com>
8687
Bheesham Persaud <bheesham123@hotmail.com> Bheesham Persaud <bheesham.persaud@live.ca>
8788
bjorn3 <17426603+bjorn3@users.noreply.github.com> <bjorn3@users.noreply.github.com>
8889
bjorn3 <17426603+bjorn3@users.noreply.github.com> <bjorn3_gh@protonmail.com>

compiler/rustc_ast_lowering/src/contract.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2323
// The order in which things are lowered is important! I.e to
2424
// refer to variables in contract_decls from postcond/precond,
2525
// we must lower it first!
26-
let contract_decls = self.lower_stmts(&contract.declarations).0;
26+
let contract_decls = self.lower_decls(contract);
2727

2828
match (&contract.requires, &contract.ensures) {
2929
(Some(req), Some(ens)) => {
@@ -124,6 +124,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
124124
}
125125
}
126126

127+
fn lower_decls(&mut self, contract: &rustc_ast::FnContract) -> &'hir [rustc_hir::Stmt<'hir>] {
128+
let (decls, decls_tail) = self.lower_stmts(&contract.declarations);
129+
130+
if let Some(e) = decls_tail {
131+
// include the tail expression in the declaration statements
132+
let tail = self.stmt_expr(e.span, *e);
133+
self.arena.alloc_from_iter(decls.into_iter().map(|d| *d).chain([tail].into_iter()))
134+
} else {
135+
decls
136+
}
137+
}
138+
127139
/// Lower the precondition check intrinsic.
128140
fn lower_precond(&mut self, req: &Box<rustc_ast::Expr>) -> rustc_hir::Stmt<'hir> {
129141
let lowered_req = self.lower_expr_mut(&req);

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
301301
visit::walk_ty(self, ty)
302302
}
303303

304-
fn visit_generics(&mut self, g: &'a ast::Generics) {
305-
for predicate in &g.where_clause.predicates {
306-
match &predicate.kind {
307-
ast::WherePredicateKind::BoundPredicate(bound_pred) => {
308-
// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`).
309-
self.check_late_bound_lifetime_defs(&bound_pred.bound_generic_params);
310-
}
311-
_ => {}
312-
}
304+
fn visit_where_predicate_kind(&mut self, kind: &'a ast::WherePredicateKind) {
305+
if let ast::WherePredicateKind::BoundPredicate(bound) = kind {
306+
// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`).
307+
self.check_late_bound_lifetime_defs(&bound.bound_generic_params);
313308
}
314-
visit::walk_generics(self, g);
309+
visit::walk_where_predicate_kind(self, kind);
315310
}
316311

317312
fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FnRetTy) {

library/core/src/num/f128.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,8 @@ impl f128 {
17531753
q
17541754
}
17551755

1756-
/// Calculates the least nonnegative remainder of `self (mod rhs)`.
1756+
/// Calculates the least nonnegative remainder of `self` when
1757+
/// divided by `rhs`.
17571758
///
17581759
/// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in
17591760
/// most cases. However, due to a floating point round-off error it can

library/core/src/num/f16.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,8 @@ impl f16 {
17281728
q
17291729
}
17301730

1731-
/// Calculates the least nonnegative remainder of `self (mod rhs)`.
1731+
/// Calculates the least nonnegative remainder of `self` when
1732+
/// divided by `rhs`.
17321733
///
17331734
/// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in
17341735
/// most cases. However, due to a floating point round-off error it can

library/core/src/num/int_log10.rs

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! These functions compute the integer logarithm of their type, assuming
22
//! that someone has already checked that the value is strictly positive.
33
4+
use crate::num::NonZero;
5+
46
// 0 < val <= u8::MAX
57
#[inline]
6-
pub(super) const fn u8(val: u8) -> u32 {
8+
const fn u8_impl(val: u8) -> u32 {
79
let val = val as u32;
810

911
// For better performance, avoid branches by assembling the solution
@@ -45,13 +47,13 @@ const fn less_than_5(val: u32) -> u32 {
4547

4648
// 0 < val <= u16::MAX
4749
#[inline]
48-
pub(super) const fn u16(val: u16) -> u32 {
50+
const fn u16_impl(val: u16) -> u32 {
4951
less_than_5(val as u32)
5052
}
5153

5254
// 0 < val <= u32::MAX
5355
#[inline]
54-
pub(super) const fn u32(mut val: u32) -> u32 {
56+
const fn u32_impl(mut val: u32) -> u32 {
5557
let mut log = 0;
5658
if val >= 100_000 {
5759
val /= 100_000;
@@ -62,7 +64,7 @@ pub(super) const fn u32(mut val: u32) -> u32 {
6264

6365
// 0 < val <= u64::MAX
6466
#[inline]
65-
pub(super) const fn u64(mut val: u64) -> u32 {
67+
const fn u64_impl(mut val: u64) -> u32 {
6668
let mut log = 0;
6769
if val >= 10_000_000_000 {
6870
val /= 10_000_000_000;
@@ -77,66 +79,87 @@ pub(super) const fn u64(mut val: u64) -> u32 {
7779

7880
// 0 < val <= u128::MAX
7981
#[inline]
80-
pub(super) const fn u128(mut val: u128) -> u32 {
82+
const fn u128_impl(mut val: u128) -> u32 {
8183
let mut log = 0;
8284
if val >= 100_000_000_000_000_000_000_000_000_000_000 {
8385
val /= 100_000_000_000_000_000_000_000_000_000_000;
8486
log += 32;
85-
return log + u32(val as u32);
87+
return log + u32_impl(val as u32);
8688
}
8789
if val >= 10_000_000_000_000_000 {
8890
val /= 10_000_000_000_000_000;
8991
log += 16;
9092
}
91-
log + u64(val as u64)
93+
log + u64_impl(val as u64)
9294
}
9395

94-
#[cfg(target_pointer_width = "16")]
95-
#[inline]
96-
pub(super) const fn usize(val: usize) -> u32 {
97-
u16(val as _)
98-
}
96+
macro_rules! define_unsigned_ilog10 {
97+
($($ty:ident => $impl_fn:ident,)*) => {$(
98+
#[inline]
99+
pub(super) const fn $ty(val: NonZero<$ty>) -> u32 {
100+
let result = $impl_fn(val.get());
99101

100-
#[cfg(target_pointer_width = "32")]
101-
#[inline]
102-
pub(super) const fn usize(val: usize) -> u32 {
103-
u32(val as _)
104-
}
102+
// SAFETY: Integer logarithm is monotonic non-decreasing, so the computed `result` cannot
103+
// exceed the value produced for the maximum input.
104+
unsafe { crate::hint::assert_unchecked(result <= const { $impl_fn($ty::MAX) }) };
105105

106-
#[cfg(target_pointer_width = "64")]
107-
#[inline]
108-
pub(super) const fn usize(val: usize) -> u32 {
109-
u64(val as _)
106+
result
107+
}
108+
)*};
110109
}
111110

112-
// 0 < val <= i8::MAX
113-
#[inline]
114-
pub(super) const fn i8(val: i8) -> u32 {
115-
u8(val as u8)
111+
define_unsigned_ilog10! {
112+
u8 => u8_impl,
113+
u16 => u16_impl,
114+
u32 => u32_impl,
115+
u64 => u64_impl,
116+
u128 => u128_impl,
116117
}
117118

118-
// 0 < val <= i16::MAX
119119
#[inline]
120-
pub(super) const fn i16(val: i16) -> u32 {
121-
u16(val as u16)
122-
}
120+
pub(super) const fn usize(val: NonZero<usize>) -> u32 {
121+
#[cfg(target_pointer_width = "16")]
122+
let impl_fn = u16;
123123

124-
// 0 < val <= i32::MAX
125-
#[inline]
126-
pub(super) const fn i32(val: i32) -> u32 {
127-
u32(val as u32)
124+
#[cfg(target_pointer_width = "32")]
125+
let impl_fn = u32;
126+
127+
#[cfg(target_pointer_width = "64")]
128+
let impl_fn = u64;
129+
130+
// SAFETY: We have selected the correct `impl_fn`, so the converting `val` to the argument is
131+
// safe.
132+
impl_fn(unsafe { NonZero::new_unchecked(val.get() as _) })
128133
}
129134

130-
// 0 < val <= i64::MAX
131-
#[inline]
132-
pub(super) const fn i64(val: i64) -> u32 {
133-
u64(val as u64)
135+
macro_rules! define_signed_ilog10 {
136+
($($ty:ident => $impl_fn:ident,)*) => {$(
137+
// 0 < val <= $ty::MAX
138+
#[inline]
139+
pub(super) const fn $ty(val: $ty) -> Option<u32> {
140+
if val > 0 {
141+
let result = $impl_fn(val.cast_unsigned());
142+
143+
// SAFETY: Integer logarithm is monotonic non-decreasing, so the computed `result`
144+
// cannot exceed the value produced for the maximum input.
145+
unsafe {
146+
crate::hint::assert_unchecked(result <= const { $impl_fn($ty::MAX.cast_unsigned()) });
147+
}
148+
149+
Some(result)
150+
} else {
151+
None
152+
}
153+
}
154+
)*};
134155
}
135156

136-
// 0 < val <= i128::MAX
137-
#[inline]
138-
pub(super) const fn i128(val: i128) -> u32 {
139-
u128(val as u128)
157+
define_signed_ilog10! {
158+
i8 => u8_impl,
159+
i16 => u16_impl,
160+
i32 => u32_impl,
161+
i64 => u64_impl,
162+
i128 => u128_impl,
140163
}
141164

142165
/// Instantiate this panic logic once, rather than for all the ilog methods

library/core/src/num/int_macros.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,7 +3147,8 @@ macro_rules! int_impl {
31473147
}
31483148

31493149

3150-
/// Calculates the least nonnegative remainder of `self (mod rhs)`.
3150+
/// Calculates the least nonnegative remainder of `self` when
3151+
/// divided by `rhs`.
31513152
///
31523153
/// This is done as if by the Euclidean division algorithm -- given
31533154
/// `r = self.rem_euclid(rhs)`, the result satisfies
@@ -3527,11 +3528,7 @@ macro_rules! int_impl {
35273528
without modifying the original"]
35283529
#[inline]
35293530
pub const fn checked_ilog10(self) -> Option<u32> {
3530-
if self > 0 {
3531-
Some(int_log10::$ActualT(self as $ActualT))
3532-
} else {
3533-
None
3534-
}
3531+
int_log10::$ActualT(self as $ActualT)
35353532
}
35363533

35373534
/// Computes the absolute value of `self`.

library/core/src/num/nonzero.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
16571657
without modifying the original"]
16581658
#[inline]
16591659
pub const fn ilog10(self) -> u32 {
1660-
super::int_log10::$Int(self.get())
1660+
super::int_log10::$Int(self)
16611661
}
16621662

16631663
/// Calculates the midpoint (average) between `self` and `rhs`.

library/core/src/num/uint_macros.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3481,7 +3481,8 @@ macro_rules! uint_impl {
34813481
}
34823482

34833483

3484-
/// Calculates the least remainder of `self (mod rhs)`.
3484+
/// Calculates the least remainder of `self` when divided by
3485+
/// `rhs`.
34853486
///
34863487
/// Since, for the positive integers, all common
34873488
/// definitions of division are equal, this

library/std/src/num/f32.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ impl f32 {
252252
core::f32::math::div_euclid(self, rhs)
253253
}
254254

255-
/// Calculates the least nonnegative remainder of `self (mod rhs)`.
255+
/// Calculates the least nonnegative remainder of `self` when divided by
256+
/// `rhs`.
256257
///
257258
/// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in
258259
/// most cases. However, due to a floating point round-off error it can

0 commit comments

Comments
 (0)