Skip to content

Commit 9d68a23

Browse files
authoredJun 1, 2017
Rollup merge of #42324 - seanmonstar:41323-compare_const_impl, r=nikomatsakis
associated_consts: check trait obligations and regionck for associated consts Closes #41323 r? @nikomatsakis
2 parents a554b74 + 62989c1 commit 9d68a23

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed
 

Diff for: ‎src/librustc_typeck/check/compare_method.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,14 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
787787
diag.emit();
788788
}
789789

790-
// FIXME(#41323) Check the obligations in the fulfillment context.
790+
// Check that all obligations are satisfied by the implementation's
791+
// version.
792+
if let Err(ref errors) = inh.fulfillment_cx.borrow_mut().select_all_or_error(&infcx) {
793+
infcx.report_fulfillment_errors(errors);
794+
return;
795+
}
796+
797+
let fcx = FnCtxt::new(&inh, impl_c_node_id);
798+
fcx.regionck_item(impl_c_node_id, impl_c_span, &[]);
791799
});
792800
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(associated_consts)]
12+
13+
trait Foo {
14+
type Out: Sized;
15+
}
16+
17+
impl Foo for String {
18+
type Out = String;
19+
}
20+
21+
trait Bar: Foo {
22+
const FROM: Self::Out;
23+
}
24+
25+
impl<T: Foo> Bar for T {
26+
const FROM: &'static str = "foo";
27+
//~^ ERROR the trait bound `T: Foo` is not satisfied [E0277]
28+
}
29+
30+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(associated_consts)]
12+
13+
trait Foo {
14+
const NAME: &'static str;
15+
}
16+
17+
18+
impl<'a> Foo for &'a () {
19+
//~^ NOTE the lifetime 'a as defined
20+
const NAME: &'a str = "unit";
21+
//~^ ERROR mismatched types [E0308]
22+
//~| NOTE lifetime mismatch
23+
//~| NOTE expected type `&'static str`
24+
//~| NOTE ...does not necessarily outlive the static lifetime
25+
}
26+
27+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.