Merge #9319
9319: internal: add derive and ord support to minicore r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
916384a1ea
@ -3016,8 +3016,8 @@ fn foo() {
|
||||
file_id: FileId(
|
||||
1,
|
||||
),
|
||||
full_range: 247..429,
|
||||
focus_range: 286..292,
|
||||
full_range: 248..430,
|
||||
focus_range: 287..293,
|
||||
name: "Future",
|
||||
kind: Trait,
|
||||
description: "pub trait Future",
|
||||
|
@ -147,74 +147,92 @@ fn opposite_logic_op(kind: ast::BinOp) -> Option<&'static str> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ide_db::helpers::FamousDefs;
|
||||
use crate::tests::{check_assist, check_assist_not_applicable};
|
||||
|
||||
use super::*;
|
||||
|
||||
use crate::tests::{check_assist, check_assist_not_applicable};
|
||||
|
||||
const ORDABLE_FIXTURE: &'static str = r"
|
||||
//- /lib.rs deps:core crate:ordable
|
||||
struct NonOrderable;
|
||||
struct Orderable;
|
||||
impl core::cmp::Ord for Orderable {}
|
||||
";
|
||||
|
||||
fn check(ra_fixture_before: &str, ra_fixture_after: &str) {
|
||||
let before = &format!(
|
||||
"//- /main.rs crate:main deps:core,ordable\n{}\n{}{}",
|
||||
ra_fixture_before,
|
||||
FamousDefs::FIXTURE,
|
||||
ORDABLE_FIXTURE
|
||||
);
|
||||
check_assist(apply_demorgan, before, &format!("{}\n", ra_fixture_after));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn demorgan_handles_leq() {
|
||||
check(
|
||||
r"use ordable::Orderable;
|
||||
check_assist(
|
||||
apply_demorgan,
|
||||
r#"
|
||||
//- minicore: ord, derive
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
struct S;
|
||||
|
||||
fn f() {
|
||||
Orderable < Orderable &&$0 Orderable <= Orderable
|
||||
}",
|
||||
r"use ordable::Orderable;
|
||||
S < S &&$0 S <= S
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
struct S;
|
||||
|
||||
fn f() {
|
||||
!(Orderable >= Orderable || Orderable > Orderable)
|
||||
}",
|
||||
!(S >= S || S > S)
|
||||
}
|
||||
"#,
|
||||
);
|
||||
check(
|
||||
r"use ordable::NonOrderable;
|
||||
|
||||
check_assist(
|
||||
apply_demorgan,
|
||||
r#"
|
||||
//- minicore: ord, derive
|
||||
struct S;
|
||||
|
||||
fn f() {
|
||||
NonOrderable < NonOrderable &&$0 NonOrderable <= NonOrderable
|
||||
}",
|
||||
r"use ordable::NonOrderable;
|
||||
S < S &&$0 S <= S
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
struct S;
|
||||
|
||||
fn f() {
|
||||
!(!(NonOrderable < NonOrderable) || !(NonOrderable <= NonOrderable))
|
||||
}",
|
||||
!(!(S < S) || !(S <= S))
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn demorgan_handles_geq() {
|
||||
check(
|
||||
r"use ordable::Orderable;
|
||||
check_assist(
|
||||
apply_demorgan,
|
||||
r#"
|
||||
//- minicore: ord, derive
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
struct S;
|
||||
|
||||
fn f() {
|
||||
Orderable > Orderable &&$0 Orderable >= Orderable
|
||||
}",
|
||||
r"use ordable::Orderable;
|
||||
S > S &&$0 S >= S
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
struct S;
|
||||
|
||||
fn f() {
|
||||
!(Orderable <= Orderable || Orderable < Orderable)
|
||||
}",
|
||||
!(S <= S || S < S)
|
||||
}
|
||||
"#,
|
||||
);
|
||||
check(
|
||||
r"use ordable::NonOrderable;
|
||||
check_assist(
|
||||
apply_demorgan,
|
||||
r#"
|
||||
//- minicore: ord, derive
|
||||
struct S;
|
||||
|
||||
fn f() {
|
||||
Orderable > Orderable &&$0 Orderable >= Orderable
|
||||
}",
|
||||
r"use ordable::NonOrderable;
|
||||
S > S &&$0 S >= S
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
struct S;
|
||||
|
||||
fn f() {
|
||||
!(!(Orderable > Orderable) || !(Orderable >= Orderable))
|
||||
}",
|
||||
!(!(S > S) || !(S >= S))
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
|
||||
RootDatabase::with_single_file(text)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) {
|
||||
let ra_fixture_after = trim_indent(ra_fixture_after);
|
||||
check(assist, ra_fixture_before, ExpectedResult::After(&ra_fixture_after), None);
|
||||
|
@ -1,15 +1,5 @@
|
||||
//- /libcore.rs crate:core
|
||||
//! Signatures of traits, types and functions from the core lib for use in tests.
|
||||
pub mod cmp {
|
||||
|
||||
pub trait Ord {
|
||||
fn cmp(&self, other: &Self) -> Ordering;
|
||||
fn max(self, other: Self) -> Self;
|
||||
fn min(self, other: Self) -> Self;
|
||||
fn clamp(self, min: Self, max: Self) -> Self;
|
||||
}
|
||||
}
|
||||
|
||||
pub mod prelude {
|
||||
pub mod rust_2018 {
|
||||
pub use crate::{
|
||||
|
@ -24,6 +24,9 @@
|
||||
//! iterators: iterator
|
||||
//! default: sized
|
||||
//! from: sized
|
||||
//! eq: sized
|
||||
//! ord: eq, option
|
||||
//! derive:
|
||||
|
||||
pub mod marker {
|
||||
// region:sized
|
||||
@ -173,6 +176,49 @@ pub mod ops {
|
||||
// endregion:fn
|
||||
}
|
||||
|
||||
// region:eq
|
||||
pub mod cmp {
|
||||
#[lang = "eq"]
|
||||
pub trait PartialEq<Rhs: ?Sized = Self> {
|
||||
fn eq(&self, other: &Rhs) -> bool;
|
||||
}
|
||||
|
||||
pub trait Eq: PartialEq<Self> {}
|
||||
|
||||
// region:derive
|
||||
#[rustc_builtin_macro]
|
||||
pub macro PartialEq($item:item) {}
|
||||
#[rustc_builtin_macro]
|
||||
pub macro Eq($item:item) {}
|
||||
// endregion:derive
|
||||
|
||||
// region:ord
|
||||
#[lang = "partial_ord"]
|
||||
pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
|
||||
fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;
|
||||
}
|
||||
|
||||
pub trait Ord: Eq + PartialOrd<Self> {
|
||||
fn cmp(&self, other: &Self) -> Ordering;
|
||||
}
|
||||
|
||||
pub enum Ordering {
|
||||
Less = -1,
|
||||
Equal = 0,
|
||||
Greater = 1,
|
||||
}
|
||||
|
||||
// region:derive
|
||||
#[rustc_builtin_macro]
|
||||
pub macro PartialOrd($item:item) {}
|
||||
#[rustc_builtin_macro]
|
||||
pub macro Ord($item:item) {}
|
||||
// endregion:derive
|
||||
|
||||
// endregion:ord
|
||||
}
|
||||
// endregion:eq
|
||||
|
||||
// region:slice
|
||||
pub mod slice {
|
||||
#[lang = "slice"]
|
||||
@ -342,16 +388,30 @@ pub mod iter {
|
||||
}
|
||||
// endregion:iterator
|
||||
|
||||
// region:derive
|
||||
mod macros {
|
||||
pub(crate) mod builtin {
|
||||
#[rustc_builtin_macro]
|
||||
pub macro derive($item:item) {
|
||||
/* compiler built-in */
|
||||
}
|
||||
}
|
||||
}
|
||||
// endregion:derive
|
||||
|
||||
pub mod prelude {
|
||||
pub mod v1 {
|
||||
pub use crate::{
|
||||
cmp::{Eq, PartialEq}, // :eq
|
||||
cmp::{Ord, PartialOrd}, // :ord
|
||||
convert::{From, Into}, // :from
|
||||
default::Default, // :default
|
||||
iter::{IntoIterator, Iterator}, // :iterator
|
||||
macros::builtin::derive, // :derive
|
||||
marker::Sized, // :sized
|
||||
ops::{Fn, FnMut, FnOnce}, // :fn
|
||||
option::Option::{self, None, Some}, // :option
|
||||
result::Result::{self, Err, Ok}, // :result
|
||||
convert::{From, Into}, // :from
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user