Skip to content

Commit da01cce

Browse files
committed
Expand weak alias types before collecting constrained and referenced late bound regions
1 parent 515d805 commit da01cce

File tree

6 files changed

+26
-25
lines changed

6 files changed

+26
-25
lines changed

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
454454
// for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
455455
// for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
456456
let late_bound_in_projection_ty =
457-
tcx.collect_constrained_late_bound_regions(&projection_ty);
457+
tcx.collect_constrained_late_bound_regions(projection_ty);
458458
let late_bound_in_term =
459-
tcx.collect_referenced_late_bound_regions(&trait_ref.rebind(term));
459+
tcx.collect_referenced_late_bound_regions(trait_ref.rebind(term));
460460
debug!(?late_bound_in_projection_ty);
461461
debug!(?late_bound_in_term);
462462

compiler/rustc_hir_analysis/src/astconv/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2678,9 +2678,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26782678
// for<'a> fn(&'a String) -> &'a str <-- 'a is ok
26792679
let inputs = bare_fn_ty.inputs();
26802680
let late_bound_in_args =
2681-
tcx.collect_constrained_late_bound_regions(&inputs.map_bound(|i| i.to_owned()));
2681+
tcx.collect_constrained_late_bound_regions(inputs.map_bound(|i| i.to_owned()));
26822682
let output = bare_fn_ty.output();
2683-
let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(&output);
2683+
let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(output);
26842684

26852685
self.validate_late_bound_regions(late_bound_in_args, late_bound_in_ret, |br_name| {
26862686
struct_span_code_err!(

compiler/rustc_hir_analysis/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ fn get_new_lifetime_name<'tcx>(
520520
generics: &hir::Generics<'tcx>,
521521
) -> String {
522522
let existing_lifetimes = tcx
523-
.collect_referenced_late_bound_regions(&poly_trait_ref)
523+
.collect_referenced_late_bound_regions(poly_trait_ref)
524524
.into_iter()
525525
.filter_map(|lt| {
526526
if let ty::BoundRegionKind::BrNamed(_, name) = lt {

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::infer::error_reporting::nice_region_error::NiceRegionError;
55
use crate::infer::TyCtxt;
66
use rustc_hir as hir;
77
use rustc_hir::def_id::LocalDefId;
8-
use rustc_middle::ty::{self, Binder, Region, Ty, TypeVisitable};
8+
use rustc_middle::ty::{self, Binder, Region, Ty, TypeFoldable};
99
use rustc_span::Span;
1010

1111
/// Information about the anonymous region we are searching for.
@@ -142,10 +142,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
142142

143143
fn includes_region(
144144
&self,
145-
ty: Binder<'tcx, impl TypeVisitable<TyCtxt<'tcx>>>,
145+
ty: Binder<'tcx, impl TypeFoldable<TyCtxt<'tcx>>>,
146146
region: ty::BoundRegionKind,
147147
) -> bool {
148-
let late_bound_regions = self.tcx().collect_referenced_late_bound_regions(&ty);
148+
let late_bound_regions = self.tcx().collect_referenced_late_bound_regions(ty);
149149
// We are only checking is any region meets the condition so order doesn't matter
150150
#[allow(rustc::potential_query_instability)]
151151
late_bound_regions.iter().any(|r| *r == region)

compiler/rustc_middle/src/ty/visit.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::ty::{self, Binder, Ty, TyCtxt, TypeFlags};
22

33
use rustc_data_structures::fx::FxHashSet;
44
use rustc_data_structures::sso::SsoHashSet;
5+
use rustc_type_ir::fold::TypeFoldable;
56
use std::ops::ControlFlow;
67

78
pub use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
@@ -109,36 +110,37 @@ impl<'tcx> TyCtxt<'tcx> {
109110
/// variables will also be equated.
110111
pub fn collect_constrained_late_bound_regions<T>(
111112
self,
112-
value: &Binder<'tcx, T>,
113+
value: Binder<'tcx, T>,
113114
) -> FxHashSet<ty::BoundRegionKind>
114115
where
115-
T: TypeVisitable<TyCtxt<'tcx>>,
116+
T: TypeFoldable<TyCtxt<'tcx>>,
116117
{
117118
self.collect_late_bound_regions(value, true)
118119
}
119120

120121
/// Returns a set of all late-bound regions that appear in `value` anywhere.
121122
pub fn collect_referenced_late_bound_regions<T>(
122123
self,
123-
value: &Binder<'tcx, T>,
124+
value: Binder<'tcx, T>,
124125
) -> FxHashSet<ty::BoundRegionKind>
125126
where
126-
T: TypeVisitable<TyCtxt<'tcx>>,
127+
T: TypeFoldable<TyCtxt<'tcx>>,
127128
{
128129
self.collect_late_bound_regions(value, false)
129130
}
130131

131132
fn collect_late_bound_regions<T>(
132133
self,
133-
value: &Binder<'tcx, T>,
134+
value: Binder<'tcx, T>,
134135
just_constrained: bool,
135136
) -> FxHashSet<ty::BoundRegionKind>
136137
where
137-
T: TypeVisitable<TyCtxt<'tcx>>,
138+
T: TypeFoldable<TyCtxt<'tcx>>,
138139
{
139-
let mut collector = LateBoundRegionsCollector::new(self, just_constrained);
140+
let mut collector = LateBoundRegionsCollector::new(just_constrained);
141+
let value = value.skip_binder();
140142
let value = if just_constrained { self.expand_weak_alias_tys(value) } else { value };
141-
let result = value.as_ref().skip_binder().visit_with(&mut collector);
143+
let result = value.visit_with(&mut collector);
142144
assert!(result.is_continue()); // should never have stopped early
143145
collector.regions
144146
}

src/librustdoc/clean/auto_trait.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,14 @@ where
318318
fn extract_for_generics(&self, pred: ty::Clause<'tcx>) -> FxHashSet<GenericParamDef> {
319319
let bound_predicate = pred.kind();
320320
let tcx = self.cx.tcx;
321-
let regions = match bound_predicate.skip_binder() {
322-
ty::ClauseKind::Trait(poly_trait_pred) => {
323-
tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred))
324-
}
325-
ty::ClauseKind::Projection(poly_proj_pred) => {
326-
tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_proj_pred))
327-
}
328-
_ => return FxHashSet::default(),
329-
};
321+
let regions =
322+
match bound_predicate.skip_binder() {
323+
ty::ClauseKind::Trait(poly_trait_pred) => tcx
324+
.collect_referenced_late_bound_regions(bound_predicate.rebind(poly_trait_pred)),
325+
ty::ClauseKind::Projection(poly_proj_pred) => tcx
326+
.collect_referenced_late_bound_regions(bound_predicate.rebind(poly_proj_pred)),
327+
_ => return FxHashSet::default(),
328+
};
330329

331330
regions
332331
.into_iter()

0 commit comments

Comments
 (0)