Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

associated_consts: check trait obligations and regionck for associated consts #42324

Merged
merged 1 commit into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/librustc_typeck/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,14 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
diag.emit();
}

// FIXME(#41323) Check the obligations in the fulfillment context.
// Check that all obligations are satisfied by the implementation's
// version.
if let Err(ref errors) = inh.fulfillment_cx.borrow_mut().select_all_or_error(&infcx) {
infcx.report_fulfillment_errors(errors);
return;
}

let fcx = FnCtxt::new(&inh, impl_c_node_id);
fcx.regionck_item(impl_c_node_id, impl_c_span, &[]);
});
}
30 changes: 30 additions & 0 deletions src/test/compile-fail/associated-const-generic-obligations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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)]

trait Foo {
type Out: Sized;
}

impl Foo for String {
type Out = String;
}

trait Bar: Foo {
const FROM: Self::Out;
}

impl<T: Foo> Bar for T {
const FROM: &'static str = "foo";
//~^ ERROR the trait bound `T: Foo` is not satisfied [E0277]
}

fn main() {}
27 changes: 27 additions & 0 deletions src/test/compile-fail/associated-const-impl-wrong-lifetime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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)]

trait Foo {
const NAME: &'static str;
}


impl<'a> Foo for &'a () {
//~^ NOTE the lifetime 'a as defined
const NAME: &'a str = "unit";
//~^ ERROR mismatched types [E0308]
//~| NOTE lifetime mismatch
//~| NOTE expected type `&'static str`
//~| NOTE ...does not necessarily outlive the static lifetime
}

fn main() {}