Skip to content

explicit-outlives-requirements should remove entire where clause if it removes the only bound #105150

Closed
@matthiaskrgr

Description

@matthiaskrgr

Given the following code:

// run-pass
#![allow(dead_code)]
#![allow(unused_variables)]
#![feature(unsize, coerce_unsized)]

#[repr(packed)]
struct UnalignedPtr<'a, T: ?Sized>
    where T: 'a,
{
    data: &'a T,
}

fn main() {

    impl<'a, T, U> std::ops::CoerceUnsized<UnalignedPtr<'a, U>> for UnalignedPtr<'a, T>
        where
        T: std::marker::Unsize<U> + ?Sized,
        U: ?Sized,
    { }

    let arr = [1, 2, 3];
    let arr_unaligned: UnalignedPtr<[i32; 3]> = UnalignedPtr { data: &arr };
    let arr_unaligned: UnalignedPtr<[i32]> = arr_unaligned;
}

The current output is:


warning: outlives requirements can be inferred
 --> src/main.rs:8:11
  |
8 |     where T: 'a,
  |           ^^^^^ help: remove this bound
  |
  = note: requested on the command line with `-W explicit-outlives-requirements`

Rustfix will fail to apply this:

The following errors were reported:
error: expected `{` after struct name, found `,`
 --> src/main.rs:8:11
  |
8 |     where ,
  |           ^ expected `{` after struct name

error: aborting due to previous error

So we need to extend span to include the where: as well?

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions