Add tests for associated types and inconsistent bounds
This commit is contained in:
parent
ba35e80534
commit
87f63ca258
4 changed files with 166 additions and 0 deletions
33
src/test/ui/trivial-bounds-inconsistent-projection-error.rs
Normal file
33
src/test/ui/trivial-bounds-inconsistent-projection-error.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2018 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(trivial_bounds)]
|
||||
#![allow(unused)]
|
||||
|
||||
struct B;
|
||||
|
||||
trait A {
|
||||
type X;
|
||||
fn get_x() -> Self::X;
|
||||
}
|
||||
|
||||
impl A for B {
|
||||
type X = u8;
|
||||
fn get_x() -> u8 { 0 }
|
||||
}
|
||||
|
||||
fn global_bound_is_hidden() -> u8
|
||||
where
|
||||
B: A<X = i32>
|
||||
{
|
||||
B::get_x() //~ ERROR
|
||||
}
|
||||
|
||||
fn main () {}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/trivial-bounds-inconsistent-projection-error.rs:30:5
|
||||
|
|
||||
LL | fn global_bound_is_hidden() -> u8
|
||||
| -- expected `u8` because of return type
|
||||
...
|
||||
LL | B::get_x() //~ ERROR
|
||||
| ^^^^^^^^^^ expected u8, found i32
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
64
src/test/ui/trivial-bounds-inconsistent-projection.rs
Normal file
64
src/test/ui/trivial-bounds-inconsistent-projection.rs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// run-pass
|
||||
// Check that global bounds result in the expected choice of associated type
|
||||
|
||||
#![feature(trivial_bounds)]
|
||||
#![allow(unused)]
|
||||
|
||||
struct B;
|
||||
|
||||
trait A {
|
||||
type X;
|
||||
fn get_x() -> Self::X;
|
||||
}
|
||||
|
||||
impl A for B {
|
||||
type X = u8;
|
||||
fn get_x() -> u8 { 0 }
|
||||
}
|
||||
|
||||
fn underspecified_bound() -> u8
|
||||
where
|
||||
B: A
|
||||
{
|
||||
B::get_x()
|
||||
}
|
||||
|
||||
fn inconsistent_bound() -> i32
|
||||
where
|
||||
B: A<X = i32>
|
||||
{
|
||||
B::get_x()
|
||||
}
|
||||
|
||||
fn redundant_bound() -> u8
|
||||
where
|
||||
B: A<X = u8>
|
||||
{
|
||||
B::get_x()
|
||||
}
|
||||
|
||||
fn inconsistent_dup_bound() -> i32
|
||||
where
|
||||
B: A<X = i32> + A
|
||||
{
|
||||
B::get_x()
|
||||
}
|
||||
|
||||
fn redundant_dup_bound() -> u8
|
||||
where
|
||||
B: A<X = u8> + A
|
||||
{
|
||||
B::get_x()
|
||||
}
|
||||
|
||||
fn main () {}
|
||||
57
src/test/ui/trivial-bounds-inconsistent-projection.stderr
Normal file
57
src/test/ui/trivial-bounds-inconsistent-projection.stderr
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
warning: Trait bound B: A does not depend on any type or lifetime parameters
|
||||
--> $DIR/trivial-bounds-inconsistent-projection.rs:29:1
|
||||
|
|
||||
LL | / fn underspecified_bound() -> u8
|
||||
LL | | where
|
||||
LL | | B: A
|
||||
LL | | {
|
||||
LL | | B::get_x()
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= note: #[warn(trivial_bounds)] on by default
|
||||
|
||||
warning: Trait bound B: A does not depend on any type or lifetime parameters
|
||||
--> $DIR/trivial-bounds-inconsistent-projection.rs:36:1
|
||||
|
|
||||
LL | / fn inconsistent_bound() -> i32
|
||||
LL | | where
|
||||
LL | | B: A<X = i32>
|
||||
LL | | {
|
||||
LL | | B::get_x()
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
warning: Trait bound B: A does not depend on any type or lifetime parameters
|
||||
--> $DIR/trivial-bounds-inconsistent-projection.rs:43:1
|
||||
|
|
||||
LL | / fn redundant_bound() -> u8
|
||||
LL | | where
|
||||
LL | | B: A<X = u8>
|
||||
LL | | {
|
||||
LL | | B::get_x()
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
warning: Trait bound B: A does not depend on any type or lifetime parameters
|
||||
--> $DIR/trivial-bounds-inconsistent-projection.rs:50:1
|
||||
|
|
||||
LL | / fn inconsistent_dup_bound() -> i32
|
||||
LL | | where
|
||||
LL | | B: A<X = i32> + A
|
||||
LL | | {
|
||||
LL | | B::get_x()
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
warning: Trait bound B: A does not depend on any type or lifetime parameters
|
||||
--> $DIR/trivial-bounds-inconsistent-projection.rs:57:1
|
||||
|
|
||||
LL | / fn redundant_dup_bound() -> u8
|
||||
LL | | where
|
||||
LL | | B: A<X = u8> + A
|
||||
LL | | {
|
||||
LL | | B::get_x()
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue