Skip to content

Commit baa7b32

Browse files
committed
Mark lints with applicability
1 parent 9d34e8d commit baa7b32

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/librustc/lint/builtin.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! compiler code, rather than using their own custom pass. Those
1515
//! lints are all available in `rustc_lint::builtin`.
1616
17-
use errors::DiagnosticBuilder;
17+
use errors::{Applicability, DiagnosticBuilder};
1818
use lint::{LintPass, LateLintPass, LintArray};
1919
use session::Session;
2020
use syntax::codemap::Span;
@@ -341,15 +341,16 @@ impl BuiltinLintDiagnostics {
341341
match self {
342342
BuiltinLintDiagnostics::Normal => (),
343343
BuiltinLintDiagnostics::BareTraitObject(span, is_global) => {
344-
let sugg = match sess.codemap().span_to_snippet(span) {
345-
Ok(ref s) if is_global => format!("dyn ({})", s),
346-
Ok(s) => format!("dyn {}", s),
347-
Err(_) => format!("dyn <type>")
344+
let (sugg, app) = match sess.codemap().span_to_snippet(span) {
345+
Ok(ref s) if is_global => (format!("dyn ({})", s),
346+
Applicability::MachineApplicable),
347+
Ok(s) => (format!("dyn {}", s), Applicability::MachineApplicable),
348+
Err(_) => (format!("dyn <type>"), Applicability::HasPlaceholders)
348349
};
349-
db.span_suggestion(span, "use `dyn`", sugg);
350+
db.span_suggestion_with_applicability(span, "use `dyn`", sugg, app);
350351
}
351352
BuiltinLintDiagnostics::AbsPathWithModule(span) => {
352-
let sugg = match sess.codemap().span_to_snippet(span) {
353+
let (sugg, app) = match sess.codemap().span_to_snippet(span) {
353354
Ok(ref s) => {
354355
// FIXME(Manishearth) ideally the emitting code
355356
// can tell us whether or not this is global
@@ -359,11 +360,11 @@ impl BuiltinLintDiagnostics {
359360
"::"
360361
};
361362

362-
format!("crate{}{}", opt_colon, s)
363+
(format!("crate{}{}", opt_colon, s), Applicability::MachineApplicable)
363364
}
364-
Err(_) => format!("crate::<path>")
365+
Err(_) => (format!("crate::<path>"), Applicability::HasPlaceholders)
365366
};
366-
db.span_suggestion(span, "use `crate`", sugg);
367+
db.span_suggestion_with_applicability(span, "use `crate`", sugg, app);
367368
}
368369
}
369370
}

src/librustc_lint/builtin.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use syntax::attr;
4646
use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_attributes};
4747
use syntax_pos::{BytePos, Span, SyntaxContext};
4848
use syntax::symbol::keywords;
49-
use syntax::errors::DiagnosticBuilder;
49+
use syntax::errors::{Applicability, DiagnosticBuilder};
5050

5151
use rustc::hir::{self, PatKind};
5252
use rustc::hir::intravisit::FnKind;
@@ -1300,7 +1300,19 @@ impl UnreachablePub {
13001300
} else {
13011301
"pub(crate)"
13021302
}.to_owned();
1303-
err.span_suggestion(pub_span, "consider restricting its visibility", replacement);
1303+
let app = if span.ctxt().outer().expn_info().is_none() {
1304+
// even if macros aren't involved the suggestion
1305+
// may be incorrect -- the user may have mistakenly
1306+
// hidden it behind a private module and this lint is
1307+
// a helpful way to catch that. However, we're trying
1308+
// not to change the nature of the code with this lint
1309+
// so it's marked as machine applicable.
1310+
Applicability::MachineApplicable
1311+
} else {
1312+
Applicability::MaybeIncorrect
1313+
};
1314+
err.span_suggestion_with_applicability(pub_span, "consider restricting its visibility",
1315+
replacement, app);
13041316
if exportable {
13051317
err.help("or consider exporting it for use by other crates");
13061318
}

0 commit comments

Comments
 (0)