Skip to content

Rollup of 4 pull requests #143183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 29, 2025
Merged
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
| sym::simd_flog
| sym::simd_flog10
| sym::simd_flog2
| sym::simd_round => {
| sym::simd_round
| sym::simd_round_ties_even => {
intrinsic_args!(fx, args => (a); intrinsic);

if !a.layout().ty.is_simd() {
Expand Down Expand Up @@ -527,6 +528,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
(sym::simd_flog2, types::F64) => "log2",
(sym::simd_round, types::F32) => "roundf",
(sym::simd_round, types::F64) => "round",
(sym::simd_round_ties_even, types::F32) => "rintf",
(sym::simd_round_ties_even, types::F64) => "rint",
_ => unreachable!("{:?}", intrinsic),
};
fx.lib_call(
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_gcc/src/intrinsic/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
sym::simd_fsin => "sin",
sym::simd_fsqrt => "sqrt",
sym::simd_round => "round",
sym::simd_round_ties_even => "rint",
sym::simd_trunc => "trunc",
_ => return_error!(InvalidMonomorphization::UnrecognizedIntrinsic { span, name }),
};
Expand Down Expand Up @@ -827,6 +828,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
| sym::simd_fsin
| sym::simd_fsqrt
| sym::simd_round
| sym::simd_round_ties_even
| sym::simd_trunc
) {
return simd_simple_float_intrinsic(name, in_elem, in_ty, in_len, bx, span, args);
Expand Down
17 changes: 16 additions & 1 deletion compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
sym::simd_fsin => "llvm.sin",
sym::simd_fsqrt => "llvm.sqrt",
sym::simd_round => "llvm.round",
sym::simd_round_ties_even => "llvm.rint",
sym::simd_trunc => "llvm.trunc",
_ => return_error!(InvalidMonomorphization::UnrecognizedIntrinsic { span, name }),
};
Expand All @@ -1563,6 +1564,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
| sym::simd_fsqrt
| sym::simd_relaxed_fma
| sym::simd_round
| sym::simd_round_ties_even
| sym::simd_trunc
) {
return simd_simple_float_intrinsic(name, in_elem, in_ty, in_len, bx, span, args);
Expand Down Expand Up @@ -2309,7 +2311,13 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
// Unary integer intrinsics
if matches!(
name,
sym::simd_bswap | sym::simd_bitreverse | sym::simd_ctlz | sym::simd_ctpop | sym::simd_cttz
sym::simd_bswap
| sym::simd_bitreverse
| sym::simd_ctlz
| sym::simd_ctpop
| sym::simd_cttz
| sym::simd_funnel_shl
| sym::simd_funnel_shr
) {
let vec_ty = bx.cx.type_vector(
match *in_elem.kind() {
Expand All @@ -2330,6 +2338,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
sym::simd_ctlz => "llvm.ctlz",
sym::simd_ctpop => "llvm.ctpop",
sym::simd_cttz => "llvm.cttz",
sym::simd_funnel_shl => "llvm.fshl",
sym::simd_funnel_shr => "llvm.fshr",
_ => unreachable!(),
};
let int_size = in_elem.int_size_and_signed(bx.tcx()).0.bits();
Expand All @@ -2350,6 +2360,11 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
// simple unary argument cases
Ok(bx.call_intrinsic(llvm_intrinsic, &[vec_ty], &[args[0].immediate()]))
}
sym::simd_funnel_shl | sym::simd_funnel_shr => Ok(bx.call_intrinsic(
llvm_intrinsic,
&[vec_ty],
&[args[0].immediate(), args[1].immediate(), args[2].immediate()],
)),
_ => unreachable!(),
};
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_analysis/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,9 @@ pub(crate) fn check_intrinsic_type(
| sym::simd_ceil
| sym::simd_floor
| sym::simd_round
| sym::simd_round_ties_even
| sym::simd_trunc => (1, 0, vec![param(0)], param(0)),
sym::simd_fma | sym::simd_relaxed_fma => {
sym::simd_fma | sym::simd_relaxed_fma | sym::simd_funnel_shl | sym::simd_funnel_shr => {
(1, 0, vec![param(0), param(0), param(0)], param(0))
}
sym::simd_gather => (3, 0, vec![param(0), param(1), param(2)], param(0)),
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
let mut op_warned = false;

if let Some(must_use_op) = must_use_op {
let span = expr.span.find_oldest_ancestor_in_same_ctxt();
cx.emit_span_lint(
UNUSED_MUST_USE,
expr.span,
Expand All @@ -191,11 +192,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
label: expr.span,
suggestion: if expr_is_from_block {
UnusedOpSuggestion::BlockTailExpr {
before_span: expr.span.shrink_to_lo(),
after_span: expr.span.shrink_to_hi(),
before_span: span.shrink_to_lo(),
after_span: span.shrink_to_hi(),
}
} else {
UnusedOpSuggestion::NormalExpr { span: expr.span.shrink_to_lo() }
UnusedOpSuggestion::NormalExpr { span: span.shrink_to_lo() }
},
},
);
Expand Down Expand Up @@ -508,9 +509,10 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
);
}
MustUsePath::Def(span, def_id, reason) => {
let span = span.find_oldest_ancestor_in_same_ctxt();
cx.emit_span_lint(
UNUSED_MUST_USE,
*span,
span,
UnusedDef {
pre: descr_pre,
post: descr_post,
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,8 @@ symbols! {
simd_fmin,
simd_fsin,
simd_fsqrt,
simd_funnel_shl,
simd_funnel_shr,
simd_gather,
simd_ge,
simd_gt,
Expand Down Expand Up @@ -2004,6 +2006,7 @@ symbols! {
simd_relaxed_fma,
simd_rem,
simd_round,
simd_round_ties_even,
simd_saturating_add,
simd_saturating_sub,
simd_scatter,
Expand Down
42 changes: 42 additions & 0 deletions library/core/src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,40 @@ pub unsafe fn simd_shl<T>(lhs: T, rhs: T) -> T;
#[rustc_nounwind]
pub unsafe fn simd_shr<T>(lhs: T, rhs: T) -> T;

/// Funnel Shifts vector left elementwise, with UB on overflow.
///
/// Concatenates `a` and `b` elementwise (with `a` in the most significant half),
/// creating a vector of the same length, but with each element being twice as
/// wide. Then shift this vector left elementwise by `shift`, shifting in zeros,
/// and extract the most significant half of each of the elements. If `a` and `b`
/// are the same, this is equivalent to an elementwise rotate left operation.
///
/// `T` must be a vector of integers.
///
/// # Safety
///
/// Each element of `shift` must be less than `<int>::BITS`.
#[rustc_intrinsic]
#[rustc_nounwind]
pub unsafe fn simd_funnel_shl<T>(a: T, b: T, shift: T) -> T;

/// Funnel Shifts vector right elementwise, with UB on overflow.
///
/// Concatenates `a` and `b` elementwise (with `a` in the most significant half),
/// creating a vector of the same length, but with each element being twice as
/// wide. Then shift this vector right elementwise by `shift`, shifting in zeros,
/// and extract the least significant half of each of the elements. If `a` and `b`
/// are the same, this is equivalent to an elementwise rotate right operation.
///
/// `T` must be a vector of integers.
///
/// # Safety
///
/// Each element of `shift` must be less than `<int>::BITS`.
#[rustc_intrinsic]
#[rustc_nounwind]
pub unsafe fn simd_funnel_shr<T>(a: T, b: T, shift: T) -> T;

/// "Ands" vectors elementwise.
///
/// `T` must be a vector of integers.
Expand Down Expand Up @@ -678,6 +712,14 @@ pub unsafe fn simd_floor<T>(x: T) -> T;
#[rustc_nounwind]
pub unsafe fn simd_round<T>(x: T) -> T;

/// Rounds each element to the closest integer-valued float.
/// Ties are resolved by rounding to the number with an even least significant digit
///
/// `T` must be a vector of floats.
#[rustc_intrinsic]
#[rustc_nounwind]
pub unsafe fn simd_round_ties_even<T>(x: T) -> T;

/// Returns the integer part of each element as an integer-valued float.
/// In other words, non-integer values are truncated towards zero.
///
Expand Down
2 changes: 2 additions & 0 deletions src/tools/miri/src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
| "ceil"
| "floor"
| "round"
| "round_ties_even"
| "trunc"
| "fsqrt"
| "fsin"
Expand Down Expand Up @@ -71,6 +72,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"ceil" => Op::Round(rustc_apfloat::Round::TowardPositive),
"floor" => Op::Round(rustc_apfloat::Round::TowardNegative),
"round" => Op::Round(rustc_apfloat::Round::NearestTiesToAway),
"round_ties_even" => Op::Round(rustc_apfloat::Round::NearestTiesToEven),
"trunc" => Op::Round(rustc_apfloat::Round::TowardZero),
"ctlz" => Op::Numeric(sym::ctlz),
"ctpop" => Op::Numeric(sym::ctpop),
Expand Down
8 changes: 8 additions & 0 deletions src/tools/miri/tests/pass/intrinsics/portable-simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ fn simd_round() {
f32x4::from_array([0.9, 1.001, 2.0, -4.5]).round(),
f32x4::from_array([1.0, 1.0, 2.0, -5.0])
);
assert_eq!(
unsafe { intrinsics::simd_round_ties_even(f32x4::from_array([0.9, 1.001, 2.0, -4.5])) },
f32x4::from_array([1.0, 1.0, 2.0, -4.0])
);
assert_eq!(
f32x4::from_array([0.9, 1.001, 2.0, -4.5]).trunc(),
f32x4::from_array([0.0, 1.0, 2.0, -4.0])
Expand All @@ -586,6 +590,10 @@ fn simd_round() {
f64x4::from_array([0.9, 1.001, 2.0, -4.5]).round(),
f64x4::from_array([1.0, 1.0, 2.0, -5.0])
);
assert_eq!(
unsafe { intrinsics::simd_round_ties_even(f64x4::from_array([0.9, 1.001, 2.0, -4.5])) },
f64x4::from_array([1.0, 1.0, 2.0, -4.0])
);
assert_eq!(
f64x4::from_array([0.9, 1.001, 2.0, -4.5]).trunc(),
f64x4::from_array([0.0, 1.0, 2.0, -4.0])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! Check that the default global Rust allocator produces non-null Box allocations for ZSTs.
//!
//! See https://github.com/rust-lang/rust/issues/11998
//@ run-pass

pub fn main() {
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/associated-types/unconstrained-lifetime-assoc-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Regression test for issue #22077
//! lifetime parameters must be constrained in associated type definitions
trait Fun {
type Output;
fn call<'x>(&'x self) -> Self::Output;
}

struct Holder {
x: String,
}

impl<'a> Fun for Holder {
//~^ ERROR E0207
type Output = &'a str;
fn call<'b>(&'b self) -> &'b str {
&self.x[..]
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
--> $DIR/impl-unused-rps-in-assoc-type.rs:11:6
--> $DIR/unconstrained-lifetime-assoc-type.rs:13:6
|
LL | impl<'a> Fun for Holder {
| ^^ unconstrained lifetime parameter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Test that #[inline] attribute cannot be applied to enum variants
enum Foo {
#[inline]
//~^ ERROR attribute should be applied
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0518]: attribute should be applied to function or closure
--> $DIR/inline-disallow-on-variant.rs:2:5
--> $DIR/inline-attribute-enum-variant-error.rs:4:5
|
LL | #[inline]
| ^^^^^^^^^
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/attributes/inline-main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Test that #[inline(always)] can be applied to main function

//@ run-pass

#[inline(always)]
fn main() {}
8 changes: 0 additions & 8 deletions tests/ui/diverging-fn-tail-35849.rs

This file was deleted.

10 changes: 0 additions & 10 deletions tests/ui/early-ret-binop-add.rs

This file was deleted.

18 changes: 0 additions & 18 deletions tests/ui/elide-errors-on-mismatched-tuple.rs

This file was deleted.

5 changes: 0 additions & 5 deletions tests/ui/elided-test.rs

This file was deleted.

9 changes: 0 additions & 9 deletions tests/ui/elided-test.stderr

This file was deleted.

20 changes: 0 additions & 20 deletions tests/ui/else-if.rs

This file was deleted.

19 changes: 19 additions & 0 deletions tests/ui/expr/early-return-in-binop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Test early return within binary operation expressions
//@ run-pass

#![allow(dead_code)]
#![allow(unreachable_code)]

use std::ops::Add;

/// Function that performs addition with an early return in the right operand
fn add_with_early_return<T: Add<Output = T> + Copy>(n: T) -> T {
n + { return n }
}

pub fn main() {
// Test with different numeric types to ensure generic behavior works
let _result1 = add_with_early_return(42i32);
let _result2 = add_with_early_return(3.14f64);
}
Loading