Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my trait definition compile with the 2015 edition but not with the 2018 edition?

Tags:

rust

rust-2018

I wrote this simple program:

trait Command<T> {                                                                                                      
    fn execute(&self, &mut T);                                                                                          
}                                                                                                                       

fn main() {                                                                                                             
    let x = 0;                                                                                                          
}    

I compiled this with rustc --edition=2018 main.rs and get the error message:

error: expected one of `:` or `@`, found `)`
 --> main.rs:2:29
  |
2 |     fn execute(&self, &mut T);
  |                             ^ expected one of `:` or `@` here

Compiling via rustc --edition=2015 main.rs or rustc main.rs doesn't cause this error, although there are some warnings.

What's the problem with this code?

like image 342
T.Shin Avatar asked Feb 09 '19 15:02

T.Shin


People also ask

When was the perma model created?

The PERMA Model, or Theory, of wellbeing was formulated by psychologist Martin Seligman and published in his 2011 book Flourish 1.

What is the perma V model?

The PERMA-V model can be a useful tool when creating well-being strategies. This science-based model stems from positive psychology, and is an acronym that consists of six important building blocks: Positivity, Engagement, Relationships, Meaning, Achievement, and Vitality.

What does my perma score mean?

Questionnaires Overview The PERMA Profiler is a general measure, developed for adults, which measures flourishing in terms of 5 domains: positive emotion, engagement, relationships, meaning, and accomplishment, following Dr. Seligman's well-being theory (see the book Flourish for more information).

Is resilience always a good thing?

Researchers, managers, consultants, and psychologists all know that resilience is the most important factor not only to mental health but to performance and success. People who are resilient to adversity, difficulty, and stress quickly rise to the top. They are today's best performers and tomorrows leaders.


1 Answers

Anonymous trait parameters have been removed in 2018 edition: No more anonymous trait parameters.

Add _: before &mut T if you want to ignore the parameter:

trait Command<T> {
    fn execute(&self, _: &mut T);
}

Compiling with rustc main.rs works, because it defaults to --edition=2015.


Indeed, if you put your main.rs in a new Cargo project, then remove edition = "2018" from Cargo.toml, and run

cargo fix --edition

then Cargo will add the missing _: automatically. See Transitioning an existing project to a new edition.

like image 200
Andrey Tyukin Avatar answered Sep 18 '22 07:09

Andrey Tyukin