Skip to content

The type_alias_bounds lint misfires when impl Trait is used in a portion of a type alias #94395

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

Closed
yvt opened this issue Feb 26, 2022 · 1 comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@yvt
Copy link
Contributor

yvt commented Feb 26, 2022

#![feature(type_alias_impl_trait)]

type Alias<T: Send> = (impl Send,);

pub fn foo<T: Send>(x: T) -> Alias<T> {
    (x,)
}

Compiling this code (Playground) produces the following diagnostics:

warning: bounds on generic parameters are not enforced in type aliases
 --> src/lib.rs:3:15
  |
3 | type Alias<T: Send> = (impl Send,);
  |               ^^^^
  |
  = note: `#[warn(type_alias_bounds)]` on by default
help: the bound will not be checked when the type alias is used, and should be removed
  |
3 - type Alias<T: Send> = (impl Send,);
3 + type Alias<T> = (impl Send,);
  | 

I expected to see this happen: The compiler should not have suggested removing : Send from the type alias.

Instead, this happened: Removing : Send as per the compiler's suggestion breaks the code.

error[E0277]: `T` cannot be sent between threads safely
 --> src/lib.rs:3:18
  |
3 | type Alias<T> = (impl Send,);
  |                  ^^^^^^^^^ `T` cannot be sent between threads safely
  |
help: consider restricting type parameter `T`
  |
3 | type Alias<T: std::marker::Send> = (impl Send,);
  |             +++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error

Meta

rustc --version --verbose:

rustc 1.61.0-nightly (532d3cda9 2022-02-23)
binary: rustc
commit-hash: 532d3cda90b8a729cd982548649d32803d265052
commit-date: 2022-02-23
host: aarch64-apple-darwin
release: 1.61.0-nightly
LLVM version: 14.0.0
@yvt yvt added the C-bug Category: This is a bug. label Feb 26, 2022
@yvt yvt changed the title The type_alias_bounds lint misfires when impl Trait is used as a subcomponent of a type alias The type_alias_bounds lint misfires when impl Trait is used in a portion of a type alias Feb 26, 2022
@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` and removed needs-triage-legacy labels Jan 24, 2024
@fmease
Copy link
Member

fmease commented Jan 24, 2024

Ah, I've fixed that one a while ago, namely in #114228. No longer warns. Closing as fixed.

@fmease fmease closed this as completed Jan 24, 2024
@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` 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