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

unsafe keyword should be marked as redundant if the using unsafe directive doesn't require it #67988

Closed
jhinder opened this issue Apr 26, 2023 · 2 comments
Labels
Area-IDE Feature Request untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@jhinder
Copy link
Contributor

jhinder commented Apr 26, 2023

Summary

If a "using unsafe" directive could also be a regular using directive, a new analyzer/fixer could identify and remove such redundant keywords.

Background and Motivation

It's legal, albeit pointless, to use a "using unsafe" or "using static unsafe" directive with types that would also be legal without the unsafe keyword. Examples:

using unsafe T = int;
using static unsafe System.Console;

Proposed Feature

Either a compiler diagnostic or an IDExxxx diagnostic (whichever is better suited for this scenario) that reports that the unsafe keyword is redundant. This could be complemented by a new code fixer that offers to remove that keyword.

Alternative Designs

n/a

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 26, 2023
@Youssef1313
Copy link
Member

Looks like it falls into #48031 ?

@CyrusNajmabadi
Copy link
Member

Agreed. Closing out as this is already tracked.

@CyrusNajmabadi CyrusNajmabadi closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Feature Request untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

3 participants