Skip to content

Commit 10b5d58

Browse files
authored
Merge pull request #181 from oli-obk/spanned
Move most of our span handling out into a crate
2 parents 1ebfcc5 + 5861b37 commit 10b5d58

File tree

16 files changed

+265
-328
lines changed

16 files changed

+265
-328
lines changed

Cargo.lock

Lines changed: 21 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ indicatif = "0.17.6"
2929
prettydiff = { version = "0.6.4", default_features = false }
3030
annotate-snippets = { version = "0.9.1", features = ["color"] }
3131
levenshtein = "1.0.5"
32+
spanned = "0.1.3"
3233

3334
[dependencies.regex]
3435
version = "1.5.5"

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
parser::{Pattern, Spanned},
3-
rustc_stderr::{Message, Span},
2+
parser::{Pattern, Span, Spanned},
3+
rustc_stderr::Message,
44
Mode,
55
};
66
use std::{num::NonZeroUsize, path::PathBuf, process::ExitStatus};

src/lib.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use dependencies::{Build, BuildManager};
1616
use lazy_static::lazy_static;
1717
use parser::{ErrorMatch, MaybeSpanned, OptWithLine, Revisioned, Spanned};
1818
use regex::bytes::{Captures, Regex};
19-
use rustc_stderr::{Level, Message, Span};
19+
use rustc_stderr::{Level, Message};
20+
use spanned::Span;
2021
use status_emitter::{StatusEmitter, TestStatus};
2122
use std::borrow::Cow;
2223
use std::collections::{HashSet, VecDeque};
@@ -432,7 +433,7 @@ fn parse_and_test_file(
432433
mut config: Config,
433434
file_contents: Vec<u8>,
434435
) -> Result<Vec<TestRun>, Errored> {
435-
let comments = parse_comments(&file_contents)?;
436+
let comments = parse_comments(&file_contents, status.path())?;
436437
const EMPTY: &[String] = &[String::new()];
437438
// Run the test for all revisions
438439
let revisions = comments.revisions.as_deref().unwrap_or(EMPTY);
@@ -470,8 +471,8 @@ fn parse_and_test_file(
470471
.collect())
471472
}
472473

473-
fn parse_comments(file_contents: &[u8]) -> Result<Comments, Errored> {
474-
match Comments::parse(file_contents) {
474+
fn parse_comments(file_contents: &[u8], file: &Path) -> Result<Comments, Errored> {
475+
match Comments::parse(file_contents, file) {
475476
Ok(comments) => Ok(comments),
476477
Err(errors) => Err(Errored {
477478
command: Command::new("parse comments"),
@@ -526,7 +527,7 @@ fn build_aux(
526527
stderr: err.to_string().into_bytes(),
527528
stdout: vec![],
528529
})?;
529-
let comments = parse_comments(&file_contents)?;
530+
let comments = parse_comments(&file_contents, aux_file)?;
530531
assert_eq!(
531532
comments.revisions, None,
532533
"aux builds cannot specify revisions"
@@ -826,7 +827,9 @@ fn run_rustfix(
826827
extra_args: Vec<OsString>,
827828
) -> Result<(), Errored> {
828829
let no_run_rustfix =
829-
comments.find_one_for_revision(revision, "`no-rustfix` annotations", |r| r.no_rustfix)?;
830+
comments.find_one_for_revision(revision, "`no-rustfix` annotations", |r| {
831+
r.no_rustfix.clone()
832+
})?;
830833

831834
let global_rustfix = match mode {
832835
Mode::Pass | Mode::Run { .. } | Mode::Panic => RustfixMode::Disabled,
@@ -877,7 +880,7 @@ fn run_rustfix(
877880
let edition = comments.edition(revision, config)?;
878881
let edition = edition
879882
.map(|mwl| {
880-
let line = mwl.span().unwrap_or(Span::INVALID);
883+
let line = mwl.span().unwrap_or_default();
881884
Spanned::new(mwl.into_inner(), line)
882885
})
883886
.into();
@@ -886,7 +889,7 @@ fn run_rustfix(
886889
revisioned: std::iter::once((
887890
vec![],
888891
Revisioned {
889-
span: Span::INVALID,
892+
span: Span::default(),
890893
ignore: vec![],
891894
only: vec![],
892895
stderr_per_bitwidth: false,
@@ -908,8 +911,8 @@ fn run_rustfix(
908911
.flat_map(|r| r.aux_builds.iter().cloned())
909912
.collect(),
910913
edition,
911-
mode: OptWithLine::new(Mode::Pass, Span::INVALID),
912-
no_rustfix: OptWithLine::new((), Span::INVALID),
914+
mode: OptWithLine::new(Mode::Pass, Span::default()),
915+
no_rustfix: OptWithLine::new((), Span::default()),
913916
needs_asm_support: false,
914917
},
915918
))
@@ -1127,11 +1130,12 @@ fn check_annotations(
11271130
let required_annotation_level = comments.find_one_for_revision(
11281131
revision,
11291132
"`require_annotations_for_level` annotations",
1130-
|r| r.require_annotations_for_level,
1133+
|r| r.require_annotations_for_level.clone(),
11311134
)?;
11321135

1133-
let required_annotation_level =
1134-
required_annotation_level.map_or(lowest_annotation_level, |l| *l);
1136+
let required_annotation_level = required_annotation_level
1137+
.into_inner()
1138+
.map_or(lowest_annotation_level, |l| *l);
11351139
let filter = |mut msgs: Vec<Message>| -> Vec<_> {
11361140
msgs.retain(|msg| msg.level >= required_annotation_level);
11371141
msgs
@@ -1155,9 +1159,9 @@ fn check_annotations(
11551159
errors.push(Error::ErrorsWithoutPattern {
11561160
path: Some(Spanned::new(
11571161
path.to_path_buf(),
1158-
Span {
1162+
spanned::Span {
11591163
line_start: line,
1160-
..Span::INVALID
1164+
..spanned::Span::default()
11611165
},
11621166
)),
11631167
msgs,

src/mode.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub enum Mode {
4949
}
5050

5151
impl Mode {
52+
#[allow(clippy::result_large_err)]
5253
pub(crate) fn ok(self, status: ExitStatus) -> Result<(), Error> {
5354
let expected = match self {
5455
Mode::Run { exit_code } => exit_code,
@@ -72,8 +73,10 @@ impl Mode {
7273
comments: &Comments,
7374
revision: &str,
7475
) -> Result<MaybeSpanned<Self>, Errored> {
75-
let mode = comments.find_one_for_revision(revision, "mode changes", |r| r.mode)?;
76-
Ok(mode.map_or(MaybeSpanned::new_config(self), Into::into))
76+
let mode = comments.find_one_for_revision(revision, "mode changes", |r| r.mode.clone())?;
77+
Ok(mode
78+
.into_inner()
79+
.map_or(MaybeSpanned::new_config(self), Into::into))
7780
}
7881
}
7982

0 commit comments

Comments
 (0)