suggestions from camelid review

This commit is contained in:
Ethan Brierley 2020-12-06 21:30:30 +00:00
parent 0c13a9c020
commit 67db0ea4a7
4 changed files with 32 additions and 68 deletions

View File

@ -403,6 +403,32 @@ impl InherentCollect<'tcx> {
// OK
}
_ => {
let to_implement = if assoc_items.len() == 0 {
String::new()
} else {
let plural = assoc_items.len() > 1;
let assoc_items_kind = {
let item_types = assoc_items.iter().map(|x| x.kind);
if item_types.clone().all(|x| x == hir::AssocItemKind::Const) {
"constant"
} else if item_types
.clone()
.all(|x| matches! {x, hir::AssocItemKind::Fn{ .. } })
{
"method"
} else {
"associated item"
}
};
format!(
" to implement {} {}{}",
if plural { "these" } else { "this" },
assoc_items_kind,
if plural { "s" } else { "" }
)
};
struct_span_err!(
self.tcx.sess,
span,
@ -412,34 +438,7 @@ impl InherentCollect<'tcx> {
lang,
ty
)
.span_help(
span,
&format!("consider using a trait{}", {
if assoc_items.len() == 0 {
String::new()
} else {
let plural = assoc_items.len() > 1;
format!(
" to implement {} {}{}",
if plural { "these" } else { "this" },
{
let item_types = assoc_items.iter().map(|x| x.kind);
if item_types.clone().all(|x| x == hir::AssocItemKind::Const) {
"constant"
} else if item_types
.clone()
.all(|x| matches! {x, hir::AssocItemKind::Fn{ .. } })
{
"method"
} else {
"associated item"
}
},
if plural { "s" } else { "" }
)
}
}),
)
.help(&format!("consider using a trait{}", to_implement))
.emit();
}
}

View File

@ -4,11 +4,7 @@ error[E0390]: only a single inherent implementation marked with `#[lang = "mut_p
LL | impl *mut Foo {}
| ^^^^^^^^^^^^^^^^
|
help: consider using a trait
--> $DIR/E0390.rs:5:1
|
LL | impl *mut Foo {}
| ^^^^^^^^^^^^^^^^
= help: consider using a trait
error: aborting due to previous error

View File

@ -7,14 +7,7 @@ LL | | pub const B: u8 = 0;
LL | | }
| |_^
|
help: consider using a trait to implement this constant
--> $DIR/kinds-of-primitive-impl.rs:4:1
|
LL | / impl u8 {
LL | |
LL | | pub const B: u8 = 0;
LL | | }
| |_^
= help: consider using a trait to implement this constant
error[E0390]: only a single inherent implementation marked with `#[lang = "str"]` is allowed for the `str` primitive
--> $DIR/kinds-of-primitive-impl.rs:9:1
@ -26,15 +19,7 @@ LL | | fn bar(self) {}
LL | | }
| |_^
|
help: consider using a trait to implement these methods
--> $DIR/kinds-of-primitive-impl.rs:9:1
|
LL | / impl str {
LL | |
LL | | fn foo() {}
LL | | fn bar(self) {}
LL | | }
| |_^
= help: consider using a trait to implement these methods
error[E0390]: only a single inherent implementation marked with `#[lang = "char"]` is allowed for the `char` primitive
--> $DIR/kinds-of-primitive-impl.rs:15:1
@ -48,17 +33,7 @@ LL | | fn bar(self) {}
LL | | }
| |_^
|
help: consider using a trait to implement these associated items
--> $DIR/kinds-of-primitive-impl.rs:15:1
|
LL | / impl char {
LL | |
LL | | pub const B: u8 = 0;
LL | | pub const C: u8 = 0;
LL | | fn foo() {}
LL | | fn bar(self) {}
LL | | }
| |_^
= help: consider using a trait to implement these associated items
error: aborting due to 3 previous errors

View File

@ -6,13 +6,7 @@ LL | |
LL | | }
| |_^
|
help: consider using a trait
--> $DIR/single-primitive-inherent-impl.rs:11:1
|
LL | / impl str {
LL | |
LL | | }
| |_^
= help: consider using a trait
error: aborting due to previous error