1
Fork 0

replace fileline_{help,note} with {help,note}

The extra filename and line was mainly there to keep the indentation
relative to the main snippet; now that this doesn't include
filename/line-number as a prefix, it is distracted.
This commit is contained in:
Niko Matsakis 2016-04-20 14:49:16 -04:00
parent 1ff1887cc9
commit 489a6c95bf
25 changed files with 172 additions and 260 deletions

View file

@ -682,8 +682,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
E0309,
"{} may not live long enough",
labeled_user_string);
err.fileline_help(origin.span(),
&format!("consider adding an explicit lifetime bound `{}: {}`...",
err.help(&format!("consider adding an explicit lifetime bound `{}: {}`...",
bound_kind,
sub));
err
@ -696,8 +695,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
E0310,
"{} may not live long enough",
labeled_user_string);
err.fileline_help(origin.span(),
&format!("consider adding an explicit lifetime \
err.help(&format!("consider adding an explicit lifetime \
bound `{}: 'static`...",
bound_kind));
err
@ -710,8 +708,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
E0311,
"{} may not live long enough",
labeled_user_string);
err.fileline_help(origin.span(),
&format!("consider adding an explicit lifetime bound for `{}`",
err.help(&format!("consider adding an explicit lifetime bound for `{}`",
bound_kind));
self.tcx.note_and_explain_region(
&mut err,

View file

@ -456,17 +456,13 @@ pub fn raw_struct_lint<'a>(sess: &'a Session,
it will become a hard error in a future release!");
let citation = format!("for more information, see {}",
future_incompatible.reference);
if let Some(sp) = span {
err.fileline_warn(sp, &explanation);
err.fileline_note(sp, &citation);
} else {
err.warn(&explanation);
err.note(&citation);
}
}
if let Some(span) = def {
err.span_note(span, "lint level defined here");
let explanation = "lint level defined here";
err = err.span_label(span, &explanation);
}
err
@ -542,7 +538,7 @@ pub trait LintContext: Sized {
let mut err = self.lookup(lint, Some(span), msg);
if self.current_level(lint) != Level::Allow {
if note_span == span {
err.fileline_note(note_span, note);
err.note(note);
} else {
err.span_note(note_span, note);
}

View file

@ -206,18 +206,17 @@ fn find_similar_impl_candidates<'a, 'tcx>(
impl_candidates
}
fn report_similar_impl_candidates(span: Span,
err: &mut DiagnosticBuilder,
fn report_similar_impl_candidates(err: &mut DiagnosticBuilder,
impl_candidates: &[ty::TraitRef])
{
err.fileline_help(span, &format!("the following implementations were found:"));
err.help(&format!("the following implementations were found:"));
let end = cmp::min(4, impl_candidates.len());
for candidate in &impl_candidates[0..end] {
err.fileline_help(span, &format!(" {:?}", candidate));
err.help(&format!(" {:?}", candidate));
}
if impl_candidates.len() > 4 {
err.fileline_help(span, &format!("and {} others", impl_candidates.len()-4));
err.help(&format!("and {} others", impl_candidates.len()-4));
}
}
@ -240,7 +239,7 @@ pub fn report_overflow_error<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
predicate);
if suggest_increasing_limit {
suggest_new_overflow_limit(infcx.tcx, &mut err, obligation.cause.span);
suggest_new_overflow_limit(infcx.tcx, &mut err);
}
note_obligation_cause(infcx, &mut err, obligation);
@ -353,17 +352,13 @@ pub fn try_report_overflow_error_type_of_infinite_size<'a, 'tcx>(
let mut err = recursive_type_with_infinite_size_error(tcx, main_def_id);
let len = struct_enum_tys.len();
if len > 2 {
let span = tcx.map.span_if_local(main_def_id).unwrap();
err.fileline_note(span,
&format!("type `{}` is embedded within `{}`...",
err.note(&format!("type `{}` is embedded within `{}`...",
struct_enum_tys[0],
struct_enum_tys[1]));
for &next_ty in &struct_enum_tys[1..len-1] {
err.fileline_note(span,
&format!("...which in turn is embedded within `{}`...", next_ty));
err.note(&format!("...which in turn is embedded within `{}`...", next_ty));
}
err.fileline_note(span,
&format!("...which in turn is embedded within `{}`, \
err.note(&format!("...which in turn is embedded within `{}`, \
completing the cycle.",
struct_enum_tys[len-1]));
}
@ -380,7 +375,7 @@ pub fn recursive_type_with_infinite_size_error<'tcx>(tcx: &TyCtxt<'tcx>,
let span = tcx.map.span_if_local(type_def_id).unwrap();
let mut err = struct_span_err!(tcx.sess, span, E0072, "recursive type `{}` has infinite size",
tcx.item_path_str(type_def_id));
err.fileline_help(span, &format!("insert indirection (e.g., a `Box`, `Rc`, or `&`) \
err.help(&format!("insert indirection (e.g., a `Box`, `Rc`, or `&`) \
at some point to make `{}` representable",
tcx.item_path_str(type_def_id)));
err
@ -423,15 +418,14 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
// these notes will often be of the form
// "the type `T` can't be frobnicated"
// which is somewhat confusing.
err.fileline_help(obligation.cause.span, &format!(
"consider adding a `where {}` bound",
err.help(&format!("consider adding a `where {}` bound",
trait_ref.to_predicate()
));
} else if let Some(s) = on_unimplemented_note(infcx, trait_ref,
obligation.cause.span) {
// Otherwise, if there is an on-unimplemented note,
// display it.
err.fileline_note(obligation.cause.span, &s);
err.note(&s);
} else {
// If we can't show anything useful, try to find
// similar impls.
@ -439,8 +433,7 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
let impl_candidates =
find_similar_impl_candidates(infcx, trait_ref);
if impl_candidates.len() > 0 {
report_similar_impl_candidates(obligation.cause.span,
&mut err, &impl_candidates);
report_similar_impl_candidates(&mut err, &impl_candidates);
}
}
note_obligation_cause(infcx, &mut err, obligation);
@ -499,7 +492,7 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
let found_kind = infcx.closure_kind(closure_def_id).unwrap();
let closure_span = infcx.tcx.map.span_if_local(closure_def_id).unwrap();
let mut err = struct_span_err!(
infcx.tcx.sess, closure_span, E0524,
infcx.tcx.sess, closure_span, E0525,
"expected a closure that implements the `{}` trait, but this closure \
only implements `{}`",
kind,
@ -570,40 +563,30 @@ pub fn report_object_safety_error<'tcx>(tcx: &TyCtxt<'tcx>,
}
match violation {
ObjectSafetyViolation::SizedSelf => {
err.fileline_note(
span,
"the trait cannot require that `Self : Sized`");
err.note("the trait cannot require that `Self : Sized`");
}
ObjectSafetyViolation::SupertraitSelf => {
err.fileline_note(
span,
"the trait cannot use `Self` as a type parameter \
err.note("the trait cannot use `Self` as a type parameter \
in the supertrait listing");
}
ObjectSafetyViolation::Method(method,
MethodViolationCode::StaticMethod) => {
err.fileline_note(
span,
&format!("method `{}` has no receiver",
err.note(&format!("method `{}` has no receiver",
method.name));
}
ObjectSafetyViolation::Method(method,
MethodViolationCode::ReferencesSelf) => {
err.fileline_note(
span,
&format!("method `{}` references the `Self` type \
err.note(&format!("method `{}` references the `Self` type \
in its arguments or return type",
method.name));
}
ObjectSafetyViolation::Method(method,
MethodViolationCode::Generic) => {
err.fileline_note(
span,
&format!("method `{}` has generic type parameters",
err.note(&format!("method `{}` has generic type parameters",
method.name));
}
}
@ -766,14 +749,12 @@ fn note_obligation_cause<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
note_obligation_cause_code(infcx,
err,
&obligation.predicate,
obligation.cause.span,
&obligation.cause.code);
}
fn note_obligation_cause_code<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
err: &mut DiagnosticBuilder,
predicate: &T,
cause_span: Span,
cause_code: &ObligationCauseCode<'tcx>)
where T: fmt::Display
{
@ -781,101 +762,71 @@ fn note_obligation_cause_code<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
match *cause_code {
ObligationCauseCode::MiscObligation => { }
ObligationCauseCode::SliceOrArrayElem => {
err.fileline_note(
cause_span,
"slice and array elements must have `Sized` type");
err.note("slice and array elements must have `Sized` type");
}
ObligationCauseCode::ProjectionWf(data) => {
err.fileline_note(
cause_span,
&format!("required so that the projection `{}` is well-formed",
err.note(&format!("required so that the projection `{}` is well-formed",
data));
}
ObligationCauseCode::ReferenceOutlivesReferent(ref_ty) => {
err.fileline_note(
cause_span,
&format!("required so that reference `{}` does not outlive its referent",
err.note(&format!("required so that reference `{}` does not outlive its referent",
ref_ty));
}
ObligationCauseCode::ItemObligation(item_def_id) => {
let item_name = tcx.item_path_str(item_def_id);
err.fileline_note(
cause_span,
&format!("required by `{}`", item_name));
err.note(&format!("required by `{}`", item_name));
}
ObligationCauseCode::ObjectCastObligation(object_ty) => {
err.fileline_note(
cause_span,
&format!(
"required for the cast to the object type `{}`",
err.note(&format!("required for the cast to the object type `{}`",
infcx.ty_to_string(object_ty)));
}
ObligationCauseCode::RepeatVec => {
err.fileline_note(
cause_span,
"the `Copy` trait is required because the \
err.note("the `Copy` trait is required because the \
repeated element will be copied");
}
ObligationCauseCode::VariableType(_) => {
err.fileline_note(
cause_span,
"all local variables must have a statically known size");
err.note("all local variables must have a statically known size");
}
ObligationCauseCode::ReturnType => {
err.fileline_note(
cause_span,
"the return type of a function must have a \
err.note("the return type of a function must have a \
statically known size");
}
ObligationCauseCode::AssignmentLhsSized => {
err.fileline_note(
cause_span,
"the left-hand-side of an assignment must have a statically known size");
err.note("the left-hand-side of an assignment must have a statically known size");
}
ObligationCauseCode::StructInitializerSized => {
err.fileline_note(
cause_span,
"structs must have a statically known size to be initialized");
err.note("structs must have a statically known size to be initialized");
}
ObligationCauseCode::ClosureCapture(var_id, _, builtin_bound) => {
let def_id = tcx.lang_items.from_builtin_kind(builtin_bound).unwrap();
let trait_name = tcx.item_path_str(def_id);
let name = tcx.local_var_name_str(var_id);
err.fileline_note(
cause_span,
err.note(
&format!("the closure that captures `{}` requires that all captured variables \
implement the trait `{}`",
name,
trait_name));
}
ObligationCauseCode::FieldSized => {
err.fileline_note(
cause_span,
"only the last field of a struct or enum variant \
err.note("only the last field of a struct or enum variant \
may have a dynamically sized type");
}
ObligationCauseCode::SharedStatic => {
err.fileline_note(
cause_span,
"shared static variables must have a type that implements `Sync`");
err.note("shared static variables must have a type that implements `Sync`");
}
ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
let parent_trait_ref = infcx.resolve_type_vars_if_possible(&data.parent_trait_ref);
err.fileline_note(
cause_span,
&format!("required because it appears within the type `{}`",
err.note(&format!("required because it appears within the type `{}`",
parent_trait_ref.0.self_ty()));
let parent_predicate = parent_trait_ref.to_predicate();
note_obligation_cause_code(infcx,
err,
&parent_predicate,
cause_span,
&data.parent_code);
}
ObligationCauseCode::ImplDerivedObligation(ref data) => {
let parent_trait_ref = infcx.resolve_type_vars_if_possible(&data.parent_trait_ref);
err.fileline_note(
cause_span,
err.note(
&format!("required because of the requirements on the impl of `{}` for `{}`",
parent_trait_ref,
parent_trait_ref.0.self_ty()));
@ -883,12 +834,10 @@ fn note_obligation_cause_code<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
note_obligation_cause_code(infcx,
err,
&parent_predicate,
cause_span,
&data.parent_code);
}
ObligationCauseCode::CompareImplMethodObligation => {
err.fileline_note(
cause_span,
err.note(
&format!("the requirement `{}` appears on the impl method \
but not on the corresponding trait method",
predicate));
@ -896,12 +845,10 @@ fn note_obligation_cause_code<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
}
}
fn suggest_new_overflow_limit(tcx: &TyCtxt, err:&mut DiagnosticBuilder, span: Span) {
fn suggest_new_overflow_limit(tcx: &TyCtxt, err:&mut DiagnosticBuilder) {
let current_limit = tcx.sess.recursion_limit.get();
let suggested_limit = current_limit * 2;
err.fileline_note(
span,
&format!(
err.note(&format!(
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
suggested_limit));
}

View file

@ -167,8 +167,7 @@ fn note_move_destination(err: &mut DiagnosticBuilder,
err.span_note(
move_to_span,
"attempting to move value to here");
err.fileline_help(
move_to_span,
err.help(
&format!("to prevent the move, \
use `ref {0}` or `ref mut {0}` to capture value by \
reference",

View file

@ -912,8 +912,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
};
if is_closure {
err.fileline_help(span,
"closures behind references must be called via `&mut`");
err.help("closures behind references must be called via `&mut`");
}
err.emit();
}

View file

@ -255,7 +255,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
"pattern binding `{}` is named the same as one \
of the variants of the type `{}`",
ident.node, ty_path);
fileline_help!(err, p.span,
help!(err,
"if you meant to match on a variant, \
consider making the path in the pattern qualified: `{}::{}`",
ty_path, ident.node);

View file

@ -764,7 +764,7 @@ impl LateLintPass for UnconditionalRecursion {
for call in &self_call_spans {
db.span_note(*call, "recursive call site");
}
db.fileline_help(sp, "a `loop` may express intention \
db.help("a `loop` may express intention \
better if this is on purpose");
}
db.emit();

View file

@ -241,7 +241,7 @@ impl<'a> CrateReader<'a> {
crate_rustc_version
.as_ref().map(|s| &**s)
.unwrap_or("an old version of rustc"));
err.fileline_help(span, "consider removing the compiled binaries and recompiling \
err.help("consider removing the compiled binaries and recompiling \
with your current version of rustc");
err.emit();
}

View file

@ -346,38 +346,32 @@ impl<'a> Context<'a> {
if !self.rejected_via_triple.is_empty() {
let mismatches = self.rejected_via_triple.iter();
for (i, &CrateMismatch{ ref path, ref got }) in mismatches.enumerate() {
err.fileline_note(self.span,
&format!("crate `{}`, path #{}, triple {}: {}",
err.note(&format!("crate `{}`, path #{}, triple {}: {}",
self.ident, i+1, got, path.display()));
}
}
if !self.rejected_via_hash.is_empty() {
err.span_note(self.span, "perhaps this crate needs \
to be recompiled?");
err.note("perhaps this crate needs to be recompiled?");
let mismatches = self.rejected_via_hash.iter();
for (i, &CrateMismatch{ ref path, .. }) in mismatches.enumerate() {
err.fileline_note(self.span,
&format!("crate `{}` path #{}: {}",
err.note(&format!("crate `{}` path #{}: {}",
self.ident, i+1, path.display()));
}
match self.root {
&None => {}
&Some(ref r) => {
for (i, path) in r.paths().iter().enumerate() {
err.fileline_note(self.span,
&format!("crate `{}` path #{}: {}",
err.note(&format!("crate `{}` path #{}: {}",
r.ident, i+1, path.display()));
}
}
}
}
if !self.rejected_via_kind.is_empty() {
err.fileline_help(self.span, "please recompile this crate using \
--crate-type lib");
err.help("please recompile this crate using --crate-type lib");
let mismatches = self.rejected_via_kind.iter();
for (i, &CrateMismatch { ref path, .. }) in mismatches.enumerate() {
err.fileline_note(self.span,
&format!("crate `{}` path #{}: {}",
err.note(&format!("crate `{}` path #{}: {}",
self.ident, i+1, path.display()));
}
}

View file

@ -198,9 +198,8 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
let mut err = self.tcx.sess.struct_span_err(
expr.span,
"const fns are an unstable feature");
fileline_help!(
help!(
&mut err,
expr.span,
"in Nightly builds, add `#![feature(const_fn)]` to the crate \
attributes to enable");
err.emit();

View file

@ -244,7 +244,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
E0405,
"trait `{}` is not in scope",
name);
show_candidates(&mut err, span, &candidates);
show_candidates(&mut err, &candidates);
err
}
ResolutionError::UndeclaredAssociatedType => {
@ -312,7 +312,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
"{} `{}` is undefined or not in scope",
kind,
name);
show_candidates(&mut err, span, &candidates);
show_candidates(&mut err, &candidates);
err
}
ResolutionError::DeclarationShadowsEnumVariantOrUnitLikeStruct(name) => {
@ -420,7 +420,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
match context {
UnresolvedNameContext::Other => { } // no help available
UnresolvedNameContext::PathIsMod(parent) => {
err.fileline_help(span, &match parent.map(|parent| &parent.node) {
err.help(&match parent.map(|parent| &parent.node) {
Some(&ExprField(_, ident)) => {
format!("To reference an item from the `{module}` module, \
use `{module}::{ident}`",
@ -1784,7 +1784,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// If it's a typedef, give a note
if let Def::TyAlias(..) = path_res.base_def {
err.fileline_note(trait_path.span,
err.note(trait_path.span,
"`type` aliases cannot be used for traits");
let definition_site = {
@ -2880,7 +2880,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let msg = format!("did you mean to write: `{} {{ /* fields */ }}`?",
path_name);
if self.emit_errors {
err.fileline_help(expr.span, &msg);
err.help(&msg);
} else {
err.span_help(expr.span, &msg);
}
@ -2922,7 +2922,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
path_name);
if self.emit_errors {
err.fileline_help(expr.span, &msg);
err.help(&msg);
} else {
err.span_help(expr.span, &msg);
}
@ -3420,7 +3420,6 @@ fn path_names_to_string(path: &Path, depth: usize) -> String {
/// entities with that name in all crates. This method allows outputting the
/// results of this search in a programmer-friendly way
fn show_candidates(session: &mut DiagnosticBuilder,
span: syntax::codemap::Span,
candidates: &SuggestedCandidates) {
let paths = &candidates.candidates;
@ -3440,26 +3439,23 @@ fn show_candidates(session: &mut DiagnosticBuilder,
// behave differently based on how many candidates we have:
if !paths.is_empty() {
if paths.len() == 1 {
session.fileline_help(
span,
session.help(
&format!("you can import it into scope: `use {};`.",
&path_strings[0]),
);
} else {
session.fileline_help(span, "you can import several candidates \
session.help("you can import several candidates \
into scope (`use ...;`):");
let count = path_strings.len() as isize - MAX_CANDIDATES as isize + 1;
for (idx, path_string) in path_strings.iter().enumerate() {
if idx == MAX_CANDIDATES - 1 && count > 1 {
session.fileline_help(
span,
session.help(
&format!(" and {} other candidates", count).to_string(),
);
break;
} else {
session.fileline_help(
span,
session.help(
&format!(" `{}`", path_string).to_string(),
);
}
@ -3468,8 +3464,7 @@ fn show_candidates(session: &mut DiagnosticBuilder,
}
} else {
// nothing found:
session.fileline_help(
span,
session.help(
&format!("no candidates by the name of `{}` found in your \
project; maybe you misspelled the name or forgot to import \
an external crate?", candidates.name.to_string()),

View file

@ -206,7 +206,6 @@ pub fn ast_region_to_region(tcx: &TyCtxt, lifetime: &hir::Lifetime)
fn report_elision_failure(
db: &mut DiagnosticBuilder,
default_span: Span,
params: Vec<ElisionFailureInfo>)
{
let mut m = String::new();
@ -243,26 +242,26 @@ fn report_elision_failure(
}
if len == 0 {
fileline_help!(db, default_span,
help!(db,
"this function's return type contains a borrowed value, but \
there is no value for it to be borrowed from");
fileline_help!(db, default_span,
help!(db,
"consider giving it a 'static lifetime");
} else if !any_lifetimes {
fileline_help!(db, default_span,
help!(db,
"this function's return type contains a borrowed value with \
an elided lifetime, but the lifetime cannot be derived from \
the arguments");
fileline_help!(db, default_span,
help!(db,
"consider giving it an explicit bounded or 'static \
lifetime");
} else if len == 1 {
fileline_help!(db, default_span,
help!(db,
"this function's return type contains a borrowed value, but \
the signature does not say which {} it is borrowed from",
m);
} else {
fileline_help!(db, default_span,
help!(db,
"this function's return type contains a borrowed value, but \
the signature does not say whether it is borrowed from {}",
m);
@ -286,7 +285,7 @@ pub fn opt_ast_region_to_region<'tcx>(
let mut err = struct_span_err!(this.tcx().sess, default_span, E0106,
"missing lifetime specifier");
if let Some(params) = params {
report_elision_failure(&mut err, default_span, params);
report_elision_failure(&mut err, params);
}
err.emit();
ty::ReStatic
@ -1087,7 +1086,7 @@ fn ast_ty_to_trait_ref<'tcx>(this: &AstConv<'tcx>,
}
_ => {
fileline_help!(&mut err, ty.span,
help!(&mut err,
"perhaps you forgot parentheses? (per RFC 438)");
}
}

View file

@ -64,7 +64,7 @@ pub fn check_legal_trait_for_method_call(ccx: &CrateCtxt, span: Span, trait_id:
struct_span_err!(tcx.sess, span, E0174,
"explicit use of unboxed closure method `{}` is experimental",
method)
.fileline_help(span, "add `#![feature(unboxed_closures)]` to the crate \
.help("add `#![feature(unboxed_closures)]` to the crate \
attributes to enable")
.emit();
}

View file

@ -155,8 +155,7 @@ impl<'tcx> CastCheck<'tcx> {
actual,
fcx.infcx().ty_to_string(self.cast_ty))
}, self.expr_ty, None)
.fileline_help(self.span,
&format!("cast through {} first", match e {
.help(&format!("cast through {} first", match e {
CastError::NeedViaPtr => "a raw pointer",
CastError::NeedViaThinPtr => "a thin pointer",
CastError::NeedViaInt => "an integer",
@ -167,7 +166,7 @@ impl<'tcx> CastCheck<'tcx> {
}
CastError::CastToBool => {
struct_span_err!(fcx.tcx().sess, self.span, E0054, "cannot cast as `bool`")
.fileline_help(self.span, "compare with zero instead")
.help("compare with zero instead")
.emit();
}
CastError::CastToChar => {
@ -202,7 +201,7 @@ impl<'tcx> CastCheck<'tcx> {
actual,
fcx.infcx().ty_to_string(self.cast_ty))
}, self.expr_ty, None)
.fileline_note(self.span, "vtable kinds may not match")
.note("vtable kinds may not match")
.emit();
}
}

View file

@ -148,9 +148,7 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
if is_fn_ty(&rcvr_ty, &fcx, span) {
macro_rules! report_function {
($span:expr, $name:expr) => {
err.fileline_note(
$span,
&format!("{} is a function, perhaps you wish to call it",
err.note(&format!("{} is a function, perhaps you wish to call it",
$name));
}
}
@ -172,8 +170,7 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
}
if !static_sources.is_empty() {
err.fileline_note(
span,
err.note(
"found the following associated functions; to be used as \
methods, functions must have a `self` parameter");
@ -187,8 +184,7 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
p))
.collect::<Vec<_>>()
.join(", ");
err.fileline_note(
span,
err.note(
&format!("the method `{}` exists but the \
following trait bounds were not satisfied: {}",
item_name,
@ -306,11 +302,10 @@ fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
traits_are = if candidates.len() == 1 {"trait is"} else {"traits are"},
one_of_them = if candidates.len() == 1 {"it"} else {"one of them"});
err.fileline_help(span, &msg[..]);
err.help(&msg[..]);
for (i, trait_did) in candidates.iter().enumerate() {
err.fileline_help(span,
&format!("candidate #{}: `use {}`",
err.help(&format!("candidate #{}: `use {}`",
i + 1,
fcx.tcx().item_path_str(*trait_did)));
}
@ -351,11 +346,10 @@ fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
one_of_them = if candidates.len() == 1 {"it"} else {"one of them"},
name = item_name);
err.fileline_help(span, &msg[..]);
err.help(&msg[..]);
for (i, trait_info) in candidates.iter().enumerate() {
err.fileline_help(span,
&format!("candidate #{}: `{}`",
err.help(&format!("candidate #{}: `{}`",
i + 1,
fcx.tcx().item_path_str(trait_info.def_id)));
}

View file

@ -2955,7 +2955,7 @@ fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
`{}`", field.node, actual)
},
expr_t, None)
.fileline_help(field.span,
.help(
"maybe a `()` to call it is missing? \
If not, try an anonymous function")
.emit();

View file

@ -501,8 +501,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
let suggested_marker_id = self.tcx().lang_items.phantom_data();
match suggested_marker_id {
Some(def_id) => {
err.fileline_help(
span,
err.help(
&format!("consider removing `{}` or using a marker such as `{}`",
param_name,
self.tcx().item_path_str(def_id)));

View file

@ -510,8 +510,7 @@ fn enforce_trait_manually_implementable(tcx: &TyCtxt, sp: Span, trait_def_id: De
E0183,
"manual implementations of `{}` are experimental",
trait_name);
fileline_help!(&mut err, sp,
"add `#![feature(unboxed_closures)]` to the crate attributes to enable");
help!(&mut err, "add `#![feature(unboxed_closures)]` to the crate attributes to enable");
err.emit();
}

View file

@ -1258,7 +1258,7 @@ fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
it.span,
"the `#[rustc_paren_sugar]` attribute is a temporary means of controlling \
which traits can use parenthetical notation");
fileline_help!(&mut err, it.span,
help!(&mut err,
"add `#![feature(unboxed_closures)]` to \
the crate attributes to use it");
err.emit();
@ -2196,8 +2196,7 @@ fn compute_type_scheme_of_foreign_fn_decl<'a, 'tcx>(
&format!("use of SIMD type `{}` in FFI is highly experimental and \
may result in invalid code",
pprust::ty_to_string(ast_ty)))
.fileline_help(ast_ty.span,
"add #![feature(simd_ffi)] to the crate attributes to enable")
.help("add #![feature(simd_ffi)] to the crate attributes to enable")
.emit();
}
};

View file

@ -101,9 +101,9 @@ macro_rules! span_help {
}
#[macro_export]
macro_rules! fileline_help {
($err:expr, $span:expr, $($message:tt)*) => ({
($err).fileline_help($span, &format!($($message)*));
macro_rules! help {
($err:expr, $($message:tt)*) => ({
($err).help(&format!($($message)*));
})
}

View file

@ -764,14 +764,13 @@ impl<'a> ExtCtxt<'a> {
pub fn suggest_macro_name(&mut self,
name: &str,
span: Span,
err: &mut DiagnosticBuilder<'a>) {
let names = &self.syntax_env.names;
if let Some(suggestion) = find_best_match_for_name(names.iter(), name, None) {
if suggestion != name {
err.fileline_help(span, &format!("did you mean `{}!`?", suggestion));
err.help(&format!("did you mean `{}!`?", suggestion));
} else {
err.fileline_help(span, &format!("have you added the `#[macro_use]` on the \
err.help(&format!("have you added the `#[macro_use]` on the \
module/import?"));
}
}

View file

@ -770,7 +770,7 @@ pub fn emit_feature_err(diag: &Handler, feature: &str, span: Span, issue: GateIs
err.emit();
return;
}
err.fileline_help(span, &format!("add #![feature({})] to the \
err.help(&format!("add #![feature({})] to the \
crate attributes to enable",
feature));
err.emit();

View file

@ -69,8 +69,7 @@ impl<'a> Parser<'a> {
self.diagnostic()
.struct_span_err(span,
"an inner attribute is not permitted in this context")
.fileline_help(span,
"place inner attribute at the top of the module or \
.help("place inner attribute at the top of the module or \
block")
.emit()
}

View file

@ -445,11 +445,11 @@ fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>,
if suf.len() >= 2 && looks_like_width_suffix(&['f'], suf) {
// if it looks like a width, lets try to be helpful.
sd.struct_span_err(sp, &format!("invalid width `{}` for float literal", &suf[1..]))
.fileline_help(sp, "valid widths are 32 and 64")
.help("valid widths are 32 and 64")
.emit();
} else {
sd.struct_span_err(sp, &format!("invalid suffix `{}` for float literal", suf))
.fileline_help(sp, "valid suffixes are `f32` and `f64`")
.help("valid suffixes are `f32` and `f64`")
.emit();
}
@ -621,11 +621,11 @@ pub fn integer_lit(s: &str,
if looks_like_width_suffix(&['i', 'u'], suf) {
sd.struct_span_err(sp, &format!("invalid width `{}` for integer literal",
&suf[1..]))
.fileline_help(sp, "valid widths are 8, 16, 32 and 64")
.help("valid widths are 8, 16, 32 and 64")
.emit();
} else {
sd.struct_span_err(sp, &format!("invalid suffix `{}` for numeric literal", suf))
.fileline_help(sp, "the suffix must be one of the integral types \
.help("the suffix must be one of the integral types \
(`u32`, `isize`, etc)")
.emit();
}

View file

@ -583,7 +583,7 @@ impl<'a> Parser<'a> {
let mut err = self.fatal(&format!("expected identifier, found `{}`",
self.this_token_to_string()));
if self.token == token::Underscore {
err.fileline_note(self.span, "`_` is a wildcard pattern, not an identifier");
err.note("`_` is a wildcard pattern, not an identifier");
}
Err(err)
}
@ -1082,7 +1082,7 @@ impl<'a> Parser<'a> {
}
pub fn span_fatal_help(&self, sp: Span, m: &str, help: &str) -> DiagnosticBuilder<'a> {
let mut err = self.sess.span_diagnostic.struct_span_fatal(sp, m);
err.fileline_help(sp, help);
err.help(help);
err
}
pub fn bug(&self, m: &str) -> ! {
@ -2622,8 +2622,7 @@ impl<'a> Parser<'a> {
Some(f) => f,
None => continue,
};
err.fileline_help(last_span,
&format!("try parenthesizing the first index; e.g., `(foo.{}){}`",
err.help(&format!("try parenthesizing the first index; e.g., `(foo.{}){}`",
float.trunc() as usize,
format!(".{}", fstr.splitn(2, ".").last().unwrap())));
}
@ -3134,7 +3133,7 @@ impl<'a> Parser<'a> {
let mut err = self.diagnostic().struct_span_err(op_span,
"chained comparison operators require parentheses");
if op.node == BinOpKind::Lt && *outer_op == AssocOp::Greater {
err.fileline_help(op_span,
err.help(
"use `::<...>` instead of `<...>` if you meant to specify type arguments");
}
err.emit();
@ -4951,12 +4950,12 @@ impl<'a> Parser<'a> {
if is_macro_rules {
self.diagnostic().struct_span_err(span, "can't qualify macro_rules \
invocation with `pub`")
.fileline_help(span, "did you mean #[macro_export]?")
.help("did you mean #[macro_export]?")
.emit();
} else {
self.diagnostic().struct_span_err(span, "can't qualify macro \
invocation with `pub`")
.fileline_help(span, "try adjusting the macro to put `pub` \
.help("try adjusting the macro to put `pub` \
inside the invocation")
.emit();
}
@ -5857,7 +5856,7 @@ impl<'a> Parser<'a> {
if self.eat_keyword(keywords::Mut) {
let last_span = self.last_span;
self.diagnostic().struct_span_err(last_span, "const globals cannot be mutable")
.fileline_help(last_span, "did you mean to declare a static?")
.help("did you mean to declare a static?")
.emit();
}
let (ident, item_, extra_attrs) = self.parse_item_const(None)?;