-
Notifications
You must be signed in to change notification settings - Fork 180
Fix fnptr not auto implement fn once #3492
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2222,6 +2222,56 @@ FnPtr::clone () const | |
get_combined_refs ()); | ||
} | ||
|
||
void | ||
FnPtr::setup_fn_once_output () const | ||
{ | ||
// lookup the lang items | ||
auto fn_once_lookup = mappings.lookup_lang_item (LangItem::Kind::FN_ONCE); | ||
auto fn_once_output_lookup | ||
= mappings.lookup_lang_item (LangItem::Kind::FN_ONCE_OUTPUT); | ||
if (!fn_once_lookup) | ||
{ | ||
rust_fatal_error (UNKNOWN_LOCATION, | ||
"Missing required %<fn_once%> lang item"); | ||
return; | ||
} | ||
if (!fn_once_output_lookup) | ||
{ | ||
rust_fatal_error (UNKNOWN_LOCATION, | ||
"Missing required %<fn_once_ouput%> lang item"); | ||
return; | ||
} | ||
Comment on lines
+2229
to
+2243
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. there should be a |
||
|
||
DefId &trait_id = fn_once_lookup.value (); | ||
DefId &trait_item_id = fn_once_output_lookup.value (); | ||
Comment on lines
+2245
to
+2246
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. this would also allow you to avoid these lines, as 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. i'll probably fix the original code from Philip too |
||
|
||
// resolve to the trait | ||
HIR::Item *item = mappings.lookup_defid (trait_id).value (); | ||
rust_assert (item->get_item_kind () == HIR::Item::ItemKind::Trait); | ||
HIR::Trait *trait = static_cast<HIR::Trait *> (item); | ||
|
||
Resolver::TraitReference *trait_ref | ||
= Resolver::TraitResolver::Resolve (*trait); | ||
rust_assert (!trait_ref->is_error ()); | ||
|
||
// resolve to trait item | ||
HIR::TraitItem *trait_item | ||
= mappings.lookup_trait_item_defid (trait_item_id).value (); | ||
rust_assert (trait_item->get_item_kind () | ||
== HIR::TraitItem::TraitItemKind::TYPE); | ||
std::string item_identifier = trait_item->trait_identifier (); | ||
|
||
// setup associated types #[lang = "fn_once_output"] | ||
Resolver::TraitItemReference *item_reference = nullptr; | ||
bool found = trait_ref->lookup_trait_item_by_type ( | ||
item_identifier, Resolver::TraitItemReference::TraitItemType::TYPE, | ||
&item_reference); | ||
rust_assert (found); | ||
|
||
// setup | ||
item_reference->associated_type_set (&get_result_type ()); | ||
} | ||
|
||
void | ||
ClosureType::accept_vis (TyVisitor &vis) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
#[lang = "sized"] | ||
pub trait Sized {} | ||
|
||
#[lang = "fn_once"] | ||
pub trait FnOnce<Args> { | ||
#[lang = "fn_once_output"] | ||
type Output; | ||
|
||
extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
} | ||
|
||
pub fn f(_: extern "Rust" fn()) {} |
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.
Yeah this is a dup of ClosureType::setup_fn_once_output its probably better to find a way to extract that out to be a shared helper
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.
yes, will do
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.
Would adding this to
CallableTypeInterface
work?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.
could work, ill refactor
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.
i need to rebuild clangformat 10 on my ubuntu first...
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.
tbh I just use clang format 19 -- it mostly works, aside from the once-in-6-months edge case
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.
it's refactoring some subparts of a source file and it's starting to be really a pain in the butt for me. I'm not sure if i should maintain some sort of repository to store different architecture of clang format 10...
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.
Have you used
git add -p
andgit restore -p
? May be easier than trying to get clang-format 10, depending on how far along you are