Skip to content

Commit 9191fb2

Browse files
committed
Added basic structure for explanations.
This is the first step in implementing rust-lang#36.
1 parent 77a8386 commit 9191fb2

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/bin/rust_semverver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ fn callback(state: &driver::CompileState, version: &str) {
6666
debug!("running semver analysis");
6767
let changes = run_analysis(tcx, old_def_id, new_def_id);
6868

69-
changes.output(tcx.sess, version);
69+
// TODO: arm the verbosity switch
70+
changes.output(tcx.sess, version, false);
7071
}
7172

7273
/// A wrapper to control compilation.

src/semcheck/changes.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ impl<'tcx> ChangeType<'tcx> {
314314
FnConstChanged { now_const: true } => NonBreaking,
315315
}
316316
}
317+
318+
/// Get a detailed explanation of a change, and why it is categorized as-is.
319+
fn explanation(&self) -> &'static str {
320+
// TODO: meaningful explanations
321+
"test"
322+
}
317323
}
318324

319325
impl<'a> fmt::Display for ChangeType<'a> {
@@ -485,7 +491,7 @@ impl<'tcx> Change<'tcx> {
485491
}
486492

487493
/// Report the change in a structured manner, using rustc's error reporting capabilities.
488-
fn report(&self, session: &Session) {
494+
fn report(&self, session: &Session, verbose: bool) {
489495
if self.max == Patch || !self.output {
490496
return;
491497
}
@@ -499,7 +505,12 @@ impl<'tcx> Change<'tcx> {
499505

500506
for change in &self.changes {
501507
let cat = change.0.to_category();
502-
let sub_msg = format!("{} ({})", change.0, cat);
508+
let sub_msg = if verbose {
509+
format!("{} ({}):\n{}", change.0, cat, change.0.explanation())
510+
} else {
511+
format!("{} ({})", change.0, cat)
512+
};
513+
503514
if let Some(span) = change.1 {
504515
if cat == Breaking {
505516
builder.span_warn(span, &sub_msg);
@@ -661,7 +672,7 @@ impl<'tcx> ChangeSet<'tcx> {
661672
}
662673

663674
/// Format the contents of a change set for user output.
664-
pub fn output(&self, session: &Session, version: &str) {
675+
pub fn output(&self, session: &Session, version: &str, verbose: bool) {
665676
if let Ok(mut new_version) = Version::parse(version) {
666677
match self.max {
667678
Patch => new_version.increment_patch(),
@@ -680,7 +691,7 @@ impl<'tcx> ChangeSet<'tcx> {
680691
}
681692

682693
if let Some(change) = self.changes.get(key) {
683-
change.report(session);
694+
change.report(session, verbose);
684695
}
685696
}
686697
}

0 commit comments

Comments
 (0)