1
Fork 0

Format note.rs with rustfmt

This commit is contained in:
Cengiz Can 2017-02-27 22:30:47 +03:00
parent 2f8ef50f7d
commit e136bf6a4c

View file

@ -14,166 +14,130 @@ use ty::error::TypeError;
use errors::DiagnosticBuilder; use errors::DiagnosticBuilder;
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
pub(super) fn note_region_origin(&self, err: &mut DiagnosticBuilder, origin: &SubregionOrigin<'tcx>) { pub(super) fn note_region_origin(&self,
err: &mut DiagnosticBuilder,
origin: &SubregionOrigin<'tcx>) {
match *origin { match *origin {
infer::Subtype(ref trace) => { infer::Subtype(ref trace) => {
if let Some((expected, found)) = self.values_str(&trace.values) { if let Some((expected, found)) = self.values_str(&trace.values) {
// FIXME: do we want a "the" here? // FIXME: do we want a "the" here?
err.span_note( err.span_note(trace.cause.span,
trace.cause.span,
&format!("...so that {} (expected {}, found {})", &format!("...so that {} (expected {}, found {})",
trace.cause.as_requirement_str(), expected, found)); trace.cause.as_requirement_str(),
expected,
found));
} else { } else {
// FIXME: this really should be handled at some earlier stage. Our // FIXME: this really should be handled at some earlier stage. Our
// handling of region checking when type errors are present is // handling of region checking when type errors are present is
// *terrible*. // *terrible*.
err.span_note( err.span_note(trace.cause.span,
trace.cause.span, &format!("...so that {}", trace.cause.as_requirement_str()));
&format!("...so that {}",
trace.cause.as_requirement_str()));
} }
} }
infer::Reborrow(span) => { infer::Reborrow(span) => {
err.span_note( err.span_note(span,
span, "...so that reference does not outlive borrowed content");
"...so that reference does not outlive \
borrowed content");
} }
infer::ReborrowUpvar(span, ref upvar_id) => { infer::ReborrowUpvar(span, ref upvar_id) => {
err.span_note( err.span_note(span,
span, &format!("...so that closure can access `{}`",
&format!( self.tcx
"...so that closure can access `{}`", .local_var_name_str(upvar_id.var_id)
self.tcx.local_var_name_str(upvar_id.var_id)
.to_string())); .to_string()));
} }
infer::InfStackClosure(span) => { infer::InfStackClosure(span) => {
err.span_note( err.span_note(span, "...so that closure does not outlive its stack frame");
span,
"...so that closure does not outlive its stack frame");
} }
infer::InvokeClosure(span) => { infer::InvokeClosure(span) => {
err.span_note( err.span_note(span,
span,
"...so that closure is not invoked outside its lifetime"); "...so that closure is not invoked outside its lifetime");
} }
infer::DerefPointer(span) => { infer::DerefPointer(span) => {
err.span_note( err.span_note(span,
span, "...so that pointer is not dereferenced outside its lifetime");
"...so that pointer is not dereferenced \
outside its lifetime");
} }
infer::FreeVariable(span, id) => { infer::FreeVariable(span, id) => {
err.span_note( err.span_note(span,
span, &format!("...so that captured variable `{}` does not outlive the \
&format!("...so that captured variable `{}` \ enclosing closure",
does not outlive the enclosing closure",
self.tcx.local_var_name_str(id))); self.tcx.local_var_name_str(id)));
} }
infer::IndexSlice(span) => { infer::IndexSlice(span) => {
err.span_note( err.span_note(span, "...so that slice is not indexed outside the lifetime");
span,
"...so that slice is not indexed outside the lifetime");
} }
infer::RelateObjectBound(span) => { infer::RelateObjectBound(span) => {
err.span_note( err.span_note(span, "...so that it can be closed over into an object");
span,
"...so that it can be closed over into an object");
} }
infer::CallRcvr(span) => { infer::CallRcvr(span) => {
err.span_note( err.span_note(span,
span,
"...so that method receiver is valid for the method call"); "...so that method receiver is valid for the method call");
} }
infer::CallArg(span) => { infer::CallArg(span) => {
err.span_note( err.span_note(span, "...so that argument is valid for the call");
span,
"...so that argument is valid for the call");
} }
infer::CallReturn(span) => { infer::CallReturn(span) => {
err.span_note( err.span_note(span, "...so that return value is valid for the call");
span,
"...so that return value is valid for the call");
} }
infer::Operand(span) => { infer::Operand(span) => {
err.span_note( err.span_note(span, "...so that operand is valid for operation");
span,
"...so that operand is valid for operation");
} }
infer::AddrOf(span) => { infer::AddrOf(span) => {
err.span_note( err.span_note(span, "...so that reference is valid at the time of borrow");
span,
"...so that reference is valid \
at the time of borrow");
} }
infer::AutoBorrow(span) => { infer::AutoBorrow(span) => {
err.span_note( err.span_note(span,
span, "...so that auto-reference is valid at the time of borrow");
"...so that auto-reference is valid \
at the time of borrow");
} }
infer::ExprTypeIsNotInScope(t, span) => { infer::ExprTypeIsNotInScope(t, span) => {
err.span_note( err.span_note(span,
span,
&format!("...so type `{}` of expression is valid during the \ &format!("...so type `{}` of expression is valid during the \
expression", expression",
self.ty_to_string(t))); self.ty_to_string(t)));
} }
infer::BindingTypeIsNotValidAtDecl(span) => { infer::BindingTypeIsNotValidAtDecl(span) => {
err.span_note( err.span_note(span,
span,
"...so that variable is valid at time of its declaration"); "...so that variable is valid at time of its declaration");
} }
infer::ParameterInScope(_, span) => { infer::ParameterInScope(_, span) => {
err.span_note( err.span_note(span,
span,
"...so that a type/lifetime parameter is in scope here"); "...so that a type/lifetime parameter is in scope here");
} }
infer::DataBorrowed(ty, span) => { infer::DataBorrowed(ty, span) => {
err.span_note( err.span_note(span,
span,
&format!("...so that the type `{}` is not borrowed for too long", &format!("...so that the type `{}` is not borrowed for too long",
self.ty_to_string(ty))); self.ty_to_string(ty)));
} }
infer::ReferenceOutlivesReferent(ty, span) => { infer::ReferenceOutlivesReferent(ty, span) => {
err.span_note( err.span_note(span,
span, &format!("...so that the reference type `{}` does not outlive the \
&format!("...so that the reference type `{}` \ data it points at",
does not outlive the data it points at",
self.ty_to_string(ty))); self.ty_to_string(ty)));
} }
infer::RelateParamBound(span, t) => { infer::RelateParamBound(span, t) => {
err.span_note( err.span_note(span,
span, &format!("...so that the type `{}` will meet its required \
&format!("...so that the type `{}` \ lifetime bounds",
will meet its required lifetime bounds",
self.ty_to_string(t))); self.ty_to_string(t)));
} }
infer::RelateDefaultParamBound(span, t) => { infer::RelateDefaultParamBound(span, t) => {
err.span_note( err.span_note(span,
span, &format!("...so that type parameter instantiated with `{}`, will \
&format!("...so that type parameter \ meet its declared lifetime bounds",
instantiated with `{}`, \
will meet its declared lifetime bounds",
self.ty_to_string(t))); self.ty_to_string(t)));
} }
infer::RelateRegionParamBound(span) => { infer::RelateRegionParamBound(span) => {
err.span_note( err.span_note(span,
span, "...so that the declared lifetime parameter bounds are satisfied");
"...so that the declared lifetime parameter bounds \
are satisfied");
} }
infer::SafeDestructor(span) => { infer::SafeDestructor(span) => {
err.span_note( err.span_note(span,
span, "...so that references are valid when the destructor runs");
"...so that references are valid when the destructor \
runs");
} }
infer::CompareImplMethodObligation { span, .. } => { infer::CompareImplMethodObligation { span, .. } => {
err.span_note( err.span_note(span,
span, "...so that the definition in impl matches the definition from the \
"...so that the definition in impl matches the definition from the trait"); trait");
} }
} }
} }
@ -189,9 +153,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
self.report_and_explain_type_error(trace, &terr) self.report_and_explain_type_error(trace, &terr)
} }
infer::Reborrow(span) => { infer::Reborrow(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0312, let mut err = struct_span_err!(self.tcx.sess,
"lifetime of reference outlives \ span,
lifetime of borrowed content..."); E0312,
"lifetime of reference outlives lifetime of \
borrowed content...");
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err,
"...the reference is valid for ", "...the reference is valid for ",
sub, sub,
@ -203,83 +169,84 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err err
} }
infer::ReborrowUpvar(span, ref upvar_id) => { infer::ReborrowUpvar(span, ref upvar_id) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0313, let mut err = struct_span_err!(self.tcx.sess,
"lifetime of borrowed pointer outlives \ span,
lifetime of captured variable `{}`...", E0313,
"lifetime of borrowed pointer outlives lifetime \
of captured variable `{}`...",
self.tcx.local_var_name_str(upvar_id.var_id)); self.tcx.local_var_name_str(upvar_id.var_id));
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err,
"...the borrowed pointer is valid for ", "...the borrowed pointer is valid for ",
sub, sub,
"..."); "...");
self.tcx.note_and_explain_region(&mut err, self.tcx
.note_and_explain_region(&mut err,
&format!("...but `{}` is only valid for ", &format!("...but `{}` is only valid for ",
self.tcx.local_var_name_str(upvar_id.var_id)), self.tcx
.local_var_name_str(upvar_id.var_id)),
sup, sup,
""); "");
err err
} }
infer::InfStackClosure(span) => { infer::InfStackClosure(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0314, let mut err =
"closure outlives stack frame"); struct_span_err!(self.tcx.sess, span, E0314, "closure outlives stack frame");
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err,
"...the closure must be valid for ", "...the closure must be valid for ",
sub, sub,
"..."); "...");
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err,
"...but the closure's stack frame is only valid for ", "...but the closure's stack frame is only valid \
for ",
sup, sup,
""); "");
err err
} }
infer::InvokeClosure(span) => { infer::InvokeClosure(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0315, let mut err = struct_span_err!(self.tcx.sess,
span,
E0315,
"cannot invoke closure outside of its lifetime"); "cannot invoke closure outside of its lifetime");
self.tcx.note_and_explain_region(&mut err, self.tcx
"the closure is only valid for ", .note_and_explain_region(&mut err, "the closure is only valid for ", sup, "");
sup,
"");
err err
} }
infer::DerefPointer(span) => { infer::DerefPointer(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0473, let mut err = struct_span_err!(self.tcx.sess,
span,
E0473,
"dereference of reference outside its lifetime"); "dereference of reference outside its lifetime");
self.tcx.note_and_explain_region(&mut err, self.tcx
"the reference is only valid for ", .note_and_explain_region(&mut err, "the reference is only valid for ", sup, "");
sup,
"");
err err
} }
infer::FreeVariable(span, id) => { infer::FreeVariable(span, id) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0474, let mut err = struct_span_err!(self.tcx.sess,
"captured variable `{}` does not outlive the enclosing closure", span,
E0474,
"captured variable `{}` does not outlive the \
enclosing closure",
self.tcx.local_var_name_str(id)); self.tcx.local_var_name_str(id));
self.tcx.note_and_explain_region(&mut err, self.tcx
"captured variable is valid for ", .note_and_explain_region(&mut err, "captured variable is valid for ", sup, "");
sup, self.tcx.note_and_explain_region(&mut err, "closure is valid for ", sub, "");
"");
self.tcx.note_and_explain_region(&mut err,
"closure is valid for ",
sub,
"");
err err
} }
infer::IndexSlice(span) => { infer::IndexSlice(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0475, let mut err = struct_span_err!(self.tcx.sess,
span,
E0475,
"index of slice outside its lifetime"); "index of slice outside its lifetime");
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err, "the slice is only valid for ", sup, "");
"the slice is only valid for ",
sup,
"");
err err
} }
infer::RelateObjectBound(span) => { infer::RelateObjectBound(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0476, let mut err = struct_span_err!(self.tcx.sess,
span,
E0476,
"lifetime of the source pointer does not outlive \ "lifetime of the source pointer does not outlive \
lifetime bound of the object type"); lifetime bound of the object type");
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err, "object type is valid for ", sub, "");
"object type is valid for ",
sub,
"");
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err,
"source pointer is only valid for ", "source pointer is only valid for ",
sup, sup,
@ -287,18 +254,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err err
} }
infer::RelateParamBound(span, ty) => { infer::RelateParamBound(span, ty) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0477, let mut err = struct_span_err!(self.tcx.sess,
"the type `{}` does not fulfill the required lifetime", span,
E0477,
"the type `{}` does not fulfill the required \
lifetime",
self.ty_to_string(ty)); self.ty_to_string(ty));
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err, "type must outlive ", sub, "");
"type must outlive ",
sub,
"");
err err
} }
infer::RelateRegionParamBound(span) => { infer::RelateRegionParamBound(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0478, let mut err =
"lifetime bound not satisfied"); struct_span_err!(self.tcx.sess, span, E0478, "lifetime bound not satisfied");
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err,
"lifetime parameter instantiated with ", "lifetime parameter instantiated with ",
sup, sup,
@ -310,28 +277,29 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err err
} }
infer::RelateDefaultParamBound(span, ty) => { infer::RelateDefaultParamBound(span, ty) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0479, let mut err = struct_span_err!(self.tcx.sess,
"the type `{}` (provided as the value of \ span,
a type parameter) is not valid at this point", E0479,
"the type `{}` (provided as the value of a type \
parameter) is not valid at this point",
self.ty_to_string(ty)); self.ty_to_string(ty));
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err, "type must outlive ", sub, "");
"type must outlive ",
sub,
"");
err err
} }
infer::CallRcvr(span) => { infer::CallRcvr(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0480, let mut err = struct_span_err!(self.tcx.sess,
"lifetime of method receiver does not outlive \ span,
the method call"); E0480,
self.tcx.note_and_explain_region(&mut err, "lifetime of method receiver does not outlive the \
"the receiver is only valid for ", method call");
sup, self.tcx
""); .note_and_explain_region(&mut err, "the receiver is only valid for ", sup, "");
err err
} }
infer::CallArg(span) => { infer::CallArg(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0481, let mut err = struct_span_err!(self.tcx.sess,
span,
E0481,
"lifetime of function argument does not outlive \ "lifetime of function argument does not outlive \
the function call"); the function call");
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err,
@ -341,9 +309,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err err
} }
infer::CallReturn(span) => { infer::CallReturn(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0482, let mut err = struct_span_err!(self.tcx.sess,
"lifetime of return value does not outlive \ span,
the function call"); E0482,
"lifetime of return value does not outlive the \
function call");
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err,
"the return value is only valid for ", "the return value is only valid for ",
sup, sup,
@ -351,28 +321,30 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err err
} }
infer::Operand(span) => { infer::Operand(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0483, let mut err = struct_span_err!(self.tcx.sess,
"lifetime of operand does not outlive \ span,
the operation"); E0483,
self.tcx.note_and_explain_region(&mut err, "lifetime of operand does not outlive the \
"the operand is only valid for ", operation");
sup, self.tcx
""); .note_and_explain_region(&mut err, "the operand is only valid for ", sup, "");
err err
} }
infer::AddrOf(span) => { infer::AddrOf(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0484, let mut err = struct_span_err!(self.tcx.sess,
span,
E0484,
"reference is not valid at the time of borrow"); "reference is not valid at the time of borrow");
self.tcx.note_and_explain_region(&mut err, self.tcx
"the borrow is only valid for ", .note_and_explain_region(&mut err, "the borrow is only valid for ", sup, "");
sup,
"");
err err
} }
infer::AutoBorrow(span) => { infer::AutoBorrow(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0485, let mut err = struct_span_err!(self.tcx.sess,
"automatically reference is not valid \ span,
at the time of borrow"); E0485,
"automatically reference is not valid at the time \
of borrow");
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err,
"the automatic borrow is only valid for ", "the automatic borrow is only valid for ",
sup, sup,
@ -380,51 +352,49 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err err
} }
infer::ExprTypeIsNotInScope(t, span) => { infer::ExprTypeIsNotInScope(t, span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0486, let mut err = struct_span_err!(self.tcx.sess,
"type of expression contains references \ span,
that are not valid during the expression: `{}`", E0486,
"type of expression contains references that are \
not valid during the expression: `{}`",
self.ty_to_string(t)); self.ty_to_string(t));
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err, "type is only valid for ", sup, "");
"type is only valid for ",
sup,
"");
err err
} }
infer::SafeDestructor(span) => { infer::SafeDestructor(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0487, let mut err = struct_span_err!(self.tcx.sess,
"unsafe use of destructor: destructor might be called \ span,
while references are dead"); E0487,
"unsafe use of destructor: destructor might be \
called while references are dead");
// FIXME (22171): terms "super/subregion" are suboptimal // FIXME (22171): terms "super/subregion" are suboptimal
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err, "superregion: ", sup, "");
"superregion: ", self.tcx.note_and_explain_region(&mut err, "subregion: ", sub, "");
sup,
"");
self.tcx.note_and_explain_region(&mut err,
"subregion: ",
sub,
"");
err err
} }
infer::BindingTypeIsNotValidAtDecl(span) => { infer::BindingTypeIsNotValidAtDecl(span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0488, let mut err = struct_span_err!(self.tcx.sess,
"lifetime of variable does not enclose its declaration"); span,
self.tcx.note_and_explain_region(&mut err, E0488,
"the variable is only valid for ", "lifetime of variable does not enclose its \
sup, declaration");
""); self.tcx
.note_and_explain_region(&mut err, "the variable is only valid for ", sup, "");
err err
} }
infer::ParameterInScope(_, span) => { infer::ParameterInScope(_, span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0489, let mut err = struct_span_err!(self.tcx.sess,
span,
E0489,
"type/lifetime parameter not in scope here"); "type/lifetime parameter not in scope here");
self.tcx.note_and_explain_region(&mut err, self.tcx
"the parameter is only valid for ", .note_and_explain_region(&mut err, "the parameter is only valid for ", sub, "");
sub,
"");
err err
} }
infer::DataBorrowed(ty, span) => { infer::DataBorrowed(ty, span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0490, let mut err = struct_span_err!(self.tcx.sess,
span,
E0490,
"a value of type `{}` is borrowed for too long", "a value of type `{}` is borrowed for too long",
self.ty_to_string(ty)); self.ty_to_string(ty));
self.tcx.note_and_explain_region(&mut err, "the type is valid for ", sub, ""); self.tcx.note_and_explain_region(&mut err, "the type is valid for ", sub, "");
@ -432,27 +402,24 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err err
} }
infer::ReferenceOutlivesReferent(ty, span) => { infer::ReferenceOutlivesReferent(ty, span) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0491, let mut err = struct_span_err!(self.tcx.sess,
span,
E0491,
"in type `{}`, reference has a longer lifetime \ "in type `{}`, reference has a longer lifetime \
than the data it references", than the data it references",
self.ty_to_string(ty)); self.ty_to_string(ty));
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err, "the pointer is valid for ", sub, "");
"the pointer is valid for ",
sub,
"");
self.tcx.note_and_explain_region(&mut err, self.tcx.note_and_explain_region(&mut err,
"but the referenced data is only valid for ", "but the referenced data is only valid for ",
sup, sup,
""); "");
err err
} }
infer::CompareImplMethodObligation { infer::CompareImplMethodObligation { span,
span,
item_name, item_name,
impl_item_def_id, impl_item_def_id,
trait_item_def_id, trait_item_def_id,
lint_id lint_id } => {
} => {
self.report_extra_impl_obligation(span, self.report_extra_impl_obligation(span,
item_name, item_name,
impl_item_def_id, impl_item_def_id,