Skip to content

Commit 717aec0

Browse files
committed
Auto merge of rust-lang#129521 - matthiaskrgr:rollup-uigv77m, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#128596 (stabilize const_fn_floating_point_arithmetic) - rust-lang#129199 (make writes_through_immutable_pointer a hard error) - rust-lang#129246 (Retroactively feature gate `ConstArgKind::Path`) - rust-lang#129290 (Pin `cc` to 1.0.105) - rust-lang#129323 (Implement `ptr::fn_addr_eq`) - rust-lang#129500 (remove invalid `TyCompat` relation for effects) - rust-lang#129501 (panicking: improve hint for Miri's RUST_BACKTRACE behavior) - rust-lang#129505 (interpret: ImmTy: tighten sanity checks in offset logic) - rust-lang#129510 (Fix `elided_named_lifetimes` in code) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 697d953 + e664ff5 commit 717aec0

File tree

130 files changed

+651
-630
lines changed

Some content is hidden

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

130 files changed

+651
-630
lines changed

Cargo.lock

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,9 @@ version = "0.1.0"
410410

411411
[[package]]
412412
name = "cc"
413-
version = "1.1.13"
413+
version = "1.0.105"
414414
source = "registry+https://github.com/rust-lang/crates.io-index"
415-
checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48"
416-
dependencies = [
417-
"shlex",
418-
]
415+
checksum = "5208975e568d83b6b05cc0a063c8e7e9acc2b43bee6da15616a5b73e109d7437"
419416

