adapt formatting to use new fcw info structure
This commit is contained in:
parent
0eed5ab550
commit
1eabe65151
5 changed files with 28 additions and 24 deletions
|
|
@ -1043,7 +1043,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
lint.note("for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/disjoint-capture-in-closures.html>");
|
||||
|
||||
let diagnostic_msg = format!(
|
||||
"add a dummy let to cause {migrated_variables_concat} to be fully captured"
|
||||
|
|
|
|||
|
|
@ -3400,7 +3400,6 @@ declare_lint! {
|
|||
"detects closures affected by Rust 2021 changes",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: fcw!(EditionSemanticsChange 2021 "disjoint-capture-in-closures"),
|
||||
explain_reason: false,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -516,31 +516,29 @@ impl FutureIncompatibilityReason {
|
|||
}
|
||||
}
|
||||
|
||||
fn fmt_reason(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
pub fn reference(&self) -> String {
|
||||
match self {
|
||||
Self::FutureReleaseSemanticsChange(release_fcw)
|
||||
| Self::FutureReleaseError(release_fcw)
|
||||
| Self::Custom(_, release_fcw) => release_fcw.fmt_reason(f),
|
||||
| Self::Custom(_, release_fcw) => release_fcw.to_string(),
|
||||
Self::EditionError(edition_fcw)
|
||||
| Self::EditionSemanticsChange(edition_fcw)
|
||||
| Self::EditionAndFutureReleaseError(edition_fcw)
|
||||
| Self::EditionAndFutureReleaseSemanticsChange(edition_fcw) => {
|
||||
edition_fcw.fmt_reason(f)
|
||||
}
|
||||
| Self::EditionAndFutureReleaseSemanticsChange(edition_fcw) => edition_fcw.to_string(),
|
||||
Self::Unreachable => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ReleaseFcw {
|
||||
fn fmt_reason(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
impl Display for ReleaseFcw {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let issue_number = self.issue_number;
|
||||
write!(f, "issue #{issue_number} <https://github.com/rust-lang/rust/issues/{issue_number}>")
|
||||
}
|
||||
}
|
||||
|
||||
impl EditionFcw {
|
||||
fn fmt_reason(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
impl Display for EditionFcw {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"<https://doc.rust-lang.org/edition-guide/{}/{}.html>",
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use rustc_data_structures::fx::FxIndexMap;
|
|||
use rustc_data_structures::sorted_map::SortedMap;
|
||||
use rustc_errors::{Diag, MultiSpan};
|
||||
use rustc_hir::{HirId, ItemLocalId};
|
||||
use rustc_lint_defs::EditionFcw;
|
||||
use rustc_macros::{Decodable, Encodable, HashStable};
|
||||
use rustc_session::Session;
|
||||
use rustc_session::lint::builtin::{self, FORBIDDEN_LINT_GROUPS};
|
||||
|
|
@ -395,45 +396,52 @@ pub fn lint_level(
|
|||
|
||||
if let Some(future_incompatible) = future_incompatible {
|
||||
let explanation = match future_incompatible.reason {
|
||||
FutureIncompatibilityReason::FutureReleaseError => {
|
||||
FutureIncompatibilityReason::FutureReleaseError(_) => {
|
||||
"this was previously accepted by the compiler but is being phased out; \
|
||||
it will become a hard error in a future release!"
|
||||
.to_owned()
|
||||
}
|
||||
FutureIncompatibilityReason::FutureReleaseSemanticsChange => {
|
||||
FutureIncompatibilityReason::FutureReleaseSemanticsChange(_) => {
|
||||
"this will change its meaning in a future release!".to_owned()
|
||||
}
|
||||
FutureIncompatibilityReason::EditionError(edition) => {
|
||||
FutureIncompatibilityReason::EditionError(EditionFcw { edition, .. }) => {
|
||||
let current_edition = sess.edition();
|
||||
format!(
|
||||
"this is accepted in the current edition (Rust {current_edition}) but is a hard error in Rust {edition}!"
|
||||
)
|
||||
}
|
||||
FutureIncompatibilityReason::EditionSemanticsChange(edition) => {
|
||||
FutureIncompatibilityReason::EditionSemanticsChange(EditionFcw {
|
||||
edition, ..
|
||||
}) => {
|
||||
format!("this changes meaning in Rust {edition}")
|
||||
}
|
||||
FutureIncompatibilityReason::EditionAndFutureReleaseError(edition) => {
|
||||
FutureIncompatibilityReason::EditionAndFutureReleaseError(EditionFcw {
|
||||
edition,
|
||||
..
|
||||
}) => {
|
||||
format!(
|
||||
"this was previously accepted by the compiler but is being phased out; \
|
||||
it will become a hard error in Rust {edition} and in a future release in all editions!"
|
||||
)
|
||||
}
|
||||
FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(edition) => {
|
||||
FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(
|
||||
EditionFcw { edition, .. },
|
||||
) => {
|
||||
format!(
|
||||
"this changes meaning in Rust {edition} and in a future release in all editions!"
|
||||
)
|
||||
}
|
||||
FutureIncompatibilityReason::Custom(reason) => reason.to_owned(),
|
||||
FutureIncompatibilityReason::Custom(reason, _) => reason.to_owned(),
|
||||
FutureIncompatibilityReason::Unreachable => unreachable!(),
|
||||
};
|
||||
|
||||
if future_incompatible.explain_reason {
|
||||
err.warn(explanation);
|
||||
}
|
||||
if !future_incompatible.reference.is_empty() {
|
||||
let citation =
|
||||
format!("for more information, see {}", future_incompatible.reference);
|
||||
err.note(citation);
|
||||
}
|
||||
|
||||
let citation =
|
||||
format!("for more information, see {}", future_incompatible.reason.reference());
|
||||
err.note(citation);
|
||||
}
|
||||
|
||||
// Finally, run `decorate`. `decorate` can call `trimmed_path_str` (directly or indirectly),
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ pub fn feature_warn_issue(
|
|||
let future_incompatible = lint.future_incompatible.as_ref().unwrap();
|
||||
err.is_lint(lint.name_lower(), /* has_future_breakage */ false);
|
||||
err.warn(lint.desc);
|
||||
err.note(format!("for more information, see {}", future_incompatible.reference));
|
||||
err.note(format!("for more information, see {}", future_incompatible.reason.reference()));
|
||||
|
||||
// A later feature_err call can steal and cancel this warning.
|
||||
err.stash(span, StashKey::EarlySyntaxWarning);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue