Skip to content

Commit a141d29

Browse files
committed
Do not panic in return_type_impl_trait
1 parent f1e691d commit a141d29

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

compiler/rustc_middle/src/ty/context.rs

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use rustc_hir::intravisit::Visitor;
4444
use rustc_hir::lang_items::LangItem;
4545
use rustc_hir::{
4646
Constness, HirId, ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet, Node, TraitCandidate,
47+
TraitItemKind,
4748
};
4849
use rustc_index::vec::{Idx, IndexVec};
4950
use rustc_macros::HashStable;
@@ -1509,6 +1510,12 @@ impl<'tcx> TyCtxt<'tcx> {
15091510
}
15101511
}
15111512
}
1513+
Node::TraitItem(item) => {
1514+
// #86483: Return early if it doesn't have a concrete type.
1515+
if let TraitItemKind::Type(_, None) = item.kind {
1516+
return None;
1517+
}
1518+
}
15121519
_ => { /* `type_of_def_id()` will work or panic */ }
15131520
}
15141521

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Regression test of #86483.
2+
3+
#![feature(generic_associated_types)]
4+
#![allow(incomplete_features)]
5+
6+
pub trait IceIce<T> //~ ERROR: the parameter type `T` may not live long enough
7+
where
8+
for<'a> T: 'a,
9+
{
10+
type Ice<'v>: IntoIterator<Item = &'v T>;
11+
//~^ ERROR: the parameter type `T` may not live long enough
12+
//~| ERROR: the parameter type `T` may not live long enough
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error[E0311]: the parameter type `T` may not live long enough
2+
--> $DIR/issue-86483.rs:6:1
3+
|
4+
LL | pub trait IceIce<T>
5+
| ^ - help: consider adding an explicit lifetime bound...: `T: 'a`
6+
| _|
7+
| |
8+
LL | | where
9+
LL | | for<'a> T: 'a,
10+
LL | | {
11+
... |
12+
LL | |
13+
LL | | }
14+
| |_^ ...so that the type `T` will meet its required lifetime bounds
15+
16+
error[E0311]: the parameter type `T` may not live long enough
17+
--> $DIR/issue-86483.rs:10:5
18+
|
19+
LL | pub trait IceIce<T>
20+
| - help: consider adding an explicit lifetime bound...: `T: 'a`
21+
...
22+
LL | type Ice<'v>: IntoIterator<Item = &'v T>;
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
24+
25+
error[E0309]: the parameter type `T` may not live long enough
26+
--> $DIR/issue-86483.rs:10:32
27+
|
28+
LL | pub trait IceIce<T>
29+
| - help: consider adding an explicit lifetime bound...: `T: 'v`
30+
...
31+
LL | type Ice<'v>: IntoIterator<Item = &'v T>;
32+
| ^^^^^^^^^^^^ ...so that the reference type `&'v T` does not outlive the data it points at
33+
34+
error: aborting due to 3 previous errors
35+
36+
For more information about this error, try `rustc --explain E0309`.

0 commit comments

Comments
 (0)