-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
associated_consts: check trait obligations and regionck for associate…
…d consts Closes #41323
- Loading branch information
1 parent
f89d8d1
commit 62989c1
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/test/compile-fail/associated-const-generic-obligations.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
src/test/compile-fail/associated-const-impl-wrong-lifetime.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |