-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
use
associated items of traits
- Loading branch information
1 parent
32c8a9f
commit 6905a19
Showing
9 changed files
with
255 additions
and
20 deletions.
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
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
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
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
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
63 changes: 63 additions & 0 deletions
63
tests/ui/feature-gates/feature-gate-import-trait-associated-functions.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,63 @@ | ||
//@ edition:2018 | ||
use std::collections::HashMap; | ||
|
||
use A::{DEFAULT, new}; | ||
//~^ ERROR `use` associated items of traits is unstable [E0658] | ||
//~| ERROR `use` associated items of traits is unstable [E0658] | ||
use Default::default; | ||
//~^ ERROR `use` associated items of traits is unstable [E0658] | ||
|
||
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}; | ||
//~^ ERROR `use` associated items of traits is unstable [E0658] | ||
//~| ERROR `use` associated items of traits is unstable [E0658] | ||
|
||
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() {} |
53 changes: 53 additions & 0 deletions
53
tests/ui/feature-gates/feature-gate-import-trait-associated-functions.stderr
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,53 @@ | ||
error[E0658]: `use` associated items of traits is unstable | ||
--> $DIR/feature-gate-import-trait-associated-functions.rs:4:9 | ||
| | ||
LL | use A::{DEFAULT, new}; | ||
| ^^^^^^^ | ||
| | ||
= note: see issue #134691 <https://github.com/rust-lang/rust/issues/134691> for more information | ||
= help: add `#![feature(import_trait_associated_functions)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: `use` associated items of traits is unstable | ||
--> $DIR/feature-gate-import-trait-associated-functions.rs:4:18 | ||
| | ||
LL | use A::{DEFAULT, new}; | ||
| ^^^ | ||
| | ||
= note: see issue #134691 <https://github.com/rust-lang/rust/issues/134691> for more information | ||
= help: add `#![feature(import_trait_associated_functions)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: `use` associated items of traits is unstable | ||
--> $DIR/feature-gate-import-trait-associated-functions.rs:7:5 | ||
| | ||
LL | use Default::default; | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #134691 <https://github.com/rust-lang/rust/issues/134691> for more information | ||
= help: add `#![feature(import_trait_associated_functions)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: `use` associated items of traits is unstable | ||
--> $DIR/feature-gate-import-trait-associated-functions.rs:27:26 | ||
| | ||
LL | use super::A::{self, DEFAULT, new}; | ||
| ^^^^^^^ | ||
| | ||
= note: see issue #134691 <https://github.com/rust-lang/rust/issues/134691> for more information | ||
= help: add `#![feature(import_trait_associated_functions)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: `use` associated items of traits is unstable | ||
--> $DIR/feature-gate-import-trait-associated-functions.rs:27:35 | ||
| | ||
LL | use super::A::{self, DEFAULT, new}; | ||
| ^^^ | ||
| | ||
= note: see issue #134691 <https://github.com/rust-lang/rust/issues/134691> for more information | ||
= help: add `#![feature(import_trait_associated_functions)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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,61 @@ | ||
//@ edition:2015 | ||
//@ check-pass | ||
#![feature(import_trait_associated_functions)] | ||
|
||
use std::collections::HashMap; | ||
|
||
use A::{DEFAULT, new}; | ||
use std::default::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() {} |
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,61 @@ | ||
//@ 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() {} |