Code review fixes
This commit is contained in:
parent
95409016f8
commit
e8b8f30373
@ -76,7 +76,6 @@
|
||||
|
||||
mod need_type_info;
|
||||
mod named_anon_conflict;
|
||||
mod util;
|
||||
|
||||
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
|
@ -41,12 +41,12 @@ fn find_arg_with_anonymous_region
|
||||
let id = free_region.scope;
|
||||
let node_id = self.tcx.hir.as_local_node_id(id).unwrap();
|
||||
let body_id = self.tcx.hir.maybe_body_owned_by(node_id).unwrap();
|
||||
let mut is_first = false;
|
||||
let body = self.tcx.hir.body(body_id);
|
||||
if let Some(tables) = self.in_progress_tables {
|
||||
body.arguments
|
||||
.iter()
|
||||
.filter_map(|arg| {
|
||||
.enumerate()
|
||||
.filter_map(|(index, arg)| {
|
||||
let ty = tables.borrow().node_id_to_type(arg.id);
|
||||
let mut found_anon_region = false;
|
||||
let new_arg_ty = self.tcx
|
||||
@ -57,9 +57,7 @@ fn find_arg_with_anonymous_region
|
||||
r
|
||||
});
|
||||
if found_anon_region {
|
||||
if body.arguments.iter().nth(0) == Some(&arg) {
|
||||
is_first = true;
|
||||
}
|
||||
let is_first = index == 0;
|
||||
Some((arg, new_arg_ty, free_region.bound_region, is_first))
|
||||
} else {
|
||||
None
|
||||
@ -91,19 +89,18 @@ pub fn try_report_named_anon_conflict(&self, error: &RegionResolutionError<'tcx>
|
||||
// only introduced anonymous regions in parameters) as well as a
|
||||
// version new_ty of its type where the anonymous region is replaced
|
||||
// with the named one.
|
||||
let (named, (arg, new_ty, br, is_first), scope_def_id) = if
|
||||
self.is_named_region(sub) && self.is_suitable_anonymous_region(sup).is_some() {
|
||||
(sub,
|
||||
self.find_arg_with_anonymous_region(sup, sub).unwrap(),
|
||||
self.is_suitable_anonymous_region(sup).unwrap())
|
||||
} else if
|
||||
self.is_named_region(sup) && self.is_suitable_anonymous_region(sub).is_some() {
|
||||
(sup,
|
||||
self.find_arg_with_anonymous_region(sub, sup).unwrap(),
|
||||
self.is_suitable_anonymous_region(sub).unwrap())
|
||||
} else {
|
||||
return false; // inapplicable
|
||||
};
|
||||
let (named, (arg, new_ty, br, is_first), scope_def_id) =
|
||||
if sub.is_named_region() && self.is_suitable_anonymous_region(sup).is_some() {
|
||||
(sub,
|
||||
self.find_arg_with_anonymous_region(sup, sub).unwrap(),
|
||||
self.is_suitable_anonymous_region(sup).unwrap())
|
||||
} else if sup.is_named_region() && self.is_suitable_anonymous_region(sub).is_some() {
|
||||
(sup,
|
||||
self.find_arg_with_anonymous_region(sub, sup).unwrap(),
|
||||
self.is_suitable_anonymous_region(sub).unwrap())
|
||||
} else {
|
||||
return false; // inapplicable
|
||||
};
|
||||
|
||||
// Here, we check for the case where the anonymous region
|
||||
// is in the return type.
|
||||
@ -179,8 +176,11 @@ pub fn is_suitable_anonymous_region(&self, region: Region<'tcx>) -> Option<DefId
|
||||
// proceed ahead //
|
||||
}
|
||||
Some(hir_map::NodeImplItem(..)) => {
|
||||
if self.tcx.impl_trait_ref(self.tcx.
|
||||
associated_item(anonymous_region_binding_scope).container.id()).is_some() {
|
||||
let container_id = self.tcx
|
||||
.associated_item(anonymous_region_binding_scope)
|
||||
.container
|
||||
.id();
|
||||
if self.tcx.impl_trait_ref(container_id).is_some() {
|
||||
// For now, we do not try to target impls of traits. This is
|
||||
// because this message is going to suggest that the user
|
||||
// change the fn signature, but they may not be free to do so,
|
||||
@ -189,8 +189,6 @@ pub fn is_suitable_anonymous_region(&self, region: Region<'tcx>) -> Option<DefId
|
||||
// FIXME(#42706) -- in some cases, we could do better here.
|
||||
return None;
|
||||
}
|
||||
else{ }
|
||||
|
||||
}
|
||||
_ => return None, // inapplicable
|
||||
// we target only top-level functions
|
||||
|
@ -1,30 +0,0 @@
|
||||
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! Helper for error reporting code for named_anon_conflict
|
||||
|
||||
use ty::{self, Region};
|
||||
use infer::InferCtxt;
|
||||
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
// This method returns whether the given Region is Named
|
||||
pub fn is_named_region(&self, region: Region<'tcx>) -> bool {
|
||||
|
||||
match *region {
|
||||
ty::ReFree(ref free_region) => {
|
||||
match free_region.bound_region {
|
||||
ty::BrNamed(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
@ -990,6 +990,20 @@ pub fn type_flags(&self) -> TypeFlags {
|
||||
|
||||
flags
|
||||
}
|
||||
|
||||
// This method returns whether the given Region is Named
|
||||
pub fn is_named_region(&self) -> bool {
|
||||
|
||||
match *self {
|
||||
ty::ReFree(ref free_region) => {
|
||||
match free_region.bound_region {
|
||||
ty::BrNamed(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Type utilities
|
||||
|
Loading…
Reference in New Issue
Block a user