Skip to content

Commit cb51288

Browse files
authored
Rollup merge of #99659 - compiler-errors:opaque-type-nit, r=oli-obk
Use `VecMap::get` in `ConstraintLocator::check` Also rename the `def_id` param to `item_def_id` because that's easily confused with `self.def_id` (which is the opaque ty did).
2 parents f4c2527 + f732698 commit cb51288

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

compiler/rustc_typeck/src/collect/type_of.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,9 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
538538

539539
impl ConstraintLocator<'_> {
540540
#[instrument(skip(self), level = "debug")]
541-
fn check(&mut self, def_id: LocalDefId) {
541+
fn check(&mut self, item_def_id: LocalDefId) {
542542
// Don't try to check items that cannot possibly constrain the type.
543-
if !self.tcx.has_typeck_results(def_id) {
543+
if !self.tcx.has_typeck_results(item_def_id) {
544544
debug!("no constraint: no typeck results");
545545
return;
546546
}
@@ -555,26 +555,20 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
555555
// // because we again need to reveal `Foo` so we can check whether the
556556
// // constant does not contain interior mutability.
557557
// ```
558-
let tables = self.tcx.typeck(def_id);
558+
let tables = self.tcx.typeck(item_def_id);
559559
if let Some(_) = tables.tainted_by_errors {
560560
self.found = Some(ty::OpaqueHiddenType { span: DUMMY_SP, ty: self.tcx.ty_error() });
561561
return;
562562
}
563-
if tables.concrete_opaque_types.get(&self.def_id).is_none() {
563+
if !tables.concrete_opaque_types.contains_key(&self.def_id) {
564564
debug!("no constraints in typeck results");
565565
return;
566566
}
567567
// Use borrowck to get the type with unerased regions.
568-
let concrete_opaque_types = &self.tcx.mir_borrowck(def_id).concrete_opaque_types;
568+
let concrete_opaque_types = &self.tcx.mir_borrowck(item_def_id).concrete_opaque_types;
569569
debug!(?concrete_opaque_types);
570-
for &(def_id, concrete_type) in concrete_opaque_types {
571-
if def_id != self.def_id {
572-
// Ignore constraints for other opaque types.
573-
continue;
574-
}
575-
570+
if let Some(&concrete_type) = concrete_opaque_types.get(&self.def_id) {
576571
debug!(?concrete_type, "found constraint");
577-
578572
if let Some(prev) = self.found {
579573
if concrete_type.ty != prev.ty && !(concrete_type, prev).references_error() {
580574
prev.report_mismatch(&concrete_type, self.tcx);

0 commit comments

Comments
 (0)