Skip to content

Commit 6297f53

Browse files
committed
gaming
1 parent 1a2f666 commit 6297f53

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::constraints::ConstraintSccIndex;
3232
use crate::type_check::canonical::fully_perform_op_raw;
3333
use crate::type_check::free_region_relations::UniversalRegionRelations;
3434
use crate::type_check::{Locations, MirTypeckRegionConstraints};
35-
use crate::universal_regions::{RegionClassification, UniversalRegions};
35+
use crate::universal_regions::UniversalRegions;
3636
use crate::{BorrowCheckRootCtxt, BorrowckInferCtxt, BorrowckState};
3737

3838
pub(crate) enum DeferredOpaqueTypeError<'tcx> {
@@ -261,31 +261,30 @@ fn collect_defining_uses<'tcx>(
261261

262262
let mut defining_uses = vec![];
263263
for &(opaque_type_key, hidden_type) in opaque_types {
264-
// Check whether the arguments are fully universal.
265-
//
266-
// FIXME: We currently treat `Opaque<'a, 'a>` as a defining use and then emit an error
267-
// as it's not fully universal. We should share this code with `check_opaque_type_parameter_valid`
268-
// to only consider actual defining uses as defining.
269-
270-
let is_non_external_free_region = |r| {
271-
let vid = rcx.representative(r);
272-
matches!(rcx.definitions[vid].origin, NllRegionVariableOrigin::FreeRegion)
273-
&& !matches!(
274-
rcx.universal_regions().region_classification(vid),
275-
Some(RegionClassification::External)
276-
)
277-
};
278-
let arg_regions = opaque_type_key
279-
.iter_captured_args(tcx)
280-
.filter_map(|(_, arg)| arg.as_region())
281-
.map(Region::as_var)
282-
.map(|r| if is_non_external_free_region(r) { Some(r) } else { None });
283-
let arg_regions =
284-
iter::once(Some(rcx.universal_regions().fr_static)).chain(arg_regions).collect();
285-
286-
if let Some(arg_regions) = arg_regions {
287-
defining_uses.push(DefiningUse { opaque_type_key, arg_regions, hidden_type });
264+
let non_nll_opaque_type_key =
265+
opaque_type_key.fold_captured_lifetime_args(rcx.infcx.tcx, |r| {
266+
let vid = rcx.representative(r.as_var());
267+
rcx.definitions[vid].external_name.unwrap_or(r)
268+
});
269+
if let Err(_) = check_opaque_type_parameter_valid(
270+
infcx,
271+
non_nll_opaque_type_key,
272+
hidden_type.span,
273+
DefiningScopeKind::MirBorrowck,
274+
) {
275+
debug!(?non_nll_opaque_type_key, "not a defining use");
276+
continue;
288277
}
278+
279+
let arg_regions = iter::once(rcx.universal_regions().fr_static)
280+
.chain(
281+
opaque_type_key
282+
.iter_captured_args(tcx)
283+
.filter_map(|(_, arg)| arg.as_region())
284+
.map(Region::as_var),
285+
)
286+
.collect();
287+
defining_uses.push(DefiningUse { opaque_type_key, arg_regions, hidden_type });
289288
}
290289

291290
debug!(?defining_uses);

compiler/rustc_borrowck/src/root_cx.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ impl<'tcx> BorrowCheckRootCtxt<'tcx> {
193193
// never check closures in dead code.
194194
let nested_bodies = self.tcx.nested_bodies_within(root_def_id);
195195
for def_id in nested_bodies {
196-
let _ = self.get_or_insert_final(def_id);
196+
if !self.final_results.contains_key(&def_id) {
197+
self.compute_partial_results(def_id);
198+
let _ = self.get_or_insert_final(def_id);
199+
}
197200
}
198201

199202
#[allow(rustc::potential_query_instability)]

0 commit comments

Comments
 (0)