Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP PoC for impl Trait in impl Fn return in fn parameters #1

Closed
wants to merge 5 commits into from

Conversation

alsuren
Copy link
Owner

@alsuren alsuren commented Jun 20, 2020

My amateurish attempts at getting rust-lang#45994 to work (I've never done rustc development before. Only contributed test cases so far).

I managed to make the ast lowering step accept the syntax, but I am definitely doing something wrong, because I'm not sure what to do with the impl Trait bound, so I'm dropping it on the floor. When the HIR lowering code tries to use it, it's not found in the HIR map, so it explodes (I added some debugging, and it's definitely the impl Trait bit that's going missing.)

vsonline:~/workspace/rust$ RUST_BACKTRACE=1 RUSTC_LOG=rustc::traits ./build/*/stage1/bin/rustc src/test/ui/impl-trait/where-allowed.rs 
FIXME: Generic params from impl Trait: [GenericParam { hir_id: HirId { owner: DefId(0:4), local_id: 18 }, name: Plain(impl Debug#0), attrs: [], bounds: [Trait(PolyTraitRef { bound_generic_params: [], trait_ref: TraitRef { path: Path { span: src/test/ui/impl-trait/where-allowed.rs:2:58: 2:63 (#0), res: Def(Trait, DefId(2:6178)), segments: [PathSegment { ident: Debug#0, hir_id: Some(HirId { owner: DefId(0:4), local_id: 16 }), res: Some(Def(Trait, DefId(2:6178))), args: None, infer_args: false }] }, hir_ref_id: HirId { owner: DefId(0:4), local_id: 17 } }, span: src/test/ui/impl-trait/where-allowed.rs:2:58: 2:63 (#0) }, None)], span: src/test/ui/impl-trait/where-allowed.rs:2:53: 2:63 (#0), pure_wrt_drop: false, kind: Type { default: None, synthetic: Some(ImplTrait) } }]

...

thread 'rustc' panicked at 'Can't find Entry for HirId HirId { owner: DefId(0:4 ~ where_allowed[317d]::in_impl_Fn_return_in_parameters[0]), local_id: 18 }', src/librustc_middle/hir/map/mod.rs:294:47
stack backtrace:
...
  16: core::option::Option<T>::unwrap_or_else
             at ./src/libcore/option.rs:430
  17: rustc_middle::hir::map::Map::get_entry
             at src/librustc_middle/hir/map/mod.rs:294
  18: rustc_middle::hir::map::Map::get_parent_node
             at src/librustc_middle/hir/map/mod.rs:525
  19: <dyn rustc_typeck::astconv::AstConv>::res_to_ty
             at src/librustc_typeck/astconv.rs:2751
  20: <dyn rustc_typeck::astconv::AstConv>::ast_ty_to_ty
             at src/librustc_typeck/astconv.rs:2839
  21: <dyn rustc_typeck::astconv::AstConv>::create_substs_for_ast_path::{{closure}}
             at src/librustc_typeck/astconv.rs:908
  22: core::iter::adapters::map_fold::{{closure}}
             at ./src/libcore/iter/adapters/mod.rs:830
  23: core::iter::traits::iterator::Iterator::fold
             at ./src/libcore/iter/traits/iterator.rs:2022
...

@@ -1327,6 +1327,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
attributes to enable",
);
}
// Explodes here
Copy link
Owner Author

@alsuren alsuren Jun 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Explodes here

No longer explodes here. Now explodes in self.find_entry(id).unwrap_or_else(|| panic!("Can't find Entry for HirId {:?}", id)), below.

@@ -503,7 +503,11 @@ impl<'hir> Map<'hir> {
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
pub fn find(&self, hir_id: HirId) -> Option<Node<'hir>> {
self.find_entry(hir_id).and_then(|entry| {
if let Node::Crate(..) = entry.node { None } else { Some(entry.node) }
if let Node::Crate(..) = entry.node {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing to see here. Just my rust-analyser not being set up correctly.

@alsuren alsuren changed the title Fn return impl trait PoC: Fn return impl trait Jun 21, 2020
@alsuren alsuren changed the title PoC: Fn return impl trait WIP PoC for impl Trait in impl Fn return in fn parameters Jun 21, 2020
@alsuren
Copy link
Owner Author

alsuren commented Feb 4, 2024

Just closing some old PRs. Nothing to see here.

@alsuren alsuren closed this Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant