Some drive-by housecleaning in rustc_borrowck · rust-lang/rust@d8528c6 (original) (raw)

`@@ -49,7 +49,7 @@ impl<'tcx> UniverseInfo<'tcx> {

`

49

49

`UniverseInfo::RelateTys { expected, found }

`

50

50

`}

`

51

51

``

52

``

`-

pub(crate) fn report_error(

`

``

52

`+

pub(crate) fn report_erroneous_element(

`

53

53

`&self,

`

54

54

`mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,

`

55

55

`placeholder: ty::PlaceholderRegion,

`

`@@ -68,7 +68,7 @@ impl<'tcx> UniverseInfo<'tcx> {

`

68

68

` mbcx.buffer_error(err);

`

69

69

`}

`

70

70

`UniverseInfo::TypeOp(ref type_op_info) => {

`

71

``

`-

type_op_info.report_error(mbcx, placeholder, error_element, cause);

`

``

71

`+

type_op_info.report_erroneous_element(mbcx, placeholder, error_element, cause);

`

72

72

`}

`

73

73

`UniverseInfo::Other => {

`

74

74

`// FIXME: This error message isn't great, but it doesn't show

`

`@@ -145,8 +145,11 @@ pub(crate) trait TypeOpInfo<'tcx> {

`

145

145

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

`

146

146

`) -> Option<Diag<'infcx>>;

`

147

147

``

``

148

`` +

/// Constraints require that error_element appear in the

``

``

149

`` +

/// values of placeholder, but this cannot be proven to

``

``

150

`+

/// hold. Report an error.

`

148

151

`#[instrument(level = "debug", skip(self, mbcx))]

`

149

``

`-

fn report_error(

`

``

152

`+

fn report_erroneous_element(

`

150

153

`&self,

`

151

154

`mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,

`

152

155

`placeholder: ty::PlaceholderRegion,

`

`@@ -190,12 +193,7 @@ pub(crate) trait TypeOpInfo<'tcx> {

`

190

193

`let nice_error = self.nice_error(mbcx, cause, placeholder_region, error_region);

`

191

194

``

192

195

`debug!(?nice_error);

`

193

``

-

194

``

`-

if let Some(nice_error) = nice_error {

`

195

``

`-

mbcx.buffer_error(nice_error);

`

196

``

`-

} else {

`

197

``

`-

mbcx.buffer_error(self.fallback_error(tcx, span));

`

198

``

`-

}

`

``

196

`+

mbcx.buffer_error(nice_error.unwrap_or_else(|| self.fallback_error(tcx, span)));

`

199

197

`}

`

200

198

`}

`

201

199

``

`@@ -450,7 +448,8 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(

`

450

448

` ty::ReVar(vid) => universe_of_region(vid),

`

451

449

` _ => ty::UniverseIndex::ROOT,

`

452

450

`};

`

453

``

`-

let matches =

`

``

451

`+

// Are the two regions the same?

`

``

452

`+

let regions_the_same =

`

454

453

` |a_region: Region<'tcx>, b_region: Region<'tcx>| match (a_region.kind(), b_region.kind()) {

`

455

454

`(RePlaceholder(a_p), RePlaceholder(b_p)) => a_p.bound == b_p.bound,

`

456

455

` _ => a_region == b_region,

`

`@@ -459,7 +458,7 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(

`

459

458

` |constraint: &Constraint<'tcx>, cause: &SubregionOrigin<'tcx>, exact| match *constraint {

`

460

459

`Constraint::RegSubReg(sub, sup)

`

461

460

`if ((exact && sup == placeholder_region)

`

462

``

`-

|| (!exact && matches(sup, placeholder_region)))

`

``

461

`+

|| (!exact && regions_the_same(sup, placeholder_region)))

`

463

462

` && sup != sub =>

`

464

463

`{

`

465

464

`Some((sub, cause.clone()))

`

`@@ -468,23 +467,21 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(

`

468

467

`if (exact

`

469

468

` && sup == placeholder_region

`

470

469

` && !universe_of_region(vid).can_name(placeholder_universe))

`

471

``

`-

|| (!exact && matches(sup, placeholder_region)) =>

`

``

470

`+

|| (!exact && regions_the_same(sup, placeholder_region)) =>

`

472

471

`{

`

473

472

`Some((ty::Region::new_var(infcx.tcx, vid), cause.clone()))

`

474

473

`}

`

475

474

` _ => None,

`

476

475

`};

`

477

``

`-

let mut info = region_constraints

`

478

``

`-

.constraints

`

479

``

`-

.iter()

`

480

``

`-

.find_map(|(constraint, cause)| check(constraint, cause, true));

`

481

``

`-

if info.is_none() {

`

482

``

`-

info = region_constraints

`

``

476

+

``

477

`+

let mut find_culprit = |exact_match: bool| {

`

``

478

`+

region_constraints

`

483

479

`.constraints

`

484

480

`.iter()

`

485

``

`-

.find_map(|(constraint, cause)| check(constraint, cause, false));

`

486

``

`-

}

`

487

``

`-

let (sub_region, cause) = info?;

`

``

481

`+

.find_map(|(constraint, cause)| check(constraint, cause, exact_match))

`

``

482

`+

};

`

``

483

+

``

484

`+

let (sub_region, cause) = find_culprit(true).or_else(|| find_culprit(false))?;

`

488

485

``

489

486

`debug!(?sub_region, "cause = {:#?}", cause);

`

490

487

`let error = match (error_region, *sub_region) {

`