clippy_utils

Function maybe_get_relative_path

source
pub(crate) fn maybe_get_relative_path(
    from: &DefPath,
    to: &DefPath,
    max_super: usize,
) -> String
Expand description

Tries to produce a relative path from from to to; if such a path would contain more than max_super super items, produces an absolute path instead. Both from and to should be in the local crate.

Suitable for user output/suggestions.

This ignores use items, and assumes that the target path is visible from the source path (which should be a reasonable assumption since we in order to be able to use an object of certain type T, T is required to be visible).

TODO make use of use items. Maybe we should have something more sophisticated like rust-analyzer does? https://docs.rs/ra_ap_hir_def/0.0.169/src/ra_ap_hir_def/find_path.rs.html#19-27