RustRover 2024.1 Help

Code completion

Auto-completion for your Rust code works as you type. You can also call it manually by pressing Ctrl+Space.

For example, completion is available for attributes and elements inside #[derive], including standard library traits:

Completion for inside #[derive]

For popular Rust crates, you will receive suggestions even if the crate hasn’t been added to dependencies:

Completion for items from popular crates not included in dependencies

Completion also works inside macro calls. The plugin knows the resulting macro substitution and suggests only the applicable items:

Completion for macro calls

Note that completion is available in doctest comments as well:

Completion in doctest comments

Auto-import

RustRover takes care of out-of-scope items. If you select an out-of-scope item from the completion list or paste code containing such items, RustRover will automatically insert the missing use declarations. This behavior is enabled by default, however you can always disable it in Settings | Editor | General | Auto Import (Rust section).

Auto-import on completion and paste

Automatically add import statements

Optionally, you can turn on automatic import on the fly. This way, RustRover will add missing use declarations as you type (unless there are several possible options).

  1. Press Ctrl+Alt+S to open settings and then select Editor | General | Auto Import.

  2. In the Rust section, select the Add unambiguous imports on the fly checkbox, and apply the changes.

Disable completion and auto-import for certain items

You may want to exclude certain items from completion lists and make sure they never get auto-imported. For example, you may want to exclude functions and traits that are re-exported in irrelevant crates – this way, only original ones will be suggested.

  1. Navigate to Settings | Editor | General | Auto Import and locate the Rust section.

  2. In the table, list the items that you want to exclude from completion and auto-import.

    The following rules apply:

    • Specify each path just as you would in a use declaration.

    • Add ::* to a path if you want to disable auto-import for all items whose paths include the given prefix.

    • When excluding traits, use the Apply to dropdown menu to specify whether you want to disable auto-import only for trait methods or for the trait name too.

    Completion in doctest comments

    Note that exclusion settings are ignored for items already imported with a use declaration.

Automatically add popular crates as dependencies on paste

Pasting code to an .rs file may require you to mention additional dependencies in Cargo.toml. RustRover takes care of that. By default, each time you paste such code, it will display a dialog asking you to confirm the list of crates to be added.

Required crate inserted automatically

Configure automatic dependencies on paste

Do one of the following:

  • Once the Add Crates confirmation dialog appears, select Always Add if you want the crates to be added silently or Never Add if you don't want RustRover to ever suggest any new dependencies.

  • In the Settings dialog (Ctrl+Alt+S) , go to Editor | General | Auto Import, locate the Rust section, and select the desired value in the Add crate dependencies on paste dropdown: Always, Never, or Ask.

    Add crate dependencies on paste settings

ML completion

Machine learning assisted completion is enabled by default. The suggestions are sorted by their relevance based on the rules learned from data gathered anonymously during the IDE's Early Access Program. Note that your source code is never being collected, only the information about your interactions with the code completion UI.

If you prefer to disable the ML completion feature, clear the corresponding checkbox in Settings | Editor | General | Code Completion.

ML completion settings

Set the Mark position changes in the completion popup checkbox to view the elements that were reordered to the ML data:

Enabling the ML completion markers
ML completion ranking example

Postfix completion

Postfix completion helps you reduce backward caret jumps as you type. You can transform an already-typed expression into a different one based on a postfix you type after the dot.

For example, type .assert after an expression (or select it from the completion suggestion list) to insert an assert_eq! invocation:

Postfix completion

You can check and adjust the list of postfix templates in Settings | Editor | General | Postfix Completion | Rust:

Rust postfix templates

To add a custom template, click the Add button and select Rust:

Create custom postfix templates

  1. Press Ctrl+Alt+S to open settings and then select Editor | General | Postfix Completion.

  2. Click the Add button (the Add button) on the toolbar and select Rust.

    Adding a postfix template
  3. Specify Key, a combination of symbols that will invoke the template.

  4. Select which expression types the new template will be applicable to, and type the target expression in the following format: $EXPR$ <target_expression>, for example, $EXPR$ =!null.

Last modified: 26 May 2024