Skip to content

Commit a0ddf64

Browse files
authored
Merge pull request #286 from DaniPopes/export-parser
Export parser types
2 parents 5b7b0b2 + 1452d2e commit a0ddf64

File tree

7 files changed

+28
-15
lines changed

7 files changed

+28
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Fixed
1313

14+
* exported previously-unnameable parser types
15+
1416
### Changed
1517

1618
## [0.27.0] - 2024-10-07

src/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::{
99
per_test_config::{Comments, Condition},
1010
CommandBuilder, Error, Errors,
1111
};
12-
pub use color_eyre;
1312
use color_eyre::eyre::Result;
1413
use regex::bytes::Regex;
1514
use spanned::Spanned;

src/diff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn has_both_insertions_and_deletions(diff: &[DiffOp<'_, &str>]) -> bool {
142142
seen_l && seen_r
143143
}
144144

145-
pub fn print_diff(expected: &[u8], actual: &[u8]) {
145+
pub(crate) fn print_diff(expected: &[u8], actual: &[u8]) {
146146
let expected_str = String::from_utf8_lossy(expected);
147147
let actual_str = String::from_utf8_lossy(actual);
148148

src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
clippy::enum_variant_names,
33
clippy::useless_format,
44
clippy::too_many_arguments,
5-
rustc::internal
5+
rustc::internal,
6+
// `unnameable_types` was stabilized in 1.79 which is higher than the current MSRV.
7+
// Ignore the "unknown lint" warning which is emitted on older versions.
8+
unknown_lints
69
)]
10+
#![warn(unreachable_pub, unnameable_types)]
711
#![deny(missing_docs)]
812
#![doc = include_str!("../README.md")]
913

10-
use crate::parser::Comments;
1114
use build_manager::BuildManager;
1215
use build_manager::NewJob;
1316
pub use color_eyre;
@@ -64,6 +67,7 @@ mod tests;
6467
pub use cmd::*;
6568
pub use config::*;
6669
pub use error::*;
70+
pub use parser::*;
6771
pub use spanned;
6872

6973
/// Run all tests as described in the config argument.
@@ -146,8 +150,6 @@ pub fn default_per_file_config(config: &mut Config, file_contents: &Spanned<Vec<
146150
/// Ignores various settings from `Config` that relate to finding test files.
147151
#[cfg(feature = "rustc")]
148152
pub fn test_command(mut config: Config, path: &Path) -> Result<Command> {
149-
use status_emitter::SilentStatus;
150-
151153
config.fill_host_and_target()?;
152154

153155
let content = Spanned::read_from_file(path)

src/parser.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
use bstr::{ByteSlice, Utf8Error};
55
use color_eyre::eyre::Result;
66
use regex::bytes::Regex;
7-
pub(crate) use spanned::*;
7+
pub use spanned::*;
88
use std::{
99
collections::{BTreeMap, HashMap},
1010
num::NonZeroUsize,
@@ -200,6 +200,7 @@ pub struct CommentParser<T> {
200200
comment_start: &'static str,
201201
}
202202

203+
/// Command parser function type.
203204
pub type CommandParserFunc =
204205
fn(&mut CommentParser<&mut Revisioned>, args: Spanned<&str>, span: Span);
205206

@@ -230,9 +231,10 @@ pub enum Condition {
230231
OnHost,
231232
}
232233

233-
#[derive(Debug, Clone)]
234234
/// A sub string of a target (or a whole target).
235-
/// Effectively a `String` that only allows lowercase chars, integers and dashes
235+
///
236+
/// Effectively a `String` that only allows lowercase chars, integers and dashes.
237+
#[derive(Debug, Clone)]
236238
pub struct TargetSubStr(String);
237239

238240
impl PartialEq<&str> for TargetSubStr {
@@ -266,10 +268,12 @@ impl TryFrom<String> for TargetSubStr {
266268
}
267269
}
268270

269-
#[derive(Debug, Clone)]
270271
/// An error pattern parsed from a `//~` comment.
272+
#[derive(Debug, Clone)]
271273
pub enum Pattern {
274+
/// A substring that must appear in the error message.
272275
SubString(String),
276+
/// A regex that must match the error message.
273277
Regex(Regex),
274278
}
275279

@@ -288,7 +292,7 @@ pub(crate) enum ErrorMatchKind {
288292
pub(crate) struct ErrorMatch {
289293
pub(crate) kind: ErrorMatchKind,
290294
/// The line this pattern is expecting to find a message in.
291-
pub line: NonZeroUsize,
295+
pub(crate) line: NonZeroUsize,
292296
}
293297

294298
impl Condition {
@@ -574,20 +578,23 @@ impl CommentParser<Comments> {
574578
}
575579

576580
impl<CommentsType> CommentParser<CommentsType> {
581+
/// Emits an [`InvalidComment`](Error::InvalidComment) error with the given span and message.
577582
pub fn error(&mut self, span: Span, s: impl Into<String>) {
578583
self.errors.push(Error::InvalidComment {
579584
msg: s.into(),
580585
span,
581586
});
582587
}
583588

589+
/// Checks a condition and emits an error if it is not met.
584590
pub fn check(&mut self, span: Span, cond: bool, s: impl Into<String>) {
585591
if !cond {
586592
self.error(span, s);
587593
}
588594
}
589595

590-
fn check_some<T>(&mut self, span: Span, opt: Option<T>, s: impl Into<String>) -> Option<T> {
596+
/// Checks an option and emits an error if it is `None`.
597+
pub fn check_some<T>(&mut self, span: Span, opt: Option<T>, s: impl Into<String>) -> Option<T> {
591598
self.check(span, opt.is_some(), s);
592599
opt
593600
}
@@ -703,7 +710,7 @@ impl CommentParser<&mut Revisioned> {
703710
Some((regex, to.as_bytes().to_owned()))
704711
}
705712

706-
/// Add a flag or error if it already existed
713+
/// Adds a flag, or errors if it already existed.
707714
pub fn set_custom_once(&mut self, key: &'static str, custom: impl Flag + 'static, span: Span) {
708715
let prev = self
709716
.custom

src/parser/spanned.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
pub use spanned::*;
1+
pub(crate) use spanned::*;
22

3+
/// An optional spanned value.
34
#[derive(Debug, Clone)]
45
pub struct OptWithLine<T>(Option<Spanned<T>>);
56

@@ -30,6 +31,7 @@ impl<T> Default for OptWithLine<T> {
3031
}
3132

3233
impl<T> OptWithLine<T> {
34+
/// Creates a new optional spanned value.
3335
pub fn new(data: T, span: Span) -> Self {
3436
Self(Some(Spanned::new(data, span)))
3537
}
@@ -47,6 +49,7 @@ impl<T> OptWithLine<T> {
4749
}
4850
}
4951

52+
/// Consumes `self` and returns the inner value.
5053
#[must_use]
5154
pub fn into_inner(self) -> Option<Spanned<T>> {
5255
self.0

src/status_emitter/text.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ impl TestStatus for TextTest {
431431
stderr: &'a [u8],
432432
stdout: &'a [u8],
433433
}
434-
impl<'a> Drop for Guard<'a> {
434+
impl Drop for Guard<'_> {
435435
fn drop(&mut self) {
436436
println!("{}", "full stderr:".bold());
437437
std::io::stdout().write_all(self.stderr).unwrap();

0 commit comments

Comments
 (0)