use middle::subst;
use middle::subst::Substs;
use middle::subst::Subst;
-use middle::traits::{self, FulfillmentContext, Normalized,
- SelectionContext, ObligationCause};
+use middle::traits;
use middle::ty::adjustment;
-use middle::ty::{TyVid, IntVid, FloatVid, RegionVid};
-use middle::ty::{self, Ty, HasTypeFlags};
+use middle::ty::{TyVid, IntVid, FloatVid};
+use middle::ty::{self, Ty};
use middle::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
use middle::ty::fold::{TypeFolder, TypeFoldable};
use middle::ty::relate::{Relate, RelateResult, TypeRelation};
use rustc_data_structures::unify::{self, UnificationTable};
use std::cell::{RefCell, Ref};
use std::fmt;
-use std::rc::Rc;
use syntax::ast;
use syntax::codemap;
use syntax::codemap::{Span, DUMMY_SP};
+use syntax::errors::DiagnosticBuilder;
use util::nodemap::{FnvHashMap, FnvHashSet, NodeMap};
use self::combine::CombineFields;
/// See `error_reporting.rs` for more details
#[derive(Clone, Debug)]
pub enum SubregionOrigin<'tcx> {
- // Marker to indicate a constraint that only arises due to new
- // provisions from RFC 1214. This will result in a warning, not an
- // error.
- RFC1214Subregion(Rc<SubregionOrigin<'tcx>>),
-
// Arose from a subtyping relation
Subtype(TypeTrace<'tcx>),
}
pub fn normalize_associated_type<'tcx,T>(tcx: &ty::ctxt<'tcx>, value: &T) -> T
- where T : TypeFoldable<'tcx> + HasTypeFlags
+ where T : TypeFoldable<'tcx>
{
debug!("normalize_associated_type(t={:?})", value);
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
result: &T)
-> T
- where T : TypeFoldable<'tcx> + HasTypeFlags
+ where T : TypeFoldable<'tcx>
{
match drain_fulfillment_cx(infcx, fulfill_cx, result) {
Ok(v) => v,
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
result: &T)
-> Result<T,Vec<traits::FulfillmentError<'tcx>>>
- where T : TypeFoldable<'tcx> + HasTypeFlags
+ where T : TypeFoldable<'tcx>
{
debug!("drain_fulfillment_cx(result={:?})",
result);
snapshot: &CombinedSnapshot,
value: &T)
-> T
- where T : TypeFoldable<'tcx> + HasTypeFlags
+ where T : TypeFoldable<'tcx>
{
/*! See `higher_ranked::plug_leaks` */
}
pub fn resolve_type_vars_if_possible<T>(&self, value: &T) -> T
- where T: TypeFoldable<'tcx> + HasTypeFlags
+ where T: TypeFoldable<'tcx>
{
/*!
* Where possible, replaces type/int/float variables in
value.fold_with(&mut r)
}
+ pub fn resolve_type_and_region_vars_if_possible<T>(&self, value: &T) -> T
+ where T: TypeFoldable<'tcx>
+ {
+ let mut r = resolve::OpportunisticTypeAndRegionResolver::new(self);
+ value.fold_with(&mut r)
+ }
+
/// Resolves all type variables in `t` and then, if any were left
/// unresolved, substitutes an error type. This is used after the
/// main checking when doing a second pass before writeback. The
sp: Span,
mk_msg: M,
actual_ty: String,
- err: Option<&TypeError<'tcx>>) where
- M: FnOnce(Option<String>, String) -> String,
+ err: Option<&TypeError<'tcx>>)
+ where M: FnOnce(Option<String>, String) -> String,
{
self.type_error_message_str_with_expected(sp, mk_msg, None, actual_ty, err)
}
+ pub fn type_error_struct_str<M>(&self,
+ sp: Span,
+ mk_msg: M,
+ actual_ty: String,
+ err: Option<&TypeError<'tcx>>)
+ -> DiagnosticBuilder<'tcx>
+ where M: FnOnce(Option<String>, String) -> String,
+ {
+ self.type_error_struct_str_with_expected(sp, mk_msg, None, actual_ty, err)
+ }
+
pub fn type_error_message_str_with_expected<M>(&self,
sp: Span,
mk_msg: M,
expected_ty: Option<Ty<'tcx>>,
actual_ty: String,
- err: Option<&TypeError<'tcx>>) where
- M: FnOnce(Option<String>, String) -> String,
+ err: Option<&TypeError<'tcx>>)
+ where M: FnOnce(Option<String>, String) -> String,
+ {
+ self.type_error_struct_str_with_expected(sp, mk_msg, expected_ty, actual_ty, err)
+ .emit();
+ }
+
+ pub fn type_error_struct_str_with_expected<M>(&self,
+ sp: Span,
+ mk_msg: M,
+ expected_ty: Option<Ty<'tcx>>,
+ actual_ty: String,
+ err: Option<&TypeError<'tcx>>)
+ -> DiagnosticBuilder<'tcx>
+ where M: FnOnce(Option<String>, String) -> String,
{
debug!("hi! expected_ty = {:?}, actual_ty = {}", expected_ty, actual_ty);
format!(" ({})", t_err)
});
- self.tcx.sess.span_err(sp, &format!("{}{}",
+ let mut db = self.tcx.sess.struct_span_err(sp, &format!("{}{}",
mk_msg(resolved_expected.map(|t| self.ty_to_string(t)), actual_ty),
error_str));
if let Some(err) = err {
- self.tcx.note_and_explain_type_err(err, sp)
+ self.tcx.note_and_explain_type_err(&mut db, err, sp);
}
+ db
+ } else {
+ self.tcx.sess.diagnostic().struct_dummy()
}
}
sp: Span,
mk_msg: M,
actual_ty: Ty<'tcx>,
- err: Option<&TypeError<'tcx>>) where
- M: FnOnce(String) -> String,
+ err: Option<&TypeError<'tcx>>)
+ where M: FnOnce(String) -> String,
+ {
+ self.type_error_struct(sp, mk_msg, actual_ty, err).emit();
+ }
+
+ pub fn type_error_struct<M>(&self,
+ sp: Span,
+ mk_msg: M,
+ actual_ty: Ty<'tcx>,
+ err: Option<&TypeError<'tcx>>)
+ -> DiagnosticBuilder<'tcx>
+ where M: FnOnce(String) -> String,
{
let actual_ty = self.resolve_type_vars_if_possible(&actual_ty);
// Don't report an error if actual type is TyError.
if actual_ty.references_error() {
- return;
+ return self.tcx.sess.diagnostic().struct_dummy();
}
- self.type_error_message_str(sp,
+ self.type_error_struct_str(sp,
move |_e, a| { mk_msg(a) },
- self.ty_to_string(actual_ty), err);
+ self.ty_to_string(actual_ty), err)
}
pub fn report_mismatched_types(&self,
impl<'tcx> SubregionOrigin<'tcx> {
pub fn span(&self) -> Span {
match *self {
- RFC1214Subregion(ref a) => a.span(),
Subtype(ref a) => a.span(),
InfStackClosure(a) => a,
InvokeClosure(a) => a,