Skip to content

Commit

Permalink
Merge branch 'master' into default-fileid
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann150 authored Mar 4, 2021
2 parents e31a93d + 16df309 commit 8028cdd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
13 changes: 7 additions & 6 deletions codespan-reporting/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#[cfg(feature = "serialization")]
use serde::{Deserialize, Serialize};
use std::ops::Range;
use std::string::ToString;

/// A severity level for diagnostic messages.
///
Expand Down Expand Up @@ -104,8 +105,8 @@ impl<FileId> Label<FileId> {
}

/// Set the message for the diagnostic. The old message (if any) is discarded.
pub fn with_message(mut self, message: impl Into<String>) -> Label<FileId> {
self.message = message.into();
pub fn with_message(mut self, message: impl ToString) -> Label<FileId> {
self.message = message.to_string();
self
}

Expand Down Expand Up @@ -231,14 +232,14 @@ impl<FileId> Diagnostic<FileId> {
}

/// Set the error code of the diagnostic.
pub fn with_code(mut self, code: impl Into<String>) -> Diagnostic<FileId> {
self.code = Some(code.into());
pub fn with_code(mut self, code: impl ToString) -> Diagnostic<FileId> {
self.code = Some(code.to_string());
self
}

/// Set the message of the diagnostic.
pub fn with_message(mut self, message: impl Into<String>) -> Diagnostic<FileId> {
self.message = message.into();
pub fn with_message(mut self, message: impl ToString) -> Diagnostic<FileId> {
self.message = message.to_string();
self
}

Expand Down
4 changes: 2 additions & 2 deletions codespan-reporting/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ pub fn column_index(source: &str, line_range: Range<usize>, byte_index: usize) -
/// assert_eq!(line_index(&line_starts, 5), Some(1));
/// ```
// NOTE: this is copied in `codespan::file::line_starts` and should be kept in sync.
pub fn line_starts<'source>(source: &'source str) -> impl 'source + Iterator<Item = usize> {
pub fn line_starts(source: &str) -> impl '_ + Iterator<Item = usize> {
std::iter::once(0).chain(source.match_indices('\n').map(|(i, _)| i + 1))
}

Expand Down Expand Up @@ -351,7 +351,7 @@ where
/// This is useful for simple language tests, but it might be worth creating a
/// custom implementation when a language scales beyond a certain size.
/// It is a glorified `Vec<SimpleFile>` that implements the `Files` trait.
#[derive(Debug, Clone)]
#[derive(Debug, Default, Clone)]
pub struct SimpleFiles<Name, Source> {
files: Vec<SimpleFile<Name, Source>>,
}
Expand Down
6 changes: 3 additions & 3 deletions codespan/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ where
/// refer to it again.
pub fn add(&mut self, name: impl Into<OsString>, source: Source) -> FileId {
let file_id = FileId::new(self.files.len());
self.files.push(File::new(name.into(), source.into()));
self.files.push(File::new(name.into(), source));
file_id
}

Expand All @@ -72,7 +72,7 @@ where
/// This will mean that any outstanding byte indexes will now point to
/// invalid locations.
pub fn update(&mut self, file_id: FileId, source: Source) {
self.get_mut(file_id).update(source.into())
self.get_mut(file_id).update(source)
}

/// Get a the source file using the file id.
Expand Down Expand Up @@ -381,7 +381,7 @@ where
}

// NOTE: this is copied from `codespan_reporting::files::line_starts` and should be kept in sync.
fn line_starts<'source>(source: &'source str) -> impl 'source + Iterator<Item = usize> {
fn line_starts(source: &str) -> impl '_ + Iterator<Item = usize> {
std::iter::once(0).chain(source.match_indices('\n').map(|(i, _)| i + 1))
}

Expand Down

0 comments on commit 8028cdd

Please sign in to comment.