resolve: improve "try using tuple struct" message
This commit improves the tuple struct case added in rust-lang/rust#77341 so that the context is mentioned in more of the message. Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
parent
adf31e95e4
commit
f897162f3e
3 changed files with 20 additions and 20 deletions
|
@ -1341,21 +1341,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
|||
|
||||
let non_suggestable_variant_count = variants.len() - suggestable_variants.len();
|
||||
|
||||
if !suggestable_variants.is_empty() {
|
||||
let msg = if non_suggestable_variant_count == 0 && suggestable_variants.len() == 1 {
|
||||
"try using the enum's variant"
|
||||
} else {
|
||||
"try using one of the enum's variants"
|
||||
};
|
||||
|
||||
err.span_suggestions(
|
||||
span,
|
||||
msg,
|
||||
suggestable_variants.drain(..),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
|
||||
let source_msg = if source.is_call() {
|
||||
"to construct"
|
||||
} else if matches!(source, PathSource::TupleStruct(..)) {
|
||||
|
@ -1364,6 +1349,21 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
|||
unreachable!()
|
||||
};
|
||||
|
||||
if !suggestable_variants.is_empty() {
|
||||
let msg = if non_suggestable_variant_count == 0 && suggestable_variants.len() == 1 {
|
||||
format!("try {} the enum's variant", source_msg)
|
||||
} else {
|
||||
format!("try {} one of the enum's variants", source_msg)
|
||||
};
|
||||
|
||||
err.span_suggestions(
|
||||
span,
|
||||
&msg,
|
||||
suggestable_variants.drain(..),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
|
||||
// If the enum has no tuple variants..
|
||||
if non_suggestable_variant_count == variants.len() {
|
||||
err.help(&format!("the enum has no tuple variants {}", source_msg));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue