Skip to content

Commit e7c0d27

Browse files
committed
Auto merge of #131747 - compiler-errors:rollup-0fnymws, r=compiler-errors
Rollup of 7 pull requests Successful merges: - #129794 (uefi: Implement getcwd and chdir) - #130568 (Make some float methods unstable `const fn`) - #131521 (rename RcBox to RcInner for consistency) - #131701 (Don't report `on_unimplemented` message for negative traits) - #131705 (Fix most ui tests on emscripten target) - #131733 (Fix uninlined_format_args in stable_mir) - #131734 (Update `arm64e-apple-tvos` maintainer) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a0c2aba + d344fdf commit e7c0d27

File tree

45 files changed

+767
-419
lines changed

Some content is hidden

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

45 files changed

+767
-419
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -992,10 +992,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
992992
match op.val {
993993
Pair(data_ptr, meta) => {
994994
// In the case of Rc<Self>, we need to explicitly pass a
995-
// *mut RcBox<Self> with a Scalar (not ScalarPair) ABI. This is a hack
995+
// *mut RcInner<Self> with a Scalar (not ScalarPair) ABI. This is a hack
996996
// that is understood elsewhere in the compiler as a method on
997997
// `dyn Trait`.
998-
// To get a `*mut RcBox<Self>`, we just keep unwrapping newtypes until
998+
// To get a `*mut RcInner<Self>`, we just keep unwrapping newtypes until
999999
// we get a value of a built-in pointer type.
10001000
//
10011001
// This is also relevant for `Pin<&mut Self>`, where we need to peel the

compiler/rustc_const_eval/src/interpret/cast.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
334334
{
335335
use rustc_type_ir::TyKind::*;
336336

337-
fn adjust_nan<
338-
'tcx,
339-
M: Machine<'tcx>,
340-
F1: rustc_apfloat::Float + FloatConvert<F2>,
341-
F2: rustc_apfloat::Float,
342-
>(
343-
ecx: &InterpCx<'tcx, M>,
344-
f1: F1,
345-
f2: F2,
346-
) -> F2 {
347-
if f2.is_nan() { M::generate_nan(ecx, &[f1]) } else { f2 }
348-
}
349-
350337
match *dest_ty.kind() {
351338
// float -> uint
352339
Uint(t) => {
@@ -367,11 +354,17 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
367354
}
368355
// float -> float
369356
Float(fty) => match fty {
370-
FloatTy::F16 => Scalar::from_f16(adjust_nan(self, f, f.convert(&mut false).value)),
371-
FloatTy::F32 => Scalar::from_f32(adjust_nan(self, f, f.convert(&mut false).value)),
372-
FloatTy::F64 => Scalar::from_f64(adjust_nan(self, f, f.convert(&mut false).value)),
357+
FloatTy::F16 => {
358+
Scalar::from_f16(self.adjust_nan(f.convert(&mut false).value, &[f]))
359+
}
360+
FloatTy::F32 => {
361+
Scalar::from_f32(self.adjust_nan(f.convert(&mut false).value, &[f]))
362+
}
363+
FloatTy::F64 => {
364+
Scalar::from_f64(self.adjust_nan(f.convert(&mut false).value, &[f]))
365+
}
373366
FloatTy::F128 => {
374-
Scalar::from_f128(adjust_nan(self, f, f.convert(&mut false).value))
367+
Scalar::from_f128(self.adjust_nan(f.convert(&mut false).value, &[f]))
375368
}
376369
},
377370
// That's it.

compiler/rustc_const_eval/src/interpret/eval_context.rs

+8
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,14 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
599599
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
600600
Frame::generate_stacktrace_from_stack(self.stack())
601601
}
602+
603+
pub fn adjust_nan<F1, F2>(&self, f: F2, inputs: &[F1]) -> F2
604+
where
605+
F1: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F2>,
606+
F2: rustc_apfloat::Float,
607+
{
608+
if f.is_nan() { M::generate_nan(self, inputs) } else { f }
609+
}
602610
}
603611

604612
#[doc(hidden)]

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+80
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
use std::assert_matches::assert_matches;
66

7+
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
78
use rustc_hir::def_id::DefId;
89
use rustc_middle::mir::{self, BinOp, ConstValue, NonDivergingIntrinsic};
910
use rustc_middle::ty::layout::{LayoutOf as _, TyAndLayout, ValidityRequirement};
@@ -438,6 +439,26 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
438439
self.write_scalar(Scalar::from_target_usize(align.bytes(), self), dest)?;
439440
}
440441

442+
sym::minnumf16 => self.float_min_intrinsic::<Half>(args, dest)?,
443+
sym::minnumf32 => self.float_min_intrinsic::<Single>(args, dest)?,
444+
sym::minnumf64 => self.float_min_intrinsic::<Double>(args, dest)?,
445+
sym::minnumf128 => self.float_min_intrinsic::<Quad>(args, dest)?,
446+
447+
sym::maxnumf16 => self.float_max_intrinsic::<Half>(args, dest)?,
448+
sym::maxnumf32 => self.float_max_intrinsic::<Single>(args, dest)?,
449+
sym::maxnumf64 => self.float_max_intrinsic::<Double>(args, dest)?,
450+
sym::maxnumf128 => self.float_max_intrinsic::<Quad>(args, dest)?,
451+
452+
sym::copysignf16 => self.float_copysign_intrinsic::<Half>(args, dest)?,
453+
sym::copysignf32 => self.float_copysign_intrinsic::<Single>(args, dest)?,
454+
sym::copysignf64 => self.float_copysign_intrinsic::<Double>(args, dest)?,
455+
sym::copysignf128 => self.float_copysign_intrinsic::<Quad>(args, dest)?,
456+
457+
sym::fabsf16 => self.float_abs_intrinsic::<Half>(args, dest)?,
458+
sym::fabsf32 => self.float_abs_intrinsic::<Single>(args, dest)?,
459+
sym::fabsf64 => self.float_abs_intrinsic::<Double>(args, dest)?,
460+
sym::fabsf128 => self.float_abs_intrinsic::<Quad>(args, dest)?,
461+
441462
// Unsupported intrinsic: skip the return_to_block below.
442463
_ => return interp_ok(false),
443464
}
@@ -697,4 +718,63 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
697718
let rhs_bytes = get_bytes(self, rhs)?;
698719
interp_ok(Scalar::from_bool(lhs_bytes == rhs_bytes))
699720
}
721+
722+
fn float_min_intrinsic<F>(
723+
&mut self,
724+
args: &[OpTy<'tcx, M::Provenance>],
725+
dest: &MPlaceTy<'tcx, M::Provenance>,
726+
) -> InterpResult<'tcx, ()>
727+
where
728+
F: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F> + Into<Scalar<M::Provenance>>,
729+
{
730+
let a: F = self.read_scalar(&args[0])?.to_float()?;
731+
let b: F = self.read_scalar(&args[1])?.to_float()?;
732+
let res = self.adjust_nan(a.min(b), &[a, b]);
733+
self.write_scalar(res, dest)?;
734+
interp_ok(())
735+
}
736+
737+
fn float_max_intrinsic<F>(
738+
&mut self,
739+
args: &[OpTy<'tcx, M::Provenance>],
740+
dest: &MPlaceTy<'tcx, M::Provenance>,
741+
) -> InterpResult<'tcx, ()>
742+
where
743+
F: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F> + Into<Scalar<M::Provenance>>,
744+
{
745+
let a: F = self.read_scalar(&args[0])?.to_float()?;
746+
let b: F = self.read_scalar(&args[1])?.to_float()?;
747+
let res = self.adjust_nan(a.max(b), &[a, b]);
748+
self.write_scalar(res, dest)?;
749+
interp_ok(())
750+
}
751+
752+
fn float_copysign_intrinsic<F>(
753+
&mut self,
754+
args: &[OpTy<'tcx, M::Provenance>],
755+
dest: &MPlaceTy<'tcx, M::Provenance>,
756+
) -> InterpResult<'tcx, ()>
757+
where
758+
F: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F> + Into<Scalar<M::Provenance>>,
759+
{
760+
let a: F = self.read_scalar(&args[0])?.to_float()?;
761+
let b: F = self.read_scalar(&args[1])?.to_float()?;
762+
// bitwise, no NaN adjustments
763+
self.write_scalar(a.copy_sign(b), dest)?;
764+
interp_ok(())
765+
}
766+
767+
fn float_abs_intrinsic<F>(
768+
&mut self,
769+
args: &[OpTy<'tcx, M::Provenance>],
770+
dest: &MPlaceTy<'tcx, M::Provenance>,
771+
) -> InterpResult<'tcx, ()>
772+
where
773+
F: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F> + Into<Scalar<M::Provenance>>,
774+
{
775+
let x: F = self.read_scalar(&args[0])?.to_float()?;
776+
// bitwise, no NaN adjustments
777+
self.write_scalar(x.abs(), dest)?;
778+
interp_ok(())
779+
}
700780
}

compiler/rustc_const_eval/src/interpret/operator.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
6464
use rustc_middle::mir::BinOp::*;
6565

6666
// Performs appropriate non-deterministic adjustments of NaN results.
67-
let adjust_nan =
68-
|f: F| -> F { if f.is_nan() { M::generate_nan(self, &[l, r]) } else { f } };
67+
let adjust_nan = |f: F| -> F { self.adjust_nan(f, &[l, r]) };
6968

7069
match bin_op {
7170
Eq => ImmTy::from_bool(l == r, *self.tcx),

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
960960
continue;
961961
}
962962
unimplemented_traits.entry(p.trait_ref.def_id).or_insert((
963-
predicate.kind().rebind(p.trait_ref),
963+
predicate.kind().rebind(p),
964964
Obligation {
965965
cause: cause.clone(),
966966
param_env: self.param_env,

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
202202
notes,
203203
parent_label,
204204
append_const_msg,
205-
} = self.on_unimplemented_note(main_trait_ref, o, &mut long_ty_file);
205+
} = self.on_unimplemented_note(main_trait_predicate, o, &mut long_ty_file);
206206

207207
let have_alt_message = message.is_some() || label.is_some();
208208
let is_try_conversion = self.is_try_conversion(span, main_trait_ref.def_id());

compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_macros::LintDiagnostic;
1010
use rustc_middle::bug;
1111
use rustc_middle::ty::print::PrintTraitRefExt as _;
12-
use rustc_middle::ty::{self, GenericArgsRef, GenericParamDefKind, TyCtxt};
12+
use rustc_middle::ty::{self, GenericArgsRef, GenericParamDefKind, ToPolyTraitRef, TyCtxt};
1313
use rustc_parse_format::{ParseMode, Parser, Piece, Position};
1414
use rustc_session::lint::builtin::UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES;
1515
use rustc_span::Span;
@@ -108,14 +108,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
108108

109109
pub fn on_unimplemented_note(
110110
&self,
111-
trait_ref: ty::PolyTraitRef<'tcx>,
111+
trait_pred: ty::PolyTraitPredicate<'tcx>,
112112
obligation: &PredicateObligation<'tcx>,
113113
long_ty_file: &mut Option<PathBuf>,
114114
) -> OnUnimplementedNote {
115+
if trait_pred.polarity() != ty::PredicatePolarity::Positive {
116+
return OnUnimplementedNote::default();
117+
}
118+
115119
let (def_id, args) = self
116-
.impl_similar_to(trait_ref, obligation)
117-
.unwrap_or_else(|| (trait_ref.def_id(), trait_ref.skip_binder().args));
118-
let trait_ref = trait_ref.skip_binder();
120+
.impl_similar_to(trait_pred.to_poly_trait_ref(), obligation)
121+
.unwrap_or_else(|| (trait_pred.def_id(), trait_pred.skip_binder().trait_ref.args));
122+
let trait_pred = trait_pred.skip_binder();
119123

120124
let mut flags = vec![];
121125
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): HIR is not present for RPITITs,
@@ -144,13 +148,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
144148
flags.push((sym::cause, Some("MainFunctionType".to_string())));
145149
}
146150

147-
flags.push((sym::Trait, Some(trait_ref.print_trait_sugared().to_string())));
151+
flags.push((sym::Trait, Some(trait_pred.trait_ref.print_trait_sugared().to_string())));
148152

149153
// Add all types without trimmed paths or visible paths, ensuring they end up with
150154
// their "canonical" def path.
151155
ty::print::with_no_trimmed_paths!(ty::print::with_no_visible_paths!({
152156
let generics = self.tcx.generics_of(def_id);
153-
let self_ty = trait_ref.self_ty();
157+
let self_ty = trait_pred.self_ty();
154158
// This is also included through the generics list as `Self`,
155159
// but the parser won't allow you to use it
156160
flags.push((sym::_Self, Some(self_ty.to_string())));
@@ -266,7 +270,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
266270
}));
267271

268272
if let Ok(Some(command)) = OnUnimplementedDirective::of_item(self.tcx, def_id) {
269-
command.evaluate(self.tcx, trait_ref, &flags, long_ty_file)
273+
command.evaluate(self.tcx, trait_pred.trait_ref, &flags, long_ty_file)
270274
} else {
271275
OnUnimplementedNote::default()
272276
}

compiler/rustc_ty_utils/src/abi.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -822,10 +822,10 @@ fn make_thin_self_ptr<'tcx>(
822822
_ => bug!("receiver type has unsupported layout: {:?}", layout),
823823
}
824824

825-
// In the case of Rc<Self>, we need to explicitly pass a *mut RcBox<Self>
825+
// In the case of Rc<Self>, we need to explicitly pass a *mut RcInner<Self>
826826
// with a Scalar (not ScalarPair) ABI. This is a hack that is understood
827827
// elsewhere in the compiler as a method on a `dyn Trait`.
828-
// To get the type `*mut RcBox<Self>`, we just keep unwrapping newtypes until we
828+
// To get the type `*mut RcInner<Self>`, we just keep unwrapping newtypes until we
829829
// get a built-in pointer type
830830
let mut wide_pointer_layout = layout;
831831
while !wide_pointer_layout.ty.is_unsafe_ptr() && !wide_pointer_layout.ty.is_ref() {
@@ -838,7 +838,7 @@ fn make_thin_self_ptr<'tcx>(
838838
wide_pointer_layout.ty
839839
};
840840

841-
// we now have a type like `*mut RcBox<dyn Trait>`
841+
// we now have a type like `*mut RcInner<dyn Trait>`
842842
// change its layout to that of `*mut ()`, a thin pointer, but keep the same type
843843
// this is understood as a special case elsewhere in the compiler
844844
let unit_ptr_ty = Ty::new_mut_ptr(tcx, tcx.types.unit);

compiler/stable_mir/src/mir/pretty.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Debug for Place {
2222
}
2323

2424
pub(crate) fn function_body<W: Write>(writer: &mut W, body: &Body, name: &str) -> io::Result<()> {
25-
write!(writer, "fn {}(", name)?;
25+
write!(writer, "fn {name}(")?;
2626
body.arg_locals()
2727
.iter()
2828
.enumerate()
@@ -54,7 +54,7 @@ pub(crate) fn function_body<W: Write>(writer: &mut W, body: &Body, name: &str) -
5454
.iter()
5555
.enumerate()
5656
.map(|(index, block)| -> io::Result<()> {
57-
writeln!(writer, " bb{}: {{", index)?;
57+
writeln!(writer, " bb{index}: {{")?;
5858
let _ = block
5959
.statements
6060
.iter()
@@ -75,7 +75,7 @@ pub(crate) fn function_body<W: Write>(writer: &mut W, body: &Body, name: &str) -
7575
fn pretty_statement<W: Write>(writer: &mut W, statement: &StatementKind) -> io::Result<()> {
7676
match statement {
7777
StatementKind::Assign(place, rval) => {
78-
write!(writer, " {:?} = ", place)?;
78+
write!(writer, " {place:?} = ")?;
7979
pretty_rvalue(writer, rval)?;
8080
writeln!(writer, ";")
8181
}
@@ -165,7 +165,7 @@ fn pretty_terminator_head<W: Write>(writer: &mut W, terminator: &TerminatorKind)
165165
Abort => write!(writer, "{INDENT}abort"),
166166
Return => write!(writer, "{INDENT}return"),
167167
Unreachable => write!(writer, "{INDENT}unreachable"),
168-
Drop { place, .. } => write!(writer, "{INDENT}drop({:?})", place),
168+
Drop { place, .. } => write!(writer, "{INDENT}drop({place:?})"),
169169
Call { func, args, destination, .. } => {
170170
write!(writer, "{INDENT}{:?} = {}(", destination, pretty_operand(func))?;
171171
let mut args_iter = args.iter();
@@ -304,10 +304,10 @@ fn pretty_assert_message<W: Write>(writer: &mut W, msg: &AssertMessage) -> io::R
304304
fn pretty_operand(operand: &Operand) -> String {
305305
match operand {
306306
Operand::Copy(copy) => {
307-
format!("{:?}", copy)
307+
format!("{copy:?}")
308308
}
309309
Operand::Move(mv) => {
310-
format!("move {:?}", mv)
310+
format!("move {mv:?}")
311311
}
312312
Operand::Constant(cnst) => pretty_mir_const(&cnst.const_),
313313
}
@@ -344,13 +344,13 @@ fn pretty_rvalue<W: Write>(writer: &mut W, rval: &Rvalue) -> io::Result<()> {
344344
write!(writer, "Checked{:?}({}, {})", bin, pretty_operand(op1), pretty_operand(op2))
345345
}
346346
Rvalue::CopyForDeref(deref) => {
347-
write!(writer, "CopyForDeref({:?})", deref)
347+
write!(writer, "CopyForDeref({deref:?})")
348348
}
349349
Rvalue::Discriminant(place) => {
350-
write!(writer, "discriminant({:?})", place)
350+
write!(writer, "discriminant({place:?})")
351351
}
352352
Rvalue::Len(len) => {
353-
write!(writer, "len({:?})", len)
353+
write!(writer, "len({len:?})")
354354
}
355355
Rvalue::Ref(_, borrowkind, place) => {
356356
let kind = match borrowkind {
@@ -359,17 +359,17 @@ fn pretty_rvalue<W: Write>(writer: &mut W, rval: &Rvalue) -> io::Result<()> {
359359
BorrowKind::Fake(FakeBorrowKind::Shallow) => "&fake shallow ",
360360
BorrowKind::Mut { .. } => "&mut ",
361361
};
362-
write!(writer, "{kind}{:?}", place)
362+
write!(writer, "{kind}{place:?}")
363363
}
364364
Rvalue::Repeat(op, cnst) => {
365365
write!(writer, "{} \" \" {}", pretty_operand(op), pretty_ty_const(cnst))
366366
}
367367
Rvalue::ShallowInitBox(_, _) => Ok(()),
368368
Rvalue::ThreadLocalRef(item) => {
369-
write!(writer, "thread_local_ref{:?}", item)
369+
write!(writer, "thread_local_ref{item:?}")
370370
}
371371
Rvalue::NullaryOp(nul, ty) => {
372-
write!(writer, "{:?} {} \" \"", nul, ty)
372+
write!(writer, "{nul:?} {ty} \" \"")
373373
}
374374
Rvalue::UnaryOp(un, op) => {
375375
write!(writer, "{} \" \" {:?}", pretty_operand(op), un)

0 commit comments

Comments
 (0)