Rollup merge of #55800 - estebank:abolish-ice-for-lifetime, r=oli-obk
Fix ICE in `return_type_impl_trait` Fix #55796.
This commit is contained in:
commit
ff8ee964ae
3 changed files with 87 additions and 1 deletions
|
|
@ -17,7 +17,7 @@ use session::Session;
|
|||
use session::config::{BorrowckMode, OutputFilenames};
|
||||
use session::config::CrateType;
|
||||
use middle;
|
||||
use hir::{TraitCandidate, HirId, ItemLocalId, Node};
|
||||
use hir::{TraitCandidate, HirId, ItemKind, ItemLocalId, Node};
|
||||
use hir::def::{Def, Export};
|
||||
use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
|
||||
use hir::map as hir_map;
|
||||
|
|
@ -1602,6 +1602,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
&self,
|
||||
scope_def_id: DefId,
|
||||
) -> Option<Ty<'tcx>> {
|
||||
// HACK: `type_of_def_id()` will fail on these (#55796), so return None
|
||||
let node_id = self.hir.as_local_node_id(scope_def_id).unwrap();
|
||||
match self.hir.get(node_id) {
|
||||
Node::Item(item) => {
|
||||
match item.node {
|
||||
ItemKind::Fn(..) => { /* type_of_def_id() will work */ }
|
||||
_ => {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => { /* type_of_def_id() will work or panic */ }
|
||||
}
|
||||
|
||||
let ret_ty = self.type_of(scope_def_id);
|
||||
match ret_ty.sty {
|
||||
ty::FnDef(_, _) => {
|
||||
|
|
|
|||
22
src/test/ui/issues/issue-55796.rs
Normal file
22
src/test/ui/issues/issue-55796.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
pub trait EdgeTrait<N> {
|
||||
fn target(&self) -> N;
|
||||
}
|
||||
|
||||
pub trait Graph<'a> {
|
||||
type Node;
|
||||
type Edge: EdgeTrait<Self::Node>;
|
||||
type NodesIter: Iterator<Item = Self::Node> + 'a;
|
||||
type EdgesIter: Iterator<Item = Self::Edge> + 'a;
|
||||
|
||||
fn nodes(&'a self) -> Self::NodesIter;
|
||||
fn out_edges(&'a self, u: &Self::Node) -> Self::EdgesIter;
|
||||
fn in_edges(&'a self, u: &Self::Node) -> Self::EdgesIter;
|
||||
|
||||
fn out_neighbors(&'a self, u: &Self::Node) -> Box<Iterator<Item = Self::Node>> {
|
||||
Box::new(self.out_edges(u).map(|e| e.target()))
|
||||
}
|
||||
|
||||
fn in_neighbors(&'a self, u: &Self::Node) -> Box<Iterator<Item = Self::Node>> {
|
||||
Box::new(self.in_edges(u).map(|e| e.target()))
|
||||
}
|
||||
}
|
||||
50
src/test/ui/issues/issue-55796.stderr
Normal file
50
src/test/ui/issues/issue-55796.stderr
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
error[E0601]: `main` function not found in crate `issue_55796`
|
||||
|
|
||||
= note: consider adding a `main` function to `$DIR/issue-55796.rs`
|
||||
|
||||
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
|
||||
--> $DIR/issue-55796.rs:16:9
|
||||
|
|
||||
LL | Box::new(self.out_edges(u).map(|e| e.target()))
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: first, the lifetime cannot outlive the lifetime 'a as defined on the trait at 5:17...
|
||||
--> $DIR/issue-55796.rs:5:17
|
||||
|
|
||||
LL | pub trait Graph<'a> {
|
||||
| ^^
|
||||
note: ...so that the type `std::iter::Map<<Self as Graph<'a>>::EdgesIter, [closure@$DIR/issue-55796.rs:16:40: 16:54]>` will meet its required lifetime bounds
|
||||
--> $DIR/issue-55796.rs:16:9
|
||||
|
|
||||
LL | Box::new(self.out_edges(u).map(|e| e.target()))
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: but, the lifetime must be valid for the static lifetime...
|
||||
= note: ...so that the expression is assignable:
|
||||
expected std::boxed::Box<(dyn std::iter::Iterator<Item=<Self as Graph<'a>>::Node> + 'static)>
|
||||
found std::boxed::Box<dyn std::iter::Iterator<Item=<Self as Graph<'a>>::Node>>
|
||||
|
||||
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
|
||||
--> $DIR/issue-55796.rs:20:9
|
||||
|
|
||||
LL | Box::new(self.in_edges(u).map(|e| e.target()))
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: first, the lifetime cannot outlive the lifetime 'a as defined on the trait at 5:17...
|
||||
--> $DIR/issue-55796.rs:5:17
|
||||
|
|
||||
LL | pub trait Graph<'a> {
|
||||
| ^^
|
||||
note: ...so that the type `std::iter::Map<<Self as Graph<'a>>::EdgesIter, [closure@$DIR/issue-55796.rs:20:39: 20:53]>` will meet its required lifetime bounds
|
||||
--> $DIR/issue-55796.rs:20:9
|
||||
|
|
||||
LL | Box::new(self.in_edges(u).map(|e| e.target()))
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: but, the lifetime must be valid for the static lifetime...
|
||||
= note: ...so that the expression is assignable:
|
||||
expected std::boxed::Box<(dyn std::iter::Iterator<Item=<Self as Graph<'a>>::Node> + 'static)>
|
||||
found std::boxed::Box<dyn std::iter::Iterator<Item=<Self as Graph<'a>>::Node>>
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors occurred: E0495, E0601.
|
||||
For more information about an error, try `rustc --explain E0495`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue