Skip to content

Commit 733616f

Browse files
committed
Auto merge of rust-lang#133841 - matthiaskrgr:rollup-2snj3hc, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#133651 (Update `NonZero` and `NonNull` to not field-project (per MCP#807)) - rust-lang#133764 (rustdoc: Rename `set_back_info` to `restore_module_data`.) - rust-lang#133784 (Fix MutVisitor's default implementations to visit Stmt's and BinOp's spans) - rust-lang#133798 (stop replacing bivariant args with `'static` when computing closure requirements) - rust-lang#133804 (Improve code for FileName retrieval in rustdoc) - rust-lang#133817 (Use `eprintln` instead of `println` in bootstrap/compiletest/tidy) Failed merges: - rust-lang#133810 (remove unnecessary `eval_verify_bound`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2633e01 + 0585134 commit 733616f

File tree

62 files changed

+913
-830
lines changed

Some content is hidden

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

62 files changed

+913
-830
lines changed

compiler/rustc_ast/src/mut_visit.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -1625,9 +1625,10 @@ pub fn walk_expr<T: MutVisitor>(vis: &mut T, Expr { kind, id, span, attrs, token
16251625
visit_thin_exprs(vis, call_args);
16261626
vis.visit_span(span);
16271627
}
1628-
ExprKind::Binary(_binop, lhs, rhs) => {
1628+
ExprKind::Binary(binop, lhs, rhs) => {
16291629
vis.visit_expr(lhs);
16301630
vis.visit_expr(rhs);
1631+
vis.visit_span(&mut binop.span);
16311632
}
16321633
ExprKind::Unary(_unop, ohs) => vis.visit_expr(ohs),
16331634
ExprKind::Cast(expr, ty) => {
@@ -1785,20 +1786,21 @@ pub fn noop_filter_map_expr<T: MutVisitor>(vis: &mut T, mut e: P<Expr>) -> Optio
17851786

17861787
pub fn walk_flat_map_stmt<T: MutVisitor>(
17871788
vis: &mut T,
1788-
Stmt { kind, mut span, mut id }: Stmt,
1789+
Stmt { kind, span, mut id }: Stmt,
17891790
) -> SmallVec<[Stmt; 1]> {
17901791
vis.visit_id(&mut id);
1791-
let stmts: SmallVec<_> = walk_flat_map_stmt_kind(vis, kind)
1792+
let mut stmts: SmallVec<[Stmt; 1]> = walk_flat_map_stmt_kind(vis, kind)
17921793
.into_iter()
17931794
.map(|kind| Stmt { id, kind, span })
17941795
.collect();
1795-
if stmts.len() > 1 {
1796-
panic!(
1796+
match stmts.len() {
1797+
0 => {}
1798+
1 => vis.visit_span(&mut stmts[0].span),
1799+
2.. => panic!(
17971800
"cloning statement `NodeId`s is prohibited by default, \
17981801
the visitor should implement custom statement visiting"
1799-
);
1802+
),
18001803
}
1801-
vis.visit_span(&mut span);
18021804
stmts
18031805
}
18041806

compiler/rustc_borrowck/src/region_infer/mod.rs

+8-43
Original file line numberDiff line numberDiff line change
@@ -973,25 +973,20 @@ impl<'tcx> RegionInferenceContext<'tcx> {
973973
propagated_outlives_requirements: &mut Vec<ClosureOutlivesRequirement<'tcx>>,
974974
) -> bool {
975975
let tcx = infcx.tcx;
976-
977-
let TypeTest { generic_kind, lower_bound, span: _, verify_bound: _ } = type_test;
976+
let TypeTest { generic_kind, lower_bound, span: blame_span, ref verify_bound } = *type_test;
978977

979978
let generic_ty = generic_kind.to_ty(tcx);
980979
let Some(subject) = self.try_promote_type_test_subject(infcx, generic_ty) else {
981980
return false;
982981
};
983982

984-
debug!("subject = {:?}", subject);
985-
986-
let r_scc = self.constraint_sccs.scc(*lower_bound);
987-
983+
let r_scc = self.constraint_sccs.scc(lower_bound);
988984
debug!(
989985
"lower_bound = {:?} r_scc={:?} universe={:?}",
990986
lower_bound,
991987
r_scc,
992988
self.constraint_sccs.annotation(r_scc).min_universe()
993989
);
994-
995990
// If the type test requires that `T: 'a` where `'a` is a
996991
// placeholder from another universe, that effectively requires
997992
// `T: 'static`, so we have to propagate that requirement.
@@ -1004,7 +999,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1004999
propagated_outlives_requirements.push(ClosureOutlivesRequirement {
10051000
subject,
10061001
outlived_free_region: static_r,
1007-
blame_span: type_test.span,
1002+
blame_span,
10081003
category: ConstraintCategory::Boring,
10091004
});
10101005

@@ -1031,12 +1026,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10311026
// where `ur` is a local bound -- we are sometimes in a
10321027
// position to prove things that our caller cannot. See
10331028
// #53570 for an example.
1034-
if self.eval_verify_bound(infcx, generic_ty, ur, &type_test.verify_bound) {
1029+
if self.eval_verify_bound(infcx, generic_ty, ur, &verify_bound) {
10351030
continue;
10361031
}
10371032

10381033
let non_local_ub = self.universal_region_relations.non_local_upper_bounds(ur);
1039-
debug!("try_promote_type_test: non_local_ub={:?}", non_local_ub);
1034+
debug!(?non_local_ub);
10401035

10411036
// This is slightly too conservative. To show T: '1, given `'2: '1`
10421037
// and `'3: '1` we only need to prove that T: '2 *or* T: '3, but to
@@ -1049,10 +1044,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10491044
let requirement = ClosureOutlivesRequirement {
10501045
subject,
10511046
outlived_free_region: upper_bound,
1052-
blame_span: type_test.span,
1047+
blame_span,
10531048
category: ConstraintCategory::Boring,
10541049
};
1055-
debug!("try_promote_type_test: pushing {:#?}", requirement);
1050+
debug!(?requirement, "adding closure requirement");
10561051
propagated_outlives_requirements.push(requirement);
10571052
}
10581053
}
@@ -1063,44 +1058,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10631058
/// variables in the type `T` with an equal universal region from the
10641059
/// closure signature.
10651060
/// This is not always possible, so this is a fallible process.
1066-
#[instrument(level = "debug", skip(self, infcx))]
1061+
#[instrument(level = "debug", skip(self, infcx), ret)]
10671062
fn try_promote_type_test_subject(
10681063
&self,
10691064
infcx: &InferCtxt<'tcx>,
10701065
ty: Ty<'tcx>,
10711066
) -> Option<ClosureOutlivesSubject<'tcx>> {
10721067
let tcx = infcx.tcx;
1073-
1074-
// Opaque types' args may include useless lifetimes.
1075-
// We will replace them with ReStatic.
1076-
struct OpaqueFolder<'tcx> {
1077-
tcx: TyCtxt<'tcx>,
1078-
}
1079-
impl<'tcx> ty::TypeFolder<TyCtxt<'tcx>> for OpaqueFolder<'tcx> {
1080-
fn cx(&self) -> TyCtxt<'tcx> {
1081-
self.tcx
1082-
}
1083-
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
1084-
use ty::TypeSuperFoldable as _;
1085-
let tcx = self.tcx;
1086-
let &ty::Alias(ty::Opaque, ty::AliasTy { args, def_id, .. }) = t.kind() else {
1087-
return t.super_fold_with(self);
1088-
};
1089-
let args = std::iter::zip(args, tcx.variances_of(def_id)).map(|(arg, v)| {
1090-
match (arg.unpack(), v) {
1091-
(ty::GenericArgKind::Lifetime(_), ty::Bivariant) => {
1092-
tcx.lifetimes.re_static.into()
1093-
}
1094-
_ => arg.fold_with(self),
1095-
}
1096-
});
1097-
Ty::new_opaque(tcx, def_id, tcx.mk_args_from_iter(args))
1098-
}
1099-
}
1100-
1101-
let ty = ty.fold_with(&mut OpaqueFolder { tcx });
11021068
let mut failed = false;
1103-
11041069
let ty = fold_regions(tcx, ty, |r, _depth| {
11051070
let r_vid = self.to_region_vid(r);
11061071
let r_scc = self.constraint_sccs.scc(r_vid);

library/core/src/num/nonzero.rs

+28-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub unsafe trait ZeroablePrimitive: Sized + Copy + private::Sealed {
3737
macro_rules! impl_zeroable_primitive {
3838
($($NonZeroInner:ident ( $primitive:ty )),+ $(,)?) => {
3939
mod private {
40+
use super::*;
41+
4042
#[unstable(
4143
feature = "nonzero_internals",
4244
reason = "implementation detail which may disappear or be replaced at any time",
@@ -45,7 +47,11 @@ macro_rules! impl_zeroable_primitive {
4547
pub trait Sealed {}
4648

4749
$(
48-
#[derive(Debug, Clone, Copy, PartialEq)]
50+
// This inner type is never shown directly, so intentionally does not have Debug
51+
#[expect(missing_debug_implementations)]
52+
// Since this struct is non-generic and derives Copy,
53+
// the derived Clone is `*self` and thus doesn't field-project.
54+
#[derive(Clone, Copy)]
4955
#[repr(transparent)]
5056
#[rustc_layout_scalar_valid_range_start(1)]
5157
#[rustc_nonnull_optimization_guaranteed]
@@ -55,6 +61,16 @@ macro_rules! impl_zeroable_primitive {
5561
issue = "none"
5662
)]
5763
pub struct $NonZeroInner($primitive);
64+
65+
// This is required to allow matching a constant. We don't get it from a derive
66+
// because the derived `PartialEq` would do a field projection, which is banned
67+
// by <https://github.com/rust-lang/compiler-team/issues/807>.
68+
#[unstable(
69+
feature = "nonzero_internals",
70+
reason = "implementation detail which may disappear or be replaced at any time",
71+
issue = "none"
72+
)]
73+
impl StructuralPartialEq for $NonZeroInner {}
5874
)+
5975
}
6076

@@ -172,7 +188,7 @@ where
172188
{
173189
#[inline]
174190
fn clone(&self) -> Self {
175-
Self(self.0)
191+
*self
176192
}
177193
}
178194

@@ -440,15 +456,21 @@ where
440456
#[rustc_const_stable(feature = "const_nonzero_get", since = "1.34.0")]
441457
#[inline]
442458
pub const fn get(self) -> T {
443-
// FIXME: This can be changed to simply `self.0` once LLVM supports `!range` metadata
444-
// for function arguments: https://github.com/llvm/llvm-project/issues/76628
445-
//
446459
// Rustc can set range metadata only if it loads `self` from
447460
// memory somewhere. If the value of `self` was from by-value argument
448461
// of some not-inlined function, LLVM don't have range metadata
449462
// to understand that the value cannot be zero.
450463
//
451-
// For now, using the transmute `assume`s the range at runtime.
464+
// Using the transmute `assume`s the range at runtime.
465+
//
466+
// Even once LLVM supports `!range` metadata for function arguments
467+
// (see <https://github.com/llvm/llvm-project/issues/76628>), this can't
468+
// be `.0` because MCP#807 bans field-projecting into `scalar_valid_range`
469+
// types, and it arguably wouldn't want to be anyway because if this is
470+
// MIR-inlined, there's no opportunity to put that argument metadata anywhere.
471+
//
472+
// The good answer here will eventually be pattern types, which will hopefully
473+
// allow it to go back to `.0`, maybe with a cast of some sort.
452474
//
453475
// SAFETY: `ZeroablePrimitive` guarantees that the size and bit validity
454476
// of `.0` is such that this transmute is sound.

0 commit comments

Comments
 (0)