style: Avoid cloning all over the error reporter.

This commit is contained in:
Emilio Cobos Álvarez 2017-03-14 00:12:38 +01:00
parent eaf27ccfa0
commit b4de69e3eb
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
36 changed files with 186 additions and 154 deletions

View file

@ -11,16 +11,16 @@ use log;
use servo_url::ServoUrl;
/// A generic trait for an error reporter.
pub trait ParseErrorReporter {
pub trait ParseErrorReporter : Sync + Send {
/// Called the style engine detects an error.
///
/// Returns the current input being parsed, the source position it was
/// reported from, and a message.
fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str, url: &ServoUrl);
/// Clone this error reporter.
///
/// TODO(emilio): I'm pretty sure all the box shenanigans can go away.
fn clone(&self) -> Box<ParseErrorReporter + Send + Sync>;
fn report_error(&self,
input: &mut Parser,
position: SourcePosition,
message: &str,
url: &ServoUrl);
}
/// An error reporter that reports the errors to the `info` log channel.
@ -28,15 +28,14 @@ pub trait ParseErrorReporter {
/// TODO(emilio): The name of this reporter is a lie, and should be renamed!
pub struct StdoutErrorReporter;
impl ParseErrorReporter for StdoutErrorReporter {
fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str,
url: &ServoUrl) {
fn report_error(&self,
input: &mut Parser,
position: SourcePosition,
message: &str,
url: &ServoUrl) {
if log_enabled!(log::LogLevel::Info) {
let location = input.source_location(position);
info!("Url:\t{}\n{}:{} {}", url.as_str(), location.line, location.column, message)
}
}
fn clone(&self) -> Box<ParseErrorReporter + Send + Sync> {
Box::new(StdoutErrorReporter)
}
}