2 min read

Rust 2018 RC1 was released yesterday. This new version of the Rust programming language contains features like raw identifiers, better path clarity and other additions. Some of the changes in Rust 2018 RC1 include:

Raw identifiers

Like many programming languages, Rust too has the concept of “keywords”. These identifiers cannot be used in places like variable names, function names, and other places. With Rust 2018 RC1, raw identifiers let you use keywords where they are not allowed normally. New confirmed keywords in Rust 2018 RC1 are async, await, and try.

Better path clarity

One of the hardest things for people new to Rust is the module system. While there are simple and consistent rules defining the module system, their consequences can appear to be inconsistent and hard to understand.

Rust 2018 RC1 introduces a few new module system features to simplify the module system and give a better picture of what is going on.

  • extern crate is no longer needed. The crate keyword refers to the current crate. Absolute paths begin with a crate name, where again the keyword crate refers to the current crate.
  • A foo.rs and foo/ subdirectory may coexist. mod.rs is no longer required when placing submodules in a subdirectory.

Anonymous trait parameters are deprecated

Parameters in trait method declarations are no longer allowed to be anonymous.

In Rust 2015, the following was allowed:

trait Foo {
    fn foo(&self, u8);
}

In Rust 2018 RC1, all parameters require an argument name (even if it’s just _):

trait Foo {
    fn foo(&self, baz: u8);
}

Non-lexical lifetimes

The borrow checker has been enhanced to accept more code. This is performed via a mechanism called ‘non-lexical lifetimes’. Previously, the below code would have produced an error, but now it will compile just fine:

fn main() {
    let mut x = 5;
    let y = &x;
    let z = &mut x;
}

Lifetimes follow “lexical scope”. This means that the borrow from y is considered to be held until y goes out of scope at the end of main. This is the case even though y will never be used again in the code. The above code works fine, but in the older versions, the borrow checker was not able handle it.

Installation

To try and install Rust 2018 RC1 you need to install the Rust 1.30 beta toolchain. This beta is a little different from the normal beta, states the Rust Blog.

> rustup install beta
> rustc +beta --version 
rustc 1.30.0-beta.2 (7a0062e46 2018-09-19)

The feature flags for Rust 2018 RC1 are turned on and can be used to report issues.

These were only a select few changes. Other changes in this beta include Lifetime elison in impl, T: ‘a inference in structs, macro changes etc. For more information and details on the complete list of updates, read the Rust edition guide where the new features are marked as beta.

Read next

Rust 1.29 is out with improvements to its package manager, Cargo

Deno, an attempt to fix Node.js flaws, is rewritten in Rust

Creating Macros in Rust [Tutorial]

Data science enthusiast. Cycling, music, food, movies. Likes FPS and strategy games.