420417
[[package]]
421418
name = "cfg-if"

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
220220
let parent_def_id = self.current_def_id_parent;
221221
let node_id = self.next_node_id();
222222
// HACK(min_generic_const_args): see lower_anon_const
223-
if !expr.is_potential_trivial_const_arg() {
223+
if !self.tcx.features().const_arg_path
224+
|| !expr.is_potential_trivial_const_arg()
225+
{
224226
self.create_def(
225227
parent_def_id,
226228
node_id,

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
387387
let node_id = self.next_node_id();
388388

389389
// HACK(min_generic_const_args): see lower_anon_const
390-
if !arg.is_potential_trivial_const_arg() {
390+
if !self.tcx.features().const_arg_path || !arg.is_potential_trivial_const_arg() {
391391
// Add a definition for the in-band const def.
392392
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
393393
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23582358
span: Span,
23592359
) -> &'hir hir::ConstArg<'hir> {
23602360
let ct_kind = match res {
2361-
Res::Def(DefKind::ConstParam, _) => {
2361+
Res::Def(DefKind::ConstParam, _) if self.tcx.features().const_arg_path => {
23622362
let qpath = self.lower_qpath(
23632363
ty_id,
23642364
&None,
@@ -2433,7 +2433,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24332433
self.resolver.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
24342434
debug!("res={:?}", maybe_res);
24352435
// FIXME(min_generic_const_args): for now we only lower params to ConstArgKind::Path
2436-
if let Some(res) = maybe_res
2436+
if self.tcx.features().const_arg_path
2437+
&& let Some(res) = maybe_res
24372438
&& let Res::Def(DefKind::ConstParam, _) = res
24382439
&& let ExprKind::Path(qself, path) = &expr.kind
24392440
{
@@ -2464,7 +2465,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24642465
/// See [`hir::ConstArg`] for when to use this function vs
24652466
/// [`Self::lower_anon_const_to_const_arg`].
24662467
fn lower_anon_const_to_anon_const(&mut self, c: &AnonConst) -> &'hir hir::AnonConst {
2467-
if c.value.is_potential_trivial_const_arg() {
2468+
if self.tcx.features().const_arg_path && c.value.is_potential_trivial_const_arg() {
24682469
// HACK(min_generic_const_args): see DefCollector::visit_anon_const
24692470
// Over there, we guess if this is a bare param and only create a def if
24702471
// we think it's not. However we may can guess wrong (see there for example)

compiler/rustc_codegen_ssa/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2021"
88
ar_archive_writer = "0.4.2"
99
arrayvec = { version = "0.7", default-features = false }
1010
bitflags = "2.4.1"
11-
cc = "1.0.90"
11+
cc = "=1.0.105" # FIXME(cc): pinned to keep support for VS2013
1212
either = "1.5.0"
1313
itertools = "0.12"
1414
jobserver = "0.1.28"

compiler/rustc_codegen_ssa/src/back/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub trait ArchiveBuilderBuilder {
125125
rlib: &'a Path,
126126
outdir: &Path,
127127
bundled_lib_file_names: &FxIndexSet<Symbol>,
128-
) -> Result<(), ExtractBundledLibsError<'_>> {
128+
) -> Result<(), ExtractBundledLibsError<'a>> {
129129
let archive_map = unsafe {
130130
Mmap::map(
131131
File::open(rlib)

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
575575

576576
Rvalue::UnaryOp(_, operand) => {
577577
let ty = operand.ty(self.body, self.tcx);
578-
if is_int_bool_or_char(ty) {
579-
// Int, bool, and char operations are fine.
580-
} else if ty.is_floating_point() {
581-
self.check_op(ops::FloatingPointOp);
578+
if is_int_bool_float_or_char(ty) {
579+
// Int, bool, float, and char operations are fine.
582580
} else {
583581
span_bug!(self.span, "non-primitive type in `Rvalue::UnaryOp`: {:?}", ty);
584582
}
@@ -588,8 +586,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
588586
let lhs_ty = lhs.ty(self.body, self.tcx);
589587
let rhs_ty = rhs.ty(self.body, self.tcx);
590588

591-
if is_int_bool_or_char(lhs_ty) && is_int_bool_or_char(rhs_ty) {
592-
// Int, bool, and char operations are fine.
589+
if is_int_bool_float_or_char(lhs_ty) && is_int_bool_float_or_char(rhs_ty) {
590+
// Int, bool, float, and char operations are fine.
593591
} else if lhs_ty.is_fn_ptr() || lhs_ty.is_unsafe_ptr() {
594592
assert_matches!(
595593
op,
@@ -603,8 +601,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
603601
);
604602

605603
self.check_op(ops::RawPtrComparison);
606-
} else if lhs_ty.is_floating_point() || rhs_ty.is_floating_point() {
607-
self.check_op(ops::FloatingPointOp);
608604
} else {
609605
span_bug!(
610606
self.span,
@@ -1009,8 +1005,8 @@ fn place_as_reborrow<'tcx>(
10091005
}
10101006
}
10111007

1012-
fn is_int_bool_or_char(ty: Ty<'_>) -> bool {
1013-
ty.is_bool() || ty.is_integral() || ty.is_char()
1008+
fn is_int_bool_float_or_char(ty: Ty<'_>) -> bool {
1009+
ty.is_bool() || ty.is_integral() || ty.is_char() || ty.is_floating_point()
10141010
}
10151011

10161012
fn emit_unstable_in_stable_error(ccx: &ConstCx<'_, '_>, span: Span, gate: Symbol) {

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,6 @@ pub trait NonConstOp<'tcx>: std::fmt::Debug {
5555
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx>;
5656
}
5757

58-
#[derive(Debug)]
59-
pub struct FloatingPointOp;
60-
impl<'tcx> NonConstOp<'tcx> for FloatingPointOp {
61-
fn status_in_item(&self, ccx: &ConstCx<'_, 'tcx>) -> Status {
62-
if ccx.const_kind() == hir::ConstContext::ConstFn {
63-
Status::Unstable(sym::const_fn_floating_point_arithmetic)
64-
} else {
65-
Status::Allowed
66-
}
67-
}
68-
69-
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
70-
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
71-
feature_err(
72-
&ccx.tcx.sess,
73-
sym::const_fn_floating_point_arithmetic,
74-
span,
75-
format!("floating point arithmetic is not allowed in {}s", ccx.const_kind()),
76-
)
77-
}
78-
}
79-
8058
/// A function call where the callee is a pointer.
8159
#[derive(Debug)]
8260
pub struct FnCallIndirect;
@@ -440,22 +418,12 @@ impl<'tcx> NonConstOp<'tcx> for CellBorrow {
440418
DiagImportance::Secondary
441419
}
442420
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
443-
// FIXME: Maybe a more elegant solution to this if else case
444-
if let hir::ConstContext::Static(_) = ccx.const_kind() {
445-
ccx.dcx().create_err(errors::InteriorMutableDataRefer {
446-
span,
447-
opt_help: true,
448-
kind: ccx.const_kind(),
449-
teach: ccx.tcx.sess.teach(E0492),
450-
})
451-
} else {
452-
ccx.dcx().create_err(errors::InteriorMutableDataRefer {
453-
span,
454-
opt_help: false,
455-
kind: ccx.const_kind(),
456-
teach: ccx.tcx.sess.teach(E0492),
457-
})
458-
}
421+
ccx.dcx().create_err(errors::InteriorMutableDataRefer {
422+
span,
423+
opt_help: matches!(ccx.const_kind(), hir::ConstContext::Static(_)),
424+
kind: ccx.const_kind(),
425+
teach: ccx.tcx.sess.teach(E0492),
426+
})
459427
}
460428
}
461429

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub enum ConstEvalErrKind {
2222
RecursiveStatic,
2323
AssertFailure(AssertKind<ConstInt>),
2424
Panic { msg: Symbol, line: u32, col: u32, file: Symbol },
25+
WriteThroughImmutablePointer,
2526
}
2627

2728
impl MachineStopType for ConstEvalErrKind {
@@ -35,12 +36,16 @@ impl MachineStopType for ConstEvalErrKind {
3536
Panic { .. } => const_eval_panic,
3637
RecursiveStatic => const_eval_recursive_static,
3738
AssertFailure(x) => x.diagnostic_message(),
39+
WriteThroughImmutablePointer => const_eval_write_through_immutable_pointer,
3840
}
3941
}
4042
fn add_args(self: Box<Self>, adder: &mut dyn FnMut(DiagArgName, DiagArgValue)) {
4143
use ConstEvalErrKind::*;
4244
match *self {
43-
RecursiveStatic | ConstAccessesMutGlobal | ModifiedGlobal => {}
45+
RecursiveStatic
46+
| ConstAccessesMutGlobal
47+
| ModifiedGlobal
48+
| WriteThroughImmutablePointer => {}
4449
AssertFailure(kind) => kind.add_args(adder),
4550
Panic { msg, line, col, file } => {
4651
adder("msg".into(), msg.into_diag_arg());
@@ -159,6 +164,7 @@ where
159164

160165
/// Emit a lint from a const-eval situation, with a backtrace.
161166
// Even if this is unused, please don't remove it -- chances are we will need to emit a lint during const-eval again in the future!
167+
#[allow(unused)]
162168
pub(super) fn lint<'tcx, L>(
163169
tcx: TyCtxtAt<'tcx>,
164170
machine: &CompileTimeMachine<'tcx>,

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_middle::query::TyCtxtAt;
1212
use rustc_middle::ty::layout::{FnAbiOf, TyAndLayout};
1313
use rustc_middle::ty::{self, TyCtxt};
1414
use rustc_middle::{bug, mir};
15-
use rustc_session::lint::builtin::WRITES_THROUGH_IMMUTABLE_POINTER;
1615
use rustc_span::symbol::{sym, Symbol};
1716
use rustc_span::Span;
1817
use rustc_target::abi::{Align, Size};
@@ -732,8 +731,8 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
732731
}
733732

734733
fn before_memory_write(
735-
tcx: TyCtxtAt<'tcx>,
736-
machine: &mut Self,
734+
_tcx: TyCtxtAt<'tcx>,
735+
_machine: &mut Self,
737736
_alloc_extra: &mut Self::AllocExtra,
738737
(_alloc_id, immutable): (AllocId, bool),
739738
range: AllocRange,
@@ -744,9 +743,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
744743
}
745744
// Reject writes through immutable pointers.
746745
if immutable {
747-
super::lint(tcx, machine, WRITES_THROUGH_IMMUTABLE_POINTER, |frames| {
748-
crate::errors::WriteThroughImmutablePointer { frames }
749-
});
746+
return Err(ConstEvalErrKind::WriteThroughImmutablePointer.into());
750747
}
751748
// Everything else is fine.
752749
Ok(())

0 commit comments

Comments
 (0)