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

bare_trait_objects suggestion JSON includes stray suggestion #102902

Closed
ehuss opened this issue Oct 10, 2022 · 4 comments
Closed

bare_trait_objects suggestion JSON includes stray suggestion #102902

ehuss opened this issue Oct 10, 2022 · 4 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Oct 10, 2022

Given the following code:

pub type T = Copy;

Running rustc foo.rs --error=format=json produces two machine-applicable suggestions. One of them is an empty span which has no effect. The relevant part of the JSON output is:

{
    "message": "use `dyn`",
    "code": null,
    "level": "help",
    "spans":
    [
        {
            "file_name": "foo.rs",
            "byte_start": 13,
            "byte_end": 13,
            "line_start": 1,
            "line_end": 1,
            "column_start": 14,
            "column_end": 14,
            "is_primary": true,
            "text":
            [
                {
                    "text": "pub type T = Copy;",
                    "highlight_start": 14,
                    "highlight_end": 14
                }
            ],
            "label": null,
            "suggested_replacement": "dyn ",
            "suggestion_applicability": "MachineApplicable",
            "expansion": null
        },
        {
            "file_name": "foo.rs",
            "byte_start": 17,
            "byte_end": 17,
            "line_start": 1,
            "line_end": 1,
            "column_start": 18,
            "column_end": 18,
            "is_primary": true,
            "text":
            [
                {
                    "text": "pub type T = Copy;",
                    "highlight_start": 18,
                    "highlight_end": 18
                }
            ],
            "label": null,
            "suggested_replacement": "",
            "suggestion_applicability": "MachineApplicable",
            "expansion": null
        }
    ],
    "children":
    [],
    "rendered": null
}

Notice that the second suggestion is an empty string for an empty span.

I expect this to not emit an empty span suggestion.

rustc 1.66.0-nightly (8b0c05d9a 2022-10-07)
binary: rustc
commit-hash: 8b0c05d9ad7121cdb97600f261bcd5f04c8db20d
commit-date: 2022-10-07
host: x86_64-apple-darwin
release: 1.66.0-nightly
LLVM version: 15.0.2
@ehuss ehuss added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Oct 10, 2022
@compiler-errors
Copy link
Member

I bet this is the span to insert ) if it's a complex trait object that needs parens. While this can probably be fixed in that one case specifically, it's probably better to filter multipart suggestion parts that are empty spans with empty replacements out of the list before emitting them as JSON.

This shouldn't be too hard.

@compiler-errors compiler-errors added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Oct 10, 2022
@kper
Copy link
Contributor

kper commented Oct 11, 2022

@rustbot claim

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Oct 18, 2022
… r=oli-obk

Filtering spans when emitting json

According to the issue rust-lang#102902, we shouldn't emit spans which have an empty span and no suggested replacement.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Oct 21, 2022
… r=oli-obk

Filtering spans when emitting json

According to the issue rust-lang#102902, we shouldn't emit spans which have an empty span and no suggested replacement.
@kper
Copy link
Contributor

kper commented Oct 22, 2022

@ehuss the fix was merged. Can you close the ticket?

@ehuss
Copy link
Contributor Author

ehuss commented Oct 22, 2022

Indeed, thanks!

@ehuss ehuss closed this as completed Oct 22, 2022
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 21, 2022
… r=oli-obk

Filtering spans when emitting json

According to the issue rust-lang#102902, we shouldn't emit spans which have an empty span and no suggested replacement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants