-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gccrs: Track fn_once output lang item properly
In order to setup the Output assoicated type we can rely on using generic argument bindings. So for example when we have the FnOnce trait: #[lang = "fn_once"] pub trait FnOnce<Args> { #[lang = "fn_once_output"] type Output; extern "rust-call" fn call_once(self, args: Args) -> Self::Output; } Thn we might have a function such as: pub fn map<R, F: FnOnce(T) -> R>(self, f: F) -> Option<R> { ... } This trait bound predicate of FnOnce(T) -> R we setup generics for the bound as: FnOnce<(T), Output=R> This means we can reuse our generic arguments handling to get this support. Fixes #2105 gcc/rust/ChangeLog: * typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): track output * util/rust-hir-map.cc (Mappings::lookup_trait_item_lang_item): new helper * util/rust-hir-map.h: add prototype for helper gcc/testsuite/ChangeLog: * rust/compile/issue-2105.rs: New test. Signed-off-by: Philip Herron <[email protected]>
- Loading branch information
Showing
4 changed files
with
57 additions
and
14 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pub enum Option<T> { | ||
Some(T), | ||
None, | ||
} | ||
|
||
pub use Option::{None, Some}; | ||
|
||
#[lang = "fn_once"] | ||
pub trait FnOnce<Args> { | ||
#[lang = "fn_once_output"] | ||
type Output; | ||
|
||
extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
} | ||
|
||
impl<T> Option<T> { | ||
pub fn map<R, F: FnOnce(T) -> R>(self, f: F) -> Option<R> { | ||
match self { | ||
Some(value) => Some(f(value)), | ||
None => None, | ||
} | ||
} | ||
} |