Skip to content

Commit e585b71

Browse files
committed
Auto merge of #9475 - Nemo157:mod-files-remap, r=xFrednet
Make module-style lints resilient to --remap-path-prefix changelog: [`self_named_module_files`], [`mod_module_files`]: Make module-style lints resilient to `--remap-path-prefix` Without this if a user has configured `--remap-path-prefix` to be used for a prefix containing the current source directory the lints would silently fail to generate a warning.
2 parents bae4699 + e9722fe commit e585b71

File tree

6 files changed

+32
-3
lines changed

6 files changed

+32
-3
lines changed

clippy_lints/src/module_style.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_ast::ast;
22
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
33
use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext};
44
use rustc_session::{declare_tool_lint, impl_lint_pass};
5-
use rustc_span::{FileName, RealFileName, SourceFile, Span, SyntaxContext};
5+
use rustc_span::{FileName, SourceFile, Span, SyntaxContext};
66
use std::ffi::OsStr;
77
use std::path::{Component, Path};
88

@@ -79,7 +79,7 @@ impl EarlyLintPass for ModStyle {
7979

8080
let files = cx.sess().source_map().files();
8181

82-
let RealFileName::LocalPath(trim_to_src) = &cx.sess().opts.working_dir else { return };
82+
let Some(trim_to_src) = cx.sess().opts.working_dir.local_path() else { return };
8383

8484
// `folder_segments` is all unique folder path segments `path/to/foo.rs` gives
8585
// `[path, to]` but not foo
@@ -90,7 +90,7 @@ impl EarlyLintPass for ModStyle {
9090
// `{ foo => path/to/foo.rs, .. }
9191
let mut file_map = FxHashMap::default();
9292
for file in files.iter() {
93-
if let FileName::Real(RealFileName::LocalPath(lp)) = &file.name {
93+
if let FileName::Real(name) = &file.name && let Some(lp) = name.local_path() {
9494
let path = if lp.is_relative() {
9595
lp
9696
} else if let Ok(relative) = lp.strip_prefix(trim_to_src) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "fail-mod-remap"
3+
version = "0.1.0"
4+
edition = "2018"
5+
publish = false
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod inner;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compile-flags: --remap-path-prefix {{src-base}}=/remapped
2+
3+
#![warn(clippy::self_named_module_files)]
4+
5+
mod bad;
6+
7+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: `mod.rs` files are required, found `bad.rs`
2+
--> /remapped/module_style/fail_mod_remap/src/bad.rs:1:1
3+
|
4+
LL | pub mod inner;
5+
| ^
6+
|
7+
= note: `-D clippy::self-named-module-files` implied by `-D warnings`
8+
= help: move `bad.rs` to `bad/mod.rs`
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)