Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer lifetime suggestion over generic error #13071

Merged
merged 1 commit into from
Mar 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion src/librustc/middle/typeck/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,15 @@ impl<'a> ErrorReporting for InferCtxt<'a> {
// failed (so the return value of this method should not be used)
fn process_errors(&self, errors: &Vec<RegionResolutionError>)
-> Vec<RegionResolutionError> {
debug!("process_errors()");
let mut var_origins = Vec::new();
let mut trace_origins = Vec::new();
let mut same_regions = Vec::new();
let mut processed_errors = Vec::new();
for error in errors.iter() {
match *error {
ConcreteFailure(origin, sub, sup) => {
debug!("processing ConcreteFailure")
let trace = match origin {
infer::Subtype(trace) => Some(trace),
_ => None,
Expand All @@ -218,6 +220,7 @@ impl<'a> ErrorReporting for InferCtxt<'a> {
}
}
SubSupConflict(var_origin, _, sub_r, _, sup_r) => {
debug!("processing SubSupConflict")
match free_regions_from_same_fn(self.tcx, sub_r, sup_r) {
Some(ref same_frs) => {
var_origins.push(var_origin);
Expand All @@ -237,10 +240,13 @@ impl<'a> ErrorReporting for InferCtxt<'a> {
// declaration, we want to make sure that they are, in fact,
// from the same scope
if sr.scope_id != common_scope_id {
debug!("returning empty result from process_errors because
{} != {}", sr.scope_id, common_scope_id);
return vec!();
}
}
let pe = ProcessedErrors(var_origins, trace_origins, same_regions);
debug!("errors processed: {:?}", pe);
processed_errors.push(pe);
}
return processed_errors;
Expand All @@ -256,6 +262,7 @@ impl<'a> ErrorReporting for InferCtxt<'a> {
sub: Region,
sup: Region)
-> Option<FreeRegionsFromSameFn> {
debug!("free_regions_from_same_fn(sub={:?}, sup={:?})", sub, sup);
let (scope_id, fr1, fr2) = match (sub, sup) {
(ReFree(fr1), ReFree(fr2)) => {
if fr1.scope_id != fr2.scope_id {
Expand Down Expand Up @@ -284,7 +291,10 @@ impl<'a> ErrorReporting for InferCtxt<'a> {
},
_ => None
},
None => None
None => {
debug!("no parent node of scope_id {}", scope_id)
None
}
}
}

Expand Down
20 changes: 18 additions & 2 deletions src/librustc/middle/typeck/infer/region_inference/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,17 +1117,33 @@ impl<'a> RegionVarBindings<'a> {
{
// Errors in expanding nodes result from a lower-bound that is
// not contained by an upper-bound.
let (lower_bounds, lower_dup) =
let (mut lower_bounds, lower_dup) =
self.collect_concrete_regions(graph, var_data, node_idx,
graph::Incoming, dup_vec);
let (upper_bounds, upper_dup) =
let (mut upper_bounds, upper_dup) =
self.collect_concrete_regions(graph, var_data, node_idx,
graph::Outgoing, dup_vec);

if lower_dup || upper_dup {
return;
}

// We place free regions first because we are special casing
// SubSupConflict(ReFree, ReFree) when reporting error, and so
// the user will more likely get a specific suggestion.
fn free_regions_first(a: &RegionAndOrigin,
b: &RegionAndOrigin)
-> Ordering {
match (a.region, b.region) {
(ReFree(..), ReFree(..)) => Equal,
(ReFree(..), _) => Less,
(_, ReFree(..)) => Greater,
(_, _) => Equal,
}
}
lower_bounds.sort_by(|a, b| { free_regions_first(a, b) });
upper_bounds.sort_by(|a, b| { free_regions_first(a, b) });

for lower_bound in lower_bounds.iter() {
for upper_bound in upper_bounds.iter() {
if !self.is_subregion_of(lower_bound.region,
Expand Down