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

Error Report on Unused Generic Parameters #98909

Open
realquantumcookie opened this issue Jul 5, 2022 · 1 comment
Open

Error Report on Unused Generic Parameters #98909

realquantumcookie opened this issue Jul 5, 2022 · 1 comment
Labels
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.

Comments

@realquantumcookie
Copy link

realquantumcookie commented Jul 5, 2022

Given the following code: code

pub trait SomeGenericTrait<Struct>{
    fn do_something(&self,data: &Struct) -> String;
}

pub struct SomeOtherStruct<T: SomeGenericTrait<S>, S>{
    placeholder: PhantomData<S>, //a placeholder variable is required here for the compiler to remain calm
    pub abc: T
}

If we were to remove the PhantomData<S> typed member placeholder in SomeOtherStruct, the compiler would spit out the following error

 |
7 | pub struct SomeOtherStruct<T: SomeGenericTrait<S>, S>{
  |                                                    ^ unused parameter
  |
  = help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData`
  = help: if you intended `S` to be a const parameter, use `const S: usize` instead

But if we follow the direction of the compiler and further remove the S type parameter in SomeOtherStruct, we get

error[[E0412]](https://doc.rust-lang.org/nightly/error-index.html#E0412): cannot find type `S` in this scope
 --> src/main.rs:7:48
  |
7 | pub struct SomeOtherStruct<T: SomeGenericTrait<S>>{
  |                                                ^ not found in this scope

For more information about this error, try `rustc --explain E0412`.

So I was wondering if there's a better way for the compiler to either:

  1. not output an error since S was used as a type parameter for T
  2. add support to place holder type parameters to enable semantics like pub struct SomeOtherStruct<T: SomeGenericTrait<_>>{...}
@realquantumcookie realquantumcookie 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. labels Jul 5, 2022
@realquantumcookie
Copy link
Author

Would like to add a certain use case other than my small examples,
See the second proposal of Axum's issue 1116, tokio-rs/axum#1116

@realquantumcookie realquantumcookie changed the title Error Report on Generic Trait Bound with a trait that has generic type parameters Error Report on Unused Generic Parameters Jul 13, 2022
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 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

1 participant