Skip to content

Commit

Permalink
Added basic structure for explanations.
Browse files Browse the repository at this point in the history
This is the first step in implementing rust-lang#36.
  • Loading branch information
ibabushkin committed Feb 7, 2018
1 parent 77a8386 commit 9191fb2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/bin/rust_semverver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ fn callback(state: &driver::CompileState, version: &str) {
debug!("running semver analysis");
let changes = run_analysis(tcx, old_def_id, new_def_id);

changes.output(tcx.sess, version);
// TODO: arm the verbosity switch
changes.output(tcx.sess, version, false);
}

/// A wrapper to control compilation.
Expand Down
19 changes: 15 additions & 4 deletions src/semcheck/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ impl<'tcx> ChangeType<'tcx> {
FnConstChanged { now_const: true } => NonBreaking,
}
}

/// Get a detailed explanation of a change, and why it is categorized as-is.
fn explanation(&self) -> &'static str {
// TODO: meaningful explanations
"test"
}
}

impl<'a> fmt::Display for ChangeType<'a> {
Expand Down Expand Up @@ -485,7 +491,7 @@ impl<'tcx> Change<'tcx> {
}

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

for change in &self.changes {
let cat = change.0.to_category();
let sub_msg = format!("{} ({})", change.0, cat);
let sub_msg = if verbose {
format!("{} ({}):\n{}", change.0, cat, change.0.explanation())
} else {
format!("{} ({})", change.0, cat)
};

if let Some(span) = change.1 {
if cat == Breaking {
builder.span_warn(span, &sub_msg);
Expand Down Expand Up @@ -661,7 +672,7 @@ impl<'tcx> ChangeSet<'tcx> {
}

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

if let Some(change) = self.changes.get(key) {
change.report(session);
change.report(session, verbose);
}
}
}
Expand Down

0 comments on commit 9191fb2

Please sign in to comment.