nice_region_error: rustfmt
This commit is contained in:
parent
3720242c75
commit
a28ab84025
3 changed files with 98 additions and 83 deletions
|
@ -72,22 +72,28 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
|
|
||||||
let ty_sub = or_false!(self.find_anon_type(sub, &bregion_sub));
|
let ty_sub = or_false!(self.find_anon_type(sub, &bregion_sub));
|
||||||
|
|
||||||
debug!("try_report_anon_anon_conflict: found_arg1={:?} sup={:?} br1={:?}",
|
debug!(
|
||||||
ty_sub,
|
"try_report_anon_anon_conflict: found_arg1={:?} sup={:?} br1={:?}",
|
||||||
sup,
|
ty_sub,
|
||||||
bregion_sup);
|
sup,
|
||||||
debug!("try_report_anon_anon_conflict: found_arg2={:?} sub={:?} br2={:?}",
|
bregion_sup
|
||||||
ty_sup,
|
);
|
||||||
sub,
|
debug!(
|
||||||
bregion_sub);
|
"try_report_anon_anon_conflict: found_arg2={:?} sub={:?} br2={:?}",
|
||||||
|
ty_sup,
|
||||||
|
sub,
|
||||||
|
bregion_sub
|
||||||
|
);
|
||||||
|
|
||||||
let (ty_sup, ty_fndecl_sup) = ty_sup;
|
let (ty_sup, ty_fndecl_sup) = ty_sup;
|
||||||
let (ty_sub, ty_fndecl_sub) = ty_sub;
|
let (ty_sub, ty_fndecl_sub) = ty_sub;
|
||||||
|
|
||||||
let AnonymousArgInfo { arg: anon_arg_sup, .. } =
|
let AnonymousArgInfo {
|
||||||
or_false!(self.find_arg_with_region(sup, sup));
|
arg: anon_arg_sup, ..
|
||||||
let AnonymousArgInfo { arg: anon_arg_sub, .. } =
|
} = or_false!(self.find_arg_with_region(sup, sup));
|
||||||
or_false!(self.find_arg_with_region(sub, sub));
|
let AnonymousArgInfo {
|
||||||
|
arg: anon_arg_sub, ..
|
||||||
|
} = or_false!(self.find_arg_with_region(sub, sub));
|
||||||
|
|
||||||
let sup_is_ret_type =
|
let sup_is_ret_type =
|
||||||
self.is_return_type_anon(scope_def_id_sup, bregion_sup, ty_fndecl_sup);
|
self.is_return_type_anon(scope_def_id_sup, bregion_sup, ty_fndecl_sup);
|
||||||
|
@ -110,34 +116,45 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
let (span_1, span_2, main_label, span_label) = match (sup_is_ret_type, sub_is_ret_type) {
|
let (span_1, span_2, main_label, span_label) = match (sup_is_ret_type, sub_is_ret_type) {
|
||||||
(None, None) => {
|
(None, None) => {
|
||||||
let (main_label_1, span_label_1) = if ty_sup == ty_sub {
|
let (main_label_1, span_label_1) = if ty_sup == ty_sub {
|
||||||
|
(
|
||||||
(format!("this type is declared with multiple lifetimes..."),
|
format!("this type is declared with multiple lifetimes..."),
|
||||||
format!("...but data{} flows{} here",
|
format!(
|
||||||
format!(" with one lifetime"),
|
"...but data{} flows{} here",
|
||||||
format!(" into the other")))
|
format!(" with one lifetime"),
|
||||||
|
format!(" into the other")
|
||||||
|
),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
(format!("these two types are declared with different lifetimes..."),
|
(
|
||||||
format!("...but data{} flows{} here",
|
format!("these two types are declared with different lifetimes..."),
|
||||||
span_label_var1,
|
format!(
|
||||||
span_label_var2))
|
"...but data{} flows{} here",
|
||||||
|
span_label_var1,
|
||||||
|
span_label_var2
|
||||||
|
),
|
||||||
|
)
|
||||||
};
|
};
|
||||||
(ty_sup.span, ty_sub.span, main_label_1, span_label_1)
|
(ty_sup.span, ty_sub.span, main_label_1, span_label_1)
|
||||||
}
|
}
|
||||||
|
|
||||||
(Some(ret_span), _) => {
|
(Some(ret_span), _) => (
|
||||||
(ty_sub.span,
|
ty_sub.span,
|
||||||
ret_span,
|
ret_span,
|
||||||
format!("this parameter and the return type are declared \
|
format!(
|
||||||
with different lifetimes...",),
|
"this parameter and the return type are declared \
|
||||||
format!("...but data{} is returned here", span_label_var1))
|
with different lifetimes...",
|
||||||
}
|
),
|
||||||
(_, Some(ret_span)) => {
|
format!("...but data{} is returned here", span_label_var1),
|
||||||
(ty_sup.span,
|
),
|
||||||
ret_span,
|
(_, Some(ret_span)) => (
|
||||||
format!("this parameter and the return type are declared \
|
ty_sup.span,
|
||||||
with different lifetimes...",),
|
ret_span,
|
||||||
format!("...but data{} is returned here", span_label_var1))
|
format!(
|
||||||
}
|
"this parameter and the return type are declared \
|
||||||
|
with different lifetimes...",
|
||||||
|
),
|
||||||
|
format!("...but data{} is returned here", span_label_var1),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,4 +166,3 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ use infer::InferCtxt;
|
||||||
use ty::{self, Region};
|
use ty::{self, Region};
|
||||||
use hir::map as hir_map;
|
use hir::map as hir_map;
|
||||||
use middle::resolve_lifetime as rl;
|
use middle::resolve_lifetime as rl;
|
||||||
use hir::intravisit::{self, Visitor, NestedVisitorMap};
|
use hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||||
|
|
||||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
/// This function calls the `visit_ty` method for the parameters
|
/// This function calls the `visit_ty` method for the parameters
|
||||||
|
|
|
@ -68,17 +68,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
// i32, which is the type of y but with the anonymous region replaced
|
// i32, which is the type of y but with the anonymous region replaced
|
||||||
// with 'a, the corresponding bound region and is_first which is true if
|
// with 'a, the corresponding bound region and is_first which is true if
|
||||||
// the hir::Arg is the first argument in the function declaration.
|
// the hir::Arg is the first argument in the function declaration.
|
||||||
pub(super) fn find_arg_with_region(&self,
|
pub(super) fn find_arg_with_region(
|
||||||
anon_region: Region<'tcx>,
|
&self,
|
||||||
replace_region: Region<'tcx>)
|
anon_region: Region<'tcx>,
|
||||||
-> Option<AnonymousArgInfo> {
|
replace_region: Region<'tcx>,
|
||||||
|
) -> Option<AnonymousArgInfo> {
|
||||||
let (id, bound_region) = match *anon_region {
|
let (id, bound_region) = match *anon_region {
|
||||||
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
|
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
|
||||||
ty::ReEarlyBound(ref ebr) => {
|
ty::ReEarlyBound(ref ebr) => (
|
||||||
(self.tcx.parent_def_id(ebr.def_id).unwrap(),
|
self.tcx.parent_def_id(ebr.def_id).unwrap(),
|
||||||
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name))
|
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
|
||||||
}
|
),
|
||||||
_ => return None, // not a free region
|
_ => return None, // not a free region
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -94,21 +94,22 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
// May return None; sometimes the tables are not yet populated.
|
// May return None; sometimes the tables are not yet populated.
|
||||||
let ty = tables.borrow().node_id_to_type_opt(arg.hir_id)?;
|
let ty = tables.borrow().node_id_to_type_opt(arg.hir_id)?;
|
||||||
let mut found_anon_region = false;
|
let mut found_anon_region = false;
|
||||||
let new_arg_ty = self.tcx
|
let new_arg_ty = self.tcx.fold_regions(&ty, &mut false, |r, _| {
|
||||||
.fold_regions(&ty, &mut false, |r, _| if *r == *anon_region {
|
if *r == *anon_region {
|
||||||
found_anon_region = true;
|
found_anon_region = true;
|
||||||
replace_region
|
replace_region
|
||||||
} else {
|
} else {
|
||||||
r
|
r
|
||||||
});
|
}
|
||||||
|
});
|
||||||
if found_anon_region {
|
if found_anon_region {
|
||||||
let is_first = index == 0;
|
let is_first = index == 0;
|
||||||
Some(AnonymousArgInfo {
|
Some(AnonymousArgInfo {
|
||||||
arg: arg,
|
arg: arg,
|
||||||
arg_ty: new_arg_ty,
|
arg_ty: new_arg_ty,
|
||||||
bound_region: bound_region,
|
bound_region: bound_region,
|
||||||
is_first: is_first,
|
is_first: is_first,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -127,13 +128,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
|
|
||||||
// This method returns the DefId and the BoundRegion corresponding to the given region.
|
// This method returns the DefId and the BoundRegion corresponding to the given region.
|
||||||
pub(super) fn is_suitable_region(&self, region: Region<'tcx>) -> Option<FreeRegionInfo> {
|
pub(super) fn is_suitable_region(&self, region: Region<'tcx>) -> Option<FreeRegionInfo> {
|
||||||
|
|
||||||
let (suitable_region_binding_scope, bound_region) = match *region {
|
let (suitable_region_binding_scope, bound_region) = match *region {
|
||||||
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
|
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
|
||||||
ty::ReEarlyBound(ref ebr) => {
|
ty::ReEarlyBound(ref ebr) => (
|
||||||
(self.tcx.parent_def_id(ebr.def_id).unwrap(),
|
self.tcx.parent_def_id(ebr.def_id).unwrap(),
|
||||||
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name))
|
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
|
||||||
}
|
),
|
||||||
_ => return None, // not a free region
|
_ => return None, // not a free region
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -142,9 +142,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
.as_local_node_id(suitable_region_binding_scope)
|
.as_local_node_id(suitable_region_binding_scope)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let is_impl_item = match self.tcx.hir.find(node_id) {
|
let is_impl_item = match self.tcx.hir.find(node_id) {
|
||||||
|
Some(hir_map::NodeItem(..)) | Some(hir_map::NodeTraitItem(..)) => false,
|
||||||
Some(hir_map::NodeItem(..)) |
|
|
||||||
Some(hir_map::NodeTraitItem(..)) => false,
|
|
||||||
Some(hir_map::NodeImplItem(..)) => {
|
Some(hir_map::NodeImplItem(..)) => {
|
||||||
self.is_bound_region_in_impl_item(suitable_region_binding_scope)
|
self.is_bound_region_in_impl_item(suitable_region_binding_scope)
|
||||||
}
|
}
|
||||||
|
@ -152,21 +150,21 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
return Some(FreeRegionInfo {
|
return Some(FreeRegionInfo {
|
||||||
def_id: suitable_region_binding_scope,
|
def_id: suitable_region_binding_scope,
|
||||||
boundregion: bound_region,
|
boundregion: bound_region,
|
||||||
is_impl_item: is_impl_item,
|
is_impl_item: is_impl_item,
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here, we check for the case where the anonymous region
|
// Here, we check for the case where the anonymous region
|
||||||
// is in the return type.
|
// is in the return type.
|
||||||
// FIXME(#42703) - Need to handle certain cases here.
|
// FIXME(#42703) - Need to handle certain cases here.
|
||||||
pub(super) fn is_return_type_anon(&self,
|
pub(super) fn is_return_type_anon(
|
||||||
scope_def_id: DefId,
|
&self,
|
||||||
br: ty::BoundRegion,
|
scope_def_id: DefId,
|
||||||
decl: &hir::FnDecl)
|
br: ty::BoundRegion,
|
||||||
-> Option<Span> {
|
decl: &hir::FnDecl,
|
||||||
|
) -> Option<Span> {
|
||||||
let ret_ty = self.tcx.type_of(scope_def_id);
|
let ret_ty = self.tcx.type_of(scope_def_id);
|
||||||
match ret_ty.sty {
|
match ret_ty.sty {
|
||||||
ty::TyFnDef(_, _) => {
|
ty::TyFnDef(_, _) => {
|
||||||
|
@ -186,14 +184,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
// FIXME(#42700) - Need to format self properly to
|
// FIXME(#42700) - Need to format self properly to
|
||||||
// enable E0621 for it.
|
// enable E0621 for it.
|
||||||
pub(super) fn is_self_anon(&self, is_first: bool, scope_def_id: DefId) -> bool {
|
pub(super) fn is_self_anon(&self, is_first: bool, scope_def_id: DefId) -> bool {
|
||||||
is_first &&
|
is_first
|
||||||
self.tcx
|
&& self.tcx
|
||||||
.opt_associated_item(scope_def_id)
|
.opt_associated_item(scope_def_id)
|
||||||
.map(|i| i.method_has_self_argument) == Some(true)
|
.map(|i| i.method_has_self_argument) == Some(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here we check if the bound region is in Impl Item.
|
// Here we check if the bound region is in Impl Item.
|
||||||
pub(super) fn is_bound_region_in_impl_item(&self, suitable_region_binding_scope: DefId) -> bool {
|
pub(super) fn is_bound_region_in_impl_item(
|
||||||
|
&self,
|
||||||
|
suitable_region_binding_scope: DefId,
|
||||||
|
) -> bool {
|
||||||
let container_id = self.tcx
|
let container_id = self.tcx
|
||||||
.associated_item(suitable_region_binding_scope)
|
.associated_item(suitable_region_binding_scope)
|
||||||
.container
|
.container
|
||||||
|
@ -213,12 +214,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
// This method returns whether the given Region is Named
|
// This method returns whether the given Region is Named
|
||||||
pub(super) fn is_named_region(&self, region: Region<'tcx>) -> bool {
|
pub(super) fn is_named_region(&self, region: Region<'tcx>) -> bool {
|
||||||
match *region {
|
match *region {
|
||||||
ty::ReFree(ref free_region) => {
|
ty::ReFree(ref free_region) => match free_region.bound_region {
|
||||||
match free_region.bound_region {
|
ty::BrNamed(..) => true,
|
||||||
ty::BrNamed(..) => true,
|
_ => false,
|
||||||
_ => false,
|
},
|
||||||
}
|
|
||||||
}
|
|
||||||
ty::ReEarlyBound(_) => true,
|
ty::ReEarlyBound(_) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue