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 0125528

Browse files
authoredOct 9, 2023
Rollup merge of rust-lang#115882 - aliemjay:diag-name-region-1, r=compiler-errors
improve the suggestion of `generic_bound_failure` - Fixes rust-lang#115375 - suggest the bound in the correct scope: trait or impl header vs assoc item. See `tests/ui/suggestions/lifetimes/type-param-bound-scope.rs` - don't suggest a lifetime name that conflicts with the other late-bound regions of the function: ```rust type Inv<'a> = *mut &'a (); fn check_bound<'a, T: 'a>(_: T, _: Inv<'a>) {} fn test<'a, T>(_: &'a str, t: T, lt: Inv<'_>) { // suggests a new name `'a` check_bound(t, lt); //~ ERROR } ```
2 parents 7ed044c + a883063 commit 0125528

File tree

82 files changed

+1172
-737
lines changed

Some content is hidden

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

82 files changed

+1172
-737
lines changed
 

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

+198-310
Large diffs are not rendered by default.

‎compiler/rustc_middle/src/ty/context.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -1057,24 +1057,29 @@ impl<'tcx> TyCtxt<'tcx> {
10571057
}
10581058

10591059
/// Returns the `DefId` and the `BoundRegionKind` corresponding to the given region.
1060-
pub fn is_suitable_region(self, region: Region<'tcx>) -> Option<FreeRegionInfo> {
1061-
let (suitable_region_binding_scope, bound_region) = match *region {
1062-
ty::ReFree(ref free_region) => {
1063-
(free_region.scope.expect_local(), free_region.bound_region)
1060+
pub fn is_suitable_region(self, mut region: Region<'tcx>) -> Option<FreeRegionInfo> {
1061+
let (suitable_region_binding_scope, bound_region) = loop {
1062+
let def_id = match region.kind() {
1063+
ty::ReFree(fr) => fr.bound_region.get_id()?.as_local()?,
1064+
ty::ReEarlyBound(ebr) => ebr.def_id.expect_local(),
1065+
_ => return None, // not a free region
1066+
};
1067+
let scope = self.local_parent(def_id);
1068+
if self.def_kind(scope) == DefKind::OpaqueTy {
1069+
// Lifetime params of opaque types are synthetic and thus irrelevant to
1070+
// diagnostics. Map them back to their origin!
1071+
region = self.map_rpit_lifetime_to_fn_lifetime(def_id);
1072+
continue;
10641073
}
1065-
ty::ReEarlyBound(ref ebr) => (
1066-
self.local_parent(ebr.def_id.expect_local()),
1067-
ty::BoundRegionKind::BrNamed(ebr.def_id, ebr.name),
1068-
),
1069-
_ => return None, // not a free region
1074+
break (scope, ty::BrNamed(def_id.into(), self.item_name(def_id.into())));
10701075
};
10711076

10721077
let is_impl_item = match self.hir().find_by_def_id(suitable_region_binding_scope) {
10731078
Some(Node::Item(..) | Node::TraitItem(..)) => false,
10741079
Some(Node::ImplItem(..)) => {
10751080
self.is_bound_region_in_impl_item(suitable_region_binding_scope)
10761081
}
1077-
_ => return None,
1082+
_ => false,
10781083
};
10791084

10801085
Some(FreeRegionInfo {

0 commit comments

Comments
 (0)
Please sign in to comment.