Skip to content

Commit bdb77cc

Browse files
borsflip1995
authored andcommitted
Auto merge of #11760 - compiler-errors:escaping, r=Jarcho
Don't check for late-bound vars, check for escaping bound vars Fixes an assertion that didn't make sense. Many valid and well-formed types *have* late-bound vars (e.g. `for<'a> fn(&'a ())`), they just must not have *escaping* late-bound vars in order to be normalized correctly. Addresses rust-lang/rust-clippy#11230, cc `@jyn514` and `@matthiaskrgr` changelog: don't check for late-bound vars, check for escaping bound vars. Addresses rust-lang/rust-clippy#11230
1 parent ed1336c commit bdb77cc

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/tools/clippy/clippy_utils/src/ty.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,12 @@ pub fn make_normalized_projection<'tcx>(
11601160
) -> Option<Ty<'tcx>> {
11611161
fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: AliasTy<'tcx>) -> Option<Ty<'tcx>> {
11621162
#[cfg(debug_assertions)]
1163-
if let Some((i, arg)) = ty.args.iter().enumerate().find(|(_, arg)| arg.has_late_bound_regions()) {
1163+
if let Some((i, arg)) = ty
1164+
.args
1165+
.iter()
1166+
.enumerate()
1167+
.find(|(_, arg)| arg.has_escaping_bound_vars())
1168+
{
11641169
debug_assert!(
11651170
false,
11661171
"args contain late-bound region at index `{i}` which can't be normalized.\n\
@@ -1233,7 +1238,12 @@ pub fn make_normalized_projection_with_regions<'tcx>(
12331238
) -> Option<Ty<'tcx>> {
12341239
fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: AliasTy<'tcx>) -> Option<Ty<'tcx>> {
12351240
#[cfg(debug_assertions)]
1236-
if let Some((i, arg)) = ty.args.iter().enumerate().find(|(_, arg)| arg.has_late_bound_regions()) {
1241+
if let Some((i, arg)) = ty
1242+
.args
1243+
.iter()
1244+
.enumerate()
1245+
.find(|(_, arg)| arg.has_escaping_bound_vars())
1246+
{
12371247
debug_assert!(
12381248
false,
12391249
"args contain late-bound region at index `{i}` which can't be normalized.\n\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// Test for https://github.com/rust-lang/rust-clippy/issues/11230
2+
3+
fn main() {
4+
const A: &[for<'a> fn(&'a ())] = &[];
5+
for v in A.iter() {}
6+
}

0 commit comments

Comments
 (0)