Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Missing fixes for 2018 #149

Closed as not planned
Closed as not planned
@SimonSapin

Description

@SimonSapin

https://blog.rust-lang.org/2018/10/30/help-test-rust-2018.html

The first step is to run cargo fix:

$ cargo fix --edition

This will check your code, and automatically fix any issues that it can. cargo fix is still pretty new, and so it can’t always fix your code automatically. If cargo fix can’t fix something, it will print the warning that it cannot fix to the console. If you see one of these warnings, you’ll have to update your code manually.

Indeed, running (roughly) this command with nightly-2018-11-01 prints some warnings. So many warnings that just transferring them through SSH saturates the 100 Mbps link from my build server.

$ touch **/lib.rs
$ cargo fix --edition --allow-dirty --manifest-path ports/servo/Cargo.toml > /tmp/fix.log 2>&1
$ ls -sh /tmp/fix.log 
96M /tmp/fix.log
$ wc --lines /tmp/fix.log
1450907 /tmp/fix.log
$ grep '^warning:' /tmp/fix.log -c          
160015
$  grep '^warning:' /tmp/fix.log|sort|uniq -c 
 159696 warning: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
      9 warning: anonymous parameters are deprecated and will be removed in the next edition.
      8 warning: `async` is a keyword in the 2018 edition
    302 warning: `try` is a keyword in the 2018 edition
$ grep 'help: use `crate`:' /tmp/fix.log -c   
157968

To be fair these numbers are inflated because a lot of the relevant code is generated. But still, I hope this shows that the absolute-path warnings are extremely common. I feel it is essential that rustfix can fix them automatically for the edition migration path to be viable.

These absolute-path warnings seem to be mostly in one of three cases:

  1. An use statement for an item in the same crate. The warning message suggests adding crate:: and even shows what the new import should look like. So it seems like we’re most of the way there to apply this fix automatically.

  2. An use statement for an item in an external crate, but that crate has been renamed with for example extern crate mozjs as js;. In this case a path starting with js:: could be considered absolute and referring to an external crate. (Though this is a language change rather than a rustfix change.)

  3. An #[derive(…)] attribute with a derive defined in a proc-macro crate. (“Built-in” derives like #[derive(Clone)] are not affected.) The correct fix is probably to add use crate_name::DeriveName; near the start of the module? Again, automatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions