Make module-style lints resilient to --remap-path-prefix
This commit is contained in:
parent
556415870d
commit
e9722feef3
@ -2,7 +2,7 @@
|
|||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext};
|
use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext};
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
use rustc_span::{FileName, RealFileName, SourceFile, Span, SyntaxContext};
|
use rustc_span::{FileName, SourceFile, Span, SyntaxContext};
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::path::{Component, Path};
|
use std::path::{Component, Path};
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
|
|||||||
|
|
||||||
let files = cx.sess().source_map().files();
|
let files = cx.sess().source_map().files();
|
||||||
|
|
||||||
let RealFileName::LocalPath(trim_to_src) = &cx.sess().opts.working_dir else { return };
|
let Some(trim_to_src) = cx.sess().opts.working_dir.local_path() else { return };
|
||||||
|
|
||||||
// `folder_segments` is all unique folder path segments `path/to/foo.rs` gives
|
// `folder_segments` is all unique folder path segments `path/to/foo.rs` gives
|
||||||
// `[path, to]` but not foo
|
// `[path, to]` but not foo
|
||||||
@ -90,7 +90,7 @@ fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
|
|||||||
// `{ foo => path/to/foo.rs, .. }
|
// `{ foo => path/to/foo.rs, .. }
|
||||||
let mut file_map = FxHashMap::default();
|
let mut file_map = FxHashMap::default();
|
||||||
for file in files.iter() {
|
for file in files.iter() {
|
||||||
if let FileName::Real(RealFileName::LocalPath(lp)) = &file.name {
|
if let FileName::Real(name) = &file.name && let Some(lp) = name.local_path() {
|
||||||
let path = if lp.is_relative() {
|
let path = if lp.is_relative() {
|
||||||
lp
|
lp
|
||||||
} else if let Ok(relative) = lp.strip_prefix(trim_to_src) {
|
} else if let Ok(relative) = lp.strip_prefix(trim_to_src) {
|
||||||
|
9
tests/ui-cargo/module_style/fail_mod_remap/Cargo.toml
Normal file
9
tests/ui-cargo/module_style/fail_mod_remap/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "fail-mod-remap"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
1
tests/ui-cargo/module_style/fail_mod_remap/src/bad.rs
Normal file
1
tests/ui-cargo/module_style/fail_mod_remap/src/bad.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod inner;
|
@ -0,0 +1 @@
|
|||||||
|
|
7
tests/ui-cargo/module_style/fail_mod_remap/src/main.rs
Normal file
7
tests/ui-cargo/module_style/fail_mod_remap/src/main.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// compile-flags: --remap-path-prefix {{src-base}}=/remapped
|
||||||
|
|
||||||
|
#![warn(clippy::self_named_module_files)]
|
||||||
|
|
||||||
|
mod bad;
|
||||||
|
|
||||||
|
fn main() {}
|
11
tests/ui-cargo/module_style/fail_mod_remap/src/main.stderr
Normal file
11
tests/ui-cargo/module_style/fail_mod_remap/src/main.stderr
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
error: `mod.rs` files are required, found `bad.rs`
|
||||||
|
--> /remapped/module_style/fail_mod_remap/src/bad.rs:1:1
|
||||||
|
|
|
||||||
|
LL | pub mod inner;
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
= note: `-D clippy::self-named-module-files` implied by `-D warnings`
|
||||||
|
= help: move `bad.rs` to `bad/mod.rs`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user