Do not panic in return_type_impl_trait

This commit is contained in:
Yuki Okushi 2021-06-21 14:53:50 +09:00
parent f1e691da2e
commit a141d29612
No known key found for this signature in database
GPG Key ID: DABA5B072961C18A
3 changed files with 58 additions and 0 deletions

View 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 */ }
}

View File

@ -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() {}

View File

@ -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`.