Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
04c0fa5
hir-ty: walk container exprs for unused_must_use
MavenRain Jun 7, 2026
d96d687
Support Cargo 1.97.0 lockfile path setting
ChayimFriedman2 Jun 30, 2026
c3add6e
misc improvements
ada4a Jun 28, 2026
41b216e
turn queries into methods on `MacroCallId`
ada4a Jul 2, 2026
6645218
turn queries into methods on `HirFileId`
ada4a Jul 2, 2026
9566dad
reproduction of miscompilation
dingxiangfei2009 Jun 30, 2026
f0f0a3d
internal: log when cache priming completes on startup
tilladam Jun 19, 2026
f3402e5
internal: address cache priming review feedback
tilladam Jul 5, 2026
401dc21
fix remapping in indexing and self-assignments
dingxiangfei2009 Jul 1, 2026
74c99d9
Document NonNull layout guarantees
0xEgao Jun 23, 2026
0b521ee
internal: Remove dead struct field
Wilfred Jul 6, 2026
4eb9f54
Merge pull request #22728 from Wilfred/unused_docs_field
ChayimFriedman2 Jul 6, 2026
b587ba0
Add do_not_recommend test
mejrs Jul 6, 2026
21b1c6f
Merge pull request #22581 from tilladam/internal/startup-time-to-ready
ChayimFriedman2 Jul 6, 2026
f8b1950
Merge pull request #22719 from ada4a/unquerygroup-macro_call_id-and-h…
Veykril Jul 7, 2026
8b2330e
misc improvements
ada4a Jul 4, 2026
2e58a75
adjust existing uses of `*span_map` queries
ada4a Jul 4, 2026
2987fc9
migrate `ExpandDatabase::*span_map` queries
ada4a Jul 6, 2026
c01e2d3
Merge pull request #22729 from ada4a/unquerygroup-span_map
ChayimFriedman2 Jul 7, 2026
ee33800
Fix proc macros `TokenStream::from_str()` for doc comments
ChayimFriedman2 Jul 7, 2026
325cfdc
Change some things for `#[doc = macro!()]` expansion
ChayimFriedman2 Jun 27, 2026
8627859
internal: some string alloc perf
A4-Tacks Jun 6, 2026
b9735cf
fix: pretty assoc const when trait in macro
A4-Tacks Jun 6, 2026
c7e3f0f
fix: avoid panic in merge imports on trailing path separator
edragain2nd Jul 7, 2026
571d721
misc improvements
ada4a Jul 7, 2026
c657dd4
reduce uses of `hir_expand::db::expand_speculative`
ada4a Jul 7, 2026
3af3197
internal: make `expand_speculative` a method on `MacroCallId`
ada4a Jul 7, 2026
0360ac7
Merge pull request #22733 from ada4a/push-knkslvrorrnk
ChayimFriedman2 Jul 8, 2026
340b9b1
migrate `ExpandDatabase::resolve_span`
ada4a Jul 7, 2026
5aff04a
rm `ExpandDatabase::macro_expander` and hence `TokenExpander`
ada4a Jul 7, 2026
8c35922
migrate `ExpandDatabase::decl_macro_expander`
ada4a Jul 7, 2026
73d9357
rm `ExpandDatabase`
ada4a Jul 8, 2026
550ebe5
Merge pull request #22739 from ada4a/unquerygroup-expanddatabase
ChayimFriedman2 Jul 8, 2026
ec4462a
internal: simplify `fn_macro::register_builtin!`
ada4a Jul 3, 2026
5e7d7fb
Merge pull request #22717 from ada4a/push-qnvtxrzymspn
Veykril Jul 8, 2026
60cfd3c
Merge pull request #22654 from ChayimFriedman2/doc-macro-recursion-limit
ChayimFriedman2 Jul 8, 2026
5c69628
suggest code action fixes produced from diagnostics under cursor with…
bend-n Jul 5, 2026
447b874
Merge pull request #22726 from bend-n/pr2
ChayimFriedman2 Jul 8, 2026
ef08060
misc improvements
ada4a Jul 8, 2026
15f86ee
move `FindPathConfig` to `find_path.rs`
ada4a Jul 8, 2026
34a250b
Merge pull request #22742 from ada4a/push-uqokpmlponwx
ChayimFriedman2 Jul 8, 2026
60aa191
Pretty-print user self types too.
cjgillot Jun 23, 2026
1c85606
Bump gen-lsp-types to v0.10.0
ribru17 Jun 24, 2026
b9fe7dd
Don't suggest ..Default::default in default impl
detrumi Jul 9, 2026
064c144
internal: remove `cycle_{fn,initial}` support from `#[query_group]`
ada4a Jul 8, 2026
c4abfb4
misc improvements
ada4a Jul 8, 2026
bef8bf7
migrate `DefDatabase::macro_def`
ada4a Jul 8, 2026
caa7195
migrate `DefDatabase::assoc_visibility`
ada4a Jul 8, 2026
68bf3b8
rm `DefDatabase::crate_supports_no_std`
ada4a Jul 8, 2026
d5ddb42
migrate `DefDatabase::file_item_tree`
ada4a Jul 8, 2026
420d173
migrate `DefDatabase::crate_notable_traits`
ada4a Jul 8, 2026
c3fe319
migrate `DefDatabase::include_macro_invoc`
ada4a Jul 8, 2026
e01ce1c
move `ExpandProcAttrMacros` to `lib.rs`
ada4a Jul 8, 2026
04e9daf
rm `DefDatabase`
ada4a Jul 8, 2026
01128e6
Merge pull request #22746 from ada4a/unquerygroup-cycle
Veykril Jul 9, 2026
9be9239
Merge pull request #22744 from detrumi/default-completion-in-own-impl
Veykril Jul 9, 2026
8fa6546
Merge pull request #22745 from ada4a/unquerygroup-defdatabase
Veykril Jul 9, 2026
eaa142c
Remove unused tokens helper methods along with last reminents to clon…
Shourya742 Jul 9, 2026
e213d96
fix: Crash on code actions when an unresolved module is present
Wilfred Jul 9, 2026
8e98aa2
Fix 1.97.0 Clippy
ChayimFriedman2 Jul 9, 2026
e770493
Merge pull request #22750 from ChayimFriedman2/fix-clippy
ChayimFriedman2 Jul 9, 2026
9135016
Merge pull request #22736 from edragain2nd/fix_merge_import
ChayimFriedman2 Jul 9, 2026
b9abffb
Merge pull request #22748 from Shourya742/2026-07-09-remove-redundant…
ChayimFriedman2 Jul 9, 2026
f82c8f9
fix: Crash on MIR lowering for out-of-range tuple access
Wilfred Jul 3, 2026
226edba
fix: MIR projection crash on tuple destructuring with type aliases
Wilfred Jul 3, 2026
bc5e5be
Merge pull request #22707 from Wilfred/mir_crash_projection
ChayimFriedman2 Jul 9, 2026
7b155bf
Merge pull request #22749 from Wilfred/fix-generate-function-unresolv…
ChayimFriedman2 Jul 9, 2026
f41b9b5
Correctly handled cfg'ed tail expr, take 2
ChayimFriedman2 Jul 9, 2026
c725ecb
Merge pull request #22635 from ribru17/glt_bump
ChayimFriedman2 Jul 9, 2026
393f1f2
enable `do_not_recommend` attr for method call errors in current solver
mejrs Jul 9, 2026
03b474f
fix!: make lsp-server `Response` type closer aligned to JSON-RPC
ribru17 Jul 10, 2026
1a4befe
internal: match_ast macro supports guard
A4-Tacks Jul 10, 2026
21e1ee8
Merge pull request #22755 from A4-Tacks/match-ast-guard
ChayimFriedman2 Jul 10, 2026
3f53f28
Merge pull request #22751 from ChayimFriedman2/tail-cfg-v2
ShoyuVanilla Jul 10, 2026
9b8b91b
Merge pull request #22683 from ChayimFriedman2/stabilize-lockfile-path
ShoyuVanilla Jul 10, 2026
08d79a6
chore: add codegen test for issue 91010
amirHdev Jul 10, 2026
b0d0ed5
Merge pull request #22405 from MavenRain/feat-must-use-container-exprs
ChayimFriedman2 Jul 10, 2026
3cc48c7
Merge pull request #22735 from ChayimFriedman2/proc-macro-doc-comment
Veykril Jul 11, 2026
f3cd98c
Merge pull request #22753 from ribru17/response_typing
Veykril Jul 11, 2026
8c61f2f
fix: add parens in transformed dyn type in ref type
A4-Tacks Jul 8, 2026
308e86c
Move util to prec.rs and add make ty_paren()
A4-Tacks Jul 11, 2026
7d20cf8
Add ImplTraitType prec condition
A4-Tacks Jul 11, 2026
a8f0a76
internal: Use expression parsing entrypoint in `make` constructor
Veykril Jul 11, 2026
f5a24ba
Merge pull request #22741 from A4-Tacks/transform-ty-parens
Veykril Jul 11, 2026
0168999
Merge pull request #22764 from Veykril/lukaswirth/push-kmzwrkxlxpos
Veykril Jul 11, 2026
6d441fd
Merge pull request #22535 from A4-Tacks/macro-const-impl-item
Veykril Jul 11, 2026
77bce37
Rename `select_trait_candidate`
mejrs Jul 11, 2026
13fac73
internal: Share same proc-macro servers between workspaces
Veykril Jul 11, 2026
6f7f5a0
Merge pull request #22766 from Veykril/lukaswirth/push-rwmmzyuozvpl
Veykril Jul 11, 2026
efa67ae
fix: strange behavior onEnter deleting $bar solved
j-ricardo-goncalves Jul 11, 2026
e8f64cc
rustc_target: Add acquire-release to implied features of v8
taiki-e Jul 12, 2026
0a8e33a
fix: clamp cttz const-eval result to type width
qti3e Jul 12, 2026
238a0ee
Merge pull request #22770 from qti3e/p/cttz-zero
ChayimFriedman2 Jul 12, 2026
dc0ec74
fix: moved escape_snippet_bits to ide_db under SnippetEdit
j-ricardo-goncalves Jul 12, 2026
e6bad71
Merge pull request #22768 from j-ricardo-goncalves/master
ChayimFriedman2 Jul 12, 2026
844a8b9
feat: add fixes for array length for type_mismatch
A4-Tacks Jul 7, 2026
89418c2
Use Type::could_unify_with instead Type::eq
A4-Tacks Jul 12, 2026
abeb7e4
Use container's range to trigger
A4-Tacks Jul 12, 2026
bd96c8a
Merge pull request #22734 from A4-Tacks/array-len-fixes
A4-Tacks Jul 12, 2026
fb737bf
Remove the `Database` assoc type from the `Intern` & `Lookup` traits
ChayimFriedman2 Jul 13, 2026
63344e6
Merge pull request #22774 from ChayimFriedman2/intern-db
ChayimFriedman2 Jul 13, 2026
9a3aed4
borrowck: Represent 'best blame constraint' as index into `Vec<Outliv…
Enselic Jun 30, 2026
eef0fd9
Don't use `ShouldRun::crates` in `clean_crate_tree!`
Zalathar Jul 13, 2026
36559ce
Replace `ShouldRun::crates` with `crate_or_deps_filtered`
Zalathar Jul 13, 2026
6b3bc86
Avoid some useless string clones when sorting crates by name
Zalathar Jul 13, 2026
c674878
Add a case to the `multiple-tail-expr-behind-cfg.rs` test
nnethercote Jul 13, 2026
8955385
Fix typo in `attr_on_non_tail_expr`
nnethercote Jul 13, 2026
5a5d130
add regression tests
qaijuang Jun 6, 2026
6be6d75
fix relative paths in private import suggestions
qaijuang Jun 6, 2026
59a0940
address suggested nits
qaijuang Jul 11, 2026
db1ab0b
split only rustfix eligible test
qaijuang Jul 11, 2026
7e51cb2
Rollup merge of #159210 - lnicola:sync-from-ra, r=lnicola
jhpratt Jul 13, 2026
e945ea4
Rollup merge of #158655 - dingxiangfei2009:fix-remapping, r=dingxiang…
jhpratt Jul 13, 2026
c6dbaaa
Rollup merge of #159205 - Zalathar:crate-or-deps, r=jieyouxu
jhpratt Jul 13, 2026
7cc01ce
Rollup merge of #159208 - nnethercote:fix-attr_on_non_tail_expr-typo,…
jhpratt Jul 13, 2026
c8ac079
Rollup merge of #157524 - qaijuang:fix-private-import-relative-path, …
jhpratt Jul 13, 2026
063c692
Rollup merge of #158325 - 0xEgao:docs-non-null, r=RalfJung
jhpratt Jul 13, 2026
9b48049
Rollup merge of #158882 - mejrs:do_not_recommend_old_solver, r=khyperia
jhpratt Jul 13, 2026
d498abe
Rollup merge of #158982 - cjgillot:pretty-ascribe-user-ty, r=davidtwco
jhpratt Jul 13, 2026
27be0a2
Rollup merge of #159069 - amirHdev:add-codegen-test-issue-91010, r=nn…
jhpratt Jul 13, 2026
c0d7119
Rollup merge of #159163 - taiki-e:armv8-target-feature, r=davidtwco
jhpratt Jul 13, 2026
fc4cd8e
Rollup merge of #159201 - Enselic:best-blame-index, r=jieyouxu
jhpratt Jul 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 38 additions & 32 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use tracing::{debug, instrument};
use super::explain_borrow::{BorrowExplanation, LaterUseKind};
use super::{DescribePlaceOpt, RegionName, RegionNameSource, UseSpans};
use crate::borrow_set::{BorrowData, TwoPhaseActivation};
use crate::consumers::OutlivesConstraint;
use crate::diagnostics::conflict_errors::StorageDeadOrDrop::LocalStorageDead;
use crate::diagnostics::{CapturedMessageOpt, call_kind, find_all_local_uses};
use crate::{InitializationRequiringAction, MirBorrowckCtxt, WriteKind, borrowck_errors};
Expand Down Expand Up @@ -3076,40 +3077,48 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
),
(
Some(name),
BorrowExplanation::MustBeValidFor {
category:
category @ (ConstraintCategory::Return(_)
| ConstraintCategory::CallArgument(_)
| ConstraintCategory::OpaqueType),
from_closure: false,
ref region_name,
span,
..
},
) if borrow_spans.for_coroutine() || borrow_spans.for_closure() => self
.report_escaping_closure_capture(
BorrowExplanation::MustBeValidFor { ref best_blame, ref region_name, .. },
) if let OutlivesConstraint {
category:
category @ (ConstraintCategory::Return(_)
| ConstraintCategory::CallArgument(_)
| ConstraintCategory::OpaqueType),
from_closure: false,
span,
..
} = best_blame.constraint()
&& (borrow_spans.for_coroutine() || borrow_spans.for_closure()) =>
{
self.report_escaping_closure_capture(
borrow_spans,
borrow_span,
region_name,
category,
span,
*category,
*span,
&format!("`{name}`"),
"function",
),
)
}
(
name,
BorrowExplanation::MustBeValidFor {
category: ConstraintCategory::Assignment,
from_closure: false,
ref best_blame,
region_name:
RegionName {
source: RegionNameSource::AnonRegionFromUpvar(upvar_span, upvar_name),
..
},
span,
..
},
) => self.report_escaping_data(borrow_span, &name, upvar_span, upvar_name, span),
) if let OutlivesConstraint {
category: ConstraintCategory::Assignment,
from_closure: false,
span,
..
} = best_blame.constraint() =>
{
self.report_escaping_data(borrow_span, &name, upvar_span, upvar_name, *span)
}
(Some(name), explanation) => self.report_local_value_does_not_live_long_enough(
location,
&name,
Expand Down Expand Up @@ -3143,18 +3152,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
explanation: BorrowExplanation<'tcx>,
) -> Diag<'infcx> {
let borrow_span = borrow_spans.var_or_use_path_span();
if let BorrowExplanation::MustBeValidFor {
category,
span,
ref opt_place_desc,
from_closure: false,
..
} = explanation
if let BorrowExplanation::MustBeValidFor { best_blame, opt_place_desc, .. } = &explanation
&& let OutlivesConstraint { category, span, from_closure: false, .. } =
best_blame.constraint()
&& let Err(diag) = self.try_report_cannot_return_reference_to_local(
borrow,
borrow_span,
span,
category,
*span,
*category,
opt_place_desc.as_ref(),
)
{
Expand Down Expand Up @@ -3356,14 +3361,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
proper_span: Span,
explanation: BorrowExplanation<'tcx>,
) -> Diag<'infcx> {
if let BorrowExplanation::MustBeValidFor { category, span, from_closure: false, .. } =
explanation
if let BorrowExplanation::MustBeValidFor { ref best_blame, .. } = explanation
&& let OutlivesConstraint { category, span, from_closure: false, .. } =
best_blame.constraint()
{
if let Err(diag) = self.try_report_cannot_return_reference_to_local(
borrow,
proper_span,
span,
category,
*span,
*category,
None,
) {
return diag;
Expand Down
27 changes: 10 additions & 17 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::{RegionName, UseSpans, find_use};
use crate::borrow_set::BorrowData;
use crate::constraints::OutlivesConstraint;
use crate::nll::ConstraintDescription;
use crate::region_infer::{BlameConstraint, Cause};
use crate::region_infer::{BestBlame, Cause};
use crate::{MirBorrowckCtxt, WriteKind};

#[derive(Debug)]
Expand All @@ -35,12 +35,9 @@ pub(crate) enum BorrowExplanation<'tcx> {
should_note_order: bool,
},
MustBeValidFor {
category: ConstraintCategory<'tcx>,
from_closure: bool,
span: Span,
best_blame: BestBlame<'tcx>,
region_name: RegionName,
opt_place_desc: Option<String>,
path: Vec<OutlivesConstraint<'tcx>>,
},
Unexplained,
}
Expand Down Expand Up @@ -376,13 +373,13 @@ impl<'tcx> BorrowExplanation<'tcx> {
}
}
BorrowExplanation::MustBeValidFor {
category,
span,
ref best_blame,
ref region_name,
ref opt_place_desc,
from_closure: _,
ref path,
} => {
let OutlivesConstraint { category, span, .. } = *best_blame.constraint();
let path = best_blame.path();

region_name.highlight_region_name(err);

if let Some(desc) = opt_place_desc {
Expand All @@ -403,8 +400,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
);
};

cx.add_placeholder_from_predicate_note(err, &path);
cx.add_sized_or_copy_bound_info(err, category, &path);
cx.add_placeholder_from_predicate_note(err, path);
cx.add_sized_or_copy_bound_info(err, category, path);

if let ConstraintCategory::Cast {
is_raw_ptr_dyn_type_cast: _,
Expand Down Expand Up @@ -689,22 +686,18 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
// Here, under NLL: no cause was found. Under polonius: no cause was found, or a
// boring local was found, which we ignore like NLLs do to match its diagnostics.
if let Some(region) = self.regioncx.to_error_region_vid(borrow_region_vid) {
let (blame_constraint, path) = self.regioncx.best_blame_constraint(
let best_blame = self.regioncx.best_blame_constraint(
borrow_region_vid,
NllRegionVariableOrigin::FreeRegion,
region,
);
let BlameConstraint { category, from_closure, span, .. } = blame_constraint;

if let Some(region_name) = self.give_region_a_name(region) {
let opt_place_desc = self.describe_place(borrow.borrowed_place.as_ref());
BorrowExplanation::MustBeValidFor {
category,
from_closure,
span,
best_blame,
region_name,
opt_place_desc,
path,
}
} else {
debug!("Could not generate a region name");
Expand Down
21 changes: 10 additions & 11 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ use rustc_trait_selection::traits::{Obligation, ObligationCtxt};
use tracing::{debug, instrument, trace};

use super::{LIMITATION_NOTE, OutlivesSuggestionBuilder, RegionName, RegionNameSource};
use crate::consumers::RegionInferenceContext;
use crate::consumers::{OutlivesConstraint, RegionInferenceContext};
use crate::nll::ConstraintDescription;
use crate::region_infer::{BlameConstraint, TypeTest};
use crate::region_infer::TypeTest;
use crate::session_diagnostics::{
FnMutError, FnMutReturnTypeErr, GenericDoesNotLiveLongEnough, LifetimeOutliveErr,
LifetimeReturnCategoryErr, RequireStaticErr, VarHereDenote,
Expand Down Expand Up @@ -414,9 +414,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
};

// Find the code to blame for the fact that `longer_fr` outlives `error_fr`.
let (blame_constraint, path) =
self.regioncx.best_blame_constraint(longer_fr, origin_longer, error_vid);
let cause = blame_constraint.to_obligation_cause_from_path(&path);
let best_blame = self.regioncx.best_blame_constraint(longer_fr, origin_longer, error_vid);
let cause = best_blame.to_obligation_cause();

// FIXME these methods should have better names, and also probably not be this generic.
// FIXME note that we *throw away* the error element here! We probably want to
Expand Down Expand Up @@ -447,9 +446,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
) {
debug!("report_region_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);

let (blame_constraint, path) =
self.regioncx.best_blame_constraint(fr, fr_origin, outlived_fr);
let BlameConstraint { category, span, variance_info, .. } = blame_constraint;
let best_blame = self.regioncx.best_blame_constraint(fr, fr_origin, outlived_fr);
let OutlivesConstraint { category, span, variance_info, .. } = *best_blame.constraint();
let path = best_blame.path();

debug!("report_region_error: category={:?} {:?} {:?}", category, span, variance_info);

Expand Down Expand Up @@ -563,10 +562,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
}
}

self.add_placeholder_from_predicate_note(&mut diag, &path);
self.add_sized_or_copy_bound_info(&mut diag, category, &path);
self.add_placeholder_from_predicate_note(&mut diag, path);
self.add_sized_or_copy_bound_info(&mut diag, category, path);

for constraint in &path {
for constraint in path {
if let ConstraintCategory::Cast { is_raw_ptr_dyn_type_cast: true, .. } =
constraint.category
{
Expand Down
63 changes: 33 additions & 30 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,9 +1285,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
return RegionRelationCheckResult::Error;
}

let blame_constraint = self
.best_blame_constraint(longer_fr, NllRegionVariableOrigin::FreeRegion, shorter_fr)
.0;
let best_blame = self.best_blame_constraint(
longer_fr,
NllRegionVariableOrigin::FreeRegion,
shorter_fr,
);
let OutlivesConstraint { category, span, .. } = best_blame.constraint();

// Grow `shorter_fr` until we find some non-local regions.
// We will always find at least one: `'static`. We'll call
Expand Down Expand Up @@ -1346,8 +1349,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
propagated_outlives_requirements.push(ClosureOutlivesRequirement {
subject: ClosureOutlivesSubject::Region(fr_minus),
outlived_free_region: fr_plus,
blame_span: blame_constraint.span,
category: blame_constraint.category,
blame_span: *span,
category: *category,
});
}
return RegionRelationCheckResult::Propagated;
Expand Down Expand Up @@ -1614,7 +1617,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
from_region: RegionVid,
from_region_origin: NllRegionVariableOrigin<'tcx>,
to_region: RegionVid,
) -> (BlameConstraint<'tcx>, Vec<OutlivesConstraint<'tcx>>) {
) -> BestBlame<'tcx> {
assert!(from_region != to_region, "Trying to blame a region for itself!");

let path = self.constraint_path_between_regions(from_region, to_region).unwrap();
Expand Down Expand Up @@ -1787,40 +1790,34 @@ impl<'tcx> RegionInferenceContext<'tcx> {

debug!(?best_choice, ?blame_source);

let best_constraint = if let Some(next) = path.get(best_choice + 1)
let best_blame_idx = if let Some(next) = path.get(best_choice + 1)
&& matches!(path[best_choice].category, ConstraintCategory::Return(_))
&& next.category == ConstraintCategory::OpaqueType
{
// The return expression is being influenced by the return type being
// impl Trait, point at the return type and not the return expr.
*next
best_choice + 1
} else if path[best_choice].category == ConstraintCategory::Return(ReturnConstraint::Normal)
&& let Some(field) = path.iter().find_map(|p| {
if let ConstraintCategory::ClosureUpvar(f) = p.category { Some(f) } else { None }
})
{
path[best_choice].category =
ConstraintCategory::Return(ReturnConstraint::ClosureUpvar(field));
path[best_choice]
best_choice
} else {
path[best_choice]
best_choice
};

assert!(
!matches!(
best_constraint.category,
path[best_blame_idx].category,
ConstraintCategory::OutlivesUnnameablePlaceholder(_)
),
"Illegal placeholder constraint blamed; should have redirected to other region relation"
);

let blame_constraint = BlameConstraint {
category: best_constraint.category,
from_closure: best_constraint.from_closure,
span: best_constraint.span,
variance_info: best_constraint.variance_info,
};
(blame_constraint, path)
BestBlame { path, idx: best_blame_idx }
}

pub(crate) fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
Expand Down Expand Up @@ -1895,21 +1892,19 @@ impl<'tcx> RegionInferenceContext<'tcx> {
}

#[derive(Clone, Debug)]
pub(crate) struct BlameConstraint<'tcx> {
pub category: ConstraintCategory<'tcx>,
pub from_closure: bool,
pub span: Span,
pub variance_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
pub(crate) struct BestBlame<'tcx> {
/// See docs on [`RegionInferenceContext::best_blame_constraint`] for what this is.
path: Vec<OutlivesConstraint<'tcx>>,
/// Index into `path` of the constraint most relevant to report to users.
idx: usize,
}

impl<'tcx> BlameConstraint<'tcx> {
pub(crate) fn to_obligation_cause_from_path(
&self,
path: &[OutlivesConstraint<'tcx>],
) -> ObligationCause<'tcx> {
impl<'tcx> BestBlame<'tcx> {
pub(crate) fn to_obligation_cause(&self) -> ObligationCause<'tcx> {
// FIXME - determine what we should do if we encounter multiple
// `ConstraintCategory::Predicate` constraints. Currently, we just pick the first one.
let cause_code = path
let cause_code = self
.path
.iter()
.find_map(|constraint| {
if let ConstraintCategory::Predicate(predicate_span) = constraint.category {
Expand All @@ -1923,6 +1918,14 @@ impl<'tcx> BlameConstraint<'tcx> {
})
.unwrap_or_else(|| ObligationCauseCode::Misc);

ObligationCause::new(self.span, CRATE_DEF_ID, cause_code.clone())
ObligationCause::new(self.constraint().span, CRATE_DEF_ID, cause_code.clone())
}

pub(crate) fn constraint(&self) -> &OutlivesConstraint<'tcx> {
&self.path[self.idx]
}

pub(crate) fn path(&self) -> &[OutlivesConstraint<'tcx>] {
&self.path
}
}
Loading
Loading