Skip to content

Commit ca743ec

Browse files
committed
rustup: fix breakage in diagnostics API
Also adds a function to add the clippy wiki note, which is used a few times.
1 parent 397b940 commit ca743ec

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

src/methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ fn lint_cstring_as_ptr(cx: &LateContext, expr: &Expr, new: &Expr, unwrap: &Expr)
602602
span_lint_and_then(cx, TEMPORARY_CSTRING_AS_PTR, expr.span,
603603
"you are getting the inner pointer of a temporary `CString`",
604604
|db| {
605-
db.fileline_note(expr.span, "that pointer will be invalid outside this expression");
605+
db.note("that pointer will be invalid outside this expression");
606606
db.span_help(unwrap.span, "assign the `CString` to a variable to extend its lifetime");
607607
});
608608
}}

src/swap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn check_manual_swap(cx: &LateContext, block: &Block) {
9595
if !what.is_empty() {
9696
db.span_suggestion(span, "try",
9797
format!("std::mem::swap(&mut {}, &mut {})", lhs, rhs));
98-
db.fileline_note(span, "or maybe you should use `std::mem::replace`?");
98+
db.note("or maybe you should use `std::mem::replace`?");
9999
}
100100
});
101101
}}
@@ -130,7 +130,7 @@ fn check_suspicious_swap(cx: &LateContext, block: &Block) {
130130
if !what.is_empty() {
131131
db.span_suggestion(span, "try",
132132
format!("std::mem::swap(&mut {}, &mut {})", lhs, rhs));
133-
db.fileline_note(span, "or maybe you should use `std::mem::replace`?");
133+
db.note("or maybe you should use `std::mem::replace`?");
134134
}
135135
});
136136
}}

src/utils/mod.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -471,44 +471,44 @@ impl<'a> Deref for DiagnosticWrapper<'a> {
471471
}
472472
}
473473

474+
impl<'a> DiagnosticWrapper<'a> {
475+
fn wiki_link(&mut self, lint: &'static Lint) {
476+
self.help(&format!("for further information visit https://github.com/Manishearth/rust-clippy/wiki#{}",
477+
lint.name_lower()));
478+
}
479+
}
480+
474481
pub fn span_lint<'a, T: LintContext>(cx: &'a T, lint: &'static Lint, sp: Span, msg: &str) -> DiagnosticWrapper<'a> {
475-
let mut db = cx.struct_span_lint(lint, sp, msg);
482+
let mut db = DiagnosticWrapper(cx.struct_span_lint(lint, sp, msg));
476483
if cx.current_level(lint) != Level::Allow {
477-
db.fileline_help(sp,
478-
&format!("for further information visit https://github.com/Manishearth/rust-clippy/wiki#{}",
479-
lint.name_lower()));
484+
db.wiki_link(lint);
480485
}
481-
DiagnosticWrapper(db)
486+
db
482487
}
483488

484489
pub fn span_help_and_lint<'a, T: LintContext>(cx: &'a T, lint: &'static Lint, span: Span, msg: &str, help: &str)
485490
-> DiagnosticWrapper<'a> {
486-
let mut db = cx.struct_span_lint(lint, span, msg);
491+
let mut db = DiagnosticWrapper(cx.struct_span_lint(lint, span, msg));
487492
if cx.current_level(lint) != Level::Allow {
488-
db.fileline_help(span,
489-
&format!("{}\nfor further information visit \
490-
https://github.com/Manishearth/rust-clippy/wiki#{}",
491-
help,
492-
lint.name_lower()));
493+
db.help(help);
494+
db.wiki_link(lint);
493495
}
494-
DiagnosticWrapper(db)
496+
db
495497
}
496498

497499
pub fn span_note_and_lint<'a, T: LintContext>(cx: &'a T, lint: &'static Lint, span: Span, msg: &str, note_span: Span,
498500
note: &str)
499501
-> DiagnosticWrapper<'a> {
500-
let mut db = cx.struct_span_lint(lint, span, msg);
502+
let mut db = DiagnosticWrapper(cx.struct_span_lint(lint, span, msg));
501503
if cx.current_level(lint) != Level::Allow {
502504
if note_span == span {
503-
db.fileline_note(note_span, note);
505+
db.note(note);
504506
} else {
505507
db.span_note(note_span, note);
506508
}
507-
db.fileline_help(span,
508-
&format!("for further information visit https://github.com/Manishearth/rust-clippy/wiki#{}",
509-
lint.name_lower()));
509+
db.wiki_link(lint);
510510
}
511-
DiagnosticWrapper(db)
511+
db
512512
}
513513

514514
pub fn span_lint_and_then<'a, T: LintContext, F>(cx: &'a T, lint: &'static Lint, sp: Span, msg: &str, f: F)
@@ -518,9 +518,7 @@ pub fn span_lint_and_then<'a, T: LintContext, F>(cx: &'a T, lint: &'static Lint,
518518
let mut db = DiagnosticWrapper(cx.struct_span_lint(lint, sp, msg));
519519
if cx.current_level(lint) != Level::Allow {
520520
f(&mut db);
521-
db.fileline_help(sp,
522-
&format!("for further information visit https://github.com/Manishearth/rust-clippy/wiki#{}",
523-
lint.name_lower()));
521+
db.wiki_link(lint);
524522
}
525523
db
526524
}

0 commit comments

Comments
 (0)