- err_out_of_scope(super_scope, sub_scope) => {
- self.tcx.note_and_explain_region(
- db,
- "reference must be valid for ",
- sub_scope,
- "...");
- self.tcx.note_and_explain_region(
- db,
- "...but borrowed value is only valid for ",
- super_scope,
- "");
+ err_out_of_scope(super_scope, sub_scope, cause) => {
+ match cause {
+ euv::ClosureCapture(s) => {
+ match db.span.primary_span() {
+ Some(primary) => {
+ db.span = MultiSpan::from_span(s);
+ db.span_label(primary, &format!("capture occurs here"));
+ db.span_label(s, &format!("does not live long enough"));
+ }
+ None => ()
+ }
+ }
+ _ => {
+ db.span_label(error_span, &format!("does not live long enough"));
+ }
+ }
+
+ let sub_span = self.convert_region_to_span(sub_scope);
+ let super_span = self.convert_region_to_span(super_scope);
+
+ match (sub_span, super_span) {
+ (Some(s1), Some(s2)) if s1 == s2 => {
+ db.span_label(s1, &"borrowed value dropped before borrower");
+ db.note("values in a scope are dropped in the opposite order \
+ they are created");
+ }
+ _ => {
+ match sub_span {
+ Some(s) => {
+ db.span_label(s, &"borrowed value must be valid until here");
+ }
+ None => {
+ self.tcx.note_and_explain_region(
+ db,
+ "borrowed value must be valid for ",
+ sub_scope,
+ "...");
+ }
+ }
+ match super_span {
+ Some(s) => {
+ db.span_label(s, &"borrowed value only valid until here");
+ }
+ None => {
+ self.tcx.note_and_explain_region(
+ db,
+ "...but borrowed value is only valid for ",
+ super_scope,
+ "");
+ }
+ }
+ }
+ }
+