use middle::lang_items::UnsizeTraitLangItem;
use rustc::ty::subst::{self, Subst};
use rustc::ty::{self, TyCtxt, TypeFoldable};
-use rustc::traits::{self, ProjectionMode};
+use rustc::traits::{self, Reveal};
use rustc::ty::{ImplOrTraitItemId, ConstTraitItemId};
use rustc::ty::{MethodTraitItemId, TypeTraitItemId, ParameterEnvironment};
use rustc::ty::{Ty, TyBool, TyChar, TyEnum, TyError};
use rustc::ty::{TyParam, TyRawPtr};
-use rustc::ty::{TyRef, TyStruct, TyTrait, TyTuple};
+use rustc::ty::{TyRef, TyStruct, TyTrait, TyNever, TyTuple};
use rustc::ty::{TyStr, TyArray, TySlice, TyFloat, TyInfer, TyInt};
use rustc::ty::{TyUint, TyClosure, TyBox, TyFnDef, TyFnPtr};
-use rustc::ty::TyProjection;
+use rustc::ty::{TyProjection, TyAnon};
use rustc::ty::util::CopyImplementationError;
use middle::free_region::FreeRegionMap;
use CrateCtxt;
TyBool | TyChar | TyInt(..) | TyUint(..) | TyFloat(..) |
TyStr | TyArray(..) | TySlice(..) | TyFnDef(..) | TyFnPtr(_) |
- TyTuple(..) | TyParam(..) | TyError |
+ TyTuple(..) | TyParam(..) | TyError | TyNever |
TyRawPtr(_) | TyRef(_, _) | TyProjection(..) => {
None
}
- TyInfer(..) | TyClosure(..) => {
+ TyInfer(..) | TyClosure(..) | TyAnon(..) => {
// `ty` comes from a user declaration so we should only expect types
// that the user can type
span_bug!(
if let Some(impl_node_id) = tcx.map.as_local_node_id(impl_did) {
match tcx.map.find(impl_node_id) {
Some(hir_map::NodeItem(item)) => {
- span_err!(tcx.sess, item.span, E0120,
- "the Drop trait may only be implemented on structures");
+ let span = match item.node {
+ ItemImpl(_, _, _, _, ref ty, _) => {
+ ty.span
+ },
+ _ => item.span
+ };
+ struct_span_err!(tcx.sess, span, E0120,
+ "the Drop trait may only be implemented on structures")
+ .span_label(span,
+ &format!("implementing Drop requires a struct"))
+ .emit();
}
_ => {
bug!("didn't find impl in ast map");
}
} else {
bug!("found external impl of Drop trait on \
- :omething other than a struct");
+ something other than a struct");
}
}
}
match param_env.can_type_implement_copy(tcx, self_type, span) {
Ok(()) => {}
Err(CopyImplementationError::InfrigingField(name)) => {
- span_err!(tcx.sess, span, E0204,
- "the trait `Copy` may not be \
- implemented for this type; field \
- `{}` does not implement `Copy`",
- name)
+ struct_span_err!(tcx.sess, span, E0204,
+ "the trait `Copy` may not be implemented for \
+ this type")
+ .span_label(span, &format!(
+ "field `{}` does not implement `Copy`", name)
+ )
+ .emit()
+
}
Err(CopyImplementationError::InfrigingVariant(name)) => {
- span_err!(tcx.sess, span, E0205,
- "the trait `Copy` may not be \
- implemented for this type; variant \
- `{}` does not implement `Copy`",
- name)
+ let item = tcx.map.expect_item(impl_node_id);
+ let span = if let ItemImpl(_, _, _, Some(ref tr), _, _) = item.node {
+ tr.path.span
+ } else {
+ span
+ };
+
+ struct_span_err!(tcx.sess, span, E0205,
+ "the trait `Copy` may not be implemented for this type")
+ .span_label(span, &format!("variant `{}` does not implement `Copy`",
+ name))
+ .emit()
}
Err(CopyImplementationError::NotAnAdt) => {
- span_err!(tcx.sess, span, E0206,
- "the trait `Copy` may not be implemented \
- for this type; type is not a structure or \
- enumeration")
+ let item = tcx.map.expect_item(impl_node_id);
+ let span = if let ItemImpl(_, _, _, _, ref ty, _) = item.node {
+ ty.span
+ } else {
+ span
+ };
+
+ struct_span_err!(tcx.sess, span, E0206,
+ "the trait `Copy` may not be implemented for this type")
+ .span_label(span, &format!("type is not a structure or enumeration"))
+ .emit();
}
Err(CopyImplementationError::HasDestructor) => {
span_err!(tcx.sess, span, E0184,
debug!("check_implementations_of_coerce_unsized: {:?} -> {:?} (free)",
source, target);
- tcx.infer_ctxt(None, Some(param_env), ProjectionMode::Topmost).enter(|infcx| {
+ tcx.infer_ctxt(None, Some(param_env), Reveal::ExactMatch).enter(|infcx| {
let origin = TypeOrigin::Misc(span);
let check_mutbl = |mt_a: ty::TypeAndMut<'gcx>, mt_b: ty::TypeAndMut<'gcx>,
mk_ptr: &Fn(Ty<'gcx>) -> Ty<'gcx>| {
pub fn check_coherence(ccx: &CrateCtxt) {
let _task = ccx.tcx.dep_graph.in_task(DepNode::Coherence);
- ccx.tcx.infer_ctxt(None, None, ProjectionMode::Topmost).enter(|infcx| {
+ ccx.tcx.infer_ctxt(None, None, Reveal::ExactMatch).enter(|infcx| {
CoherenceChecker {
crate_context: ccx,
inference_context: infcx,