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

trait_duplication_in_bounds false positive for repeated From bound #9626

Closed
jedel1043 opened this issue Oct 10, 2022 · 0 comments · Fixed by #13493
Closed

trait_duplication_in_bounds false positive for repeated From bound #9626

jedel1043 opened this issue Oct 10, 2022 · 0 comments · Fixed by #13493
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@jedel1043
Copy link

Summary

Another false positive for trait_duplication_in_bounds, but now for repeated From clauses with different generic arguments.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=20909581fd02460b126ebe30d969ba51

Lint Name

trait_duplication_in_bounds

Reproducer

I tried this code:

#![deny(clippy::trait_duplication_in_bounds)]

pub struct JSInternedStrRef<'a, 'b> {
    utf8: Option<&'a str>,
    utf16: &'b [u16],
}

impl<'a, 'b> JSInternedStrRef<'a, 'b> {
    pub fn into_common<C>(self, prioritize_utf8: bool) -> C
    where
        C: From<&'a str> + From<&'b [u16]>,
    {
        if let Some(str) = self.utf8 {
            return C::from(str);
        }
        C::from(self.utf16)
    }
}

I saw this happen:

error: these where clauses contain repeated elements
  --> src/lib.rs:11:12
   |
11 |         C: From<&'a str> + From<&'b [u16]>,
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `From<&'a str>`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds
note: the lint level is defined here
  --> src/lib.rs:1:9
   |
1  | #![deny(clippy::trait_duplication_in_bounds)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I expected to see this happen:

Compilation without errors.

Following the suggestion causes:

error[[E0308]](https://doc.rust-lang.org/stable/error-index.html#E0308): mismatched types
  --> src/lib.rs:16:17
   |
16 |         C::from(self.utf16)
   |         ------- ^^^^^^^^^^ expected `str`, found slice `[u16]`
   |         |
   |         arguments to this function are incorrect
   |
   = note: expected reference `&'a str`
              found reference `&'b [u16]`
note: associated function defined here

Version

rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-unknown-linux-gnu
release: 1.64.0
LLVM version: 14.0.6

Additional Labels

@rustbot label +I-suggestion-causes-error

@jedel1043 jedel1043 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Oct 10, 2022
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Oct 10, 2022
@bors bors closed this as completed in a01975b Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants