Skip to content

Commit

Permalink
Strip line numbers outside of the one input file
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 26, 2021
1 parent d8c5756 commit 9db3ce5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
43 changes: 32 additions & 11 deletions src/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub fn diagnostics(output: Vec<u8>, context: Context) -> Variations {
CargoRegistry,
ArrowOtherCrate,
RelativeToDir,
LinesOutsideInputFile,
]
.iter()
.map(|normalization| apply(&from_bytes, *normalization, context))
Expand Down Expand Up @@ -95,6 +96,7 @@ enum Normalization {
CargoRegistry,
ArrowOtherCrate,
RelativeToDir,
LinesOutsideInputFile,
// New normalization steps are to be inserted here at the end so that any
// snapshots saved before your normalization change remain passing.
}
Expand Down Expand Up @@ -166,24 +168,43 @@ impl<'a> Filter<'a> {
.to_string_lossy()
.to_ascii_lowercase()
.replace('\\', "/");
let mut other_crate = false;
if let Some(i) = line_lower.find(&source_dir_pat) {
if self.normalization >= RelativeToDir && i == indent + 4 {
line.replace_range(i..i + source_dir_pat.len(), "");
if self.normalization < LinesOutsideInputFile {
return Some(line);
}
let input_file_pat = self
.context
.input_file
.to_string_lossy()
.to_ascii_lowercase()
.replace('\\', "/");
if line_lower[i + source_dir_pat.len()..].starts_with(&input_file_pat) {
// Keep line numbers only within the input file (the
// path passed to our `fn compile_fail`. All other
// source files get line numbers erased below.
return Some(line);
}
} else {
line.replace_range(i..i + source_dir_pat.len() - 1, "$DIR");
if self.normalization < LinesOutsideInputFile {
return Some(line);
}
}
return Some(line);
}
let mut other_crate = false;
let workspace_pat = self
.context
.workspace
.to_string_lossy()
.to_ascii_lowercase()
.replace('\\', "/");
if let Some(i) = line_lower.find(&workspace_pat) {
line.replace_range(i..i + workspace_pat.len() - 1, "$WORKSPACE");
other_crate = true;
} else {
let workspace_pat = self
.context
.workspace
.to_string_lossy()
.to_ascii_lowercase()
.replace('\\', "/");
if let Some(i) = line_lower.find(&workspace_pat) {
line.replace_range(i..i + workspace_pat.len() - 1, "$WORKSPACE");
other_crate = true;
}
}
if self.normalization >= PathDependencies && !other_crate {
for path_dep in self.context.path_dependencies {
Expand Down
5 changes: 2 additions & 3 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ Additional crates such as `pyo3-asyncio` can be used to integrate async Rust and
| ^^^^^
"}

// FIXME: should strip the line numbers on src/handler.rs
test_normalize! {test_dropshot_required_by
DIR="/git/dropshot/dropshot"
WORKSPACE="/git/dropshot"
Expand All @@ -297,8 +296,8 @@ error[E0277]: the trait bound `QueryParams: schemars::JsonSchema` is not satisfi
| ^^^^^^^^^^^^^^^^^^ the trait `schemars::JsonSchema` is not implemented for `QueryParams`
|
note: required by a bound in `dropshot::Query`
--> src/handler.rs:547:48
--> src/handler.rs
|
547 | pub struct Query<QueryType: DeserializeOwned + JsonSchema + Send + Sync> {
| pub struct Query<QueryType: DeserializeOwned + JsonSchema + Send + Sync> {
| ^^^^^^^^^^ required by this bound in `dropshot::Query`
"}

0 comments on commit 9db3ce5

Please sign in to comment.