Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5cdab3a

Browse files
committedApr 24, 2022
Auto merge of rust-lang#96363 - matthiaskrgr:rollup-mthdja5, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#94893 (diagnostics: regression test for `<usize as Iterator>::rev`) - rust-lang#95504 (Add `x {check,build,doc} {compiler,library}` aliases.) - rust-lang#96237 (compiletest: combine `--*-python` args) - rust-lang#96303 (Improve bootstrap tests) - rust-lang#96352 (Improve span for `consider adding an explicit lifetime bound` suggestions under NLL) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d8e59ed + aef9eb5 commit 5cdab3a

File tree

45 files changed

+400
-287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+400
-287
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed
44
use rustc_infer::infer::{
55
error_reporting::nice_region_error::NiceRegionError,
66
error_reporting::unexpected_hidden_region_diagnostic, NllRegionVariableOrigin,
7+
RelateParamBound,
78
};
89
use rustc_middle::hir::place::PlaceBase;
910
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
@@ -166,11 +167,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
166167
let type_test_span = type_test.locations.span(&self.body);
167168

168169
if let Some(lower_bound_region) = lower_bound_region {
170+
let generic_ty = type_test.generic_kind.to_ty(self.infcx.tcx);
171+
let origin = RelateParamBound(type_test_span, generic_ty, None);
169172
self.buffer_error(self.infcx.construct_generic_bound_failure(
170173
type_test_span,
171-
None,
174+
Some(origin),
172175
type_test.generic_kind,
173176
lower_bound_region,
177+
self.body.source.def_id().as_local(),
174178
));
175179
} else {
176180
// FIXME. We should handle this case better. It

‎compiler/rustc_infer/src/infer/error_reporting/mod.rs

+25-28
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
6161
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed};
6262
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString, MultiSpan};
6363
use rustc_hir as hir;
64-
use rustc_hir::def_id::DefId;
64+
use rustc_hir::def_id::{DefId, LocalDefId};
6565
use rustc_hir::lang_items::LangItem;
6666
use rustc_hir::{Item, ItemKind, Node};
6767
use rustc_middle::dep_graph::DepContext;
@@ -2285,7 +2285,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
22852285
bound_kind: GenericKind<'tcx>,
22862286
sub: Region<'tcx>,
22872287
) {
2288-
self.construct_generic_bound_failure(span, origin, bound_kind, sub).emit();
2288+
let owner =
2289+
self.in_progress_typeck_results.map(|typeck_results| typeck_results.borrow().hir_owner);
2290+
self.construct_generic_bound_failure(span, origin, bound_kind, sub, owner).emit();
22892291
}
22902292

22912293
pub fn construct_generic_bound_failure(
@@ -2294,31 +2296,29 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
22942296
origin: Option<SubregionOrigin<'tcx>>,
22952297
bound_kind: GenericKind<'tcx>,
22962298
sub: Region<'tcx>,
2299+
owner: Option<LocalDefId>,
22972300
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
22982301
let hir = self.tcx.hir();
22992302
// Attempt to obtain the span of the parameter so we can
23002303
// suggest adding an explicit lifetime bound to it.
2301-
let generics = self
2302-
.in_progress_typeck_results
2303-
.map(|typeck_results| typeck_results.borrow().hir_owner)
2304-
.map(|owner| {
2305-
let hir_id = hir.local_def_id_to_hir_id(owner);
2306-
let parent_id = hir.get_parent_item(hir_id);
2307-
(
2308-
// Parent item could be a `mod`, so we check the HIR before calling:
2309-
if let Some(Node::Item(Item {
2310-
kind: ItemKind::Trait(..) | ItemKind::Impl { .. },
2311-
..
2312-
})) = hir.find_by_def_id(parent_id)
2313-
{
2314-
Some(self.tcx.generics_of(parent_id))
2315-
} else {
2316-
None
2317-
},
2318-
self.tcx.generics_of(owner.to_def_id()),
2319-
hir.span(hir_id),
2320-
)
2321-
});
2304+
let generics = owner.map(|owner| {
2305+
let hir_id = hir.local_def_id_to_hir_id(owner);
2306+
let parent_id = hir.get_parent_item(hir_id);
2307+
(
2308+
// Parent item could be a `mod`, so we check the HIR before calling:
2309+
if let Some(Node::Item(Item {
2310+
kind: ItemKind::Trait(..) | ItemKind::Impl { .. },
2311+
..
2312+
})) = hir.find_by_def_id(parent_id)
2313+
{
2314+
Some(self.tcx.generics_of(parent_id))
2315+
} else {
2316+
None
2317+
},
2318+
self.tcx.generics_of(owner.to_def_id()),
2319+
hir.span(hir_id),
2320+
)
2321+
});
23222322

23232323
let span = match generics {
23242324
// This is to get around the trait identity obligation, that has a `DUMMY_SP` as signal
@@ -2606,11 +2606,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
26062606
None,
26072607
);
26082608
if let Some(infer::RelateParamBound(_, t, _)) = origin {
2609-
let return_impl_trait = self
2610-
.in_progress_typeck_results
2611-
.map(|typeck_results| typeck_results.borrow().hir_owner)
2612-
.and_then(|owner| self.tcx.return_type_impl_trait(owner))
2613-
.is_some();
2609+
let return_impl_trait =
2610+
owner.and_then(|owner| self.tcx.return_type_impl_trait(owner)).is_some();
26142611
let t = self.resolve_vars_if_possible(t);
26152612
match t.kind() {
26162613
// We've got:

0 commit comments

Comments
 (0)
Please sign in to comment.