Skip to content

Commit 64bcb32

Browse files
committed
Auto merge of #110752 - matthiaskrgr:rollup-959s77u, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #110255 (Suggest using integration tests for test crate using own proc-macro) - #110514 (Remove `find_map_relevant_impl`) - #110566 (Don't create projection ty for const projection) - #110637 (Group some sections of our logs in github actions) - #110706 (Add `intrinsics::transmute_unchecked`) - #110714 (Normalize types and consts in MIR opts.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f65615f + 2ce9b57 commit 64bcb32

38 files changed

+509
-395
lines changed

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
198198
| sym::assert_zero_valid
199199
| sym::assert_mem_uninitialized_valid => (1, Vec::new(), tcx.mk_unit()),
200200
sym::forget => (1, vec![param(0)], tcx.mk_unit()),
201-
sym::transmute => (2, vec![param(0)], param(1)),
201+
sym::transmute | sym::transmute_unchecked => (2, vec![param(0)], param(1)),
202202
sym::prefetch_read_data
203203
| sym::prefetch_write_data
204204
| sym::prefetch_read_instruction

compiler/rustc_middle/src/ty/trait_def.rs

+18-44
Original file line numberDiff line numberDiff line change
@@ -139,40 +139,6 @@ impl<'tcx> TyCtxt<'tcx> {
139139
treat_projections: TreatProjections,
140140
mut f: impl FnMut(DefId),
141141
) {
142-
let _: Option<()> =
143-
self.find_map_relevant_impl(trait_def_id, self_ty, treat_projections, |did| {
144-
f(did);
145-
None
146-
});
147-
}
148-
149-
/// `trait_def_id` MUST BE the `DefId` of a trait.
150-
pub fn non_blanket_impls_for_ty(
151-
self,
152-
trait_def_id: DefId,
153-
self_ty: Ty<'tcx>,
154-
) -> impl Iterator<Item = DefId> + 'tcx {
155-
let impls = self.trait_impls_of(trait_def_id);
156-
if let Some(simp) = fast_reject::simplify_type(self, self_ty, TreatParams::AsCandidateKey) {
157-
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
158-
return impls.iter().copied();
159-
}
160-
}
161-
162-
[].iter().copied()
163-
}
164-
165-
/// Applies function to every impl that could possibly match the self type `self_ty` and returns
166-
/// the first non-none value.
167-
///
168-
/// `trait_def_id` MUST BE the `DefId` of a trait.
169-
pub fn find_map_relevant_impl<T>(
170-
self,
171-
trait_def_id: DefId,
172-
self_ty: Ty<'tcx>,
173-
treat_projections: TreatProjections,
174-
mut f: impl FnMut(DefId) -> Option<T>,
175-
) -> Option<T> {
176142
// FIXME: This depends on the set of all impls for the trait. That is
177143
// unfortunate wrt. incremental compilation.
178144
//
@@ -181,9 +147,7 @@ impl<'tcx> TyCtxt<'tcx> {
181147
let impls = self.trait_impls_of(trait_def_id);
182148

183149
for &impl_def_id in impls.blanket_impls.iter() {
184-
if let result @ Some(_) = f(impl_def_id) {
185-
return result;
186-
}
150+
f(impl_def_id);
187151
}
188152

189153
// Note that we're using `TreatParams::ForLookup` to query `non_blanket_impls` while using
@@ -199,20 +163,30 @@ impl<'tcx> TyCtxt<'tcx> {
199163
if let Some(simp) = fast_reject::simplify_type(self, self_ty, treat_params) {
200164
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
201165
for &impl_def_id in impls {
202-
if let result @ Some(_) = f(impl_def_id) {
203-
return result;
204-
}
166+
f(impl_def_id);
205167
}
206168
}
207169
} else {
208170
for &impl_def_id in impls.non_blanket_impls.values().flatten() {
209-
if let result @ Some(_) = f(impl_def_id) {
210-
return result;
211-
}
171+
f(impl_def_id);
212172
}
213173
}
174+
}
214175

215-
None
176+
/// `trait_def_id` MUST BE the `DefId` of a trait.
177+
pub fn non_blanket_impls_for_ty(
178+
self,
179+
trait_def_id: DefId,
180+
self_ty: Ty<'tcx>,
181+
) -> impl Iterator<Item = DefId> + 'tcx {
182+
let impls = self.trait_impls_of(trait_def_id);
183+
if let Some(simp) = fast_reject::simplify_type(self, self_ty, TreatParams::AsCandidateKey) {
184+
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
185+
return impls.iter().copied();
186+
}
187+
}
188+
189+
[].iter().copied()
216190
}
217191

218192
/// Returns an iterator containing all impls for `trait_def_id`.

compiler/rustc_middle/src/ty/util.rs

+22-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
44
use crate::mir;
5-
use crate::ty::fast_reject::TreatProjections;
65
use crate::ty::layout::IntegerExt;
76
use crate::ty::{
87
self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
@@ -359,21 +358,29 @@ impl<'tcx> TyCtxt<'tcx> {
359358
self.ensure().coherent_trait(drop_trait);
360359

361360
let ty = self.type_of(adt_did).subst_identity();
362-
let (did, constness) = self.find_map_relevant_impl(
363-
drop_trait,
364-
ty,
365-
// FIXME: This could also be some other mode, like "unexpected"
366-
TreatProjections::ForLookup,
367-
|impl_did| {
368-
if let Some(item_id) = self.associated_item_def_ids(impl_did).first() {
369-
if validate(self, impl_did).is_ok() {
370-
return Some((*item_id, self.constness(impl_did)));
371-
}
372-
}
373-
None
374-
},
375-
)?;
361+
let mut dtor_candidate = None;
362+
self.for_each_relevant_impl(drop_trait, ty, |impl_did| {
363+
let Some(item_id) = self.associated_item_def_ids(impl_did).first() else {
364+
self.sess.delay_span_bug(self.def_span(impl_did), "Drop impl without drop function");
365+
return;
366+
};
367+
368+
if validate(self, impl_did).is_err() {
369+
// Already `ErrorGuaranteed`, no need to delay a span bug here.
370+
return;
371+
}
372+
373+
if let Some((old_item_id, _)) = dtor_candidate {
374+
self.sess
375+
.struct_span_err(self.def_span(item_id), "multiple drop impls found")
376+
.span_note(self.def_span(old_item_id), "other impl here")
377+
.delay_as_bug();
378+
}
379+
380+
dtor_candidate = Some((*item_id, self.constness(impl_did)));
381+
});
376382

383+
let (did, constness) = dtor_candidate?;
377384
Some(ty::Destructor { did, constness })
378385
}
379386

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl<'tcx> std::fmt::Debug for ScalarTy<'tcx> {
323323

324324
impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
325325
pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, map: Map) -> Self {
326-
let param_env = tcx.param_env(body.source.def_id());
326+
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
327327
Self {
328328
map,
329329
tcx,

compiler/rustc_mir_transform/src/large_enums.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl EnumSizeOpt {
120120
fn optim<'tcx>(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
121121
let mut alloc_cache = FxHashMap::default();
122122
let body_did = body.source.def_id();
123-
let param_env = tcx.param_env(body_did);
123+
let param_env = tcx.param_env_reveal_all_normalized(body_did);
124124

125125
let blocks = body.basic_blocks.as_mut();
126126
let local_decls = &mut body.local_decls;

compiler/rustc_mir_transform/src/lower_intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
221221
terminator.kind = TerminatorKind::Goto { target };
222222
}
223223
}
224-
sym::transmute => {
224+
sym::transmute | sym::transmute_unchecked => {
225225
let dst_ty = destination.ty(local_decls, tcx).ty;
226226
let Ok([arg]) = <[_; 1]>::try_from(std::mem::take(args)) else {
227227
span_bug!(

compiler/rustc_mir_transform/src/match_branches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
4646

4747
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4848
let def_id = body.source.def_id();
49-
let param_env = tcx.param_env(def_id);
49+
let param_env = tcx.param_env_reveal_all_normalized(def_id);
5050

5151
let bbs = body.basic_blocks.as_mut();
5252
let mut should_cleanup = false;

compiler/rustc_mir_transform/src/reveal_all.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,23 @@ impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
3434
self.tcx
3535
}
3636

37+
#[inline]
38+
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, _: Location) {
39+
// We have to use `try_normalize_erasing_regions` here, since it's
40+
// possible that we visit impossible-to-satisfy where clauses here,
41+
// see #91745
42+
if let Ok(c) = self.tcx.try_normalize_erasing_regions(self.param_env, constant.literal) {
43+
constant.literal = c;
44+
}
45+
}
46+
3747
#[inline]
3848
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: TyContext) {
3949
// We have to use `try_normalize_erasing_regions` here, since it's
4050
// possible that we visit impossible-to-satisfy where clauses here,
4151
// see #91745
42-
*ty = self.tcx.try_normalize_erasing_regions(self.param_env, *ty).unwrap_or(*ty);
52+
if let Ok(t) = self.tcx.try_normalize_erasing_regions(self.param_env, *ty) {
53+
*ty = t;
54+
}
4355
}
4456
}

compiler/rustc_mir_transform/src/shim.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ fn build_thread_local_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'t
355355
fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -> Body<'tcx> {
356356
debug!("build_clone_shim(def_id={:?})", def_id);
357357

358-
let param_env = tcx.param_env(def_id);
358+
let param_env = tcx.param_env_reveal_all_normalized(def_id);
359359

360360
let mut builder = CloneShimBuilder::new(tcx, def_id, self_ty);
361361
let is_copy = self_ty.is_copy_modulo_regions(tcx, param_env);
@@ -836,7 +836,7 @@ fn build_call_shim<'tcx>(
836836
pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
837837
debug_assert!(tcx.is_constructor(ctor_id));
838838

839-
let param_env = tcx.param_env(ctor_id);
839+
let param_env = tcx.param_env_reveal_all_normalized(ctor_id);
840840

841841
// Normalize the sig.
842842
let sig = tcx

compiler/rustc_mir_transform/src/simplify_branches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyConstCondition {
1616
}
1717

1818
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
19-
let param_env = tcx.param_env(body.source.def_id());
19+
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
2020
for block in body.basic_blocks_mut() {
2121
let terminator = block.terminator_mut();
2222
terminator.kind = match terminator.kind {

compiler/rustc_mir_transform/src/simplify_comparison_integral.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyComparisonIntegral {
3737
let opts = helper.find_optimizations();
3838
let mut storage_deads_to_insert = vec![];
3939
let mut storage_deads_to_remove: Vec<(usize, BasicBlock)> = vec![];
40-
let param_env = tcx.param_env(body.source.def_id());
40+
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
4141
for opt in opts {
4242
trace!("SUCCESS: Applying {:?}", opt);
4343
// replace terminator with a switchInt that switches on the integer directly

compiler/rustc_mir_transform/src/uninhabited_enum_branching.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching {
109109
continue;
110110
};
111111

112-
let layout = tcx.layout_of(tcx.param_env(body.source.def_id()).and(discriminant_ty));
112+
let layout = tcx.layout_of(
113+
tcx.param_env_reveal_all_normalized(body.source.def_id()).and(discriminant_ty),
114+
);
113115

114116
let allowed_variants = if let Ok(layout) = layout {
115117
variant_discriminants(&layout, discriminant_ty, tcx)

compiler/rustc_resolve/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,6 @@ resolve_remove_surrounding_derive =
223223
resolve_add_as_non_derive =
224224
add as non-Derive macro
225225
`#[{$macro_path}]`
226+
227+
resolve_proc_macro_same_crate = can't use a procedural macro from the same crate that defines it
228+
.help = you can define integration tests in a directory named `tests`

compiler/rustc_resolve/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,12 @@ pub(crate) struct RemoveSurroundingDerive {
508508
pub(crate) struct AddAsNonDerive<'a> {
509509
pub(crate) macro_path: &'a str,
510510
}
511+
512+
#[derive(Diagnostic)]
513+
#[diag(resolve_proc_macro_same_crate)]
514+
pub(crate) struct ProcMacroSameCrate {
515+
#[primary_span]
516+
pub(crate) span: Span,
517+
#[help]
518+
pub(crate) is_test: bool,
519+
}

compiler/rustc_resolve/src/macros.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A bunch of methods and structures more or less related to resolving macros and
22
//! interface provided by `Resolver` to macro expander.
33
4-
use crate::errors::{AddAsNonDerive, MacroExpectedFound, RemoveSurroundingDerive};
4+
use crate::errors::{self, AddAsNonDerive, MacroExpectedFound, RemoveSurroundingDerive};
55
use crate::Namespace::*;
66
use crate::{BuiltinMacroState, Determinacy};
77
use crate::{DeriveData, Finalize, ParentScope, ResolutionError, Resolver, ScopeSet};
@@ -513,10 +513,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
513513
if let Some(def_id) = def_id.as_local() {
514514
self.unused_macros.remove(&def_id);
515515
if self.proc_macro_stubs.contains(&def_id) {
516-
self.tcx.sess.span_err(
517-
path.span,
518-
"can't use a procedural macro from the same crate that defines it",
519-
);
516+
self.tcx.sess.emit_err(errors::ProcMacroSameCrate {
517+
span: path.span,
518+
is_test: self.tcx.sess.is_test_crate(),
519+
});
520520
}
521521
}
522522
}

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,7 @@ symbols! {
15051505
transmute_generic_consts,
15061506
transmute_opts,
15071507
transmute_trait,
1508+
transmute_unchecked,
15081509
transparent,
15091510
transparent_enums,
15101511
transparent_unions,

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,16 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
645645
// FIXME: Handling opaques here is kinda sus. Especially because we
646646
// simplify them to PlaceholderSimplifiedType.
647647
| ty::Alias(ty::Opaque, _) => {
648-
if let Some(def_id) = self.tcx().find_map_relevant_impl(
648+
let mut disqualifying_impl = None;
649+
self.tcx().for_each_relevant_impl_treating_projections(
649650
goal.predicate.def_id(),
650651
goal.predicate.self_ty(),
651652
TreatProjections::NextSolverLookup,
652-
Some,
653-
) {
653+
|impl_def_id| {
654+
disqualifying_impl = Some(impl_def_id);
655+
},
656+
);
657+
if let Some(def_id) = disqualifying_impl {
654658
debug!(?def_id, ?goal, "disqualified auto-trait implementation");
655659
// No need to actually consider the candidate here,
656660
// since we do that in `consider_impl_candidate`.

0 commit comments

Comments
 (0)