Skip to content

Commit

Permalink
Rollup merge of rust-lang#57699 - euclio:applicability-ify, r=petroch…
Browse files Browse the repository at this point in the history
…enkov

add applicability to remaining suggestions

Fixes rust-lang#50723.

I noticed that the suggestion methods on `DiagnosticBuilder` weren't actually deprecated due to rust-lang#57679. This PR deprecates them properly and fixes the remaining usages.

There's also a PR for clippy at rust-lang/rust-clippy#3667.
  • Loading branch information
Centril authored Jan 19, 2019
2 parents c8c03af + 02843d9 commit e78bde4
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 40 deletions.
90 changes: 56 additions & 34 deletions src/librustc_errors/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ pub struct DiagnosticBuilder<'a> {
/// it easy to declare such methods on the builder.
macro_rules! forward {
// Forward pattern for &self -> &Self
(pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self) => {
(
$(#[$attrs:meta])*
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self
) => {
$(#[$attrs])*
pub fn $n(&self, $($name: $ty),*) -> &Self {
#[allow(deprecated)]
self.diagnostic.$n($($name),*);
Expand All @@ -42,7 +46,11 @@ macro_rules! forward {
};

// Forward pattern for &mut self -> &mut Self
(pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)*) -> &mut Self) => {
(
$(#[$attrs:meta])*
pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)*) -> &mut Self
) => {
$(#[$attrs])*
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
#[allow(deprecated)]
self.diagnostic.$n($($name),*);
Expand All @@ -52,10 +60,15 @@ macro_rules! forward {

// Forward pattern for &mut self -> &mut Self, with S: Into<MultiSpan>
// type parameter. No obvious way to make this more generic.
(pub fn $n:ident<S: Into<MultiSpan>>(
&mut self,
$($name:ident: $ty:ty),*
$(,)*) -> &mut Self) => {
(
$(#[$attrs:meta])*
pub fn $n:ident<S: Into<MultiSpan>>(
&mut self,
$($name:ident: $ty:ty),*
$(,)*
) -> &mut Self
) => {
$(#[$attrs])*
pub fn $n<S: Into<MultiSpan>>(&mut self, $($name: $ty),*) -> &mut Self {
#[allow(deprecated)]
self.diagnostic.$n($($name),*);
Expand Down Expand Up @@ -177,34 +190,43 @@ impl<'a> DiagnosticBuilder<'a> {
msg: &str,
) -> &mut Self);

#[deprecated(note = "Use `span_suggestion_short_with_applicability`")]
forward!(pub fn span_suggestion_short(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
) -> &mut Self);

#[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
forward!(pub fn multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
) -> &mut Self);

#[deprecated(note = "Use `span_suggestion_with_applicability`")]
forward!(pub fn span_suggestion(&mut self,
sp: Span,
msg: &str,
suggestion: String,
) -> &mut Self);

#[deprecated(note = "Use `span_suggestions_with_applicability`")]
forward!(pub fn span_suggestions(&mut self,
sp: Span,
msg: &str,
suggestions: Vec<String>,
) -> &mut Self);
forward!(
#[deprecated(note = "Use `span_suggestion_short_with_applicability`")]
pub fn span_suggestion_short(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
) -> &mut Self
);

forward!(
#[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
pub fn multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
) -> &mut Self
);

forward!(
#[deprecated(note = "Use `span_suggestion_with_applicability`")]
pub fn span_suggestion(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
) -> &mut Self
);

forward!(
#[deprecated(note = "Use `span_suggestions_with_applicability`")]
pub fn span_suggestions(&mut self,
sp: Span,
msg: &str,
suggestions: Vec<String>,
) -> &mut Self
);

pub fn multipart_suggestion_with_applicability(&mut self,
msg: &str,
Expand Down
9 changes: 8 additions & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use std::cell::Cell;
use std::ptr;
use rustc_data_structures::sync::Lrc;

use errors::Applicability;

use syntax::ast::{Name, Ident};
use syntax::attr;

Expand Down Expand Up @@ -345,7 +347,12 @@ impl<'a> Resolver<'a> {
let module = if orig_name.is_none() && ident.name == keywords::SelfLower.name() {
self.session
.struct_span_err(item.span, "`extern crate self;` requires renaming")
.span_suggestion(item.span, "try", "extern crate self as name;".into())
.span_suggestion_with_applicability(
item.span,
"try",
"extern crate self as name;".into(),
Applicability::HasPlaceholders,
)
.emit();
return;
} else if orig_name == Some(keywords::SelfLower.name()) {
Expand Down
9 changes: 7 additions & 2 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4866,8 +4866,13 @@ impl<'a> Resolver<'a> {
} else if ident.span.rust_2018() {
let msg = "relative paths are not supported in visibilities on 2018 edition";
self.session.struct_span_err(ident.span, msg)
.span_suggestion(path.span, "try", format!("crate::{}", path))
.emit();
.span_suggestion_with_applicability(
path.span,
"try",
format!("crate::{}", path),
Applicability::MaybeIncorrect,
)
.emit();
return ty::Visibility::Public;
} else {
let ctxt = ident.span.ctxt();
Expand Down
9 changes: 8 additions & 1 deletion src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use check::{FnCtxt, Expectation, Diverges, Needs};
use check::coercion::CoerceMany;
use errors::Applicability;
use rustc::hir::{self, PatKind};
use rustc::hir::def::{Def, CtorKind};
use rustc::hir::pat_util::EnumerateAndAdjustIterator;
Expand Down Expand Up @@ -989,7 +990,13 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
let suggested_name =
find_best_match_for_name(input, &ident.as_str(), None);
if let Some(suggested_name) = suggested_name {
err.span_suggestion(*span, "did you mean", suggested_name.to_string());
err.span_suggestion_with_applicability(
*span,
"did you mean",
suggested_name.to_string(),
Applicability::MaybeIncorrect,
);

// we don't want to throw `E0027` in case we have thrown `E0026` for them
unmentioned_fields.retain(|&x| x.as_str() != suggested_name.as_str());
}
Expand Down
9 changes: 7 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4063,12 +4063,13 @@ impl<'a> Parser<'a> {

if let Some(mut err) = delayed_err {
if let Some(etc_span) = etc_span {
err.multipart_suggestion(
err.multipart_suggestion_with_applicability(
"move the `..` to the end of the field list",
vec![
(etc_span, String::new()),
(self.span, format!("{}.. }}", if ate_comma { "" } else { ", " })),
],
Applicability::MachineApplicable,
);
}
err.emit();
Expand Down Expand Up @@ -6904,7 +6905,11 @@ impl<'a> Parser<'a> {

let mut err = self.struct_span_err(fixed_name_sp, error_msg);
err.span_label(fixed_name_sp, "dash-separated idents are not valid");
err.multipart_suggestion(suggestion_msg, replacement);
err.multipart_suggestion_with_applicability(
suggestion_msg,
replacement,
Applicability::MachineApplicable,
);
err.emit();
}
Ok(ident)
Expand Down

0 comments on commit e78bde4

Please sign in to comment.