Skip to content

Commit 5eda8ed

Browse files
committed
waddup gamers, today we're gonna mess up some source code
1 parent 9fa9ef3 commit 5eda8ed

File tree

72 files changed

+567
-215
lines changed

Some content is hidden

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

72 files changed

+567
-215
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,8 +3828,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
38283828
if tcx.is_diagnostic_item(sym::deref_method, method_did) {
38293829
let deref_target =
38303830
tcx.get_diagnostic_item(sym::deref_target).and_then(|deref_target| {
3831-
Instance::try_resolve(tcx, self.param_env, deref_target, method_args)
3832-
.transpose()
3831+
Instance::try_resolve(
3832+
tcx,
3833+
self.infcx.typing_mode(self.param_env),
3834+
self.param_env,
3835+
deref_target,
3836+
method_args,
3837+
)
3838+
.transpose()
38333839
});
38343840
if let Some(Ok(instance)) = deref_target {
38353841
let deref_target_ty = instance.ty(tcx, self.param_env);

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
864864

865865
let kind = call_kind(
866866
self.infcx.tcx,
867+
self.infcx.typing_mode(self.param_env),
867868
self.param_env,
868869
method_did,
869870
method_args,

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
952952

953953
if let Ok(Some(instance)) = ty::Instance::try_resolve(
954954
tcx,
955+
self.infcx.typing_mode(self.param_env),
955956
self.param_env,
956957
*fn_did,
957958
self.infcx.resolve_vars_if_possible(args),

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
376376
let instance = if let ty::FnDef(def_id, fn_args) = *func.layout().ty.kind() {
377377
let instance = ty::Instance::expect_resolve(
378378
fx.tcx,
379+
ty::TypingMode::PostAnalysis,
379380
ty::ParamEnv::reveal_all(),
380381
def_id,
381382
fn_args,

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ fn codegen_stmt<'tcx>(
666666
let func_ref = fx.get_function_ref(
667667
Instance::resolve_for_fn_ptr(
668668
fx.tcx,
669+
ty::TypingMode::PostAnalysis,
669670
ParamEnv::reveal_all(),
670671
def_id,
671672
args,

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
7878
let cv = fx.monomorphize(constant.const_);
7979
// This cannot fail because we checked all required_consts in advance.
8080
let val = cv
81-
.eval(fx.tcx, ty::ParamEnv::reveal_all(), constant.span)
81+
.eval(fx.tcx, ty::TypingMode::PostAnalysis, ty::ParamEnv::reveal_all(), constant.span)
8282
.expect("erroneous constant missed by mono item collection");
8383
(val, cv.ty())
8484
}

compiler/rustc_codegen_cranelift/src/inline_asm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
9292
if let ty::FnDef(def_id, args) = *const_.ty().kind() {
9393
let instance = ty::Instance::resolve_for_fn_ptr(
9494
fx.tcx,
95+
ty::TypingMode::PostAnalysis,
9596
ty::ParamEnv::reveal_all(),
9697
def_id,
9798
args,
@@ -231,7 +232,7 @@ pub(crate) fn codegen_naked_asm<'tcx>(
231232
ty::EarlyBinder::bind(value.const_),
232233
);
233234
let const_value = cv
234-
.eval(tcx, ty::ParamEnv::reveal_all(), value.span)
235+
.eval(tcx, ty::TypingMode::PostAnalysis, ty::ParamEnv::reveal_all(), value.span)
235236
.expect("erroneous constant missed by mono item collection");
236237

237238
let value = rustc_codegen_ssa::common::asm_const_to_str(
@@ -256,6 +257,7 @@ pub(crate) fn codegen_naked_asm<'tcx>(
256257
if let ty::FnDef(def_id, args) = *const_.ty().kind() {
257258
let instance = ty::Instance::resolve_for_fn_ptr(
258259
tcx,
260+
ty::TypingMode::PostAnalysis,
259261
ty::ParamEnv::reveal_all(),
260262
def_id,
261263
args,

compiler/rustc_codegen_cranelift/src/main_shim.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ pub(crate) fn maybe_create_entry_wrapper(
113113
.unwrap();
114114
let report = Instance::expect_resolve(
115115
tcx,
116+
ty::TypingMode::PostAnalysis,
116117
ParamEnv::reveal_all(),
117118
report.def_id,
118119
tcx.mk_args(&[GenericArg::from(main_ret_ty)]),
@@ -139,6 +140,7 @@ pub(crate) fn maybe_create_entry_wrapper(
139140
let start_def_id = tcx.require_lang_item(LangItem::Start, None);
140141
let start_instance = Instance::expect_resolve(
141142
tcx,
143+
ty::TypingMode::PostAnalysis,
142144
ParamEnv::reveal_all(),
143145
start_def_id,
144146
tcx.mk_args(&[main_ret_ty.into()]),

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
459459
Some(def_id) if !wants_msvc_seh(self.sess()) => {
460460
let instance = ty::Instance::expect_resolve(
461461
tcx,
462+
ty::TypingMode::PostAnalysis,
462463
ty::ParamEnv::reveal_all(),
463464
def_id,
464465
ty::List::empty(),

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
642642
let llfn = match tcx.lang_items().eh_personality() {
643643
Some(def_id) if name.is_none() => self.get_fn_addr(ty::Instance::expect_resolve(
644644
tcx,
645+
ty::TypingMode::PostAnalysis,
645646
ty::ParamEnv::reveal_all(),
646647
def_id,
647648
ty::List::empty(),

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
495495
let start_def_id = cx.tcx().require_lang_item(LangItem::Start, None);
496496
let start_instance = ty::Instance::expect_resolve(
497497
cx.tcx(),
498+
ty::TypingMode::PostAnalysis,
498499
ty::ParamEnv::reveal_all(),
499500
start_def_id,
500501
cx.tcx().mk_args(&[main_ret_ty.into()]),

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
839839
Some(
840840
ty::Instance::expect_resolve(
841841
bx.tcx(),
842+
ty::TypingMode::PostAnalysis,
842843
ty::ParamEnv::reveal_all(),
843844
def_id,
844845
args,
@@ -1180,6 +1181,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11801181
if let ty::FnDef(def_id, args) = *const_.ty().kind() {
11811182
let instance = ty::Instance::resolve_for_fn_ptr(
11821183
bx.tcx(),
1184+
ty::TypingMode::PostAnalysis,
11831185
ty::ParamEnv::reveal_all(),
11841186
def_id,
11851187
args,

compiler/rustc_codegen_ssa/src/mir/constant.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2424
// `MirUsedCollector` visited all required_consts before codegen began, so if we got here
2525
// there can be no more constants that fail to evaluate.
2626
self.monomorphize(constant.const_)
27-
.eval(self.cx.tcx(), ty::ParamEnv::reveal_all(), constant.span)
27+
.eval(
28+
self.cx.tcx(),
29+
ty::TypingMode::PostAnalysis,
30+
ty::ParamEnv::reveal_all(),
31+
constant.span,
32+
)
2833
.expect("erroneous constant missed by mono item collection")
2934
}
3035

@@ -57,7 +62,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5762
other => span_bug!(constant.span, "{other:#?}"),
5863
};
5964
let uv = self.monomorphize(uv);
60-
self.cx.tcx().const_eval_resolve_for_typeck(ty::ParamEnv::reveal_all(), uv, constant.span)
65+
self.cx.tcx().const_eval_resolve_for_typeck(
66+
ty::TypingMode::PostAnalysis,
67+
ty::ParamEnv::reveal_all(),
68+
uv,
69+
constant.span,
70+
)
6171
}
6272

6373
/// process constant containing SIMD shuffle indices & constant vectors

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
474474
ty::FnDef(def_id, args) => {
475475
let instance = ty::Instance::resolve_for_fn_ptr(
476476
bx.tcx(),
477+
ty::TypingMode::PostAnalysis,
477478
ty::ParamEnv::reveal_all(),
478479
def_id,
479480
args,

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,13 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
625625
// This skips the check below that ensures we only call `const fn`.
626626
is_trait = true;
627627

628-
if let Ok(Some(instance)) =
629-
Instance::try_resolve(tcx, param_env, callee, fn_args)
630-
&& let InstanceKind::Item(def) = instance.def
628+
if let Ok(Some(instance)) = Instance::try_resolve(
629+
tcx,
630+
infcx.typing_mode(param_env),
631+
param_env,
632+
callee,
633+
fn_args,
634+
) && let InstanceKind::Item(def) = instance.def
631635
{
632636
// Resolve a trait method call to its concrete implementation, which may be in a
633637
// `const` trait impl. This is only used for the const stability check below, since

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,16 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
132132
}
133133
};
134134

135-
let call_kind =
136-
call_kind(tcx, ccx.param_env, callee, args, span, call_source.from_hir_call(), None);
135+
let call_kind = call_kind(
136+
tcx,
137+
body.typing_mode(tcx),
138+
ccx.param_env,
139+
callee,
140+
args,
141+
span,
142+
call_source.from_hir_call(),
143+
None,
144+
);
137145

138146
debug!(?call_kind);
139147

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
253253
let const_def_id = self.tcx.require_lang_item(LangItem::ConstPanicFmt, None);
254254
let new_instance = ty::Instance::expect_resolve(
255255
*self.tcx,
256+
// TODO why does this use an empty env if we've got a `param_env` right here.
257+
ty::TypingMode::PostAnalysis,
256258
ty::ParamEnv::reveal_all(),
257259
const_def_id,
258260
instance.args,

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
688688

689689
let concrete_method = Instance::expect_resolve_for_vtable(
690690
tcx,
691+
self.typing_mode(),
691692
self.param_env,
692693
def_id,
693694
instance.args.rebase_onto(tcx, trait_def_id, concrete_trait_ref.args),

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
8383
ty::FnDef(def_id, args) => {
8484
let instance = ty::Instance::resolve_for_fn_ptr(
8585
*self.tcx,
86+
self.typing_mode(),
8687
self.param_env,
8788
def_id,
8889
args,

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
319319
trace!("resolve: {:?}, {:#?}", def, args);
320320
trace!("param_env: {:#?}", self.param_env);
321321
trace!("args: {:#?}", args);
322-
match ty::Instance::try_resolve(*self.tcx, self.param_env, def, args) {
322+
match ty::Instance::try_resolve(*self.tcx, self.typing_mode(), self.param_env, def, args) {
323323
Ok(Some(instance)) => interp_ok(instance),
324324
Ok(None) => throw_inval!(TooGeneric),
325325

@@ -587,7 +587,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
587587
layout: Option<TyAndLayout<'tcx>>,
588588
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
589589
M::eval_mir_constant(self, *val, span, layout, |ecx, val, span, layout| {
590-
let const_val = val.eval(*ecx.tcx, ecx.param_env, span).map_err(|err| {
590+
let const_val = val.eval(*ecx.tcx, ecx.typing_mode(), ecx.param_env, span).map_err(|err| {
591591
if M::ALL_CONSTS_ARE_PRECHECKED {
592592
match err {
593593
ErrorHandled::TooGeneric(..) => {},

compiler/rustc_const_eval/src/interpret/stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
379379
for &const_ in body.required_consts() {
380380
let c =
381381
self.instantiate_from_current_frame_and_normalize_erasing_regions(const_.const_)?;
382-
c.eval(*self.tcx, self.param_env, const_.span).map_err(|err| {
382+
c.eval(*self.tcx, self.typing_mode(), self.param_env, const_.span).map_err(|err| {
383383
err.emit_note(*self.tcx);
384384
err
385385
})?;

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14691469
}
14701470
}
14711471
} else if self.tcx.features().generic_const_exprs() {
1472-
ct.normalize_internal(self.tcx, self.param_env)
1472+
ct.normalize_internal(self.tcx, ty::TypingMode::PostAnalysis, self.param_env)
14731473
} else {
14741474
ct
14751475
}

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ use rustc_middle::ty::fold::{
3838
use rustc_middle::ty::visit::TypeVisitableExt;
3939
use rustc_middle::ty::{
4040
self, ConstVid, FloatVid, GenericArg, GenericArgKind, GenericArgs, GenericArgsRef,
41-
GenericParamDefKind, InferConst, IntVid, Ty, TyCtxt, TyVid, TypingMode,
41+
GenericParamDefKind, InferConst, IntVid, PseudoCanonicalInput, Ty, TyCtxt, TyVid,
42+
TypeVisitable, TypingMode,
4243
};
4344
use rustc_middle::{bug, span_bug};
4445
use rustc_span::Span;
@@ -1279,6 +1280,24 @@ impl<'tcx> InferCtxt<'tcx> {
12791280
u
12801281
}
12811282

1283+
/// Similar to [Self::canonicalize_query], except that it returns
1284+
/// a [PseudoCanonicalInput] and requires both the `value`` and the
1285+
/// `param_env` to not contain any inference variables or placeholders.
1286+
pub fn pseudo_canonicalize_query<V>(
1287+
&self,
1288+
param_env: ty::ParamEnv<'tcx>,
1289+
value: V,
1290+
) -> PseudoCanonicalInput<'tcx, V>
1291+
where
1292+
V: TypeVisitable<TyCtxt<'tcx>>,
1293+
{
1294+
debug_assert!(!value.has_infer());
1295+
debug_assert!(!value.has_placeholders());
1296+
debug_assert!(!param_env.has_infer());
1297+
debug_assert!(!param_env.has_placeholders());
1298+
PseudoCanonicalInput { typing_mode: self.typing_mode(param_env), param_env, value }
1299+
}
1300+
12821301
pub fn try_const_eval_resolve(
12831302
&self,
12841303
param_env: ty::ParamEnv<'tcx>,
@@ -1345,16 +1364,12 @@ impl<'tcx> InferCtxt<'tcx> {
13451364
}
13461365
}
13471366

1348-
let param_env_erased = tcx.erase_regions(param_env);
1349-
let args_erased = tcx.erase_regions(args);
1350-
debug!(?param_env_erased);
1351-
debug!(?args_erased);
1352-
1353-
let unevaluated = ty::UnevaluatedConst { def: unevaluated.def, args: args_erased };
1354-
1367+
let param_env = tcx.erase_regions(param_env);
1368+
let args = tcx.erase_regions(args);
1369+
let unevaluated = ty::UnevaluatedConst { def: unevaluated.def, args };
13551370
// The return value is the evaluated value which doesn't contain any reference to inference
13561371
// variables, thus we don't need to instantiate back the original values.
1357-
tcx.const_eval_resolve_for_typeck(param_env_erased, unevaluated, span)
1372+
tcx.const_eval_resolve_for_typeck(self.typing_mode(param_env), param_env, unevaluated, span)
13581373
}
13591374

13601375
/// The returned function is used in a fast path. If it returns `true` the variable is

compiler/rustc_lint/src/internal.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY, UNTRACKED_QUE
103103
impl LateLintPass<'_> for QueryStability {
104104
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
105105
let Some((span, def_id, args)) = typeck_results_of_method_fn(cx, expr) else { return };
106-
if let Ok(Some(instance)) = ty::Instance::try_resolve(cx.tcx, cx.param_env, def_id, args) {
106+
if let Ok(Some(instance)) =
107+
ty::Instance::try_resolve(cx.tcx, cx.typing_mode(), cx.param_env, def_id, args)
108+
{
107109
let def_id = instance.def_id();
108110
if cx.tcx.has_attr(def_id, sym::rustc_lint_query_instability) {
109111
cx.emit_span_lint(POTENTIAL_QUERY_INSTABILITY, span, QueryInstability {
@@ -544,7 +546,9 @@ impl Diagnostics {
544546
) {
545547
// Is the callee marked with `#[rustc_lint_diagnostics]`?
546548
let Some(inst) =
547-
ty::Instance::try_resolve(cx.tcx, cx.param_env, def_id, fn_gen_args).ok().flatten()
549+
ty::Instance::try_resolve(cx.tcx, cx.typing_mode(), cx.param_env, def_id, fn_gen_args)
550+
.ok()
551+
.flatten()
548552
else {
549553
return;
550554
};

compiler/rustc_lint/src/noop_method_call.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
9696
.tcx
9797
.normalize_erasing_regions(cx.param_env, cx.typeck_results().node_args(expr.hir_id));
9898
// Resolve the trait method instance.
99-
let Ok(Some(i)) = ty::Instance::try_resolve(cx.tcx, cx.param_env, did, args) else {
99+
let Ok(Some(i)) =
100+
ty::Instance::try_resolve(cx.tcx, cx.typing_mode(), cx.param_env, did, args)
101+
else {
100102
return;
101103
};
102104
// (Re)check that it implements the noop diagnostic.

0 commit comments

Comments
 (0)