Auto merge of #118386 - compiler-errors:const-deref, r= · rust-lang/rust@4a90a2c (original) (raw)
`@@ -17,6 +17,8 @@ use rustc_infer::infer::DefineOpaqueTypes;
`
17
17
`use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
`
18
18
`use rustc_middle::middle::stability;
`
19
19
`use rustc_middle::query::Providers;
`
``
20
`+
use rustc_middle::traits::query::type_op::MethodAutoderef;
`
``
21
`+
use rustc_middle::traits::query::CanonicalMethodAutoderefGoal;
`
20
22
`use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
`
21
23
`use rustc_middle::ty::AssocItem;
`
22
24
`use rustc_middle::ty::GenericParamDefKind;
`
`@@ -36,7 +38,6 @@ use rustc_trait_selection::traits::query::method_autoderef::MethodAutoderefBadTy
`
36
38
`use rustc_trait_selection::traits::query::method_autoderef::{
`
37
39
`CandidateStep, MethodAutoderefStepsResult,
`
38
40
`};
`
39
``
`-
use rustc_trait_selection::traits::query::CanonicalTyGoal;
`
40
41
`use rustc_trait_selection::traits::NormalizeExt;
`
41
42
`use rustc_trait_selection::traits::{self, ObligationCause};
`
42
43
`use std::cell::RefCell;
`
`@@ -371,34 +372,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
`
371
372
`OP: FnOnce(ProbeContext<'_, 'tcx>) -> Result<R, MethodError<'tcx>>,
`
372
373
`{
`
373
374
`let mut orig_values = OriginalQueryValues::default();
`
374
``
`-
let param_env_and_self_ty = self.canonicalize_query(
`
375
``
`-
ParamEnvAnd { param_env: self.param_env, value: self_ty },
`
376
``
`-
&mut orig_values,
`
377
``
`-
);
`
``
375
`+
let goal = MethodAutoderef {
`
``
376
`+
self_ty,
`
``
377
`+
host_effect_param: self.tcx.expected_host_effect_param_for_body(self.body_id),
`
``
378
`+
};
`
``
379
`+
let canonical_goal = self.canonicalize_query(self.param_env.and(goal), &mut orig_values);
`
378
380
``
379
381
`let steps = match mode {
`
380
``
`-
Mode::MethodCall => self.tcx.method_autoderef_steps(param_env_and_self_ty),
`
``
382
`+
Mode::MethodCall => self.tcx.method_autoderef_steps(canonical_goal),
`
381
383
`Mode::Path => self.probe(|_| {
`
382
384
`// Mode::Path - the deref steps is "trivial". This turns
`
383
385
`// our CanonicalQuery into a "trivial" QueryResponse. This
`
384
386
`// is a bit inefficient, but I don't think that writing
`
385
387
`// special handling for this "trivial case" is a good idea.
`
386
388
``
387
389
`let infcx = &self.infcx;
`
388
``
`-
let (ParamEnvAnd { param_env: _, value: self_ty }, canonical_inference_vars) =
`
389
``
`-
infcx.instantiate_canonical_with_fresh_inference_vars(
`
390
``
`-
span,
`
391
``
`-
¶m_env_and_self_ty,
`
392
``
`-
);
`
``
390
`+
let (ParamEnvAnd { param_env: _, value: goal }, canonical_inference_vars) =
`
``
391
`+
infcx.instantiate_canonical_with_fresh_inference_vars(span, &canonical_goal);
`
393
392
`debug!(
`
394
``
`-
"probe_op: Mode::Path, param_env_and_self_ty={:?} self_ty={:?}",
`
395
``
`-
param_env_and_self_ty, self_ty
`
``
393
`+
"probe_op: Mode::Path, canonical_goal={:?} self_ty={:?}",
`
``
394
`+
canonical_goal, self_ty
`
396
395
`);
`
397
396
`MethodAutoderefStepsResult {
`
398
397
`steps: infcx.tcx.arena.alloc_from_iter([CandidateStep {
`
399
398
`self_ty: self.make_query_response_ignoring_pending_obligations(
`
400
399
` canonical_inference_vars,
`
401
``
`-
self_ty,
`
``
400
`+
goal.self_ty,
`
402
401
`),
`
403
402
`autoderefs: 0,
`
404
403
`from_unsafe_deref: false,
`
`@@ -510,17 +509,23 @@ pub fn provide(providers: &mut Providers) {
`
510
509
``
511
510
`fn method_autoderef_steps<'tcx>(
`
512
511
`tcx: TyCtxt<'tcx>,
`
513
``
`-
goal: CanonicalTyGoal<'tcx>,
`
``
512
`+
goal: CanonicalMethodAutoderefGoal<'tcx>,
`
514
513
`) -> MethodAutoderefStepsResult<'tcx> {
`
515
514
`debug!("method_autoderef_steps({:?})", goal);
`
516
515
``
517
516
`let (ref infcx, goal, inference_vars) = tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &goal);
`
518
``
`-
let ParamEnvAnd { param_env, value: self_ty } = goal;
`
519
``
-
520
``
`-
let mut autoderef =
`
521
``
`-
Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
`
522
``
`-
.include_raw_pointers()
`
523
``
`-
.silence_errors();
`
``
517
`+
let ParamEnvAnd { param_env, value: MethodAutoderef { self_ty, host_effect_param } } = goal;
`
``
518
+
``
519
`+
let mut autoderef = Autoderef::new(
`
``
520
`+
infcx,
`
``
521
`+
param_env,
`
``
522
`+
hir::def_id::CRATE_DEF_ID,
`
``
523
`+
DUMMY_SP,
`
``
524
`+
self_ty,
`
``
525
`+
host_effect_param,
`
``
526
`+
)
`
``
527
`+
.include_raw_pointers()
`
``
528
`+
.silence_errors();
`
524
529
`let mut reached_raw_pointer = false;
`
525
530
`let mut steps: Vec<_> = autoderef
`
526
531
`.by_ref()
`