Skip to content

Commit 49b9cc5

Browse files
committed
Auto merge of #108521 - matthiaskrgr:rollup-exkviev, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #108319 (Don't project specializable RPITIT projection) - #108364 (Unify validity checks into a single query) - #108463 (bootstrap: Update the output of the `check` descriptions) - #108477 (Make `match` arm comma suggestion more clear) - #108486 (Merge diagnostic_items duplicate diagnostics) - #108494 (Clean up JS files code a bit) - #108500 (update Miri) - #108502 (Don't trigger error for ReError when other region is empty.) - #108513 (Remove `@nagisa` from review rotation) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 58136ff + ce33975 commit 49b9cc5

File tree

58 files changed

+660
-232
lines changed

Some content is hidden

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

58 files changed

+660
-232
lines changed

Cargo.lock

+2-8
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ dependencies = [
444444
"directories",
445445
"rustc-build-sysroot",
446446
"rustc-workspace-hack",
447-
"rustc_tools_util 0.2.1",
447+
"rustc_tools_util",
448448
"rustc_version",
449449
"serde",
450450
"serde_json",
@@ -738,7 +738,7 @@ dependencies = [
738738
"regex",
739739
"rustc-semver",
740740
"rustc-workspace-hack",
741-
"rustc_tools_util 0.3.0",
741+
"rustc_tools_util",
742742
"semver",
743743
"serde",
744744
"syn",
@@ -4725,12 +4725,6 @@ dependencies = [
47254725
"tracing",
47264726
]
47274727

4728-
[[package]]
4729-
name = "rustc_tools_util"
4730-
version = "0.2.1"
4731-
source = "registry+https://github.com/rust-lang/crates.io-index"
4732-
checksum = "598f48ce2a421542b3e64828aa742b687cc1b91d2f96591cfdb7ac5988cd6366"
4733-
47344728
[[package]]
47354729
name = "rustc_tools_util"
47364730
version = "0.3.0"

compiler/rustc_abi/src/lib.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1505,14 +1505,6 @@ pub struct PointeeInfo {
15051505
pub safe: Option<PointerKind>,
15061506
}
15071507

1508-
/// Used in `might_permit_raw_init` to indicate the kind of initialisation
1509-
/// that is checked to be valid
1510-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1511-
pub enum InitKind {
1512-
Zero,
1513-
UninitMitigated0x01Fill,
1514-
}
1515-
15161508
impl LayoutS {
15171509
/// Returns `true` if the layout corresponds to an unsized type.
15181510
pub fn is_unsized(&self) -> bool {

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ mod simd;
2121
pub(crate) use cpuid::codegen_cpuid_call;
2222
pub(crate) use llvm::codegen_llvm_intrinsic_call;
2323

24-
use rustc_middle::ty::layout::HasParamEnv;
24+
use rustc_middle::ty;
25+
use rustc_middle::ty::layout::{HasParamEnv, InitKind};
2526
use rustc_middle::ty::print::with_no_trimmed_paths;
2627
use rustc_middle::ty::subst::SubstsRef;
2728
use rustc_span::symbol::{kw, sym, Symbol};
@@ -642,7 +643,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
642643
if intrinsic == sym::assert_zero_valid
643644
&& !fx
644645
.tcx
645-
.permits_zero_init(fx.param_env().and(ty))
646+
.check_validity_of_init((InitKind::Zero, fx.param_env().and(ty)))
646647
.expect("expected to have layout during codegen")
647648
{
648649
with_no_trimmed_paths!({
@@ -661,7 +662,10 @@ fn codegen_regular_intrinsic_call<'tcx>(
661662
if intrinsic == sym::assert_mem_uninitialized_valid
662663
&& !fx
663664
.tcx
664-
.permits_uninit_init(fx.param_env().and(ty))
665+
.check_validity_of_init((
666+
InitKind::UninitMitigated0x01Fill,
667+
fx.param_env().and(ty),
668+
))
665669
.expect("expected to have layout during codegen")
666670
{
667671
with_no_trimmed_paths!({

compiler/rustc_codegen_ssa/src/mir/block.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
1414
use rustc_hir::lang_items::LangItem;
1515
use rustc_index::vec::Idx;
1616
use rustc_middle::mir::{self, AssertKind, SwitchTargets};
17-
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
17+
use rustc_middle::ty::layout::{HasTyCtxt, InitKind, LayoutOf};
1818
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
1919
use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt};
2020
use rustc_session::config::OptLevel;
@@ -676,11 +676,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
676676
Inhabited => layout.abi.is_uninhabited(),
677677
ZeroValid => !bx
678678
.tcx()
679-
.permits_zero_init(bx.param_env().and(ty))
679+
.check_validity_of_init((InitKind::Zero, bx.param_env().and(ty)))
680680
.expect("expected to have layout during codegen"),
681681
MemUninitializedValid => !bx
682682
.tcx()
683-
.permits_uninit_init(bx.param_env().and(ty))
683+
.check_validity_of_init((
684+
InitKind::UninitMitigated0x01Fill,
685+
bx.param_env().and(ty),
686+
))
684687
.expect("expected to have layout during codegen"),
685688
};
686689
Some(if do_panic {

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::mir::{
1111
BinOp, NonDivergingIntrinsic,
1212
};
1313
use rustc_middle::ty;
14-
use rustc_middle::ty::layout::LayoutOf as _;
14+
use rustc_middle::ty::layout::{InitKind, LayoutOf as _};
1515
use rustc_middle::ty::subst::SubstsRef;
1616
use rustc_middle::ty::{Ty, TyCtxt};
1717
use rustc_span::symbol::{sym, Symbol};
@@ -437,7 +437,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
437437
if intrinsic_name == sym::assert_zero_valid {
438438
let should_panic = !self
439439
.tcx
440-
.permits_zero_init(self.param_env.and(ty))
440+
.check_validity_of_init((InitKind::Zero, self.param_env.and(ty)))
441441
.map_err(|_| err_inval!(TooGeneric))?;
442442

443443
if should_panic {
@@ -454,7 +454,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
454454
if intrinsic_name == sym::assert_mem_uninitialized_valid {
455455
let should_panic = !self
456456
.tcx
457-
.permits_uninit_init(self.param_env.and(ty))
457+
.check_validity_of_init((
458+
InitKind::UninitMitigated0x01Fill,
459+
self.param_env.and(ty),
460+
))
458461
.map_err(|_| err_inval!(TooGeneric))?;
459462

460463
if should_panic {

compiler/rustc_const_eval/src/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
3838
use rustc_macros::fluent_messages;
3939
use rustc_middle::ty;
4040
use rustc_middle::ty::query::Providers;
41-
use rustc_target::abi::InitKind;
4241

4342
fluent_messages! { "../locales/en-US.ftl" }
4443

@@ -62,9 +61,7 @@ pub fn provide(providers: &mut Providers) {
6261
let (param_env, value) = param_env_and_value.into_parts();
6362
const_eval::deref_mir_constant(tcx, param_env, value)
6463
};
65-
providers.permits_uninit_init = |tcx, param_env_and_ty| {
66-
util::might_permit_raw_init(tcx, param_env_and_ty, InitKind::UninitMitigated0x01Fill)
64+
providers.check_validity_of_init = |tcx, (init_kind, param_env_and_ty)| {
65+
util::might_permit_raw_init(tcx, init_kind, param_env_and_ty)
6766
};
68-
providers.permits_zero_init =
69-
|tcx, param_env_and_ty| util::might_permit_raw_init(tcx, param_env_and_ty, InitKind::Zero);
7067
}

compiler/rustc_const_eval/src/util/might_permit_raw_init.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use rustc_middle::ty::layout::{LayoutCx, LayoutError, LayoutOf, TyAndLayout};
1+
use rustc_middle::ty::layout::{InitKind, LayoutCx, LayoutError, LayoutOf, TyAndLayout};
22
use rustc_middle::ty::{ParamEnv, ParamEnvAnd, Ty, TyCtxt};
33
use rustc_session::Limit;
4-
use rustc_target::abi::{Abi, FieldsShape, InitKind, Scalar, Variants};
4+
use rustc_target::abi::{Abi, FieldsShape, Scalar, Variants};
55

66
use crate::const_eval::{CheckAlignment, CompileTimeInterpreter};
77
use crate::interpret::{InterpCx, MemoryKind, OpTy};
@@ -20,8 +20,8 @@ use crate::interpret::{InterpCx, MemoryKind, OpTy};
2020
/// to the full uninit check).
2121
pub fn might_permit_raw_init<'tcx>(
2222
tcx: TyCtxt<'tcx>,
23-
param_env_and_ty: ParamEnvAnd<'tcx, Ty<'tcx>>,
2423
kind: InitKind,
24+
param_env_and_ty: ParamEnvAnd<'tcx, Ty<'tcx>>,
2525
) -> Result<bool, LayoutError<'tcx>> {
2626
if tcx.sess.opts.unstable_opts.strict_init_checks {
2727
might_permit_raw_init_strict(tcx.layout_of(param_env_and_ty)?, tcx, kind)

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+7
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,13 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
648648
tcx.fn_sig(trait_m.def_id).subst(tcx, trait_to_placeholder_substs),
649649
)
650650
.fold_with(&mut collector);
651+
652+
debug_assert_ne!(
653+
collector.types.len(),
654+
0,
655+
"expect >1 RPITITs in call to `collect_return_position_impl_trait_in_trait_tys`"
656+
);
657+
651658
let trait_sig = ocx.normalize(&norm_cause, param_env, unnormalized_trait_sig);
652659
trait_sig.error_reported()?;
653660
let trait_return_ty = trait_sig.output();

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,11 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
438438
}
439439
(VarValue::Value(a), VarValue::Empty(_)) => {
440440
match *a {
441-
ReLateBound(..) | ReErased | ReError(_) => {
441+
// this is always on an error path,
442+
// so it doesn't really matter if it's shorter or longer than an empty region
443+
ReError(_) => false,
444+
445+
ReLateBound(..) | ReErased => {
442446
bug!("cannot relate region: {:?}", a);
443447
}
444448

@@ -467,7 +471,11 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
467471
}
468472
(VarValue::Empty(a_ui), VarValue::Value(b)) => {
469473
match *b {
470-
ReLateBound(..) | ReErased | ReError(_) => {
474+
// this is always on an error path,
475+
// so it doesn't really matter if it's shorter or longer than an empty region
476+
ReError(_) => false,
477+
478+
ReLateBound(..) | ReErased => {
471479
bug!("cannot relate region: {:?}", b);
472480
}
473481

compiler/rustc_middle/src/hir/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,17 @@ impl ModuleItems {
6464
self.foreign_items.iter().copied()
6565
}
6666

67-
pub fn definitions(&self) -> impl Iterator<Item = LocalDefId> + '_ {
67+
pub fn owners(&self) -> impl Iterator<Item = OwnerId> + '_ {
6868
self.items
6969
.iter()
70-
.map(|id| id.owner_id.def_id)
71-
.chain(self.trait_items.iter().map(|id| id.owner_id.def_id))
72-
.chain(self.impl_items.iter().map(|id| id.owner_id.def_id))
73-
.chain(self.foreign_items.iter().map(|id| id.owner_id.def_id))
70+
.map(|id| id.owner_id)
71+
.chain(self.trait_items.iter().map(|id| id.owner_id))
72+
.chain(self.impl_items.iter().map(|id| id.owner_id))
73+
.chain(self.foreign_items.iter().map(|id| id.owner_id))
74+
}
75+
76+
pub fn definitions(&self) -> impl Iterator<Item = LocalDefId> + '_ {
77+
self.owners().map(|id| id.def_id)
7478
}
7579

7680
pub fn par_items(&self, f: impl Fn(ItemId) + Send + Sync) {

compiler/rustc_middle/src/query/keys.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use crate::infer::canonical::Canonical;
44
use crate::mir;
55
use crate::traits;
66
use crate::ty::fast_reject::SimplifiedType;
7+
use crate::ty::layout::{InitKind, TyAndLayout};
78
use crate::ty::subst::{GenericArg, SubstsRef};
8-
use crate::ty::{self, layout::TyAndLayout, Ty, TyCtxt};
9+
use crate::ty::{self, Ty, TyCtxt};
910
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
1011
use rustc_hir::hir_id::{HirId, OwnerId};
1112
use rustc_query_system::query::{DefaultCacheSelector, SingleCacheSelector, VecCacheSelector};
@@ -696,3 +697,24 @@ impl Key for HirId {
696697
None
697698
}
698699
}
700+
701+
impl<'tcx> Key for (InitKind, ty::ParamEnvAnd<'tcx, Ty<'tcx>>) {
702+
type CacheSelector = DefaultCacheSelector<Self>;
703+
704+
// Just forward to `Ty<'tcx>`
705+
#[inline(always)]
706+
fn query_crate_is_local(&self) -> bool {
707+
true
708+
}
709+
710+
fn default_span(&self, _: TyCtxt<'_>) -> Span {
711+
DUMMY_SP
712+
}
713+
714+
fn ty_adt_id(&self) -> Option<DefId> {
715+
match self.1.value.kind() {
716+
ty::Adt(adt, _) => Some(adt.did()),
717+
_ => None,
718+
}
719+
}
720+
}

compiler/rustc_middle/src/query/mod.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -2173,12 +2173,8 @@ rustc_queries! {
21732173
separate_provide_extern
21742174
}
21752175

2176-
query permits_uninit_init(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> Result<bool, ty::layout::LayoutError<'tcx>> {
2177-
desc { "checking to see if `{}` permits being left uninit", key.value }
2178-
}
2179-
2180-
query permits_zero_init(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> Result<bool, ty::layout::LayoutError<'tcx>> {
2181-
desc { "checking to see if `{}` permits being left zeroed", key.value }
2176+
query check_validity_of_init(key: (InitKind, ty::ParamEnvAnd<'tcx, Ty<'tcx>>)) -> Result<bool, ty::layout::LayoutError<'tcx>> {
2177+
desc { "checking to see if `{}` permits being left {}", key.1.value, key.0 }
21822178
}
21832179

21842180
query compare_impl_const(

compiler/rustc_middle/src/ty/layout.rs

+17
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,23 @@ pub const FAT_PTR_EXTRA: usize = 1;
169169
/// * Cranelift stores the base-2 log of the lane count in a 4 bit integer.
170170
pub const MAX_SIMD_LANES: u64 = 1 << 0xF;
171171

172+
/// Used in `might_permit_raw_init` to indicate the kind of initialisation
173+
/// that is checked to be valid
174+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
175+
pub enum InitKind {
176+
Zero,
177+
UninitMitigated0x01Fill,
178+
}
179+
180+
impl fmt::Display for InitKind {
181+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
182+
match self {
183+
Self::Zero => f.write_str("zeroed"),
184+
Self::UninitMitigated0x01Fill => f.write_str("filled with 0x01"),
185+
}
186+
}
187+
}
188+
172189
#[derive(Copy, Clone, Debug, HashStable, TyEncodable, TyDecodable)]
173190
pub enum LayoutError<'tcx> {
174191
Unknown(Ty<'tcx>),

compiler/rustc_middle/src/ty/query.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::traits::specialization_graph;
3232
use crate::traits::{self, ImplSource};
3333
use crate::ty::context::TyCtxtFeed;
3434
use crate::ty::fast_reject::SimplifiedType;
35+
use crate::ty::layout::InitKind;
3536
use crate::ty::subst::{GenericArg, SubstsRef};
3637
use crate::ty::util::AlwaysRequiresDrop;
3738
use crate::ty::GeneratorDiagnosticData;

0 commit comments

Comments
 (0)