forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2434231
tdd: impl trait in bare fn return position
alsuren cf97b9a
run with debugging (crashes later)
alsuren bc7fa17
REVERT ME: yes it is the impl Trait hir id that it can't find
alsuren cc572eb
simplify harder
alsuren a502135
fix name of argument description
alsuren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -291,7 +291,7 @@ impl<'hir> Map<'hir> { | |
} | ||
|
||
fn get_entry(&self, id: HirId) -> Entry<'hir> { | ||
self.find_entry(id).unwrap() | ||
self.find_entry(id).unwrap_or_else(|| panic!("Can't find Entry for HirId {:?}", id)) | ||
} | ||
|
||
pub fn item(&self, id: HirId) -> &'hir Item<'hir> { | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
None | ||
} else { | ||
Some(entry.node) | ||
} | ||
}) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,224 +1,2 @@ | ||
//! A simple test for testing many permutations of allowedness of | ||
//! impl Trait | ||
use std::fmt::Debug; | ||
|
||
// Allowed | ||
fn in_parameters(_: impl Debug) { panic!() } | ||
|
||
// Allowed | ||
fn in_return() -> impl Debug { panic!() } | ||
|
||
// Allowed | ||
fn in_adt_in_parameters(_: Vec<impl Debug>) { panic!() } | ||
|
||
// Disallowed | ||
fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
//~^^ ERROR nested `impl Trait` is not allowed | ||
|
||
// Disallowed | ||
fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
//~| ERROR nested `impl Trait` is not allowed | ||
|
||
// Disallowed | ||
fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
|
||
// Allowed | ||
fn in_impl_Trait_in_parameters(_: impl Iterator<Item = impl Iterator>) { panic!() } | ||
|
||
// Allowed | ||
fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> { | ||
vec![vec![0; 10], vec![12; 7], vec![8; 3]] | ||
} | ||
|
||
// Disallowed | ||
struct InBraceStructField { x: impl Debug } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
struct InAdtInBraceStructField { x: Vec<impl Debug> } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
struct InTupleStructField(impl Debug); | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
// Disallowed | ||
enum InEnum { | ||
InBraceVariant { x: impl Debug }, | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
InTupleVariant(impl Debug), | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
} | ||
|
||
// Allowed | ||
trait InTraitDefnParameters { | ||
fn in_parameters(_: impl Debug); | ||
} | ||
|
||
// Disallowed | ||
trait InTraitDefnReturn { | ||
fn in_return() -> impl Debug; | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
} | ||
|
||
// Allowed and disallowed in trait impls | ||
trait DummyTrait { | ||
type Out; | ||
fn in_trait_impl_parameter(_: impl Debug); | ||
fn in_trait_impl_return() -> Self::Out; | ||
} | ||
impl DummyTrait for () { | ||
type Out = impl Debug; | ||
//~^ ERROR `impl Trait` in type aliases is unstable | ||
//~^^ ERROR could not find defining uses | ||
|
||
fn in_trait_impl_parameter(_: impl Debug) { } | ||
// Allowed | ||
|
||
fn in_trait_impl_return() -> impl Debug { () } | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
} | ||
|
||
// Allowed | ||
struct DummyType; | ||
impl DummyType { | ||
fn in_inherent_impl_parameters(_: impl Debug) { } | ||
fn in_inherent_impl_return() -> impl Debug { () } | ||
} | ||
|
||
// Disallowed | ||
extern "C" { | ||
fn in_foreign_parameters(_: impl Debug); | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
|
||
fn in_foreign_return() -> impl Debug; | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
} | ||
|
||
// Allowed | ||
extern "C" fn in_extern_fn_parameters(_: impl Debug) { | ||
} | ||
|
||
// Allowed | ||
extern "C" fn in_extern_fn_return() -> impl Debug { | ||
22 | ||
} | ||
|
||
type InTypeAlias<R> = impl Debug; | ||
//~^ ERROR `impl Trait` in type aliases is unstable | ||
//~^^ ERROR could not find defining uses | ||
|
||
type InReturnInTypeAlias<R> = fn() -> impl Debug; | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
//~| ERROR `impl Trait` in type aliases is unstable | ||
|
||
// Disallowed in impl headers | ||
impl PartialEq<impl Debug> for () { | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
} | ||
|
||
// Disallowed in impl headers | ||
impl PartialEq<()> for impl Debug { | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
} | ||
|
||
// Disallowed in inherent impls | ||
impl impl Debug { | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
} | ||
|
||
// Disallowed in inherent impls | ||
struct InInherentImplAdt<T> { t: T } | ||
impl InInherentImplAdt<impl Debug> { | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
} | ||
|
||
// Disallowed in where clauses | ||
fn in_fn_where_clause() | ||
where impl Debug: Debug | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
{ | ||
} | ||
|
||
// Disallowed in where clauses | ||
fn in_adt_in_fn_where_clause() | ||
where Vec<impl Debug>: Debug | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
{ | ||
} | ||
|
||
// Disallowed | ||
fn in_trait_parameter_in_fn_where_clause<T>() | ||
where T: PartialEq<impl Debug> | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
{ | ||
} | ||
|
||
// Disallowed | ||
fn in_Fn_parameter_in_fn_where_clause<T>() | ||
where T: Fn(impl Debug) | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
{ | ||
} | ||
|
||
// Disallowed | ||
fn in_Fn_return_in_fn_where_clause<T>() | ||
where T: Fn() -> impl Debug | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
{ | ||
} | ||
|
||
fn main() { | ||
let _in_local_variable: impl Fn() = || {}; | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
let _in_return_in_local_variable = || -> impl Fn() { || {} }; | ||
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer explodes here. Now explodes in
self.find_entry(id).unwrap_or_else(|| panic!("Can't find Entry for HirId {:?}", id))
, below.