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

Add source slices #257

Open
gavrilikhin-d opened this issue Apr 30, 2023 · 1 comment
Open

Add source slices #257

gavrilikhin-d opened this issue Apr 30, 2023 · 1 comment

Comments

@gavrilikhin-d
Copy link
Contributor

gavrilikhin-d commented Apr 30, 2023

SourceSlice may be helpful when:

  1. Using slices into source instead of source+span. (nom uses this approach)
  2. Using slice in error description
#[derive(Error, Diagnostic, Debug, Clone, PartialEq)]
#[error("return type mismatch: got \"{got}\", expected \"{expected}\"")]
pub struct ReturnTypeMismatch<'i> {
	/// Type of return value
	pub got: String,
        /// Span of returned value
        #[label("this has \"{got}\" type")]
        pub got_span: SourceSpan, 

	/// Expected type of return value
	pub expected: &'i str,
        #[label("return type specified here")]
        pub expected_span: SourceSpan,  // <- This may be inferred from `expected`
}

could be changed to

#[derive(Error, Diagnostic, Debug, Clone, PartialEq)]
#[error("return type mismatch: got \"{got}\", expected \"{expected}\"")]
pub struct ReturnTypeMismatch<'i> {
	/// Type of return value
	pub got: String,
        /// Span of returned value
        #[label("this has \"{got}\" type")]
        pub got_span: SourceSpan, 

	/// Expected type of return value
        // Maybe need to add something like: #[source_slice] 
        #[label("return type specified here")]  // <- assumes that this is subslice of source code
	pub expected: &'i str, 
}
@gavrilikhin-d gavrilikhin-d changed the title Add SourceSlice Add source slices Apr 30, 2023
@gavrilikhin-d
Copy link
Contributor Author

@zkat what do you think of this idea? Would you accept a PR for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant