rust/tests/ui/use/import_trait_associated_functions.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
909 B
Rust
Raw Normal View History

//@ edition:2018
//@ check-pass
#![feature(import_trait_associated_functions)]
use std::collections::HashMap;
use A::{DEFAULT, new};
use Default::default;
struct S {
a: HashMap<i32, i32>,
}
impl S {
fn new() -> S {
S { a: default() }
}
}
trait A: Sized {
const DEFAULT: Option<Self> = None;
fn new() -> Self;
fn do_something(&self);
}
mod b {
use super::A::{self, DEFAULT, new};
struct B();
impl A for B {
const DEFAULT: Option<Self> = Some(B());
fn new() -> Self {
B()
}
fn do_something(&self) {}
}
fn f() {
let b: B = new();
b.do_something();
let c: B = DEFAULT.unwrap();
}
}
impl A for S {
fn new() -> Self {
S::new()
}
fn do_something(&self) {}
}
fn f() {
let s: S = new();
s.do_something();
let t: Option<S> = DEFAULT;
}
fn main() {}