Skip to content

False positive of lint missing_debug_implementations if Debug is implemented for an alias type (e.g., projection) that can get normalized to the relevant type #157758

@fmease

Description

@fmease

Subissue: #157757.

#![deny(missing_debug_implementations)]

pub struct Local; //~ ERROR type does not implement `Debug`; consider adding `#[derive(Debug)]` or a manu

impl std::fmt::Debug for <Local as Identity>::Output {
    fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Ok(()) }
}

pub trait Identity { type Output; }
impl<T> Identity for T { type Output = T; }

For some reason missing_debug_implementations doesn't actually query the trait solver (!) (if the fast path doesn't apply), it literally does

        let has_impl = cx
            .tcx
            .non_blanket_impls_for_ty(
                debug,
                cx.tcx.type_of(item.owner_id).instantiate_identity().skip_norm_wip(),
            )
            .next()
            .is_some();

but I don't think that function should be used for "correctness" (well, it's a lint), ideally it would only be used as a fast path (barring more specific use cases).

For comparison, lint missing_copy_implementations calls tcx.type_is_copy_modulo_regions() which has a fast path but then queries the trait solver.

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-false-positiveLint: False positive (should not have fired).L-missing_debug_implementationsLint: missing_debug_implementationsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions