diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 98db885ba4227..00ebca5abc147 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -686,7 +686,7 @@ impl FnCtxt { result::Err(RegionError { msg: { fmt!("named region `%s` not in scope here", - bound_region_to_str(self.tcx(), br)) + bound_region_ptr_to_str(self.tcx(), br)) }, replacement: { self.infcx().next_region_var( diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/typeck/infer/error_reporting.rs index 7217f29794746..e533f019b4692 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/typeck/infer/error_reporting.rs @@ -59,7 +59,7 @@ time of error detection. */ -use core::prelude::*; +use std::prelude::*; use middle::ty; use middle::ty::Region; use middle::typeck::infer; @@ -80,10 +80,46 @@ use syntax::opt_vec::OptVec; use util::ppaux::UserString; use util::ppaux::note_and_explain_region; -impl InferCtxt { +pub trait ErrorReporting { + pub fn report_region_errors(@mut self, + errors: &OptVec); + + pub fn report_and_explain_type_error(@mut self, + trace: TypeTrace, + terr: &ty::type_err); + + fn values_str(@mut self, values: &ValuePairs) -> Option<~str>; + + fn expected_found_str( + @mut self, + exp_found: &ty::expected_found) + -> Option<~str>; + + fn report_concrete_failure(@mut self, + origin: SubregionOrigin, + sub: Region, + sup: Region); + + fn report_sub_sup_conflict(@mut self, + var_origin: RegionVariableOrigin, + sub_origin: SubregionOrigin, + sub_region: Region, + sup_origin: SubregionOrigin, + sup_region: Region); + + fn report_sup_sup_conflict(@mut self, + var_origin: RegionVariableOrigin, + origin1: SubregionOrigin, + region1: Region, + origin2: SubregionOrigin, + region2: Region); +} + + +impl ErrorReporting for InferCtxt { pub fn report_region_errors(@mut self, errors: &OptVec) { - for errors.each |error| { + for errors.iter().advance |error| { match *error { ConcreteFailure(origin, sub, sup) => { self.report_concrete_failure(origin, sub, sup); diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index bddd0276c6abe..3360edc6a4678 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -31,6 +31,7 @@ use middle::typeck::infer::sub::Sub; use middle::typeck::infer::lub::Lub; use middle::typeck::infer::to_str::InferStr; use middle::typeck::infer::unify::{ValsAndBindings, Root}; +use middle::typeck::infer::error_reporting::ErrorReporting; use middle::typeck::isr_alist; use util::common::indent; use util::ppaux::{bound_region_to_str, ty_to_str, trait_ref_to_str, Repr, diff --git a/src/librustc/middle/typeck/infer/region_inference/mod.rs b/src/librustc/middle/typeck/infer/region_inference/mod.rs index b474b95d0fec2..96cb5d3c747c3 100644 --- a/src/librustc/middle/typeck/infer/region_inference/mod.rs +++ b/src/librustc/middle/typeck/infer/region_inference/mod.rs @@ -36,7 +36,8 @@ mod doc; enum Constraint { ConstrainVarSubVar(RegionVid, RegionVid), ConstrainRegSubVar(Region, RegionVid), - ConstrainVarSubReg(RegionVid, Region) + ConstrainVarSubReg(RegionVid, Region), + ConstrainRegSubReg(Region, Region), } #[deriving(Eq, IterBytes)] @@ -454,7 +455,7 @@ impl RegionVarBindings { { let mut result_set = result_set; if r == r1 { // Clearly, this is potentially inefficient. - if !result_set.iter().any_(|x| x == r2) { + if !result_set.iter().any_(|x| *x == r2) { result_set.push(r2); } } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 1a0cdd6fa64fa..6289407114534 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -610,7 +610,7 @@ impl Repr for @ast::pat { impl Repr for ty::bound_region { fn repr(&self, tcx: ctxt) -> ~str { - bound_region_to_str(tcx, *self) + bound_region_ptr_to_str(tcx, *self) } } diff --git a/src/test/compile-fail/regions-bounds.rs b/src/test/compile-fail/regions-bounds.rs index f92ea7f18cec4..ab2ac6cc0e5b9 100644 --- a/src/test/compile-fail/regions-bounds.rs +++ b/src/test/compile-fail/regions-bounds.rs @@ -16,12 +16,12 @@ struct an_enum<'self>(&'self int); struct a_class<'self> { x:&'self int } fn a_fn1<'a,'b>(e: an_enum<'a>) -> an_enum<'b> { - return e; //~ ERROR mismatched types: expected `an_enum<'b> ` but found `an_enum<'a> ` + return e; //~ ERROR mismatched types: expected `an_enum<'b>` but found `an_enum<'a>` //~^ ERROR cannot infer an appropriate lifetime } fn a_fn3<'a,'b>(e: a_class<'a>) -> a_class<'b> { - return e; //~ ERROR mismatched types: expected `a_class<'b> ` but found `a_class<'a> ` + return e; //~ ERROR mismatched types: expected `a_class<'b>` but found `a_class<'a>` //~^ ERROR cannot infer an appropriate lifetime }