Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Ben Sago <ogham@users.noreply.github.com> <ogham@bsago.me>
Ben Striegel <ben.striegel@gmail.com>
Benjamin Jackman <ben@jackman.biz>
Benoît Cortier <benoit.cortier@fried-world.eu>
binarycat <binarycat@envs.net> lolbinarycat <dogedoge61+github@gmail.com> <dogedoge61@gmail.com>
Bheesham Persaud <bheesham123@hotmail.com> Bheesham Persaud <bheesham.persaud@live.ca>
bjorn3 <17426603+bjorn3@users.noreply.github.com> <bjorn3@users.noreply.github.com>
bjorn3 <17426603+bjorn3@users.noreply.github.com> <bjorn3_gh@protonmail.com>
Expand Down
14 changes: 13 additions & 1 deletion compiler/rustc_ast_lowering/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// The order in which things are lowered is important! I.e to
// refer to variables in contract_decls from postcond/precond,
// we must lower it first!
let contract_decls = self.lower_stmts(&contract.declarations).0;
let contract_decls = self.lower_decls(contract);

match (&contract.requires, &contract.ensures) {
(Some(req), Some(ens)) => {
Expand Down Expand Up @@ -124,6 +124,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}

fn lower_decls(&mut self, contract: &rustc_ast::FnContract) -> &'hir [rustc_hir::Stmt<'hir>] {
let (decls, decls_tail) = self.lower_stmts(&contract.declarations);

if let Some(e) = decls_tail {
// include the tail expression in the declaration statements
let tail = self.stmt_expr(e.span, *e);
self.arena.alloc_from_iter(decls.into_iter().map(|d| *d).chain([tail].into_iter()))
} else {
decls
}
}

/// Lower the precondition check intrinsic.
fn lower_precond(&mut self, req: &Box<rustc_ast::Expr>) -> rustc_hir::Stmt<'hir> {
let lowered_req = self.lower_expr_mut(&req);
Expand Down
15 changes: 5 additions & 10 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
visit::walk_ty(self, ty)
}

fn visit_generics(&mut self, g: &'a ast::Generics) {
for predicate in &g.where_clause.predicates {
match &predicate.kind {
ast::WherePredicateKind::BoundPredicate(bound_pred) => {
// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`).
self.check_late_bound_lifetime_defs(&bound_pred.bound_generic_params);
}
_ => {}
}
fn visit_where_predicate_kind(&mut self, kind: &'a ast::WherePredicateKind) {
if let ast::WherePredicateKind::BoundPredicate(bound) = kind {
// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`).
self.check_late_bound_lifetime_defs(&bound.bound_generic_params);
}
visit::walk_generics(self, g);
visit::walk_where_predicate_kind(self, kind);
}

fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FnRetTy) {
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/num/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,8 @@ impl f128 {
q
}

/// Calculates the least nonnegative remainder of `self (mod rhs)`.
/// Calculates the least nonnegative remainder of `self` when
/// divided by `rhs`.
///
/// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in
/// most cases. However, due to a floating point round-off error it can
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/num/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,8 @@ impl f16 {
q
}

/// Calculates the least nonnegative remainder of `self (mod rhs)`.
/// Calculates the least nonnegative remainder of `self` when
/// divided by `rhs`.
///
/// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in
/// most cases. However, due to a floating point round-off error it can
Expand Down
105 changes: 64 additions & 41 deletions library/core/src/num/int_log10.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! These functions compute the integer logarithm of their type, assuming
//! that someone has already checked that the value is strictly positive.

use crate::num::NonZero;

// 0 < val <= u8::MAX
#[inline]
pub(super) const fn u8(val: u8) -> u32 {
const fn u8_impl(val: u8) -> u32 {
let val = val as u32;

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

// 0 < val <= u16::MAX
#[inline]
pub(super) const fn u16(val: u16) -> u32 {
const fn u16_impl(val: u16) -> u32 {
less_than_5(val as u32)
}

// 0 < val <= u32::MAX
#[inline]
pub(super) const fn u32(mut val: u32) -> u32 {
const fn u32_impl(mut val: u32) -> u32 {
let mut log = 0;
if val >= 100_000 {
val /= 100_000;
Expand All @@ -62,7 +64,7 @@ pub(super) const fn u32(mut val: u32) -> u32 {

// 0 < val <= u64::MAX
#[inline]
pub(super) const fn u64(mut val: u64) -> u32 {
const fn u64_impl(mut val: u64) -> u32 {
let mut log = 0;
if val >= 10_000_000_000 {
val /= 10_000_000_000;
Expand All @@ -77,66 +79,87 @@ pub(super) const fn u64(mut val: u64) -> u32 {

// 0 < val <= u128::MAX
#[inline]
pub(super) const fn u128(mut val: u128) -> u32 {
const fn u128_impl(mut val: u128) -> u32 {
let mut log = 0;
if val >= 100_000_000_000_000_000_000_000_000_000_000 {
val /= 100_000_000_000_000_000_000_000_000_000_000;
log += 32;
return log + u32(val as u32);
return log + u32_impl(val as u32);
}
if val >= 10_000_000_000_000_000 {
val /= 10_000_000_000_000_000;
log += 16;
}
log + u64(val as u64)
log + u64_impl(val as u64)
}

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

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

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

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

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

// 0 < val <= i32::MAX
#[inline]
pub(super) const fn i32(val: i32) -> u32 {
u32(val as u32)
#[cfg(target_pointer_width = "32")]
let impl_fn = u32;

#[cfg(target_pointer_width = "64")]
let impl_fn = u64;

// SAFETY: We have selected the correct `impl_fn`, so the converting `val` to the argument is
// safe.
impl_fn(unsafe { NonZero::new_unchecked(val.get() as _) })
}

// 0 < val <= i64::MAX
#[inline]
pub(super) const fn i64(val: i64) -> u32 {
u64(val as u64)
macro_rules! define_signed_ilog10 {
($($ty:ident => $impl_fn:ident,)*) => {$(
// 0 < val <= $ty::MAX
#[inline]
pub(super) const fn $ty(val: $ty) -> Option<u32> {
if val > 0 {
let result = $impl_fn(val.cast_unsigned());

// SAFETY: Integer logarithm is monotonic non-decreasing, so the computed `result`
// cannot exceed the value produced for the maximum input.
unsafe {
crate::hint::assert_unchecked(result <= const { $impl_fn($ty::MAX.cast_unsigned()) });
}

Some(result)
} else {
None
}
}
)*};
}

// 0 < val <= i128::MAX
#[inline]
pub(super) const fn i128(val: i128) -> u32 {
u128(val as u128)
define_signed_ilog10! {
i8 => u8_impl,
i16 => u16_impl,
i32 => u32_impl,
i64 => u64_impl,
i128 => u128_impl,
}

/// Instantiate this panic logic once, rather than for all the ilog methods
Expand Down
9 changes: 3 additions & 6 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3147,7 +3147,8 @@ macro_rules! int_impl {
}


/// Calculates the least nonnegative remainder of `self (mod rhs)`.
/// Calculates the least nonnegative remainder of `self` when
/// divided by `rhs`.
///
/// This is done as if by the Euclidean division algorithm -- given
/// `r = self.rem_euclid(rhs)`, the result satisfies
Expand Down Expand Up @@ -3527,11 +3528,7 @@ macro_rules! int_impl {
without modifying the original"]
#[inline]
pub const fn checked_ilog10(self) -> Option<u32> {
if self > 0 {
Some(int_log10::$ActualT(self as $ActualT))
} else {
None
}
int_log10::$ActualT(self as $ActualT)
}

/// Computes the absolute value of `self`.
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
without modifying the original"]
#[inline]
pub const fn ilog10(self) -> u32 {
super::int_log10::$Int(self.get())
super::int_log10::$Int(self)
}

/// Calculates the midpoint (average) between `self` and `rhs`.
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3481,7 +3481,8 @@ macro_rules! uint_impl {
}


/// Calculates the least remainder of `self (mod rhs)`.
/// Calculates the least remainder of `self` when divided by
/// `rhs`.
///
/// Since, for the positive integers, all common
/// definitions of division are equal, this
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ impl f32 {
core::f32::math::div_euclid(self, rhs)
}

/// Calculates the least nonnegative remainder of `self (mod rhs)`.
/// Calculates the least nonnegative remainder of `self` when divided by
/// `rhs`.
///
/// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in
/// most cases. However, due to a floating point round-off error it can
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ impl f64 {
core::f64::math::div_euclid(self, rhs)
}

/// Calculates the least nonnegative remainder of `self (mod rhs)`.
/// Calculates the least nonnegative remainder of `self` when divided by
/// `rhs`.
///
/// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in
/// most cases. However, due to a floating point round-off error it can
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ pub(crate) struct Android {
}

pub(crate) fn discover_android(builder: &Builder<'_>, target: TargetSelection) -> Option<Android> {
if !target.contains("android") {
return None;
}

let adb_path = "adb";
// See <https://github.com/rust-lang/rust/pull/102755>.
let adb_test_dir = "/data/local/tmp/work";

let android_cross_path = if target.contains("android") && !builder.config.dry_run() {
let android_cross_path = if !builder.config.dry_run() {
builder.cc(target).parent().unwrap().parent().unwrap().to_owned()
} else {
PathBuf::new()
Expand Down
17 changes: 7 additions & 10 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::core::builder::{
};
use crate::core::config::TargetSelection;
use crate::core::config::flags::{Subcommand, get_completion, top_level_help};
use crate::core::debuggers;
use crate::core::{android, debuggers};
use crate::utils::build_stamp::{self, BuildStamp};
use crate::utils::exec::{BootstrapCommand, command};
use crate::utils::helpers::{
Expand Down Expand Up @@ -2114,21 +2114,18 @@ Please disable assertions with `rust.debug-assertions = false`.
builder.config.python.as_ref().expect("python is required for running rustdoc tests"),
);

// FIXME(#148099): Currently we set these Android-related flags in all
// modes, even though they should only be needed in "debuginfo" mode,
// because the GDB-discovery code in compiletest currently assumes that
// `--android-cross-path` is always set for Android targets.
if let Some(debuggers::Android { adb_path, adb_test_dir, android_cross_path }) =
debuggers::discover_android(builder, target)
{
// Discover and set some flags related to running tests on Android targets.
let android = android::discover_android(builder, target);
if let Some(android::Android { adb_path, adb_test_dir, android_cross_path }) = &android {
cmd.arg("--adb-path").arg(adb_path);
cmd.arg("--adb-test-dir").arg(adb_test_dir);
cmd.arg("--android-cross-path").arg(android_cross_path);
}

if mode == "debuginfo" {
if let Some(debuggers::Gdb { gdb }) = debuggers::discover_gdb(builder) {
cmd.arg("--gdb").arg(gdb);
if let Some(debuggers::Gdb { gdb }) = debuggers::discover_gdb(builder, android.as_ref())
{
cmd.arg("--gdb").arg(gdb.as_ref());
}

if let Some(debuggers::Lldb { lldb_exe, lldb_version }) =
Expand Down
Loading
Loading