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

SpanExt name collision with proc_macro2 #13

Closed
bart358 opened this issue Feb 17, 2024 · 2 comments
Closed

SpanExt name collision with proc_macro2 #13

bart358 opened this issue Feb 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@bart358
Copy link

bart358 commented Feb 17, 2024

SpanExt defines a method:

fn end(&self) -> Span;

And implements it on Span. However, proc-marco2 with feature span-locations also defines a method on Span:

    #[cfg(span_locations)]
    #[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))]
    pub fn end(&self) -> LineColumn {
        self.inner.end()
    }

When calling end on a Span object with that feature enabled the above method takes precedence. This breaks code in an ast module where it defines:

diag = diag.span_error(v.span().end(), "missing discriminant");

Since the SpanExt is in scope the intention was for .end() to return a Span object which works since it implements MultiSpan required by span_error. With span-locations enabled It returns a LineColumn which does not implement MultiSpan:

   --> int-enum-1.0.0/src/ast.rs:120:36
    |
120 |             diag = diag.span_error(v.span().end(), "missing discriminant");
    |                         ---------- ^^^^^^^^^^^^^^ the trait `proc_macro2_diagnostics::diagnostic::MultiSpan` is not implemented for `LineColumn`
    |                         |
    |                         required by a bound introduced by this call
    |
    = help: the following other types implement trait `proc_macro2_diagnostics::diagnostic::MultiSpan`:
              proc_macro2::Span
              Vec<proc_macro2::Span>
              &'a [proc_macro2::Span]
note: required by a bound in `proc_macro2_diagnostics::Diagnostic::span_error`

The solution would be to refer to the trait explicitly:

diag = diag.span_error(<Span as SpanExt>::end(&v.span()), "missing discriminant");
@Juici
Copy link
Owner

Juici commented Feb 17, 2024

I just noticed the build errors, I'll fix it.

@Juici Juici added the bug Something isn't working label Feb 17, 2024
Juici added a commit that referenced this issue Feb 17, 2024
@Juici
Copy link
Owner

Juici commented Feb 17, 2024

This should be fixed by #15 for version 1.0.1.

@Juici Juici closed this as completed Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants