rustfix - Rust (original) (raw)

Expand description

Library for applying diagnostic suggestions to source code.

This is a low-level library. You pass it the JSON output from rustc, and you can then use it to apply suggestions to in-memory strings. This library doesnโ€™t execute commands, or read or write from the filesystem.

If you are looking for the cargo fix implementation, the core of it is located in cargo::ops::fix.

The general outline of how to use this library is:

  1. Call rustc and collect the JSON data.
  2. Pass the json data to get_suggestions_from_json.
  3. Create a CodeFix with the source of a file to modify.
  4. Call CodeFix::apply to apply a change.
  5. Call CodeFix::finish to get the result and write it back to disk.

This crate is maintained by the Cargo team, primarily for use by Cargo and Rust compiler test suite and not intended for external use (except as a transitive dependency). This crate may make major changes to its APIs or be deprecated without warning.

diagnostics

Rustc Diagnostic JSON Output.

error ๐Ÿ”’

Error types.

replace ๐Ÿ”’

A small module giving you a simple container that allows easy and cheap replacement of parts of its content, with the ability to commit or rollback pending changes.

CodeFix

Represents a code fix. This doesnโ€™t write to disks but is only in memory.

LinePosition

LineRange

Replacement

Represents a replacement of a snippet.

Snippet

Represents code that will get replaced.

Solution

Solution to a diagnostic item.

Suggestion

An error/warning and possible solutions for fixing it

Error

Filter

A filter to control which suggestion should be applied.

apply_suggestions

Applies multiple suggestions to the given code, handling certain conflicts automatically.

collect_span ๐Ÿ”’

Converts a DiagnosticSpan into a Replacement.

collect_suggestions

Collects code Suggestions from a single compiler diagnostic line.

get_suggestions_from_json

Collects code Suggestions from one or more compiler diagnostic lines.

span_to_snippet ๐Ÿ”’

Converts a DiagnosticSpan to a Snippet.