Skip to content

Bail on any found recursion when expanding opaque types #87546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 1, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ impl<'tcx> TyCtxt<'tcx> {
expanded_cache: FxHashMap::default(),
primary_def_id: Some(def_id),
found_recursion: false,
found_any_recursion: false,
check_recursion: true,
tcx: self,
};
Expand All @@ -560,6 +561,7 @@ struct OpaqueTypeExpander<'tcx> {
expanded_cache: FxHashMap<(DefId, SubstsRef<'tcx>), Ty<'tcx>>,
primary_def_id: Option<DefId>,
found_recursion: bool,
found_any_recursion: bool,
/// Whether or not to check for recursive opaque types.
/// This is `true` when we're explicitly checking for opaque type
/// recursion, and 'false' otherwise to avoid unnecessary work.
Expand All @@ -569,7 +571,7 @@ struct OpaqueTypeExpander<'tcx> {

impl<'tcx> OpaqueTypeExpander<'tcx> {
fn expand_opaque_ty(&mut self, def_id: DefId, substs: SubstsRef<'tcx>) -> Option<Ty<'tcx>> {
if self.found_recursion {
if self.found_any_recursion {
return None;
}
let substs = substs.fold_with(self);
Expand All @@ -591,6 +593,7 @@ impl<'tcx> OpaqueTypeExpander<'tcx> {
} else {
// If another opaque type that we contain is recursive, then it
// will report the error, so we don't have to.
self.found_any_recursion = true;
self.found_recursion = def_id == *self.primary_def_id.as_ref().unwrap();
None
}
Expand Down Expand Up @@ -1078,6 +1081,7 @@ pub fn normalize_opaque_types(
expanded_cache: FxHashMap::default(),
primary_def_id: None,
found_recursion: false,
found_any_recursion: false,
check_recursion: false,
tcx,
};
Expand Down