Skip to content

Commit 1eabe65

Browse files
committed
adapt formatting to use new fcw info structure
1 parent 0eed5ab commit 1eabe65

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10431043
}
10441044
}
10451045
}
1046-
lint.note("for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/disjoint-capture-in-closures.html>");
10471046

10481047
let diagnostic_msg = format!(
10491048
"add a dummy let to cause {migrated_variables_concat} to be fully captured"

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3400,7 +3400,6 @@ declare_lint! {
34003400
"detects closures affected by Rust 2021 changes",
34013401
@future_incompatible = FutureIncompatibleInfo {
34023402
reason: fcw!(EditionSemanticsChange 2021 "disjoint-capture-in-closures"),
3403-
explain_reason: false,
34043403
};
34053404
}
34063405

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -516,31 +516,29 @@ impl FutureIncompatibilityReason {
516516
}
517517
}
518518

519-
fn fmt_reason(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
519+
pub fn reference(&self) -> String {
520520
match self {
521521
Self::FutureReleaseSemanticsChange(release_fcw)
522522
| Self::FutureReleaseError(release_fcw)
523-
| Self::Custom(_, release_fcw) => release_fcw.fmt_reason(f),
523+
| Self::Custom(_, release_fcw) => release_fcw.to_string(),
524524
Self::EditionError(edition_fcw)
525525
| Self::EditionSemanticsChange(edition_fcw)
526526
| Self::EditionAndFutureReleaseError(edition_fcw)
527-
| Self::EditionAndFutureReleaseSemanticsChange(edition_fcw) => {
528-
edition_fcw.fmt_reason(f)
529-
}
527+
| Self::EditionAndFutureReleaseSemanticsChange(edition_fcw) => edition_fcw.to_string(),
530528
Self::Unreachable => unreachable!(),
531529
}
532530
}
533531
}
534532

535-
impl ReleaseFcw {
536-
fn fmt_reason(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
533+
impl Display for ReleaseFcw {
534+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
537535
let issue_number = self.issue_number;
538536
write!(f, "issue #{issue_number} <https://github.com/rust-lang/rust/issues/{issue_number}>")
539537
}
540538
}
541539

542-
impl EditionFcw {
543-
fn fmt_reason(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
540+
impl Display for EditionFcw {
541+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
544542
write!(
545543
f,
546544
"<https://doc.rust-lang.org/edition-guide/{}/{}.html>",

compiler/rustc_middle/src/lint.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_data_structures::fx::FxIndexMap;
44
use rustc_data_structures::sorted_map::SortedMap;
55
use rustc_errors::{Diag, MultiSpan};
66
use rustc_hir::{HirId, ItemLocalId};
7+
use rustc_lint_defs::EditionFcw;
78
use rustc_macros::{Decodable, Encodable, HashStable};
89
use rustc_session::Session;
910
use rustc_session::lint::builtin::{self, FORBIDDEN_LINT_GROUPS};
@@ -395,45 +396,52 @@ pub fn lint_level(
395396

396397
if let Some(future_incompatible) = future_incompatible {
397398
let explanation = match future_incompatible.reason {
398-
FutureIncompatibilityReason::FutureReleaseError => {
399+
FutureIncompatibilityReason::FutureReleaseError(_) => {
399400
"this was previously accepted by the compiler but is being phased out; \
400401
it will become a hard error in a future release!"
401402
.to_owned()
402403
}
403-
FutureIncompatibilityReason::FutureReleaseSemanticsChange => {
404+
FutureIncompatibilityReason::FutureReleaseSemanticsChange(_) => {
404405
"this will change its meaning in a future release!".to_owned()
405406
}
406-
FutureIncompatibilityReason::EditionError(edition) => {
407+
FutureIncompatibilityReason::EditionError(EditionFcw { edition, .. }) => {
407408
let current_edition = sess.edition();
408409
format!(
409410
"this is accepted in the current edition (Rust {current_edition}) but is a hard error in Rust {edition}!"
410411
)
411412
}
412-
FutureIncompatibilityReason::EditionSemanticsChange(edition) => {
413+
FutureIncompatibilityReason::EditionSemanticsChange(EditionFcw {
414+
edition, ..
415+
}) => {
413416
format!("this changes meaning in Rust {edition}")
414417
}
415-
FutureIncompatibilityReason::EditionAndFutureReleaseError(edition) => {
418+
FutureIncompatibilityReason::EditionAndFutureReleaseError(EditionFcw {
419+
edition,
420+
..
421+
}) => {
416422
format!(
417423
"this was previously accepted by the compiler but is being phased out; \
418424
it will become a hard error in Rust {edition} and in a future release in all editions!"
419425
)
420426
}
421-
FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(edition) => {
427+
FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(
428+
EditionFcw { edition, .. },
429+
) => {
422430
format!(
423431
"this changes meaning in Rust {edition} and in a future release in all editions!"
424432
)
425433
}
426-
FutureIncompatibilityReason::Custom(reason) => reason.to_owned(),
434+
FutureIncompatibilityReason::Custom(reason, _) => reason.to_owned(),
435+
FutureIncompatibilityReason::Unreachable => unreachable!(),
427436
};
428437

429438
if future_incompatible.explain_reason {
430439
err.warn(explanation);
431440
}
432-
if !future_incompatible.reference.is_empty() {
433-
let citation =
434-
format!("for more information, see {}", future_incompatible.reference);
435-
err.note(citation);
436-
}
441+
442+
let citation =
443+
format!("for more information, see {}", future_incompatible.reason.reference());
444+
err.note(citation);
437445
}
438446

439447
// Finally, run `decorate`. `decorate` can call `trimmed_path_str` (directly or indirectly),

compiler/rustc_session/src/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub fn feature_warn_issue(
150150
let future_incompatible = lint.future_incompatible.as_ref().unwrap();
151151
err.is_lint(lint.name_lower(), /* has_future_breakage */ false);
152152
err.warn(lint.desc);
153-
err.note(format!("for more information, see {}", future_incompatible.reference));
153+
err.note(format!("for more information, see {}", future_incompatible.reason.reference()));
154154

155155
// A later feature_err call can steal and cancel this warning.
156156
err.stash(span, StashKey::EarlySyntaxWarning);

0 commit comments

Comments
 (0)