Skip to content

Commit 3fcb893

Browse files
committed
Auto merge of #156238 - JonathanBrouwer:rollup-VXvD19K, r=JonathanBrouwer
Rollup of 7 pull requests Successful merges: - #146273 (lint ImproperCTypes: refactor linting architecture (part 2)) - #156173 (Fewer global node_id_to_def_id lookups) - #155961 (Deny warnings in the test for crates that are available on stable) - #156130 (Fold/visit tweaks) - #156131 (Metadata macro/query cleanups) - #156141 (Resolve some cases of #132279 by using the right typing mode in the next solver) - #156202 (llvm: Use correct type for splat mask)
2 parents 365c0e1 + ca8b4bf commit 3fcb893

26 files changed

Lines changed: 385 additions & 270 deletions

File tree

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
20862086
}
20872087

20882088
if name == sym::simd_splat {
2089-
let (_out_len, out_ty) = require_simd!(ret_ty, SimdReturn);
2089+
let (out_len, out_ty) = require_simd!(ret_ty, SimdReturn);
20902090

20912091
require!(
20922092
args[0].layout.ty == out_ty,
@@ -2105,7 +2105,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
21052105

21062106
// `shufflevector <N x elem> v0, <N x elem> poison, <N x i32> zeroinitializer`
21072107
// The masks is all zeros, so this splats lane 0 (which has our element in it).
2108-
let splat = bx.shuffle_vector(v0, poison_vec, bx.const_null(llret_ty));
2108+
let mask_ty = bx.type_vector(bx.type_i32(), out_len);
2109+
let splat = bx.shuffle_vector(v0, poison_vec, bx.const_null(mask_ty));
21092110

21102111
return Ok(splat);
21112112
}

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_errors::ErrorGuaranteed;
99
use rustc_hir::LangItem;
1010
use rustc_infer::infer::TyCtxtInferExt;
1111
use rustc_middle::mir::*;
12-
use rustc_middle::ty::{self, AdtDef, Ty};
12+
use rustc_middle::ty::{self, AdtDef, Ty, TypingMode};
1313
use rustc_middle::{bug, mir};
1414
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
1515
use tracing::instrument;
@@ -100,13 +100,14 @@ impl Qualif for HasMutInterior {
100100
// Instead we invoke an obligation context manually, and provide the opaque type inference settings
101101
// that allow the trait solver to just error out instead of cycling.
102102
let freeze_def_id = cx.tcx.require_lang_item(LangItem::Freeze, cx.body.span);
103-
// FIXME(#132279): Once we've got a typing mode which reveals opaque types using the HIR
104-
// typeck results without causing query cycles, we should use this here instead of defining
105-
// opaque types.
106-
let typing_env = ty::TypingEnv::new(
107-
cx.typing_env.param_env,
108-
ty::TypingMode::analysis_in_body(cx.tcx, cx.body.source.def_id().expect_local()),
109-
);
103+
let did = cx.body.source.def_id().expect_local();
104+
105+
let typing_env = if cx.tcx.use_typing_mode_borrowck() {
106+
cx.typing_env
107+
} else {
108+
ty::TypingEnv::new(cx.typing_env.param_env, TypingMode::analysis_in_body(cx.tcx, did))
109+
};
110+
110111
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(typing_env);
111112
let ocx = ObligationCtxt::new(&infcx);
112113
let obligation = Obligation::new(

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,33 @@ pub struct InferCtxt<'tcx> {
320320
pub obligation_inspector: Cell<Option<ObligationInspector<'tcx>>>,
321321
}
322322

323+
impl<'tcx> Drop for InferCtxt<'tcx> {
324+
fn drop(&mut self) {
325+
let mut inner = self.inner.borrow_mut();
326+
let opaque_type_storage = &mut inner.opaque_type_storage;
327+
328+
// No need for the drop bomb when we're in TypingMode::Borrowck, and the InferCtxt doesn't consider regions.
329+
// This is okay since in `Borrowck`, the only reason we care about opaques is in relation to regions.
330+
// In some places *after* typeck, like in lints we use `TypingMode::Borrowck`
331+
// to prevent defining opaque types and we simply don't care about regions.
332+
match self.typing_mode() {
333+
TypingMode::Coherence
334+
| TypingMode::Analysis { .. }
335+
| TypingMode::PostBorrowckAnalysis { .. }
336+
| TypingMode::PostAnalysis => {}
337+
TypingMode::Borrowck { .. } => {
338+
if !self.considering_regions {
339+
return;
340+
}
341+
}
342+
}
343+
344+
if !opaque_type_storage.is_empty() {
345+
ty::tls::with(|tcx| tcx.dcx().delayed_bug(format!("{opaque_type_storage:?}")));
346+
}
347+
}
348+
}
349+
323350
/// See the `error_reporting` module for more details.
324351
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable, TypeVisitable)]
325352
pub enum ValuePairs<'tcx> {

compiler/rustc_infer/src/infer/opaque_types/table.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ops::Deref;
33
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_data_structures::undo_log::UndoLogs;
55
use rustc_middle::bug;
6-
use rustc_middle::ty::{self, OpaqueTypeKey, ProvisionalHiddenType, Ty};
6+
use rustc_middle::ty::{OpaqueTypeKey, ProvisionalHiddenType, Ty};
77
use tracing::instrument;
88

99
use crate::infer::snapshot::undo_log::{InferCtxtUndoLogs, UndoLog};
@@ -121,14 +121,6 @@ impl<'tcx> OpaqueTypeStorage<'tcx> {
121121
}
122122
}
123123

124-
impl<'tcx> Drop for OpaqueTypeStorage<'tcx> {
125-
fn drop(&mut self) {
126-
if !self.is_empty() {
127-
ty::tls::with(|tcx| tcx.dcx().delayed_bug(format!("{:?}", self.opaque_types)));
128-
}
129-
}
130-
}
131-
132124
pub struct OpaqueTypeTable<'a, 'tcx> {
133125
storage: &'a mut OpaqueTypeStorage<'tcx>,
134126

compiler/rustc_lint/src/context.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,14 @@ impl<'tcx> LateContext<'tcx> {
633633
/// The typing mode of the currently visited node. Use this when
634634
/// building a new `InferCtxt`.
635635
pub fn typing_mode(&self) -> TypingMode<'tcx> {
636-
// FIXME(#132279): In case we're in a body, we should use a typing
637-
// mode which reveals the opaque types defined by that body.
638-
TypingMode::non_body_analysis()
636+
if let Some(body_id) = self.enclosing_body
637+
&& self.tcx.use_typing_mode_borrowck()
638+
{
639+
let def_id = self.tcx.hir_enclosing_body_owner(body_id.hir_id);
640+
TypingMode::borrowck(self.tcx, def_id)
641+
} else {
642+
TypingMode::non_body_analysis()
643+
}
639644
}
640645

641646
pub fn typing_env(&self) -> TypingEnv<'tcx> {

compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
8484
}
8585

8686
let def_id = opaque.def_id.to_def_id();
87-
let infcx = &cx.tcx.infer_ctxt().build(cx.typing_mode());
87+
let infcx = &cx.tcx.infer_ctxt().ignoring_regions().build(cx.typing_mode());
8888
// For every projection predicate in the opaque type's explicit bounds,
8989
// check that the type that we're assigning actually satisfies the bounds
9090
// of the associated type.

0 commit comments

Comments
 (0)