Skip to content

Commit

Permalink
Implement lint deprecation/removal…
Browse files Browse the repository at this point in the history
and deprecate/remove unsigned_negation lint.

This is useful to avoid causing breaking changes in case #![deny(unknown_lints)]
is used and lint is removed.
  • Loading branch information
nagisa committed Jul 15, 2015
1 parent 0c9e3dc commit 2250215
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ enum TargetLint {

/// Temporary renaming, used for easing migration pain; see #16545
Renamed(String, LintId),

/// Lint with this name existed previously, but has been removed/deprecated.
/// The string argument is the reason for removal.
Removed(String),
}

enum FindLintError {
NotFound,
Removed
}

impl LintStore {
Expand Down Expand Up @@ -166,30 +175,42 @@ impl LintStore {
self.by_name.insert(old_name.to_string(), Renamed(new_name.to_string(), target));
}

pub fn register_removed(&mut self, name: &str, reason: &str) {
self.by_name.insert(name.into(), Removed(reason.into()));
}

#[allow(unused_variables)]
fn find_lint(&self, lint_name: &str, sess: &Session, span: Option<Span>)
-> Option<LintId>
-> Result<LintId, FindLintError>
{
match self.by_name.get(lint_name) {
Some(&Id(lint_id)) => Some(lint_id),
Some(&Id(lint_id)) => Ok(lint_id),
Some(&Renamed(ref new_name, lint_id)) => {
let warning = format!("lint {} has been renamed to {}",
lint_name, new_name);
match span {
Some(span) => sess.span_warn(span, &warning[..]),
None => sess.warn(&warning[..]),
};
Some(lint_id)
}
None => None
Ok(lint_id)
},
Some(&Removed(ref reason)) => {
let warning = format!("lint {} has been removed: {}", lint_name, reason);
match span {
Some(span) => sess.span_warn(span, &warning[..]),
None => sess.warn(&warning[..])
}
Err(FindLintError::Removed)
},
None => Err(FindLintError::NotFound)
}
}

pub fn process_command_line(&mut self, sess: &Session) {
for &(ref lint_name, level) in &sess.opts.lint_opts {
match self.find_lint(&lint_name[..], sess, None) {
Some(lint_id) => self.set_level(lint_id, (level, CommandLine)),
None => {
Ok(lint_id) => self.set_level(lint_id, (level, CommandLine)),
Err(_) => {
match self.lint_groups.iter().map(|(&x, pair)| (x, pair.0.clone()))
.collect::<FnvHashMap<&'static str,
Vec<LintId>>>()
Expand Down Expand Up @@ -398,8 +419,8 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
}
Ok((lint_name, level, span)) => {
match self.lints.find_lint(&lint_name, &self.tcx.sess, Some(span)) {
Some(lint_id) => vec![(lint_id, level, span)],
None => {
Ok(lint_id) => vec![(lint_id, level, span)],
Err(FindLintError::NotFound) => {
match self.lints.lint_groups.get(&lint_name[..]) {
Some(&(ref v, _)) => v.iter()
.map(|lint_id: &LintId|
Expand All @@ -412,7 +433,8 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
continue;
}
}
}
},
Err(FindLintError::Removed) => { continue; }
}
}
};
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
store.register_renamed("raw_pointer_deriving", "raw_pointer_derive");

store.register_renamed("unknown_features", "unused_features");

store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
}

0 comments on commit 2250215

Please sign in to comment.