Skip to content

Commit

Permalink
explain_borrow bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyJado committed Sep 1, 2022
1 parent 422fde3 commit c770ac0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
16 changes: 8 additions & 8 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rustc_span::symbol::{kw, Symbol};
use rustc_span::{sym, DesugaringKind, Span};

use crate::region_infer::BlameConstraint;
use crate::session_diagnostics::RequireBorrowLasts;
use crate::{
borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt,
WriteKind,
Expand Down Expand Up @@ -257,15 +258,14 @@ impl<'tcx> BorrowExplanation<'tcx> {
),
);
} else {
err.span_label(
//FIXME: src/test/ui/consts/const-eval/const-eval-intrinsic-promotion.rs
let sub_label = RequireBorrowLasts::Lasts {
category: category.description(),
borrow_desc,
region_name,
span,
format!(
"{}requires that {}borrow lasts for `{}`",
category.description(),
borrow_desc,
region_name,
),
);
};
err.subdiagnostic(sub_label);
};

self.add_lifetime_bound_suggestion_to_diagnostic(err, &category, span, region_name);
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_borrowck/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,15 @@ pub(crate) enum RegionNameLables {
span: Span,
},
}

#[derive(SessionSubdiagnostic)]
pub(crate) enum RequireBorrowLasts<'a> {
#[label(borrowck::outlive_constraint_need_borrow_lasts_for)]
Lasts {
category: &'a str,
borrow_desc: &'a str,
region_name: &'a RegionName,
#[primary_span]
span: Span,
},
}
3 changes: 3 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/borrowck.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ borrowck_used_impl_require_static =
borrowck_lifetime_defined_here =
lifetime `{$rg_name}` defined here
borrowck_outlive_constraint_need_borrow_lasts_for =
{$category}requires that `{$borrow_desc}` lasts for `{$region_name}`

0 comments on commit c770ac0

Please sign in to comment.