diff options
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/middle/borrowck/check_loans.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/borrowck/gather_loans/move_error.rs | 7 | ||||
| -rw-r--r-- | src/librustc/middle/borrowck/mod.rs | 51 | ||||
| -rw-r--r-- | src/librustc/middle/dependency_format.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/liveness.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/resolve.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/astconv.rs | 11 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/check/mod.rs | 18 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/check/vtable.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/infer/error_reporting.rs | 27 | ||||
| -rw-r--r-- | src/librustc/util/ppaux.rs | 4 |
11 files changed, 77 insertions, 51 deletions
diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index de61f4f2b40..073b6dae0c3 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -789,7 +789,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { assignment_span, format!("cannot assign to {}", self.bccx.cmt_to_string(&*assignee_cmt)).as_slice()); - self.bccx.span_note( + self.bccx.span_help( self.tcx().map.span(upvar_id.closure_expr_id), "consider changing this closure to take self by mutable reference"); } else { diff --git a/src/librustc/middle/borrowck/gather_loans/move_error.rs b/src/librustc/middle/borrowck/gather_loans/move_error.rs index 9d4d9fcf9a9..ab6ff08c9d4 100644 --- a/src/librustc/middle/borrowck/gather_loans/move_error.rs +++ b/src/librustc/middle/borrowck/gather_loans/move_error.rs @@ -148,9 +148,12 @@ fn note_move_destination(bccx: &BorrowckCtxt, if is_first_note { bccx.span_note( move_to_span, - format!("attempting to move value to here (to prevent the move, \ + "attempting to move value to here"); + bccx.span_help( + move_to_span, + format!("to prevent the move, \ use `ref {0}` or `ref mut {0}` to capture value by \ - reference)", + reference", pat_name).as_slice()); } else { bccx.span_note(move_to_span, diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index ae8e975e843..4e2b280eba6 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -527,8 +527,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { r).as_slice()) } }; - let suggestion = move_suggestion(self.tcx, expr_ty, - "moved by default (use `copy` to override)"); + let (suggestion, _) = move_suggestion(self.tcx, expr_ty, + ("moved by default", "")); self.tcx.sess.span_note( expr_span, format!("`{}` moved here{} because it has type `{}`, which is {}", @@ -540,13 +540,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { move_data::MovePat => { let pat_ty = ty::node_id_to_type(self.tcx, the_move.id); - self.tcx.sess.span_note(self.tcx.map.span(the_move.id), + let span = self.tcx.map.span(the_move.id); + self.tcx.sess.span_note(span, format!("`{}` moved here{} because it has type `{}`, \ - which is moved by default (use `ref` to \ - override)", + which is moved by default", ol, moved_lp_msg, pat_ty.user_string(self.tcx)).as_slice()); + self.tcx.sess.span_help(span, + "use `ref` to override"); } move_data::Captured => { @@ -563,9 +565,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { r).as_slice()) } }; - let suggestion = move_suggestion(self.tcx, expr_ty, - "moved by default (make a copy and \ - capture that instead to override)"); + let (suggestion, help) = move_suggestion(self.tcx, expr_ty, + ("moved by default", "make a copy and \ + capture that instead to override")); self.tcx.sess.span_note( expr_span, format!("`{}` moved into closure environment here{} because it \ @@ -574,21 +576,23 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { moved_lp_msg, expr_ty.user_string(self.tcx), suggestion).as_slice()); + self.tcx.sess.span_help(expr_span, help); } } - fn move_suggestion(tcx: &ty::ctxt, ty: ty::t, default_msg: &'static str) - -> &'static str { + fn move_suggestion(tcx: &ty::ctxt, ty: ty::t, default_msgs: (&'static str, &'static str)) + -> (&'static str, &'static str) { match ty::get(ty).sty { ty::ty_closure(box ty::ClosureTy { store: ty::RegionTraitStore(..), .. }) => - "a non-copyable stack closure (capture it in a new closure, \ - e.g. `|x| f(x)`, to override)", + ("a non-copyable stack closure", + "capture it in a new closure, e.g. `|x| f(x)`, to override"), _ if ty::type_moves_by_default(tcx, ty) => - "non-copyable (perhaps you meant to use clone()?)", - _ => default_msg, + ("non-copyable", + "perhaps you meant to use `clone()`?"), + _ => default_msgs, } } } @@ -733,7 +737,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { self.tcx.sess.span_err(span, format!("{} in a captured outer \ variable in an `Fn` closure", prefix).as_slice()); - span_note!(self.tcx.sess, self.tcx.map.span(id), + span_help!(self.tcx.sess, self.tcx.map.span(id), "consider changing this closure to take self by mutable reference"); } mc::AliasableStatic(..) | @@ -750,7 +754,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { } if is_closure { - self.tcx.sess.span_note( + self.tcx.sess.span_help( span, "closures behind references must be called via `&mut`"); } @@ -770,7 +774,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { _ => unreachable!() }; if kind == ty::FnUnboxedClosureKind { - self.tcx.sess.span_note( + self.tcx.sess.span_help( self.tcx.map.span(upvar_id.closure_expr_id), "consider changing this closure to take \ self by mutable reference"); @@ -787,15 +791,20 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { sub_scope, "..."); let suggestion = if is_statement_scope(self.tcx, super_scope) { - "; consider using a `let` binding to increase its lifetime" + Some("consider using a `let` binding to increase its lifetime") } else { - "" + None }; - note_and_explain_region( + let span = note_and_explain_region( self.tcx, "...but borrowed value is only valid for ", super_scope, - suggestion); + ""); + match (span, suggestion) { + (_, None) => {}, + (Some(span), Some(msg)) => self.tcx.sess.span_help(span, msg), + (None, Some(msg)) => self.tcx.sess.help(msg), + } } err_borrowed_pointer_too_short(loan_scope, ptr_scope) => { diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs index 3baa8eb0cc0..15ca00f6a7f 100644 --- a/src/librustc/middle/dependency_format.rs +++ b/src/librustc/middle/dependency_format.rs @@ -213,7 +213,7 @@ fn add_library(sess: &session::Session, sess.err(format!("cannot satisfy dependencies so `{}` only \ shows up once", data.name).as_slice()); - sess.note("having upstream crates all available in one format \ + sess.help("having upstream crates all available in one format \ will likely make this go away"); } } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 80eba56ea6c..a11d5f6604e 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1568,7 +1568,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { hi: original_span.hi, expn_id: original_span.expn_id }; - self.ir.tcx.sess.span_note( + self.ir.tcx.sess.span_help( span_semicolon, "consider removing this semicolon:"); } } diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 3d102892277..9a059e5d905 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -5744,7 +5744,7 @@ impl<'a> Resolver<'a> { uses it like a function name", wrong_name).as_slice()); - self.session.span_note(expr.span, + self.session.span_help(expr.span, format!("Did you mean to write: \ `{} {{ /* fields */ }}`?", wrong_name).as_slice()); diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 66d4f73eacc..51a63a4f8b5 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -172,18 +172,18 @@ pub fn opt_ast_region_to_region<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( } } if len == 1 { - span_note!(this.tcx().sess, default_span, + span_help!(this.tcx().sess, default_span, "this function's return type contains a borrowed value, but \ the signature does not say which {} it is borrowed from", m); } else if len == 0 { - span_note!(this.tcx().sess, default_span, + span_help!(this.tcx().sess, default_span, "this function's return type contains a borrowed value, but \ there is no value for it to be borrowed from"); - span_note!(this.tcx().sess, default_span, + span_help!(this.tcx().sess, default_span, "consider giving it a 'static lifetime"); } else { - span_note!(this.tcx().sess, default_span, + span_help!(this.tcx().sess, default_span, "this function's return type contains a borrowed value, but \ the signature does not say whether it is borrowed from {}", m); @@ -302,7 +302,7 @@ fn ast_path_substs<'tcx,AC,RS>( && !this.tcx().sess.features.borrow().default_type_params { span_err!(this.tcx().sess, path.span, E0108, "default type parameters are experimental and possibly buggy"); - span_note!(this.tcx().sess, path.span, + span_help!(this.tcx().sess, path.span, "add #![feature(default_type_params)] to the crate attributes to enable"); } @@ -1168,6 +1168,7 @@ fn ty_of_method_or_bare_fn<'tcx, AC: AstConv<'tcx>>( let param_lifetimes: Vec<(String, uint)> = lifetimes_for_params.into_iter() .map(|(n, v)| (n, v.len())) + .filter(|&(_, l)| l != 0) .collect(); let output_ty = match decl.output.node { diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index f334d801692..e2d66fa580f 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1355,18 +1355,18 @@ fn check_cast(fcx: &FnCtxt, ast::MutImmutable => "" }; if ty::type_is_trait(t_1) { - span_note!(fcx.tcx().sess, t.span, "did you mean `&{}{}`?", mtstr, tstr); + span_help!(fcx.tcx().sess, t.span, "did you mean `&{}{}`?", mtstr, tstr); } else { - span_note!(fcx.tcx().sess, span, + span_help!(fcx.tcx().sess, span, "consider using an implicit coercion to `&{}{}` instead", mtstr, tstr); } } ty::ty_uniq(..) => { - span_note!(fcx.tcx().sess, t.span, "did you mean `Box<{}>`?", tstr); + span_help!(fcx.tcx().sess, t.span, "did you mean `Box<{}>`?", tstr); } _ => { - span_note!(fcx.tcx().sess, e.span, + span_help!(fcx.tcx().sess, e.span, "consider using a box or reference as appropriate"); } } @@ -2142,7 +2142,7 @@ fn try_overloaded_call<'a>(fcx: &FnCtxt, if !fcx.tcx().sess.features.borrow().overloaded_calls { span_err!(fcx.tcx().sess, call_expression.span, E0056, "overloaded calls are experimental"); - span_note!(fcx.tcx().sess, call_expression.span, + span_help!(fcx.tcx().sess, call_expression.span, "add `#![feature(overloaded_calls)]` to \ the crate attributes to enable"); } @@ -3479,8 +3479,9 @@ fn check_expr_with_unifier(fcx: &FnCtxt, }, expr_t, None); - tcx.sess.span_note(field.span, - "maybe a missing `()` to call it? If not, try an anonymous function."); + tcx.sess.span_help(field.span, + "maybe a `()` to call it is missing? \ + If not, try an anonymous function"); } Err(_) => { @@ -4787,7 +4788,8 @@ pub fn check_instantiable(tcx: &ty::ctxt, if !ty::is_instantiable(tcx, item_ty) { span_err!(tcx.sess, sp, E0073, "this type cannot be instantiated without an \ - instance of itself; consider using `Option<{}>`", + instance of itself"); + span_help!(tcx.sess, sp, "consider using `Option<{}>`", ppaux::ty_to_string(tcx, item_ty)); false } else { diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index a17194f0085..48bc3faadcd 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -521,7 +521,7 @@ fn note_obligation_cause(fcx: &FnCtxt, span_note!(tcx.sess, obligation.cause.span, "cannot implement a destructor on a \ structure or enumeration that does not satisfy Send"); - span_note!(tcx.sess, obligation.cause.span, + span_help!(tcx.sess, obligation.cause.span, "use \"#[unsafe_destructor]\" on the implementation \ to force the compiler to allow this"); } diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/typeck/infer/error_reporting.rs index 3baa9a7a5f9..bfa0f94a747 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/typeck/infer/error_reporting.rs @@ -438,9 +438,12 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { self.tcx.sess.span_err( origin.span(), format!( - "the parameter type `{}` may not live long enough; \ - consider adding an explicit lifetime bound `{}:{}`...", - param_ty.user_string(self.tcx), + "the parameter type `{}` may not live long enough", + param_ty.user_string(self.tcx)).as_slice()); + self.tcx.sess.span_help( + origin.span(), + format!( + "consider adding an explicit lifetime bound `{}: {}`...", param_ty.user_string(self.tcx), sub.user_string(self.tcx)).as_slice()); } @@ -450,9 +453,12 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { self.tcx.sess.span_err( origin.span(), format!( - "the parameter type `{}` may not live long enough; \ - consider adding an explicit lifetime bound `{}:'static`...", - param_ty.user_string(self.tcx), + "the parameter type `{}` may not live long enough", + param_ty.user_string(self.tcx)).as_slice()); + self.tcx.sess.span_help( + origin.span(), + format!( + "consider adding an explicit lifetime bound `{}: 'static`...", param_ty.user_string(self.tcx)).as_slice()); } @@ -461,9 +467,12 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { self.tcx.sess.span_err( origin.span(), format!( - "the parameter type `{}` may not live long enough; \ - consider adding an explicit lifetime bound to `{}`", - param_ty.user_string(self.tcx), + "the parameter type `{}` may not live long enough", + param_ty.user_string(self.tcx)).as_slice()); + self.tcx.sess.span_help( + origin.span(), + format!( + "consider adding an explicit lifetime bound to `{}`", param_ty.user_string(self.tcx)).as_slice()); note_and_explain_region( self.tcx, diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 8befba00fd2..b820780dbf9 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -48,16 +48,18 @@ pub trait UserString { pub fn note_and_explain_region(cx: &ctxt, prefix: &str, region: ty::Region, - suffix: &str) { + suffix: &str) -> Option<Span> { match explain_region_and_span(cx, region) { (ref str, Some(span)) => { cx.sess.span_note( span, format!("{}{}{}", prefix, *str, suffix).as_slice()); + Some(span) } (ref str, None) => { cx.sess.note( format!("{}{}{}", prefix, *str, suffix).as_slice()); + None } } } |
