Skip to content

Commit

Permalink
Rollup merge of rust-lang#53655 - jcpst:with_applicability, r=estebank
Browse files Browse the repository at this point in the history
set applicability

Update a few more calls as described in rust-lang#50723

r? @estebank
  • Loading branch information
Mark-Simulacrum authored Aug 28, 2018
2 parents 387d0c6 + 1f421d6 commit 0a0157e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 27 deletions.
62 changes: 41 additions & 21 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ use syntax::feature_gate::{feature_err, GateIssue};
use syntax::ptr::P;

use syntax_pos::{Span, DUMMY_SP, MultiSpan};
use errors::{DiagnosticBuilder, DiagnosticId};
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};

use std::cell::{Cell, RefCell};
use std::cmp;
Expand Down Expand Up @@ -221,9 +221,12 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
let sugg_msg = "try using a local type parameter instead";
if let Some((sugg_span, new_snippet)) = cm.generate_local_type_param_snippet(span) {
// Suggest the modification to the user
err.span_suggestion(sugg_span,
sugg_msg,
new_snippet);
err.span_suggestion_with_applicability(
sugg_span,
sugg_msg,
new_snippet,
Applicability::MachineApplicable,
);
} else if let Some(sp) = cm.generate_fn_name_span(span) {
err.span_label(sp, "try adding a local type parameter in this method instead");
} else {
Expand Down Expand Up @@ -3004,8 +3007,12 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
enum_path);
err.help(&msg);
} else {
err.span_suggestion(span, "you can try using the variant's enum",
enum_path);
err.span_suggestion_with_applicability(
span,
"you can try using the variant's enum",
enum_path,
Applicability::MachineApplicable,
);
}
}
}
Expand All @@ -3014,20 +3021,32 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
let self_is_available = this.self_value_is_available(path[0].span, span);
match candidate {
AssocSuggestion::Field => {
err.span_suggestion(span, "try",
format!("self.{}", path_str));
err.span_suggestion_with_applicability(
span,
"try",
format!("self.{}", path_str),
Applicability::MachineApplicable,
);
if !self_is_available {
err.span_label(span, format!("`self` value is only available in \
methods with `self` parameter"));
}
}
AssocSuggestion::MethodWithSelf if self_is_available => {
err.span_suggestion(span, "try",
format!("self.{}", path_str));
err.span_suggestion_with_applicability(
span,
"try",
format!("self.{}", path_str),
Applicability::MachineApplicable,
);
}
AssocSuggestion::MethodWithSelf | AssocSuggestion::AssocItem => {
err.span_suggestion(span, "try",
format!("Self::{}", path_str));
err.span_suggestion_with_applicability(
span,
"try",
format!("Self::{}", path_str),
Applicability::MachineApplicable,
);
}
}
return (err, candidates);
Expand Down Expand Up @@ -4662,15 +4681,16 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
format!("other_{}", name)
};

err.span_suggestion(binding.span,
rename_msg,
if snippet.ends_with(';') {
format!("{} as {};",
&snippet[..snippet.len()-1],
suggested_name)
} else {
format!("{} as {}", snippet, suggested_name)
});
err.span_suggestion_with_applicability(
binding.span,
rename_msg,
if snippet.ends_with(';') {
format!("{} as {};", &snippet[..snippet.len() - 1], suggested_name)
} else {
format!("{} as {}", snippet, suggested_name)
},
Applicability::MachineApplicable,
);
} else {
err.span_label(binding.span, rename_msg);
}
Expand Down
11 changes: 7 additions & 4 deletions src/librustc_typeck/structured_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use rustc::session::Session;
use syntax_pos::Span;
use errors::{DiagnosticId, DiagnosticBuilder};
use errors::{Applicability, DiagnosticId, DiagnosticBuilder};
use rustc::ty::{Ty, TypeFoldable};

pub trait StructuredDiagnostic<'tcx> {
Expand Down Expand Up @@ -73,9 +73,12 @@ impl<'tcx> StructuredDiagnostic<'tcx> for VariadicError<'tcx> {
)
};
if let Ok(snippet) = self.sess.source_map().span_to_snippet(self.span) {
err.span_suggestion(self.span,
&format!("cast the value to `{}`", self.cast_ty),
format!("{} as {}", snippet, self.cast_ty));
err.span_suggestion_with_applicability(
self.span,
&format!("cast the value to `{}`", self.cast_ty),
format!("{} as {}", snippet, self.cast_ty),
Applicability::MachineApplicable,
);
} else {
err.help(&format!("cast the value to `{}`", self.cast_ty));
}
Expand Down
14 changes: 12 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,12 @@ impl<'a> Parser<'a> {
} else {
err.span_label(self.span, "expected identifier");
if self.token == token::Comma && self.look_ahead(1, |t| t.is_ident()) {
err.span_suggestion(self.span, "remove this comma", String::new());
err.span_suggestion_with_applicability(
self.span,
"remove this comma",
String::new(),
Applicability::MachineApplicable,
);
}
}
err
Expand Down Expand Up @@ -6083,7 +6088,12 @@ impl<'a> Parser<'a> {
self.this_token_to_string()));
if self.token.is_ident() {
// This is likely another field; emit the diagnostic and keep going
err.span_suggestion(sp, "try adding a comma", ",".into());
err.span_suggestion_with_applicability(
sp,
"try adding a comma",
",".into(),
Applicability::MachineApplicable,
);
err.emit();
} else {
return Err(err)
Expand Down

0 comments on commit 0a0157e

Please sign in to comment.