Rollup merge of #35375 - trixnz:update-error-326, r=jonathandturner

Update error format for E0326

Fixes #35335 as part of #35233

r? @jonathandturner
This commit is contained in:
Jonathan Turner 2016-08-11 06:33:57 -07:00 committed by GitHub
commit e24c326400
2 changed files with 25 additions and 3 deletions

View File

@ -14,6 +14,8 @@ use rustc::ty;
use rustc::traits::{self, ProjectionMode};
use rustc::ty::error::ExpectedFound;
use rustc::ty::subst::{self, Subst, Substs, VecPerParamSpace};
use rustc::hir::map::Node;
use rustc::hir::{ImplItemKind, TraitItem_};
use syntax::ast;
use syntax_pos::Span;
@ -461,7 +463,7 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
// Compute skolemized form of impl and trait const tys.
let impl_ty = impl_c.ty.subst(tcx, impl_to_skol_substs);
let trait_ty = trait_c.ty.subst(tcx, &trait_to_skol_substs);
let origin = TypeOrigin::Misc(impl_c_span);
let mut origin = TypeOrigin::Misc(impl_c_span);
let err = infcx.commit_if_ok(|_| {
// There is no "body" here, so just pass dummy id.
@ -496,11 +498,31 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
debug!("checking associated const for compatibility: impl ty {:?}, trait ty {:?}",
impl_ty,
trait_ty);
// Locate the Span containing just the type of the offending impl
if let Some(impl_trait_node) = tcx.map.get_if_local(impl_c.def_id) {
if let Node::NodeImplItem(impl_trait_item) = impl_trait_node {
if let ImplItemKind::Const(ref ty, _) = impl_trait_item.node {
origin = TypeOrigin::Misc(ty.span);
}
}
}
let mut diag = struct_span_err!(
tcx.sess, origin.span(), E0326,
"implemented const `{}` has an incompatible type for trait",
trait_c.name
);
// Add a label to the Span containing just the type of the item
if let Some(orig_trait_node) = tcx.map.get_if_local(trait_c.def_id) {
if let Node::NodeTraitItem(orig_trait_item) = orig_trait_node {
if let TraitItem_::ConstTraitItem(ref ty, _) = orig_trait_item.node {
diag.span_label(ty.span, &format!("original trait requirement"));
}
}
}
infcx.note_type_err(
&mut diag, origin,
Some(infer::ValuePairs::Types(ExpectedFound {

View File

@ -11,7 +11,7 @@
#![feature(associated_consts)]
trait Foo {
const BAR: u32;
const BAR: u32; //~ NOTE original trait requirement
}
struct SignedBar;
@ -19,7 +19,7 @@ struct SignedBar;
impl Foo for SignedBar {
const BAR: i32 = -1;
//~^ ERROR implemented const `BAR` has an incompatible type for trait [E0326]
//~| expected u32, found i32
//~| NOTE expected u32, found i32
}
fn main() {}