2014-04-22 06:20:08 -05:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2014-10-17 08:12:25 -05:00
|
|
|
// Test the mechanism for warning about possible missing `self` declarations.
|
|
|
|
|
2015-02-12 09:29:52 -06:00
|
|
|
use std::marker::MarkerTrait;
|
|
|
|
|
2014-04-22 06:20:08 -05:00
|
|
|
trait CtxtFn {
|
2014-12-05 20:12:25 -06:00
|
|
|
fn f8(self, usize) -> usize;
|
|
|
|
fn f9(usize) -> usize; //~ NOTE candidate
|
2014-04-22 06:20:08 -05:00
|
|
|
}
|
|
|
|
|
2015-02-12 09:29:52 -06:00
|
|
|
trait OtherTrait : MarkerTrait {
|
2014-12-05 20:12:25 -06:00
|
|
|
fn f9(usize) -> usize; //~ NOTE candidate
|
2014-04-22 06:20:08 -05:00
|
|
|
}
|
|
|
|
|
2014-10-17 08:12:25 -05:00
|
|
|
// Note: this trait is not implemented, but we can't really tell
|
|
|
|
// whether or not an impl would match anyhow without a self
|
2014-12-05 20:12:25 -06:00
|
|
|
// declaration to match against, so we wind up prisizeing it as a
|
2014-10-17 08:12:25 -05:00
|
|
|
// candidate. This seems not unreasonable -- perhaps the user meant to
|
|
|
|
// implement it, after all.
|
2015-02-12 09:29:52 -06:00
|
|
|
trait UnusedTrait : MarkerTrait {
|
2014-12-05 20:12:25 -06:00
|
|
|
fn f9(usize) -> usize; //~ NOTE candidate
|
2014-04-22 06:20:08 -05:00
|
|
|
}
|
|
|
|
|
2014-12-05 20:12:25 -06:00
|
|
|
impl CtxtFn for usize {
|
|
|
|
fn f8(self, i: usize) -> usize {
|
2015-02-18 04:42:01 -06:00
|
|
|
i * 4_usize
|
2014-04-22 06:20:08 -05:00
|
|
|
}
|
|
|
|
|
2014-12-05 20:12:25 -06:00
|
|
|
fn f9(i: usize) -> usize {
|
2015-02-18 04:42:01 -06:00
|
|
|
i * 4_usize
|
2014-04-22 06:20:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-05 20:12:25 -06:00
|
|
|
impl OtherTrait for usize {
|
|
|
|
fn f9(i: usize) -> usize {
|
2015-02-18 04:42:01 -06:00
|
|
|
i * 8_usize
|
2014-04-22 06:20:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-05 20:12:25 -06:00
|
|
|
struct Myisize(isize);
|
2014-04-22 06:20:08 -05:00
|
|
|
|
2014-12-05 20:12:25 -06:00
|
|
|
impl Myisize {
|
|
|
|
fn fff(i: isize) -> isize { //~ NOTE candidate
|
2014-04-22 06:20:08 -05:00
|
|
|
i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-12 09:29:52 -06:00
|
|
|
trait ManyImplTrait : MarkerTrait {
|
2014-10-17 08:12:25 -05:00
|
|
|
fn is_str() -> bool { //~ NOTE candidate
|
2014-04-22 06:20:08 -05:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
impl ManyImplTrait for String {
|
2014-04-22 06:20:08 -05:00
|
|
|
fn is_str() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-05 20:12:25 -06:00
|
|
|
impl ManyImplTrait for usize {}
|
|
|
|
impl ManyImplTrait for isize {}
|
2014-04-22 06:20:08 -05:00
|
|
|
impl ManyImplTrait for char {}
|
2014-12-05 20:12:25 -06:00
|
|
|
impl ManyImplTrait for Myisize {}
|
2014-04-22 06:20:08 -05:00
|
|
|
|
2014-12-05 20:12:25 -06:00
|
|
|
fn no_param_bound(u: usize, m: Myisize) -> usize {
|
2014-04-22 06:20:08 -05:00
|
|
|
u.f8(42) + u.f9(342) + m.fff(42)
|
2014-12-05 20:12:25 -06:00
|
|
|
//~^ ERROR type `usize` does not implement any method in scope named `f9`
|
2014-04-22 06:20:08 -05:00
|
|
|
//~^^ NOTE found defined static methods, maybe a `self` is missing?
|
2014-12-05 20:12:25 -06:00
|
|
|
//~^^^ ERROR type `Myisize` does not implement any method in scope named `fff`
|
|
|
|
//~^^^^ NOTE found defined static methods, maybe a `self` is missing?
|
2014-04-22 06:20:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn param_bound<T: ManyImplTrait>(t: T) -> bool {
|
|
|
|
t.is_str()
|
|
|
|
//~^ ERROR type `T` does not implement any method in scope named `is_str`
|
|
|
|
//~^^ NOTE found defined static methods, maybe a `self` is missing?
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2014-05-22 18:57:53 -05:00
|
|
|
}
|