Skip to content

Commit

Permalink
only instantiate opaques with rigid types
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Oct 27, 2023
1 parent b5a0d26 commit 2b2c4af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
&mut borrowck_context,
);

// FIXME(-Ztrait-solver=next): A bit dubious that we're only registering
// predefined opaques in the typeck root.
if infcx.next_trait_solver() && !infcx.tcx.is_typeck_child(body.source.def_id()) {
checker.register_predefined_opaques_in_new_solver();
}
checker.check_user_type_annotations();

let mut verifier = TypeVerifier::new(&mut checker, promoted);
verifier.visit_body(&body);
Expand Down Expand Up @@ -1021,7 +1017,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
borrowck_context,
reported_errors: Default::default(),
};
checker.check_user_type_annotations();
// FIXME(-Ztrait-solver=next): A bit dubious that we're only registering
// predefined opaques in the typeck root.
if infcx.next_trait_solver() && !infcx.tcx.is_typeck_child(body.source.def_id()) {
checker.register_predefined_opaques_in_new_solver();
}
checker
}

Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_trait_selection/src/solve/project_goals/opaques.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
return self.flounder(&matches);
}
}

let expected = match self.try_normalize_ty(goal.param_env, expected) {
Some(ty) => if ty.is_ty_var() {
return self.evaluate_added_goals_and_make_canonical_response(
Certainty::AMBIGUOUS,
)
} else {
ty
},
None => return self.evaluate_added_goals_and_make_canonical_response(
Certainty::OVERFLOW,
),
};

// Otherwise, define a new opaque type
self.insert_hidden_type(opaque_type_key, goal.param_env, expected)?;
self.add_item_bounds_for_hidden_type(
Expand Down

0 comments on commit 2b2c4af

Please sign in to comment.