]> git.lizzy.rs Git - rust.git/commitdiff
Do not panic in `return_type_impl_trait`
authorYuki Okushi <yuki.okushi@huawei.com>
Mon, 21 Jun 2021 05:53:50 +0000 (14:53 +0900)
committerYuki Okushi <yuki.okushi@huawei.com>
Thu, 24 Jun 2021 05:06:28 +0000 (14:06 +0900)
compiler/rustc_middle/src/ty/context.rs
src/test/ui/generic-associated-types/issue-86483.rs [new file with mode: 0644]
src/test/ui/generic-associated-types/issue-86483.stderr [new file with mode: 0644]

index a74070100f413131b1cb2e9b4e34b96654110200..bf5176f65850942be294689be1ad5ab745c7d77f 100644 (file)
@@ -44,6 +44,7 @@
 use rustc_hir::lang_items::LangItem;
 use rustc_hir::{
     Constness, HirId, ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet, Node, TraitCandidate,
+    TraitItemKind,
 };
 use rustc_index::vec::{Idx, IndexVec};
 use rustc_macros::HashStable;
@@ -1509,6 +1510,12 @@ pub fn return_type_impl_trait(self, scope_def_id: LocalDefId) -> Option<(Ty<'tcx
                     }
                 }
             }
+            Node::TraitItem(item) => {
+                // #86483: Return early if it doesn't have a concrete type.
+                if let TraitItemKind::Type(_, None) = item.kind {
+                    return None;
+                }
+            }
             _ => { /* `type_of_def_id()` will work or panic */ }
         }
 
diff --git a/src/test/ui/generic-associated-types/issue-86483.rs b/src/test/ui/generic-associated-types/issue-86483.rs
new file mode 100644 (file)
index 0000000..9d03c9d
--- /dev/null
@@ -0,0 +1,15 @@
+// Regression test of #86483.
+
+#![feature(generic_associated_types)]
+#![allow(incomplete_features)]
+
+pub trait IceIce<T> //~ ERROR: the parameter type `T` may not live long enough
+where
+    for<'a> T: 'a,
+{
+    type Ice<'v>: IntoIterator<Item = &'v T>;
+    //~^ ERROR: the parameter type `T` may not live long enough
+    //~| ERROR: the parameter type `T` may not live long enough
+}
+
+fn main() {}
diff --git a/src/test/ui/generic-associated-types/issue-86483.stderr b/src/test/ui/generic-associated-types/issue-86483.stderr
new file mode 100644 (file)
index 0000000..c8efc2e
--- /dev/null
@@ -0,0 +1,36 @@
+error[E0311]: the parameter type `T` may not live long enough
+  --> $DIR/issue-86483.rs:6:1
+   |
+LL |   pub trait IceIce<T>
+   |   ^                - help: consider adding an explicit lifetime bound...: `T: 'a`
+   |  _|
+   | |
+LL | | where
+LL | |     for<'a> T: 'a,
+LL | | {
+...  |
+LL | |
+LL | | }
+   | |_^ ...so that the type `T` will meet its required lifetime bounds
+
+error[E0311]: the parameter type `T` may not live long enough
+  --> $DIR/issue-86483.rs:10:5
+   |
+LL | pub trait IceIce<T>
+   |                  - help: consider adding an explicit lifetime bound...: `T: 'a`
+...
+LL |     type Ice<'v>: IntoIterator<Item = &'v T>;
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
+
+error[E0309]: the parameter type `T` may not live long enough
+  --> $DIR/issue-86483.rs:10:32
+   |
+LL | pub trait IceIce<T>
+   |                  - help: consider adding an explicit lifetime bound...: `T: 'v`
+...
+LL |     type Ice<'v>: IntoIterator<Item = &'v T>;
+   |                                ^^^^^^^^^^^^ ...so that the reference type `&'v T` does not outlive the data it points at
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0309`.