Skip to content

Commit 02843d9

Browse files
committed
properly deprecate suggestion methods
1 parent 9201924 commit 02843d9

File tree

5 files changed

+86
-40
lines changed

5 files changed

+86
-40
lines changed

src/librustc_errors/diagnostic_builder.rs

+56-34
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ pub struct DiagnosticBuilder<'a> {
3333
/// it easy to declare such methods on the builder.
3434
macro_rules! forward {
3535
// Forward pattern for &self -> &Self
36-
(pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self) => {
36+
(
37+
$(#[$attrs:meta])*
38+
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self
39+
) => {
40+
$(#[$attrs])*
3741
pub fn $n(&self, $($name: $ty),*) -> &Self {
3842
#[allow(deprecated)]
3943
self.diagnostic.$n($($name),*);
@@ -42,7 +46,11 @@ macro_rules! forward {
4246
};
4347

4448
// Forward pattern for &mut self -> &mut Self
45-
(pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)*) -> &mut Self) => {
49+
(
50+
$(#[$attrs:meta])*
51+
pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)*) -> &mut Self
52+
) => {
53+
$(#[$attrs])*
4654
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
4755
#[allow(deprecated)]
4856
self.diagnostic.$n($($name),*);
@@ -52,10 +60,15 @@ macro_rules! forward {
5260

5361
// Forward pattern for &mut self -> &mut Self, with S: Into<MultiSpan>
5462
// type parameter. No obvious way to make this more generic.
55-
(pub fn $n:ident<S: Into<MultiSpan>>(
56-
&mut self,
57-
$($name:ident: $ty:ty),*
58-
$(,)*) -> &mut Self) => {
63+
(
64+
$(#[$attrs:meta])*
65+
pub fn $n:ident<S: Into<MultiSpan>>(
66+
&mut self,
67+
$($name:ident: $ty:ty),*
68+
$(,)*
69+
) -> &mut Self
70+
) => {
71+
$(#[$attrs])*
5972
pub fn $n<S: Into<MultiSpan>>(&mut self, $($name: $ty),*) -> &mut Self {
6073
#[allow(deprecated)]
6174
self.diagnostic.$n($($name),*);
@@ -177,34 +190,43 @@ impl<'a> DiagnosticBuilder<'a> {
177190
msg: &str,
178191
) -> &mut Self);
179192

180-
#[deprecated(note = "Use `span_suggestion_short_with_applicability`")]
181-
forward!(pub fn span_suggestion_short(
182-
&mut self,
183-
sp: Span,
184-
msg: &str,
185-
suggestion: String,
186-
) -> &mut Self);
187-
188-
#[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
189-
forward!(pub fn multipart_suggestion(
190-
&mut self,
191-
msg: &str,
192-
suggestion: Vec<(Span, String)>,
193-
) -> &mut Self);
194-
195-
#[deprecated(note = "Use `span_suggestion_with_applicability`")]
196-
forward!(pub fn span_suggestion(&mut self,
197-
sp: Span,
198-
msg: &str,
199-
suggestion: String,
200-
) -> &mut Self);
201-
202-
#[deprecated(note = "Use `span_suggestions_with_applicability`")]
203-
forward!(pub fn span_suggestions(&mut self,
204-
sp: Span,
205-
msg: &str,
206-
suggestions: Vec<String>,
207-
) -> &mut Self);
193+
forward!(
194+
#[deprecated(note = "Use `span_suggestion_short_with_applicability`")]
195+
pub fn span_suggestion_short(
196+
&mut self,
197+
sp: Span,
198+
msg: &str,
199+
suggestion: String,
200+
) -> &mut Self
201+
);
202+
203+
forward!(
204+
#[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
205+
pub fn multipart_suggestion(
206+
&mut self,
207+
msg: &str,
208+
suggestion: Vec<(Span, String)>,
209+
) -> &mut Self
210+
);
211+
212+
forward!(
213+
#[deprecated(note = "Use `span_suggestion_with_applicability`")]
214+
pub fn span_suggestion(
215+
&mut self,
216+
sp: Span,
217+
msg: &str,
218+
suggestion: String,
219+
) -> &mut Self
220+
);
221+
222+
forward!(
223+
#[deprecated(note = "Use `span_suggestions_with_applicability`")]
224+
pub fn span_suggestions(&mut self,
225+
sp: Span,
226+
msg: &str,
227+
suggestions: Vec<String>,
228+
) -> &mut Self
229+
);
208230

209231
pub fn multipart_suggestion_with_applicability(&mut self,
210232
msg: &str,

src/librustc_resolve/build_reduced_graph.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use std::cell::Cell;
2121
use std::ptr;
2222
use rustc_data_structures::sync::Lrc;
2323

24+
use errors::Applicability;
25+
2426
use syntax::ast::{Name, Ident};
2527
use syntax::attr;
2628

@@ -345,7 +347,12 @@ impl<'a> Resolver<'a> {
345347
let module = if orig_name.is_none() && ident.name == keywords::SelfLower.name() {
346348
self.session
347349
.struct_span_err(item.span, "`extern crate self;` requires renaming")
348-
.span_suggestion(item.span, "try", "extern crate self as name;".into())
350+
.span_suggestion_with_applicability(
351+
item.span,
352+
"try",
353+
"extern crate self as name;".into(),
354+
Applicability::HasPlaceholders,
355+
)
349356
.emit();
350357
return;
351358
} else if orig_name == Some(keywords::SelfLower.name()) {

src/librustc_resolve/lib.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -4823,8 +4823,13 @@ impl<'a> Resolver<'a> {
48234823
} else if ident.span.rust_2018() {
48244824
let msg = "relative paths are not supported in visibilities on 2018 edition";
48254825
self.session.struct_span_err(ident.span, msg)
4826-
.span_suggestion(path.span, "try", format!("crate::{}", path))
4827-
.emit();
4826+
.span_suggestion_with_applicability(
4827+
path.span,
4828+
"try",
4829+
format!("crate::{}", path),
4830+
Applicability::MaybeIncorrect,
4831+
)
4832+
.emit();
48284833
return ty::Visibility::Public;
48294834
} else {
48304835
let ctxt = ident.span.ctxt();

src/librustc_typeck/check/_match.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use check::{FnCtxt, Expectation, Diverges, Needs};
22
use check::coercion::CoerceMany;
3+
use errors::Applicability;
34
use rustc::hir::{self, PatKind};
45
use rustc::hir::def::{Def, CtorKind};
56
use rustc::hir::pat_util::EnumerateAndAdjustIterator;
@@ -989,7 +990,13 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
989990
let suggested_name =
990991
find_best_match_for_name(input, &ident.as_str(), None);
991992
if let Some(suggested_name) = suggested_name {
992-
err.span_suggestion(*span, "did you mean", suggested_name.to_string());
993+
err.span_suggestion_with_applicability(
994+
*span,
995+
"did you mean",
996+
suggested_name.to_string(),
997+
Applicability::MaybeIncorrect,
998+
);
999+
9931000
// we don't want to throw `E0027` in case we have thrown `E0026` for them
9941001
unmentioned_fields.retain(|&x| x.as_str() != suggested_name.as_str());
9951002
}

src/libsyntax/parse/parser.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -4063,12 +4063,13 @@ impl<'a> Parser<'a> {
40634063

40644064
if let Some(mut err) = delayed_err {
40654065
if let Some(etc_span) = etc_span {
4066-
err.multipart_suggestion(
4066+
err.multipart_suggestion_with_applicability(
40674067
"move the `..` to the end of the field list",
40684068
vec![
40694069
(etc_span, String::new()),
40704070
(self.span, format!("{}.. }}", if ate_comma { "" } else { ", " })),
40714071
],
4072+
Applicability::MachineApplicable,
40724073
);
40734074
}
40744075
err.emit();
@@ -6913,7 +6914,11 @@ impl<'a> Parser<'a> {
69136914

69146915
let mut err = self.struct_span_err(fixed_name_sp, error_msg);
69156916
err.span_label(fixed_name_sp, "dash-separated idents are not valid");
6916-
err.multipart_suggestion(suggestion_msg, replacement);
6917+
err.multipart_suggestion_with_applicability(
6918+
suggestion_msg,
6919+
replacement,
6920+
Applicability::MachineApplicable,
6921+
);
69176922
err.emit();
69186923
}
69196924
Ok(ident)

0 commit comments

Comments
 (0)