Skip to content

Commit ffedfc6

Browse files
committed
Auto merge of rust-lang#13795 - jonas-schievink:fix-rustfmt-edition-in-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`.
2 parents 1f74b1b + 5706910 commit ffedfc6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

crates/rust-analyzer/src/handlers.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1788,14 +1788,15 @@ fn run_rustfmt(
17881788
let file_id = from_proto::file_id(snap, &text_document.uri)?;
17891789
let file = snap.analysis.file_text(file_id)?;
17901790

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

18001801
let line_index = snap.file_line_index(file_id)?;
18011802

0 commit comments

Comments
 (0)