Rename DiagnosticMode
as DiagMode
.
This commit is contained in:
parent
573267cf3c
commit
d0e9bab51b
2 changed files with 19 additions and 22 deletions
|
@ -188,7 +188,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
&candidates,
|
&candidates,
|
||||||
if instead { Instead::Yes } else { Instead::No },
|
if instead { Instead::Yes } else { Instead::No },
|
||||||
found_use,
|
found_use,
|
||||||
DiagnosticMode::Normal,
|
DiagMode::Normal,
|
||||||
path,
|
path,
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
|
@ -723,7 +723,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
&import_suggestions,
|
&import_suggestions,
|
||||||
Instead::No,
|
Instead::No,
|
||||||
FoundUse::Yes,
|
FoundUse::Yes,
|
||||||
DiagnosticMode::Pattern,
|
DiagMode::Pattern,
|
||||||
vec![],
|
vec![],
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
|
@ -1444,7 +1444,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
&import_suggestions,
|
&import_suggestions,
|
||||||
Instead::No,
|
Instead::No,
|
||||||
found_use,
|
found_use,
|
||||||
DiagnosticMode::Normal,
|
DiagMode::Normal,
|
||||||
vec![],
|
vec![],
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
|
@ -1775,7 +1775,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
&import_suggestions,
|
&import_suggestions,
|
||||||
Instead::Yes,
|
Instead::Yes,
|
||||||
FoundUse::Yes,
|
FoundUse::Yes,
|
||||||
DiagnosticMode::Import,
|
DiagMode::Import,
|
||||||
vec![],
|
vec![],
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
|
@ -2696,7 +2696,7 @@ enum FoundUse {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether a binding is part of a pattern or a use statement. Used for diagnostics.
|
/// Whether a binding is part of a pattern or a use statement. Used for diagnostics.
|
||||||
pub(crate) enum DiagnosticMode {
|
pub(crate) enum DiagMode {
|
||||||
Normal,
|
Normal,
|
||||||
/// The binding is part of a pattern
|
/// The binding is part of a pattern
|
||||||
Pattern,
|
Pattern,
|
||||||
|
@ -2710,7 +2710,7 @@ pub(crate) fn import_candidates(
|
||||||
// This is `None` if all placement locations are inside expansions
|
// This is `None` if all placement locations are inside expansions
|
||||||
use_placement_span: Option<Span>,
|
use_placement_span: Option<Span>,
|
||||||
candidates: &[ImportSuggestion],
|
candidates: &[ImportSuggestion],
|
||||||
mode: DiagnosticMode,
|
mode: DiagMode,
|
||||||
append: &str,
|
append: &str,
|
||||||
) {
|
) {
|
||||||
show_candidates(
|
show_candidates(
|
||||||
|
@ -2738,7 +2738,7 @@ fn show_candidates(
|
||||||
candidates: &[ImportSuggestion],
|
candidates: &[ImportSuggestion],
|
||||||
instead: Instead,
|
instead: Instead,
|
||||||
found_use: FoundUse,
|
found_use: FoundUse,
|
||||||
mode: DiagnosticMode,
|
mode: DiagMode,
|
||||||
path: Vec<Segment>,
|
path: Vec<Segment>,
|
||||||
append: &str,
|
append: &str,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
@ -2799,7 +2799,7 @@ fn show_candidates(
|
||||||
};
|
};
|
||||||
|
|
||||||
let instead = if let Instead::Yes = instead { " instead" } else { "" };
|
let instead = if let Instead::Yes = instead { " instead" } else { "" };
|
||||||
let mut msg = if let DiagnosticMode::Pattern = mode {
|
let mut msg = if let DiagMode::Pattern = mode {
|
||||||
format!(
|
format!(
|
||||||
"if you meant to match on {kind}{instead}{name}, use the full path in the pattern",
|
"if you meant to match on {kind}{instead}{name}, use the full path in the pattern",
|
||||||
)
|
)
|
||||||
|
@ -2813,7 +2813,7 @@ fn show_candidates(
|
||||||
|
|
||||||
if let Some(span) = use_placement_span {
|
if let Some(span) = use_placement_span {
|
||||||
let (add_use, trailing) = match mode {
|
let (add_use, trailing) = match mode {
|
||||||
DiagnosticMode::Pattern => {
|
DiagMode::Pattern => {
|
||||||
err.span_suggestions(
|
err.span_suggestions(
|
||||||
span,
|
span,
|
||||||
msg,
|
msg,
|
||||||
|
@ -2822,14 +2822,14 @@ fn show_candidates(
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
DiagnosticMode::Import => ("", ""),
|
DiagMode::Import => ("", ""),
|
||||||
DiagnosticMode::Normal => ("use ", ";\n"),
|
DiagMode::Normal => ("use ", ";\n"),
|
||||||
};
|
};
|
||||||
for candidate in &mut accessible_path_strings {
|
for candidate in &mut accessible_path_strings {
|
||||||
// produce an additional newline to separate the new use statement
|
// produce an additional newline to separate the new use statement
|
||||||
// from the directly following item.
|
// from the directly following item.
|
||||||
let additional_newline = if let FoundUse::No = found_use
|
let additional_newline = if let FoundUse::No = found_use
|
||||||
&& let DiagnosticMode::Normal = mode
|
&& let DiagMode::Normal = mode
|
||||||
{
|
{
|
||||||
"\n"
|
"\n"
|
||||||
} else {
|
} else {
|
||||||
|
@ -2870,16 +2870,13 @@ fn show_candidates(
|
||||||
err.help(msg);
|
err.help(msg);
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
} else if !(inaccessible_path_strings.is_empty() || matches!(mode, DiagnosticMode::Import)) {
|
} else if !(inaccessible_path_strings.is_empty() || matches!(mode, DiagMode::Import)) {
|
||||||
let prefix = if let DiagnosticMode::Pattern = mode {
|
let prefix =
|
||||||
"you might have meant to match on "
|
if let DiagMode::Pattern = mode { "you might have meant to match on " } else { "" };
|
||||||
} else {
|
|
||||||
""
|
|
||||||
};
|
|
||||||
if let [(name, descr, def_id, note, _)] = &inaccessible_path_strings[..] {
|
if let [(name, descr, def_id, note, _)] = &inaccessible_path_strings[..] {
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"{prefix}{descr} `{name}`{} exists but is inaccessible",
|
"{prefix}{descr} `{name}`{} exists but is inaccessible",
|
||||||
if let DiagnosticMode::Pattern = mode { ", which" } else { "" }
|
if let DiagMode::Pattern = mode { ", which" } else { "" }
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(local_def_id) = def_id.and_then(|did| did.as_local()) {
|
if let Some(local_def_id) = def_id.and_then(|did| did.as_local()) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! A bunch of methods and structures more or less related to resolving imports.
|
//! A bunch of methods and structures more or less related to resolving imports.
|
||||||
|
|
||||||
use crate::diagnostics::{import_candidates, DiagnosticMode, Suggestion};
|
use crate::diagnostics::{import_candidates, DiagMode, Suggestion};
|
||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
CannotBeReexportedCratePublic, CannotBeReexportedCratePublicNS, CannotBeReexportedPrivate,
|
CannotBeReexportedCratePublic, CannotBeReexportedCratePublicNS, CannotBeReexportedPrivate,
|
||||||
CannotBeReexportedPrivateNS, CannotDetermineImportResolution, CannotGlobImportAllCrates,
|
CannotBeReexportedPrivateNS, CannotDetermineImportResolution, CannotGlobImportAllCrates,
|
||||||
|
@ -716,7 +716,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
&mut diag,
|
&mut diag,
|
||||||
Some(err.span),
|
Some(err.span),
|
||||||
candidates,
|
candidates,
|
||||||
DiagnosticMode::Import,
|
DiagMode::Import,
|
||||||
(source != target)
|
(source != target)
|
||||||
.then(|| format!(" as {target}"))
|
.then(|| format!(" as {target}"))
|
||||||
.as_deref()
|
.as_deref()
|
||||||
|
@ -728,7 +728,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
&mut diag,
|
&mut diag,
|
||||||
None,
|
None,
|
||||||
candidates,
|
candidates,
|
||||||
DiagnosticMode::Normal,
|
DiagMode::Normal,
|
||||||
(source != target)
|
(source != target)
|
||||||
.then(|| format!(" as {target}"))
|
.then(|| format!(" as {target}"))
|
||||||
.as_deref()
|
.as_deref()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue