about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-11-12 22:15:43 +0000
committerbors <bors@rust-lang.org>2023-11-12 22:15:43 +0000
commit07bc13007472bd2758bbe9c8f6308ebfe0d7ac6f (patch)
tree57ae2172ecba9d81981baf963351a29a7c6330b2
parent6a15f3bd49d6ee9127c042153c35130561828b3f (diff)
parent1539eb8c03362ec765991b178031e4e97ecd1602 (diff)
downloadrust-07bc13007472bd2758bbe9c8f6308ebfe0d7ac6f.tar.gz
rust-07bc13007472bd2758bbe9c8f6308ebfe0d7ac6f.zip
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
-rw-r--r--clippy_utils/src/ty.rs14
-rw-r--r--tests/ui/crashes/ice-11230.rs6
2 files changed, 18 insertions, 2 deletions
diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs
index 09d7749b2be..4d50242d81d 100644
--- a/clippy_utils/src/ty.rs
+++ b/clippy_utils/src/ty.rs
@@ -1160,7 +1160,12 @@ pub fn make_normalized_projection<'tcx>(
 ) -> Option<Ty<'tcx>> {
     fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: AliasTy<'tcx>) -> Option<Ty<'tcx>> {
         #[cfg(debug_assertions)]
-        if let Some((i, arg)) = ty.args.iter().enumerate().find(|(_, arg)| arg.has_late_bound_regions()) {
+        if let Some((i, arg)) = ty
+            .args
+            .iter()
+            .enumerate()
+            .find(|(_, arg)| arg.has_escaping_bound_vars())
+        {
             debug_assert!(
                 false,
                 "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>(
 ) -> Option<Ty<'tcx>> {
     fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: AliasTy<'tcx>) -> Option<Ty<'tcx>> {
         #[cfg(debug_assertions)]
-        if let Some((i, arg)) = ty.args.iter().enumerate().find(|(_, arg)| arg.has_late_bound_regions()) {
+        if let Some((i, arg)) = ty
+            .args
+            .iter()
+            .enumerate()
+            .find(|(_, arg)| arg.has_escaping_bound_vars())
+        {
             debug_assert!(
                 false,
                 "args contain late-bound region at index `{i}` which can't be normalized.\n\
diff --git a/tests/ui/crashes/ice-11230.rs b/tests/ui/crashes/ice-11230.rs
new file mode 100644
index 00000000000..5761882273e
--- /dev/null
+++ b/tests/ui/crashes/ice-11230.rs
@@ -0,0 +1,6 @@
+/// Test for https://github.com/rust-lang/rust-clippy/issues/11230
+
+fn main() {
+    const A: &[for<'a> fn(&'a ())] = &[];
+    for v in A.iter() {}
+}