-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gccrs: fix typechecking of Fn trait calls using ADT types
Fixes RustGcc#2953 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): fix the ty_id gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle these * rust/compile/issue-2953-1.rs: New test. * rust/compile/issue-2953-2.rs: New test. Signed-off-by: Philip Herron <[email protected]>
- Loading branch information
Showing
4 changed files
with
72 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#[lang = "sized"] | ||
pub trait Sized { | ||
// Empty. | ||
} | ||
|
||
#[lang = "fn_once"] | ||
pub trait FnOnce<Args> { | ||
/// The returned type after the call operator is used. | ||
#[lang = "fn_once_output"] | ||
type Output; | ||
|
||
/// Performs the call operation. | ||
extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
} | ||
|
||
pub enum Ordering { | ||
/// An ordering where a compared value is less than another. | ||
Less = -1, | ||
/// An ordering where a compared value is equal to another. | ||
Equal = 0, | ||
/// An ordering where a compared value is greater than another. | ||
Greater = 1, | ||
} | ||
|
||
pub fn f<F: FnOnce(i32) -> Ordering>(g: F) -> Ordering { | ||
g(1) | ||
} |
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,37 @@ | ||
#[lang = "sized"] | ||
pub trait Sized { | ||
// Empty. | ||
} | ||
|
||
#[lang = "fn_once"] | ||
pub trait FnOnce<Args> { | ||
/// The returned type after the call operator is used. | ||
#[lang = "fn_once_output"] | ||
type Output; | ||
|
||
/// Performs the call operation. | ||
extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
} | ||
|
||
pub enum Ordering { | ||
/// An ordering where a compared value is less than another. | ||
Less = -1, | ||
/// An ordering where a compared value is equal to another. | ||
Equal = 0, | ||
/// An ordering where a compared value is greater than another. | ||
Greater = 1, | ||
} | ||
|
||
pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T { | ||
match compare(&v1, &v2) { | ||
Ordering::Less | Ordering::Equal => v2, | ||
Ordering::Greater => v1, | ||
} | ||
} | ||
|
||
pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T { | ||
match compare(&v1, &v2) { | ||
Ordering::Less | Ordering::Equal => v1, | ||
Ordering::Greater => v2, | ||
} | ||
} |
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