Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback to dir_path when relative external mod resolution fails #5205

Merged
merged 1 commit into from
Mar 1, 2022

Commits on Jan 31, 2022

  1. fallback to dir_path when relative external mod resolution fails

    We only want to fall back if two conditions are met:
    
    1) Initial module resolution is performed relative to some nested
       directory.
    2) Module resolution fails because of a ModError::FileNotFound error.
    
    When these conditions are met we can try to fallback to searching for
    the module's file relative to the dir_path instead of the nested
    relative directory.
    
    Fixes 5198
    
    As demonstrated by 5198, it's possible that a directory name conflicts
    with a rust file name. For example, src/lib/ and src/lib.rs.
    
    If src/lib.rs references an external module like ``mod foo;``, then
    module resolution will try to resolve ``foo`` to src/lib/foo.rs or
    src/lib/foo/mod.rs. Module resolution would fail with a file not
    found error if the ``foo`` module were defined at src/foo.rs.
    
    When encountering these kinds of module resolution issues we now fall
    back to the current directory and attempt to resolve the module again.
    
    Given the current example, this means that if we can't find the module
    ``foo`` at src/lib/foo.rs or src/lib/foo/mod.rs, we'll attempt
    to resolve the module to src/foo.rs.
    ytmimi committed Jan 31, 2022
    Configuration menu
    Copy the full SHA
    f975b88 View commit details
    Browse the repository at this point in the history