Skip to content

Commit

Permalink
Auto merge of rust-lang#13795 - jonas-schievink:fix-rustfmt-edition-i…
Browse files Browse the repository at this point in the history
…n-path-deps, r=jonas-schievink

fix: Use the correct edition when formatting code in path dependencies

Fixes rust-lang/rust-analyzer#13790

Don't go through the Cargo workspace info, since that doesn't contain path dependencies. Instead, query the crate graph via `Analysis::crate_edition`.
  • Loading branch information
bors committed Dec 19, 2022
2 parents 1f74b1b + 5706910 commit ffedfc6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions crates/rust-analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1788,14 +1788,15 @@ fn run_rustfmt(
let file_id = from_proto::file_id(snap, &text_document.uri)?;
let file = snap.analysis.file_text(file_id)?;

// find the edition of the package the file belongs to
// (if it belongs to multiple we'll just pick the first one and pray)
let edition = snap
// Determine the edition of the crate the file belongs to (if there's multiple, we pick the
// highest edition).
let editions = snap
.analysis
.relevant_crates_for(file_id)?
.into_iter()
.find_map(|crate_id| snap.cargo_target_for_crate_root(crate_id))
.map(|(ws, target)| ws[ws[target].package].edition);
.map(|crate_id| snap.analysis.crate_edition(crate_id))
.collect::<Result<Vec<_>, _>>()?;
let edition = editions.iter().copied().max();

let line_index = snap.file_line_index(file_id)?;

Expand Down

0 comments on commit ffedfc6

Please sign in to comment.