mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 02:29:44 +00:00
Fix some things with builtin derives
1. Err on unions on derive where it's required. 2. Err on `#[derive(Default)]` on enums without `#[default]` variant. 3. Don't add where bounds `T: Default` when expanding `Default` on enums (structs need that, enums not). Also, because I was annoyed by that, in minicore, add a way to filter on multiple flags in the line-filter (`// :`). This is required for the `Debug` and `Hash` derives, because the derive should be in the prelude but the trait not.
This commit is contained in:
parent
f14bf95931
commit
9c4a7705b1
5 changed files with 191 additions and 73 deletions
|
|
@ -746,3 +746,83 @@ struct Struct9<#[pointee] T, U>(T) where T: ?Sized;
|
|||
623..690: `derive(CoercePointee)` requires `T` to be marked `?Sized`"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn union_derive() {
|
||||
check_errors(
|
||||
r#"
|
||||
//- minicore: clone, copy, default, fmt, hash, ord, eq, derive
|
||||
|
||||
#[derive(Copy)]
|
||||
union Foo1 { _v: () }
|
||||
#[derive(Clone)]
|
||||
union Foo2 { _v: () }
|
||||
#[derive(Default)]
|
||||
union Foo3 { _v: () }
|
||||
#[derive(Debug)]
|
||||
union Foo4 { _v: () }
|
||||
#[derive(Hash)]
|
||||
union Foo5 { _v: () }
|
||||
#[derive(Ord)]
|
||||
union Foo6 { _v: () }
|
||||
#[derive(PartialOrd)]
|
||||
union Foo7 { _v: () }
|
||||
#[derive(Eq)]
|
||||
union Foo8 { _v: () }
|
||||
#[derive(PartialEq)]
|
||||
union Foo9 { _v: () }
|
||||
"#,
|
||||
expect![[r#"
|
||||
78..118: this trait cannot be derived for unions
|
||||
119..157: this trait cannot be derived for unions
|
||||
158..195: this trait cannot be derived for unions
|
||||
196..232: this trait cannot be derived for unions
|
||||
233..276: this trait cannot be derived for unions
|
||||
313..355: this trait cannot be derived for unions"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_enum_without_default_attr() {
|
||||
check_errors(
|
||||
r#"
|
||||
//- minicore: default, derive
|
||||
|
||||
#[derive(Default)]
|
||||
enum Foo {
|
||||
Bar,
|
||||
}
|
||||
"#,
|
||||
expect!["1..41: `#[derive(Default)]` on enum with no `#[default]`"],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generic_enum_default() {
|
||||
check(
|
||||
r#"
|
||||
//- minicore: default, derive
|
||||
|
||||
#[derive(Default)]
|
||||
enum Foo<T> {
|
||||
Bar(T),
|
||||
#[default]
|
||||
Baz,
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
|
||||
#[derive(Default)]
|
||||
enum Foo<T> {
|
||||
Bar(T),
|
||||
#[default]
|
||||
Baz,
|
||||
}
|
||||
|
||||
impl <T, > $crate::default::Default for Foo<T, > where {
|
||||
fn default() -> Self {
|
||||
Foo::Baz
|
||||
}
|
||||
}"#]],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue