Rollup merge of #41583 - arielb1:cross-constant, r=eddyb

don't ICE on cross-crate associated const type mismatch

Fixes #41549.

r? @eddyb
This commit is contained in:
Corey Farwell 2017-04-28 00:29:37 -04:00 committed by GitHub
commit d21c9b921d
3 changed files with 47 additions and 7 deletions

View File

@ -788,16 +788,18 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait",
trait_c.name);
// Add a label to the Span containing just the type of the item
let trait_c_node_id = tcx.hir.as_local_node_id(trait_c.def_id).unwrap();
let trait_c_span = match tcx.hir.expect_trait_item(trait_c_node_id).node {
TraitItemKind::Const(ref ty, _) => ty.span,
_ => bug!("{:?} is not a trait const", trait_c),
};
let trait_c_node_id = tcx.hir.as_local_node_id(trait_c.def_id);
let trait_c_span = trait_c_node_id.map(|trait_c_node_id| {
// Add a label to the Span containing just the type of the const
match tcx.hir.expect_trait_item(trait_c_node_id).node {
TraitItemKind::Const(ref ty, _) => ty.span,
_ => bug!("{:?} is not a trait const", trait_c),
}
});
infcx.note_type_err(&mut diag,
&cause,
Some((trait_c_span, format!("type in trait"))),
trait_c_span.map(|span| (span, format!("type in trait"))),
Some(infer::ValuePairs::Types(ExpectedFound {
expected: trait_ty,
found: impl_ty,

View File

@ -0,0 +1,15 @@
// Copyright 2017 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.
#![feature(associated_consts)]
pub trait Trait {
const CONST: u32;
}

View File

@ -0,0 +1,23 @@
// Copyright 2017 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.
// aux-build:issue_41549.rs
#![feature(associated_consts)]
extern crate issue_41549;
struct S;
impl issue_41549::Trait for S {
const CONST: () = (); //~ ERROR incompatible type for trait
}
fn main() {}