Auto merge of #125468 - BoxyUwU:remove_defid_from_regionparam, r=comp… · rust-lang/rust@fec98b3

11

use rustc_errors::Diag;

2+

use rustc_hir::def_id::LocalDefId;

23

use rustc_infer::infer::canonical::Canonical;

34

use rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError;

45

use rustc_infer::infer::region_constraints::Constraint;

@@ -241,7 +242,7 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {

241242

mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);

242243

let ocx = ObligationCtxt::new(&infcx);

243244

type_op_prove_predicate_with_cause(&ocx, key, cause);

244-

try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)

245+

try_extract_error_from_fulfill_cx(&ocx, mbcx.mir_def_id(), placeholder_region, error_region)

245246

}

246247

}

247248

@@ -287,7 +288,7 @@ where

287288

let (param_env, value) = key.into_parts();

288289

let _ = ocx.normalize(&cause, param_env, value.value);

289290290-

try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)

291+

try_extract_error_from_fulfill_cx(&ocx, mbcx.mir_def_id(), placeholder_region, error_region)

291292

}

292293

}

293294

@@ -318,7 +319,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {

318319

mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);

319320

let ocx = ObligationCtxt::new(&infcx);

320321

type_op_ascribe_user_type_with_span(&ocx, key, Some(cause.span)).ok()?;

321-

try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)

322+

try_extract_error_from_fulfill_cx(&ocx, mbcx.mir_def_id(), placeholder_region, error_region)

322323

}

323324

}

324325

@@ -342,6 +343,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {

342343

) -> Option<Diag<'tcx>> {

343344

try_extract_error_from_region_constraints(

344345

mbcx.infcx,

346+

mbcx.mir_def_id(),

345347

placeholder_region,

346348

error_region,

347349

self.region_constraints.as_ref().unwrap(),

@@ -358,6 +360,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {

358360

#[instrument(skip(ocx), level = "debug")]

359361

fn try_extract_error_from_fulfill_cx<'tcx>(

360362

ocx: &ObligationCtxt<'_, 'tcx>,

363+

generic_param_scope: LocalDefId,

361364

placeholder_region: ty::Region<'tcx>,

362365

error_region: Option<ty::Region<'tcx>>,

363366

) -> Option<Diag<'tcx>> {

@@ -368,6 +371,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(

368371

let region_constraints = ocx.infcx.with_region_constraints(|r| r.clone());

369372

try_extract_error_from_region_constraints(

370373

ocx.infcx,

374+

generic_param_scope,

371375

placeholder_region,

372376

error_region,

373377

&region_constraints,

@@ -379,6 +383,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(

379383

#[instrument(level = "debug", skip(infcx, region_var_origin, universe_of_region))]

380384

fn try_extract_error_from_region_constraints<'tcx>(

381385

infcx: &InferCtxt<'tcx>,

386+

generic_param_scope: LocalDefId,

382387

placeholder_region: ty::Region<'tcx>,

383388

error_region: Option<ty::Region<'tcx>>,

384389

region_constraints: &RegionConstraintData<'tcx>,

@@ -452,15 +457,18 @@ fn try_extract_error_from_region_constraints<'tcx>(

452457

RegionResolutionError::ConcreteFailure(cause.clone(), sub_region, placeholder_region)

453458

}

454459

};

455-

NiceRegionError::new(&infcx.err_ctxt(), error).try_report_from_nll().or_else(|| {

456-

if let SubregionOrigin::Subtype(trace) = cause {

457-

Some(

458-

infcx

459-

.err_ctxt()

460-

.report_and_explain_type_error(*trace, TypeError::RegionsPlaceholderMismatch),

461-

)

462-

} else {

463-

None

464-

}

465-

})

460+

NiceRegionError::new(&infcx.err_ctxt(), generic_param_scope, error)

461+

.try_report_from_nll()

462+

.or_else(|| {

463+

if let SubregionOrigin::Subtype(trace) = cause {

464+

Some(

465+

infcx.err_ctxt().report_and_explain_type_error(

466+

*trace,

467+

TypeError::RegionsPlaceholderMismatch,

468+

),

469+

)

470+

} else {

471+

None

472+

}

473+

})

466474

}