-// Copyright 2014 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.
-
use super::{
FulfillmentError,
FulfillmentErrorCode,
}
}
- // returns if `cond` not occurring implies that `error` does not occur - i.e. that
+ // returns if `cond` not occurring implies that `error` does not occur - i.e., that
// `error` occurring implies that `cond` occurs.
fn error_implies(&self,
cond: &ty::Predicate<'tcx>,
Some(format!("[{}]", self.tcx.type_of(def.did).to_string())),
));
let tcx = self.tcx;
- if let Some(len) = len.val.try_to_scalar().and_then(|scalar| {
- scalar.to_usize(&tcx).ok()
- }) {
+ if let Some(len) = len.assert_usize(tcx) {
flags.push((
"_Self".to_owned(),
Some(format!("[{}; {}]", self.tcx.type_of(def.did).to_string(), len)),
let mut err = struct_span_err!(self.tcx.sess, sp, E0276, "{}", msg);
- if let Some(trait_item_span) = self.tcx.hir.span_if_local(trait_item_def_id) {
+ if let Some(trait_item_span) = self.tcx.hir().span_if_local(trait_item_def_id) {
let span = self.tcx.sess.source_map().def_span(trait_item_span);
err.span_label(span, format!("definition of `{}` from trait", item_name));
}
}
ty::Predicate::RegionOutlives(ref predicate) => {
- let predicate = self.resolve_type_vars_if_possible(predicate);
- let err = self.region_outlives_predicate(&obligation.cause,
- &predicate).err().unwrap();
- struct_span_err!(self.tcx.sess, span, E0279,
- "the requirement `{}` is not satisfied (`{}`)",
- predicate, err)
+ // These errors should show up as region
+ // inference failures.
+ panic!("region outlives {:?} failed", predicate);
}
ty::Predicate::Projection(..) | ty::Predicate::TypeOutlives(..) => {
ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
let found_kind = self.closure_kind(closure_def_id, closure_substs).unwrap();
let closure_span = self.tcx.sess.source_map()
- .def_span(self.tcx.hir.span_if_local(closure_def_id).unwrap());
- let node_id = self.tcx.hir.as_local_node_id(closure_def_id).unwrap();
+ .def_span(self.tcx.hir().span_if_local(closure_def_id).unwrap());
+ let node_id = self.tcx.hir().as_local_node_id(closure_def_id).unwrap();
let mut err = struct_span_err!(
self.tcx.sess, closure_span, E0525,
"expected a closure that implements the `{}` trait, \
// a particular trait.
if let Some(tables) = self.in_progress_tables {
let tables = tables.borrow();
- let closure_hir_id = self.tcx.hir.node_to_hir_id(node_id);
+ let closure_hir_id = self.tcx.hir().node_to_hir_id(node_id);
match (found_kind, tables.closure_kind_origins().get(closure_hir_id)) {
(ty::ClosureKind::FnOnce, Some((span, name))) => {
err.span_label(*span, format!(
}
ty::Predicate::WellFormed(ty) => {
- // WF predicates cannot themselves make
- // errors. They can only block due to
- // ambiguity; otherwise, they always
- // degenerate into other obligations
- // (which may fail).
- span_bug!(span, "WF predicate not satisfied for {:?}", ty);
+ if !self.tcx.sess.opts.debugging_opts.chalk {
+ // WF predicates cannot themselves make
+ // errors. They can only block due to
+ // ambiguity; otherwise, they always
+ // degenerate into other obligations
+ // (which may fail).
+ span_bug!(span, "WF predicate not satisfied for {:?}", ty);
+ } else {
+ // FIXME: we'll need a better message which takes into account
+ // which bounds actually failed to hold.
+ self.tcx.sess.struct_span_err(
+ span,
+ &format!("the type `{}` is not well-formed (chalk)", ty)
+ )
+ }
}
ty::Predicate::ConstEvaluatable(..) => {
};
let found_span = found_did.and_then(|did|
- self.tcx.hir.span_if_local(did)
+ self.tcx.hir().span_if_local(did)
).map(|sp| self.tcx.sess.source_map().def_span(sp)); // the sp could be an fn def
let found = match found_trait_ref.skip_binder().substs.type_at(1).sty {
expected_trait_ref)
} else {
let (closure_span, found) = found_did
- .and_then(|did| self.tcx.hir.get_if_local(did))
+ .and_then(|did| self.tcx.hir().get_if_local(did))
.map(|node| {
let (found_span, found) = self.get_fn_like_arguments(node);
(Some(found_span), found)
code: &ObligationCauseCode<'tcx>,
err: &mut DiagnosticBuilder<'tcx>) {
if let &ObligationCauseCode::VariableType(node_id) = code {
- let parent_node = self.tcx.hir.get_parent_node(node_id);
- if let Some(Node::Local(ref local)) = self.tcx.hir.find(parent_node) {
+ let parent_node = self.tcx.hir().get_parent_node(node_id);
+ if let Some(Node::Local(ref local)) = self.tcx.hir().find(parent_node) {
if let Some(ref expr) = local.init {
if let hir::ExprKind::Index(_, _) = expr.node {
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(expr.span) {
node: hir::ExprKind::Closure(_, ref _decl, id, span, _),
..
}) => {
- (self.tcx.sess.source_map().def_span(span), self.tcx.hir.body(id).arguments.iter()
+ (self.tcx.sess.source_map().def_span(span), self.tcx.hir().body(id).arguments.iter()
.map(|arg| {
if let hir::Pat {
node: hir::PatKind::Tuple(args, _),
).collect::<Vec<_>>())
}
Node::StructCtor(ref variant_data) => {
- (self.tcx.sess.source_map().def_span(self.tcx.hir.span(variant_data.id())),
+ (self.tcx.sess.source_map().def_span(self.tcx.hir().span(variant_data.id())),
vec![ArgKind::empty(); variant_data.fields().len()])
}
_ => panic!("non-FnLike node found: {:?}", node),
-> DiagnosticBuilder<'tcx>
{
assert!(type_def_id.is_local());
- let span = self.hir.span_if_local(type_def_id).unwrap();
+ let span = self.hir().span_if_local(type_def_id).unwrap();
let span = self.sess.source_map().def_span(span);
let mut err = struct_span_err!(self.sess, span, E0072,
"recursive type `{}` has infinite size",
match *cause_code {
ObligationCauseCode::ExprAssignable |
ObligationCauseCode::MatchExpressionArm { .. } |
- ObligationCauseCode::IfExpression |
+ ObligationCauseCode::MatchExpressionArmPattern { .. } |
+ ObligationCauseCode::IfExpression { .. } |
ObligationCauseCode::IfExpressionWithNoElse |
ObligationCauseCode::MainFunctionType |
ObligationCauseCode::StartFunctionType |
ObligationCauseCode::IntrinsicType |
ObligationCauseCode::MethodReceiver |
ObligationCauseCode::ReturnNoExpression |
- ObligationCauseCode::MiscObligation => {
- }
+ ObligationCauseCode::MiscObligation => {}
ObligationCauseCode::SliceOrArrayElem => {
err.note("slice and array elements must have `Sized` type");
}
let item_name = tcx.item_path_str(item_def_id);
let msg = format!("required by `{}`", item_name);
- if let Some(sp) = tcx.hir.span_if_local(item_def_id) {
+ if let Some(sp) = tcx.hir().span_if_local(item_def_id) {
let sp = tcx.sess.source_map().def_span(sp);
err.span_note(sp, &msg);
} else {