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

Move most of our span handling out into a crate #181

Merged
merged 1 commit into from
Oct 25, 2023
Merged
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
25 changes: 21 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ indicatif = "0.17.6"
prettydiff = { version = "0.6.4", default_features = false }
annotate-snippets = { version = "0.9.1", features = ["color"] }
levenshtein = "1.0.5"
spanned = "0.1.3"

[dependencies.regex]
version = "1.5.5"
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
parser::{Pattern, Spanned},
rustc_stderr::{Message, Span},
parser::{Pattern, Span, Spanned},
rustc_stderr::Message,
Mode,
};
use std::{num::NonZeroUsize, path::PathBuf, process::ExitStatus};
Expand Down
34 changes: 19 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use dependencies::{Build, BuildManager};
use lazy_static::lazy_static;
use parser::{ErrorMatch, MaybeSpanned, OptWithLine, Revisioned, Spanned};
use regex::bytes::{Captures, Regex};
use rustc_stderr::{Level, Message, Span};
use rustc_stderr::{Level, Message};
use spanned::Span;
use status_emitter::{StatusEmitter, TestStatus};
use std::borrow::Cow;
use std::collections::{HashSet, VecDeque};
Expand Down Expand Up @@ -432,7 +433,7 @@ fn parse_and_test_file(
mut config: Config,
file_contents: Vec<u8>,
) -> Result<Vec<TestRun>, Errored> {
let comments = parse_comments(&file_contents)?;
let comments = parse_comments(&file_contents, status.path())?;
const EMPTY: &[String] = &[String::new()];
// Run the test for all revisions
let revisions = comments.revisions.as_deref().unwrap_or(EMPTY);
Expand Down Expand Up @@ -470,8 +471,8 @@ fn parse_and_test_file(
.collect())
}

fn parse_comments(file_contents: &[u8]) -> Result<Comments, Errored> {
match Comments::parse(file_contents) {
fn parse_comments(file_contents: &[u8], file: &Path) -> Result<Comments, Errored> {
match Comments::parse(file_contents, file) {
Ok(comments) => Ok(comments),
Err(errors) => Err(Errored {
command: Command::new("parse comments"),
Expand Down Expand Up @@ -526,7 +527,7 @@ fn build_aux(
stderr: err.to_string().into_bytes(),
stdout: vec![],
})?;
let comments = parse_comments(&file_contents)?;
let comments = parse_comments(&file_contents, aux_file)?;
assert_eq!(
comments.revisions, None,
"aux builds cannot specify revisions"
Expand Down Expand Up @@ -826,7 +827,9 @@ fn run_rustfix(
extra_args: Vec<OsString>,
) -> Result<(), Errored> {
let no_run_rustfix =
comments.find_one_for_revision(revision, "`no-rustfix` annotations", |r| r.no_rustfix)?;
comments.find_one_for_revision(revision, "`no-rustfix` annotations", |r| {
r.no_rustfix.clone()
})?;

let global_rustfix = match mode {
Mode::Pass | Mode::Run { .. } | Mode::Panic => RustfixMode::Disabled,
Expand Down Expand Up @@ -877,7 +880,7 @@ fn run_rustfix(
let edition = comments.edition(revision, config)?;
let edition = edition
.map(|mwl| {
let line = mwl.span().unwrap_or(Span::INVALID);
let line = mwl.span().unwrap_or_default();
Spanned::new(mwl.into_inner(), line)
})
.into();
Expand All @@ -886,7 +889,7 @@ fn run_rustfix(
revisioned: std::iter::once((
vec![],
Revisioned {
span: Span::INVALID,
span: Span::default(),
ignore: vec![],
only: vec![],
stderr_per_bitwidth: false,
Expand All @@ -908,8 +911,8 @@ fn run_rustfix(
.flat_map(|r| r.aux_builds.iter().cloned())
.collect(),
edition,
mode: OptWithLine::new(Mode::Pass, Span::INVALID),
no_rustfix: OptWithLine::new((), Span::INVALID),
mode: OptWithLine::new(Mode::Pass, Span::default()),
no_rustfix: OptWithLine::new((), Span::default()),
needs_asm_support: false,
},
))
Expand Down Expand Up @@ -1127,11 +1130,12 @@ fn check_annotations(
let required_annotation_level = comments.find_one_for_revision(
revision,
"`require_annotations_for_level` annotations",
|r| r.require_annotations_for_level,
|r| r.require_annotations_for_level.clone(),
)?;

let required_annotation_level =
required_annotation_level.map_or(lowest_annotation_level, |l| *l);
let required_annotation_level = required_annotation_level
.into_inner()
.map_or(lowest_annotation_level, |l| *l);
let filter = |mut msgs: Vec<Message>| -> Vec<_> {
msgs.retain(|msg| msg.level >= required_annotation_level);
msgs
Expand All @@ -1155,9 +1159,9 @@ fn check_annotations(
errors.push(Error::ErrorsWithoutPattern {
path: Some(Spanned::new(
path.to_path_buf(),
Span {
spanned::Span {
line_start: line,
..Span::INVALID
..spanned::Span::default()
},
)),
msgs,
Expand Down
7 changes: 5 additions & 2 deletions src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub enum Mode {
}

impl Mode {
#[allow(clippy::result_large_err)]
pub(crate) fn ok(self, status: ExitStatus) -> Result<(), Error> {
let expected = match self {
Mode::Run { exit_code } => exit_code,
Expand All @@ -72,8 +73,10 @@ impl Mode {
comments: &Comments,
revision: &str,
) -> Result<MaybeSpanned<Self>, Errored> {
let mode = comments.find_one_for_revision(revision, "mode changes", |r| r.mode)?;
Ok(mode.map_or(MaybeSpanned::new_config(self), Into::into))
let mode = comments.find_one_for_revision(revision, "mode changes", |r| r.mode.clone())?;
Ok(mode
.into_inner()
.map_or(MaybeSpanned::new_config(self), Into::into))
}
}

Expand Down
Loading