Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f3335c6
simplify `AnonTypeDecl` in the impl trait code
nikomatsakis Dec 6, 2017
f6741d0
region_infer/values.rs: rustfmt
nikomatsakis Dec 6, 2017
e447b54
Add tracking of causes for nll
Nashenas88 Nov 21, 2017
39b0e49
rustfmt: borrow_check/mod.rs
nikomatsakis Dec 14, 2017
594c386
dump out causal information for "free region" errors
nikomatsakis Dec 7, 2017
741ef41
use Rc to store nonlexical_regioncx in Borrows
nikomatsakis Dec 7, 2017
0e64a75
integrate -Znll-dump-cause into borrowck
nikomatsakis Dec 7, 2017
fe89f4b
get the `DefiningTy` from the `body_owner_kind` not type
nikomatsakis Dec 8, 2017
4a967c9
propagate `region_bound_pairs` into MIR type-check
nikomatsakis Dec 8, 2017
e96f4be
extract `instantiate_anon_types` to the `InferCtxt`
nikomatsakis Dec 9, 2017
8e64ba8
extract `constrain_anon_types` to the `InferCtxt`
nikomatsakis Dec 9, 2017
7f50e7c
extract the writeback code for anon types into InferCtxt
nikomatsakis Dec 9, 2017
a66c651
pass `UniversalRegions` to MIR type-checker instead of fields
nikomatsakis Dec 10, 2017
da63aaa
extract `input_output` code into its own module
nikomatsakis Dec 10, 2017
93afb1a
connect NLL type checker to the impl trait code
nikomatsakis Dec 10, 2017
58b0506
Move MirVisitable to visit.rs
spastorino Dec 12, 2017
6d2987c
Move categorize logic out of visit_local function
nikomatsakis Dec 20, 2017
3a185a5
Add three point error handling to borrowck
spastorino Dec 12, 2017
e28d03f
only dump causes if we have nothing better
nikomatsakis Dec 14, 2017
4089d14
move nice-region-error reporting into its own module
nikomatsakis Dec 12, 2017
93498e0
make `util` fns private to nice_region_error
nikomatsakis Dec 12, 2017
3720242
extract `find_anon_type` into its own module
nikomatsakis Dec 12, 2017
a28ab84
nice_region_error: rustfmt
nikomatsakis Dec 12, 2017
cba4732
introduce a `NiceRegionError` type and define methods on that
nikomatsakis Dec 12, 2017
de56308
use `Option<ErrorReported>` instead of `bool`
nikomatsakis Dec 12, 2017
94e7072
give precedence to `try_report_named_anon_conflict` method
nikomatsakis Dec 12, 2017
6b39781
connect NLL machinery to the `NiceRegionError` code
nikomatsakis Dec 12, 2017
3788f42
refactor `report_generic_bound_failure` to be usable by NLL code
nikomatsakis Dec 19, 2017
508a831
use `report_generic_bound_failure` when we can in the compiler
nikomatsakis Dec 19, 2017
95b6148
Add nll_dump_cause helper to Session
spastorino Dec 19, 2017
0b2db1e
Add nll feature and make nll imply nll_dump_cause
spastorino Dec 19, 2017
2019d69
feature nll implies two-phase-borrows
spastorino Dec 19, 2017
e980fb8
feature nll implies borrowck=mir
spastorino Dec 19, 2017
cfa4ffa
document and tweak the nll, use_mir, etc helpers
nikomatsakis Dec 20, 2017
80c510e
when using feature(nll), don't warn about AST-based region errors
nikomatsakis Dec 20, 2017
cba8256
add some run-pass tests for NLL showing that things work as expected
nikomatsakis Dec 7, 2017
3f490ca
convert region-liveness-drop{-,-no-}may-dangle.rs into ui tests
nikomatsakis Dec 20, 2017
4f549fe
improve comment about instantiating anon types
nikomatsakis Dec 20, 2017
d925f4d
fix truncated comment
nikomatsakis Dec 20, 2017
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
Prev Previous commit
Next Next commit
nice_region_error: rustfmt
  • Loading branch information
nikomatsakis committed Dec 20, 2017
commit a28ab84025831f3b73810e52f432af904e6fd85c
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,28 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

let ty_sub = or_false!(self.find_anon_type(sub, &bregion_sub));

debug!("try_report_anon_anon_conflict: found_arg1={:?} sup={:?} br1={:?}",
ty_sub,
sup,
bregion_sup);
debug!("try_report_anon_anon_conflict: found_arg2={:?} sub={:?} br2={:?}",
ty_sup,
sub,
bregion_sub);
debug!(
"try_report_anon_anon_conflict: found_arg1={:?} sup={:?} br1={:?}",
ty_sub,
sup,
bregion_sup
);
debug!(
"try_report_anon_anon_conflict: found_arg2={:?} sub={:?} br2={:?}",
ty_sup,
sub,
bregion_sub
);

let (ty_sup, ty_fndecl_sup) = ty_sup;
let (ty_sub, ty_fndecl_sub) = ty_sub;

let AnonymousArgInfo { arg: anon_arg_sup, .. } =
or_false!(self.find_arg_with_region(sup, sup));
let AnonymousArgInfo { arg: anon_arg_sub, .. } =
or_false!(self.find_arg_with_region(sub, sub));
let AnonymousArgInfo {
arg: anon_arg_sup, ..
} = or_false!(self.find_arg_with_region(sup, sup));
let AnonymousArgInfo {
arg: anon_arg_sub, ..
} = or_false!(self.find_arg_with_region(sub, sub));

let sup_is_ret_type =
self.is_return_type_anon(scope_def_id_sup, bregion_sup, ty_fndecl_sup);
Expand All @@ -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) {
(None, None) => {
let (main_label_1, span_label_1) = if ty_sup == ty_sub {

(format!("this type is declared with multiple lifetimes..."),
format!("...but data{} flows{} here",
format!(" with one lifetime"),
format!(" into the other")))
(
format!("this type is declared with multiple lifetimes..."),
format!(
"...but data{} flows{} here",
format!(" with one lifetime"),
format!(" into the other")
),
)
} else {
(format!("these two types are declared with different lifetimes..."),
format!("...but data{} flows{} here",
span_label_var1,
span_label_var2))
(
format!("these two types are declared with different lifetimes..."),
format!(
"...but data{} flows{} here",
span_label_var1,
span_label_var2
),
)
};
(ty_sup.span, ty_sub.span, main_label_1, span_label_1)
}

(Some(ret_span), _) => {
(ty_sub.span,
ret_span,
format!("this parameter and the return type are declared \
with different lifetimes...",),
format!("...but data{} is returned here", span_label_var1))
}
(_, Some(ret_span)) => {
(ty_sup.span,
ret_span,
format!("this parameter and the return type are declared \
with different lifetimes...",),
format!("...but data{} is returned here", span_label_var1))
}
(Some(ret_span), _) => (
ty_sub.span,
ret_span,
format!(
"this parameter and the return type are declared \
with different lifetimes...",
),
format!("...but data{} is returned here", span_label_var1),
),
(_, Some(ret_span)) => (
ty_sup.span,
ret_span,
format!(
"this parameter and the return type are declared \
with different lifetimes...",
),
format!("...but data{} is returned here", span_label_var1),
),
};


Expand All @@ -149,4 +166,3 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
return true;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use infer::InferCtxt;
use ty::{self, Region};
use hir::map as hir_map;
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> {
/// This function calls the `visit_ty` method for the parameters
Expand Down
91 changes: 45 additions & 46 deletions src/librustc/infer/error_reporting/nice_region_error/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
// with 'a, the corresponding bound region and is_first which is true if
// the hir::Arg is the first argument in the function declaration.
pub(super) fn find_arg_with_region(&self,
anon_region: Region<'tcx>,
replace_region: Region<'tcx>)
-> Option<AnonymousArgInfo> {

pub(super) fn find_arg_with_region(
&self,
anon_region: Region<'tcx>,
replace_region: Region<'tcx>,
) -> Option<AnonymousArgInfo> {
let (id, bound_region) = match *anon_region {
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
ty::ReEarlyBound(ref ebr) => {
(self.tcx.parent_def_id(ebr.def_id).unwrap(),
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name))
}
ty::ReEarlyBound(ref ebr) => (
self.tcx.parent_def_id(ebr.def_id).unwrap(),
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
),
_ => return None, // not a free region
};

Expand All @@ -94,21 +94,22 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// May return None; sometimes the tables are not yet populated.
let ty = tables.borrow().node_id_to_type_opt(arg.hir_id)?;
let mut found_anon_region = false;
let new_arg_ty = self.tcx
.fold_regions(&ty, &mut false, |r, _| if *r == *anon_region {
let new_arg_ty = self.tcx.fold_regions(&ty, &mut false, |r, _| {
if *r == *anon_region {
found_anon_region = true;
replace_region
} else {
r
});
}
});
if found_anon_region {
let is_first = index == 0;
Some(AnonymousArgInfo {
arg: arg,
arg_ty: new_arg_ty,
bound_region: bound_region,
is_first: is_first,
})
arg: arg,
arg_ty: new_arg_ty,
bound_region: bound_region,
is_first: is_first,
})
} else {
None
}
Expand All @@ -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.
pub(super) fn is_suitable_region(&self, region: Region<'tcx>) -> Option<FreeRegionInfo> {

let (suitable_region_binding_scope, bound_region) = match *region {
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
ty::ReEarlyBound(ref ebr) => {
(self.tcx.parent_def_id(ebr.def_id).unwrap(),
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name))
}
ty::ReEarlyBound(ref ebr) => (
self.tcx.parent_def_id(ebr.def_id).unwrap(),
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
),
_ => return None, // not a free region
};

Expand All @@ -142,31 +142,29 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
.as_local_node_id(suitable_region_binding_scope)
.unwrap();
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(..)) => {
self.is_bound_region_in_impl_item(suitable_region_binding_scope)
}
_ => return None,
};

return Some(FreeRegionInfo {
def_id: suitable_region_binding_scope,
boundregion: bound_region,
is_impl_item: is_impl_item,
});

def_id: suitable_region_binding_scope,
boundregion: bound_region,
is_impl_item: is_impl_item,
});
}

// Here, we check for the case where the anonymous region
// is in the return type.
// FIXME(#42703) - Need to handle certain cases here.
pub(super) fn is_return_type_anon(&self,
scope_def_id: DefId,
br: ty::BoundRegion,
decl: &hir::FnDecl)
-> Option<Span> {
pub(super) fn is_return_type_anon(
&self,
scope_def_id: DefId,
br: ty::BoundRegion,
decl: &hir::FnDecl,
) -> Option<Span> {
let ret_ty = self.tcx.type_of(scope_def_id);
match ret_ty.sty {
ty::TyFnDef(_, _) => {
Expand All @@ -186,14 +184,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// FIXME(#42700) - Need to format self properly to
// enable E0621 for it.
pub(super) fn is_self_anon(&self, is_first: bool, scope_def_id: DefId) -> bool {
is_first &&
self.tcx
.opt_associated_item(scope_def_id)
.map(|i| i.method_has_self_argument) == Some(true)
is_first
&& self.tcx
.opt_associated_item(scope_def_id)
.map(|i| i.method_has_self_argument) == Some(true)
}

// 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
.associated_item(suitable_region_binding_scope)
.container
Expand All @@ -213,12 +214,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// This method returns whether the given Region is Named
pub(super) 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,
}
}
ty::ReFree(ref free_region) => match free_region.bound_region {
ty::BrNamed(..) => true,
_ => false,
},
ty::ReEarlyBound(_) => true,
_ => false,
}
Expand Down