Skip to content

Improve unknown crate_type diagnostic suggestions#158300

Open
evavh wants to merge 1 commit into
rust-lang:mainfrom
evavh:crate-type-suggestions
Open

Improve unknown crate_type diagnostic suggestions#158300
evavh wants to merge 1 commit into
rust-lang:mainfrom
evavh:crate-type-suggestions

Conversation

@evavh

@evavh evavh commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

I have improved the suggestions given in the unknown crate_type diagnostic.

Before (no suggestion):

error: invalid `crate_type` value
 --> bad_error.rs:1:17
  |
1 | #![crate_type = "binary"]
  |                 ^^^^^^^^
  |
  = note: `#[deny(unknown_crate_types)]` on by default

After:

error: invalid `crate_type` value
 --> bad_error.rs:1:17
  |
1 | #![crate_type = "binary"]
  |                 ^^^^^^^^ help: did you mean: `"bin"`
  |
  = note: `#[deny(unknown_crate_types)]` on by default

By increasing the allowed edit distance for the matching, as well as allowing substring matches, this now also works for mistakes like dynamiclib, where it will suggest dylib, and cdylibrary where it suggests cdylib.

r? @JonathanBrouwer

@rustbot

rustbot commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 23, 2026

@mejrs mejrs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you ensure we do not recommend unstable crate types unless their feature is active? i.e., sdylib?

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 23, 2026
@rustbot

rustbot commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@evavh

evavh commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Can you ensure we do not recommend unstable crate types unless their feature is active? i.e., sdylib?

Because this code uses CrateType::all_stable() to list the suggestion candidates, it will never suggest an unstable crate type.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 23, 2026

@JonathanBrouwer JonathanBrouwer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think never suggesting unstable candidates is reasonable enough. A potential improvement could be suggesting unstable candidates if their feature flag is enabled, but this is not that important imo and probably makes the implementation significantly more annoying

@bors r+ rollup

View changes since this review

@rust-bors

rust-bors Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 24a66cb has been approved by JonathanBrouwer

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 23, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 23, 2026
…nathanBrouwer

Improve unknown crate_type diagnostic suggestions

I have improved the suggestions given in the unknown crate_type diagnostic.

Before (no suggestion):
```
error: invalid `crate_type` value
 --> bad_error.rs:1:17
  |
1 | #![crate_type = "binary"]
  |                 ^^^^^^^^
  |
  = note: `#[deny(unknown_crate_types)]` on by default
```

After:
```
error: invalid `crate_type` value
 --> bad_error.rs:1:17
  |
1 | #![crate_type = "binary"]
  |                 ^^^^^^^^ help: did you mean: `"bin"`
  |
  = note: `#[deny(unknown_crate_types)]` on by default
```

By increasing the allowed edit distance for the matching, as well as allowing substring matches, this now also works for mistakes like `dynamiclib`, where it will suggest `dylib`, and `cdylibrary` where it suggests `cdylib`.

r? @JonathanBrouwer
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 23, 2026
…nathanBrouwer

Improve unknown crate_type diagnostic suggestions

I have improved the suggestions given in the unknown crate_type diagnostic.

Before (no suggestion):
```
error: invalid `crate_type` value
 --> bad_error.rs:1:17
  |
1 | #![crate_type = "binary"]
  |                 ^^^^^^^^
  |
  = note: `#[deny(unknown_crate_types)]` on by default
```

After:
```
error: invalid `crate_type` value
 --> bad_error.rs:1:17
  |
1 | #![crate_type = "binary"]
  |                 ^^^^^^^^ help: did you mean: `"bin"`
  |
  = note: `#[deny(unknown_crate_types)]` on by default
```

By increasing the allowed edit distance for the matching, as well as allowing substring matches, this now also works for mistakes like `dynamiclib`, where it will suggest `dylib`, and `cdylibrary` where it suggests `cdylib`.

r? @JonathanBrouwer
rust-bors Bot pushed a commit that referenced this pull request Jun 23, 2026
…uwer

Rollup of 23 pull requests

Successful merges:

 - #158315 (`rust-analyzer` subtree update)
 - #155739 (Add temporary scope to assert_eq and assert_ne)
 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157527 (Move derive tests into their dedicated folder)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #158020 (Update mingw-w64 C toolchain)
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158257 ( fix escaping placeholder check in next solver normalization folder)
 - #158263 (Only load the feature list once in the entire resolver)
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)
 - #158300 (Improve unknown crate_type diagnostic suggestions)
 - #158304 (mailmap: update mu001999)

Failed merges:

 - #158256 (Avoid parser panics bubbling out to proc macros)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 24, 2026
…nathanBrouwer

Improve unknown crate_type diagnostic suggestions

I have improved the suggestions given in the unknown crate_type diagnostic.

Before (no suggestion):
```
error: invalid `crate_type` value
 --> bad_error.rs:1:17
  |
1 | #![crate_type = "binary"]
  |                 ^^^^^^^^
  |
  = note: `#[deny(unknown_crate_types)]` on by default
```

After:
```
error: invalid `crate_type` value
 --> bad_error.rs:1:17
  |
1 | #![crate_type = "binary"]
  |                 ^^^^^^^^ help: did you mean: `"bin"`
  |
  = note: `#[deny(unknown_crate_types)]` on by default
```

By increasing the allowed edit distance for the matching, as well as allowing substring matches, this now also works for mistakes like `dynamiclib`, where it will suggest `dylib`, and `cdylibrary` where it suggests `cdylib`.

r? @JonathanBrouwer
rust-bors Bot pushed a commit that referenced this pull request Jun 24, 2026
Rollup of 27 pull requests

Successful merges:

 - #158315 (`rust-analyzer` subtree update)
 - #155739 (Add temporary scope to assert_eq and assert_ne)
 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158053 (Optimize network address parser)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157527 (Move derive tests into their dedicated folder)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #158020 (Update mingw-w64 C toolchain)
 - #158039 (c-variadic: test that we use equality up to free lifetimes)
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158257 ( fix escaping placeholder check in next solver normalization folder)
 - #158263 (Only load the feature list once in the entire resolver)
 - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use)
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)
 - #158300 (Improve unknown crate_type diagnostic suggestions)
 - #158304 (mailmap: update mu001999)
 - #158309 (Update `rustc-literal-escaper` version to `0.0.8`)

Failed merges:

 - #158256 (Avoid parser panics bubbling out to proc macros)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 24, 2026
…nathanBrouwer

Improve unknown crate_type diagnostic suggestions

I have improved the suggestions given in the unknown crate_type diagnostic.

Before (no suggestion):
```
error: invalid `crate_type` value
 --> bad_error.rs:1:17
  |
1 | #![crate_type = "binary"]
  |                 ^^^^^^^^
  |
  = note: `#[deny(unknown_crate_types)]` on by default
```

After:
```
error: invalid `crate_type` value
 --> bad_error.rs:1:17
  |
1 | #![crate_type = "binary"]
  |                 ^^^^^^^^ help: did you mean: `"bin"`
  |
  = note: `#[deny(unknown_crate_types)]` on by default
```

By increasing the allowed edit distance for the matching, as well as allowing substring matches, this now also works for mistakes like `dynamiclib`, where it will suggest `dylib`, and `cdylibrary` where it suggests `cdylib`.

r? @JonathanBrouwer
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 24, 2026
…nathanBrouwer

Improve unknown crate_type diagnostic suggestions

I have improved the suggestions given in the unknown crate_type diagnostic.

Before (no suggestion):
```
error: invalid `crate_type` value
 --> bad_error.rs:1:17
  |
1 | #![crate_type = "binary"]
  |                 ^^^^^^^^
  |
  = note: `#[deny(unknown_crate_types)]` on by default
```

After:
```
error: invalid `crate_type` value
 --> bad_error.rs:1:17
  |
1 | #![crate_type = "binary"]
  |                 ^^^^^^^^ help: did you mean: `"bin"`
  |
  = note: `#[deny(unknown_crate_types)]` on by default
```

By increasing the allowed edit distance for the matching, as well as allowing substring matches, this now also works for mistakes like `dynamiclib`, where it will suggest `dylib`, and `cdylibrary` where it suggests `cdylib`.

r? @JonathanBrouwer
rust-bors Bot pushed a commit that referenced this pull request Jun 24, 2026
Rollup of 35 pull requests

Successful merges:

 - #158315 (`rust-analyzer` subtree update)
 - #158336 (Stop excluding `stdarch` test crates from `rust-src`)
 - #155739 (Add temporary scope to assert_eq and assert_ne)
 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157419 (move rustc_type_ir Term things to term_kind.rs)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158053 (Optimize network address parser)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157527 (Move derive tests into their dedicated folder)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #157939 (Reorganize `tests/ui/issues` [8/N])
 - #157946 (Make `char::is_private_use` and `char::is_assigned` unstably public)
 - #158003 (Reorganize `tests/ui/issues` [9/N])
 - #158020 (Update mingw-w64 C toolchain)
 - #158039 (c-variadic: test that we use equality up to free lifetimes)
 - #158060 (Reorganize `tests/ui/issues` [10/N])
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158263 (Only load the feature list once in the entire resolver)
 - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use)
 - #158272 (Reorganize `tests/ui/issues` [13/N])
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)
 - #158300 (Improve unknown crate_type diagnostic suggestions)
 - #158304 (mailmap: update mu001999)
 - #158309 (Update `rustc-literal-escaper` version to `0.0.8`)
 - #158314 (Fix incorrect unsafe debug assertion in unchecked_div_exact)
 - #158326 (Add `io::ErrorKind::TooManyOpenFiles`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants