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

strip rust src lines during normalization #247

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ normalizations! {
AndOthers,
StripLongTypeNameFiles,
UnindentAfterHelp,
StripRustSrc,
// 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 @@ -130,6 +131,7 @@ fn apply(original: &str, normalization: Normalization, context: Context) -> Stri
normalization,
context,
hide_numbers: 0,
numbers_to_hide_are_rust_src: false,
};
for i in 0..lines.len() {
if let Some(line) = filter.apply(i) {
Expand All @@ -150,15 +152,21 @@ struct Filter<'a> {
normalization: Normalization,
context: Context<'a>,
hide_numbers: usize,
numbers_to_hide_are_rust_src: bool,
}

impl<'a> Filter<'a> {
fn apply(&mut self, index: usize) -> Option<String> {
let mut line = self.all_lines[index].to_owned();

if self.hide_numbers > 0 {
hide_leading_numbers(&mut line);
self.hide_numbers -= 1;
if self.numbers_to_hide_are_rust_src && self.normalization >= StripRustSrc {
// strip rust src lines as default rustup installs do not contain rust src
return None;
} else {
hide_leading_numbers(&mut line);
}
}

let trim_start = line.trim_start();
Expand Down Expand Up @@ -195,6 +203,7 @@ impl<'a> Filter<'a> {
.to_ascii_lowercase()
.replace('\\', "/");
let mut other_crate = false;
let mut is_rust_src = false;
if line_lower.find(&target_dir_pat) == Some(indent + 4) {
let mut offset = indent + 4 + target_dir_pat.len();
let mut out_dir_crate_name = None;
Expand Down Expand Up @@ -274,12 +283,12 @@ impl<'a> Filter<'a> {
// --> /home/.rustup/toolchains/nightly/lib/rustlib/src/rust/src/libstd/net/ip.rs:83:1
// --> $RUST/src/libstd/net/ip.rs:83:1
line.replace_range(indent + 4..pos + 17, "$RUST");
other_crate = true;
is_rust_src = true;
} else if let Some(pos) = line.find("/rustlib/src/rust/library/") {
// --> /home/.rustup/toolchains/nightly/lib/rustlib/src/rust/library/std/src/net/ip.rs:83:1
// --> $RUST/std/src/net/ip.rs:83:1
line.replace_range(indent + 4..pos + 25, "$RUST");
other_crate = true;
is_rust_src = true;
} else if line[indent + 4..].starts_with("/rustc/")
&& line
.get(indent + 11..indent + 51)
Expand All @@ -289,7 +298,7 @@ impl<'a> Filter<'a> {
// --> /rustc/c5c7d2b37780dac1092e75f12ab97dd56c30861e/library/std/src/net/ip.rs:83:1
// --> $RUST/std/src/net/ip.rs:83:1
line.replace_range(indent + 4..indent + 59, "$RUST");
other_crate = true;
is_rust_src = true;
}
}
if self.normalization >= CargoRegistry && !other_crate {
Expand All @@ -311,14 +320,15 @@ impl<'a> Filter<'a> {
}
}
}
if other_crate && self.normalization >= WorkspaceLines {
if (other_crate || is_rust_src) && self.normalization >= WorkspaceLines {
// Blank out line numbers for this particular error since rustc
// tends to reach into code from outside of the test case. The
// test stderr shouldn't need to be updated every time we touch
// those files.
hide_trailing_numbers(&mut line);
self.hide_numbers = 1;
while let Some(next_line) = self.all_lines.get(index + self.hide_numbers) {
self.numbers_to_hide_are_rust_src = is_rust_src;
self.hide_numbers = 0;
while let Some(next_line) = self.all_lines.get(index + self.hide_numbers + 1) {
Comment on lines +329 to +331
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that there was an off-by-one error here causing self.hide_numbers to be one higher than it needed to be. That didn't matter while the operation was just trimming leading numbers, resulted in a noop in the last line, but removing whole lines was more destructive.

match next_line.trim_start().chars().next().unwrap_or_default() {
'0'..='9' | '|' | '.' => self.hide_numbers += 1,
_ => break,
Expand Down
3 changes: 0 additions & 3 deletions src/tests/rust-lib-with-githash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@ error[E0599]: the method `to_cxx_exception` exists for reference `&NonError`, bu
which is required by `&NonError: ToCxxExceptionDefault`
note: the trait `std::fmt::Display` must be implemented
--> $RUST/core/src/fmt/mod.rs
|
| pub trait Display {
| ^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `::cxx::map_rust_error_to_cxx_exception` (in Nightly builds, run with -Z macro-backtrace for more info)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E.g. this = note: line would be removed without the off-by-one adjustment.

"}
5 changes: 0 additions & 5 deletions src/tests/rust-lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,4 @@ error[E0599]: no method named `quote_into_iter` found for struct `std::net::Ipv4
|
::: $RUST/src/libstd/net/ip.rs
::: $RUST/std/src/net/ip.rs
|
| pub struct Ipv4Addr {
| -------------------
| |
| doesn't satisfy `std::net::Ipv4Addr: quote::to_tokens::ToTokens`
"}
17 changes: 0 additions & 17 deletions src/tests/traits-must-be-implemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,6 @@ error[E0599]: the method `anyhow_kind` exists for reference `&Error`, but its tr
which is required by `&Error: anyhow::private::kind::TraitKind`
note: the following traits must be implemented
--> $RUST/core/src/convert/mod.rs
|
| / pub trait Into<T>: Sized {
| | /// Performs the conversion.
| | #[stable(feature = \"rust1\", since = \"1.0.0\")]
| | fn into(self) -> T;
| | }
| |_^
|
::: $RUST/core/src/fmt/mod.rs
|
| / pub trait Display {
| | /// Formats the value using the given formatter.
| | ///
| | /// # Examples
... |
| | fn fmt(&self, f: &mut Formatter<'_>) -> Result;
| | }
| |_^
= note: this error originates in the macro `anyhow` (in Nightly builds, run with -Z macro-backtrace for more info)
"}
27 changes: 19 additions & 8 deletions tests/ui/compile-fail-3.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
error[E0277]: `*mut _` cannot be shared between threads safely
--> tests/ui/compile-fail-3.rs:7:5
|
7 | thread::spawn(|| {
| ^^^^^^^^^^^^^ `*mut _` cannot be shared between threads safely
|
= help: the trait `Sync` is not implemented for `*mut _`
= note: required because of the requirements on the impl of `Send` for `&*mut _`
= note: required because it appears within the type `[closure@$DIR/tests/ui/compile-fail-3.rs:7:19: 9:6]`
--> tests/ui/compile-fail-3.rs:7:19
|
7 | thread::spawn(|| {
| _____-------------_^
| | |
| | required by a bound introduced by this call
8 | | println!("{:?}", x)
9 | | });
| |_____^ `*mut _` cannot be shared between threads safely
|
= help: the trait `Sync` is not implemented for `*mut _`
= note: required for `&*mut _` to implement `Send`
note: required because it's used within this closure
--> tests/ui/compile-fail-3.rs:7:19
|
7 | thread::spawn(|| {
| ^^
note: required by a bound in `spawn`
--> $RUST/std/src/thread/mod.rs