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

Don't consider generic args of supertrait in deref_into_dyn_supertrait lint #118026

Merged
merged 2 commits into from
Nov 21, 2023

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Nov 17, 2023

I actually wonder if we should just warn on any deref impl with a target type that matches a supertrait by def-id.

cc #89460

r? types

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 17, 2023
@lcnr
Copy link
Contributor

lcnr commented Nov 18, 2023

I think matching super trait by DefId feels appropriate 🤔 feels like it should also be possible to cause inference breakage that way

@lcnr
Copy link
Contributor

lcnr commented Nov 20, 2023

example breakage with trait_upcasting when sharing the same DefId

#![deny(deref_into_dyn_supertrait)]
#![feature(trait_upcasting)] // remove this and the test compiles
use std::ops::Deref;

trait Bar<T> {}
impl<T, U> Bar<U> for T {}

trait Foo: Bar<i32> {
    fn as_dyn_bar_u32<'a>(&self) -> &(dyn Bar<u32> + 'a);
}

impl Foo for () {
    fn as_dyn_bar_u32<'a>(&self) -> &(dyn Bar<u32> + 'a) {
        self
    }
}

impl<'a> Deref for dyn Foo + 'a {
    //~^ ERROR `dyn Foo` implements `Deref<Target = dyn Bar<u32>>` which conflicts with supertrait `Bar<i32>`
    //~| WARN this was previously accepted by the compiler
    type Target = dyn Bar<u32> + 'a;

    fn deref(&self) -> &Self::Target {
        self.as_dyn_bar_u32()
    }
}

fn take_dyn<T>(x: &dyn Bar<T>) -> T {
    todo!()
}

fn main() {
    let x: &dyn Foo = &();
    let y = take_dyn(x);
    let z: u32 = y;
}

@@ -9,6 +9,7 @@ LL | type Target = dyn A;
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use FutureIncompatibilityReason::FutureReleaseSemanticsChange instead of FutureReleaseErrorDontReportInDeps for this lint. Can you change that in this PR?

@lcnr
Copy link
Contributor

lcnr commented Nov 20, 2023

r=me after adding the additional behavior test and dealing with the other suggestion

@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Nov 20, 2023

📌 Commit e6ca8e1 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 20, 2023
@compiler-errors
Copy link
Member Author

@bors rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 20, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#117327 (Add documentation for some queries)
 - rust-lang#117835 (Note about object lifetime defaults in does not live long enough error)
 - rust-lang#117851 (Uplift `InferConst` to `rustc_type_ir`)
 - rust-lang#117973 (test: Add test for async-move in 2015 Rust proc macro)
 - rust-lang#117992 (Don't require intercrate mode for negative coherence)
 - rust-lang#118010 (Typeck break expr even if break is illegal)
 - rust-lang#118026 (Don't consider regions in `deref_into_dyn_supertrait` lint)
 - rust-lang#118089 (intercrate_ambiguity_causes: handle self ty infer + reservation impls)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 20, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#117327 (Add documentation for some queries)
 - rust-lang#117835 (Note about object lifetime defaults in does not live long enough error)
 - rust-lang#117851 (Uplift `InferConst` to `rustc_type_ir`)
 - rust-lang#117973 (test: Add test for async-move in 2015 Rust proc macro)
 - rust-lang#117992 (Don't require intercrate mode for negative coherence)
 - rust-lang#118010 (Typeck break expr even if break is illegal)
 - rust-lang#118026 (Don't consider regions in `deref_into_dyn_supertrait` lint)
 - rust-lang#118089 (intercrate_ambiguity_causes: handle self ty infer + reservation impls)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 21, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#117327 (Add documentation for some queries)
 - rust-lang#117835 (Note about object lifetime defaults in does not live long enough error)
 - rust-lang#117851 (Uplift `InferConst` to `rustc_type_ir`)
 - rust-lang#117973 (test: Add test for async-move in 2015 Rust proc macro)
 - rust-lang#117992 (Don't require intercrate mode for negative coherence)
 - rust-lang#118010 (Typeck break expr even if break is illegal)
 - rust-lang#118026 (Don't consider regions in `deref_into_dyn_supertrait` lint)
 - rust-lang#118089 (intercrate_ambiguity_causes: handle self ty infer + reservation impls)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ca246d3 into rust-lang:master Nov 21, 2023
11 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Nov 21, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 21, 2023
Rollup merge of rust-lang#118026 - compiler-errors:deref-into-dyn-regions, r=lcnr

Don't consider regions in `deref_into_dyn_supertrait` lint

I actually wonder if we should just warn on *any* deref impl with a target type that matches a supertrait by *def-id*.

cc rust-lang#89460

r? types
@compiler-errors
Copy link
Member Author

Holy shit lol, I definitely pushed the wrong commits here. I'm dumb.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 23, 2023
…ions, r=lcnr

Rework supertrait lint once again

I accidentally pushed the wrong commits because I totally didn't check I was on the right computer when updating rust-lang#118026.
Sorry, this should address all the nits in rust-lang#118026.

r? lcnr
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 23, 2023
Rollup merge of rust-lang#118146 - compiler-errors:deref-into-dyn-regions, r=lcnr

Rework supertrait lint once again

I accidentally pushed the wrong commits because I totally didn't check I was on the right computer when updating rust-lang#118026.
Sorry, this should address all the nits in rust-lang#118026.

r? lcnr
@lcnr lcnr changed the title Don't consider regions in deref_into_dyn_supertrait lint Don't consider generic args of supertrait in deref_into_dyn_supertrait lint Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants