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

Tracking issue for future-incompatibility lint uncovered_param_in_projection #124559

Open
fmease opened this issue Apr 30, 2024 · 6 comments
Open
Labels
A-coherence Area: Coherence A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-traits Area: Trait system C-future-incompatibility Category: Future-incompatibility lints C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. L-uncovered_param_in_projection Lint: uncovered_param_in_projection T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Apr 30, 2024

This is a tracking issue for the lint uncovered_param_in_projection which was added in #117164.

The lint detects a violation of one of Rust's orphan rules for foreign trait implementations that concerns the use of type parameters inside trait associated type paths ("projections") whose output may not be a local type that is mistakenly considered to "cover" said parameters which is unsound and which will be rejected by a future version of the compiler.

Originally reported in #99554 (kept open) and tracked in rust-lang/types-team#104.

Example

// dependency.rs

#![crate_type = "lib"]

pub trait Trait<T, U> {}
// dependent.rs

trait Identity {
    type Output;
}

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

struct Local;

impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}

fn main() {}

This will produce:

warning[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`)
  --> dependent.rs:11:6
   |
11 | impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}
   |      ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`)
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #124559 <https://github.com/rust-lang/rust/issues/124559>
   = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type
   = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last
   = note: `#[warn(uncovered_param_in_projection)]` on by default
@fmease fmease added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-traits Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-future-incompatibility Category: Future-incompatibility lints C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-types Relevant to the types team, which will review and decide on the PR/issue. A-coherence Area: Coherence labels Apr 30, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 30, 2024
Lazily normalize inside trait ref during orphan check & consider ty params in rigid alias types to be uncovered

Fixes rust-lang#99554, fixes rust-lang/types-team#104.
Fixes rust-lang#114061.

Supersedes rust-lang#100555.

Tracking issue for the future compatibility lint: rust-lang#124559.

r? lcnr
@weiznich
Copy link
Contributor

This change affects diesel in a major feature breaking way 😞

You can reproduce this by using the following steps:

git clone https://github.com/diesel-rs/diesel
cd diesel
cargo +nightly check -p diesel_cli

Which produces the following warning:

warning[E0210]: type parameter `Col` must be covered by another type when it appears before the first local type (`database::multi_connection_impl::backend::MultiBackend`)
   --> diesel_cli/src/database.rs:109:10
    |
109 | #[derive(diesel::MultiConnection)]
    |          ^^^^^^^^^^^^^^^^^^^^^^^ type parameter `Col` must be covered by another type when it appears before the first local type (`database::multi_connection_impl::backend::MultiBackend`)
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #124559 <https://github.com/rust-lang/rust/issues/124559>
    = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type
    = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last
    = note: `#[warn(uncovered_param_in_projection)]` on by default
    = note: this warning originates in the derive macro `diesel::MultiConnection` (in Nightly builds, run with -Z macro-backtrace for more info)

The relevant impl generated by the proc macro looks like this:

    impl<Col, Expr>
            diesel::insertable::InsertValues<
                Col::Table,
                super::multi_connection_impl::backend::MultiBackend,
            >
            for diesel::insertable::DefaultableColumnInsertValue<
                diesel::insertable::ColumnInsertValue<Col, Expr>,
            >
        where
            Col: diesel::prelude::Column,
            Expr: diesel::prelude::Expression<SqlType = Col::SqlType>,
            Expr: diesel::prelude::AppearsOnTable<
                diesel::internal::derives::multiconnection::NoFromClause,
            >,
            Self: diesel::query_builder::QueryFragment<
                super::multi_connection_impl::backend::MultiBackend,
            >,
            diesel::insertable::DefaultableColumnInsertValue<
                diesel::insertable::ColumnInsertValue<Col, Expr>,
            >: diesel::insertable::InsertValues<
                Col::Table,
                <PgConnection as diesel::connection::Connection>::Backend,
            >,
            diesel::insertable::DefaultableColumnInsertValue<
                diesel::insertable::ColumnInsertValue<Col, Expr>,
            >: diesel::insertable::InsertValues<
                Col::Table,
                <SqliteConnection as diesel::connection::Connection>::Backend,
            >,
        {
            fn column_names(
                &self,
                mut out: diesel::query_builder::AstPass<
                    '_,
                    '_,
                    super::multi_connection_impl::backend::MultiBackend,
                >,
            ) -> QueryResult<()> {
                use diesel::internal::derives::multiconnection::AstPassHelper;
                match out.backend(){
                    super::backend::MultiBackend::Pg(_) => {
                        <Self as diesel::insertable::InsertValues<Col::Table, <PgConnection as diesel::connection::Connection> ::Backend>> ::column_names(&self,out.cast_database(super::bind_collector::MultiBindCollector::pg,super::query_builder::MultiQueryBuilder::pg,super::backend::MultiBackend::pg, |l|{
                            <PgConnection as diesel::internal::derives::multiconnection::MultiConnectionHelper> ::from_any(l).expect("It's possible to downcast the metadata lookup type to the correct type")
                        },),)
                    },
                    super::backend::MultiBackend::Sqlite(_) => {
                        <Self as diesel::insertable::InsertValues<Col::Table, <SqliteConnection as diesel::connection::Connection> ::Backend>> ::column_names(&self,out.cast_database(super::bind_collector::MultiBindCollector::sqlite,super::query_builder::MultiQueryBuilder::sqlite,super::backend::MultiBackend::sqlite, |l|{
                            <SqliteConnection as diesel::internal::derives::multiconnection::MultiConnectionHelper> ::from_any(l).expect("It's possible to downcast the metadata lookup type to the correct type")
                        },),)
                    },

                    }
            }
        }

As far as I understand this issue this is the desired behavior that these impls are no longer valid . Removing this behavior is highly problematic for diesel as I do not see any other way to write that impl without major breaking changes to diesel itself. It's even likely that this would force us to remove a large popular feature from diesel itself in response to this breaking change.

@fmease
Copy link
Member Author

fmease commented May 13, 2024

I will look into this later. Note that the current orphan rules are unsound.

It's possible that the warning emitted for diesel are false positives (FPs) because the fix / lint for this unsoundness that is implemented on nightly (normalizing alias types in a certain way) is constrained by some known limitations of both trait solvers and that may lead to FPs.

Let me see what is the case for diesel.

@fmease
Copy link
Member Author

fmease commented May 13, 2024

I'm curious as to why diesel didn't show up in the various crater runs we did, let me double-check.

@weiznich
Copy link
Contributor

@fmease Did you already had some time to investigate that. I would like to resolve this before cutting a new diesel release.

@fmease
Copy link
Member Author

fmease commented May 24, 2024

Did you already had some time to investigate that. I would like to resolve this before cutting a new diesel release.

I've pm'ed you.

@weiznich
Copy link
Contributor

@fmease I've filled diesel-rs/diesel#4050 on diesels side to fix this. This was likely not picked up by crates as it is a change that only landed on the master branch yet. It's not in any released diesel version yet.

jdahlstrom added a commit to jdahlstrom/retrofire that referenced this issue Aug 5, 2024
jdahlstrom added a commit to jdahlstrom/retrofire that referenced this issue Aug 6, 2024
The generic Mul for Scalar impl violated orphan rules, but used to
be accepted by rustc due to a bug. Replace the impl with separate concrete
impls for f32, i32, and u32.

See rust-lang/rust#124559 for more info.


See rust-lang/rust#124559 for more info.
jdahlstrom added a commit to jdahlstrom/retrofire that referenced this issue Aug 6, 2024
The generic Mul for Scalar impl violated orphan rules, but used to
be accepted by rustc due to a bug. Replace the impl with separate concrete
impls for f32, i32, and u32.

See rust-lang/rust#124559 for more info.
jdahlstrom added a commit to jdahlstrom/retrofire that referenced this issue Aug 6, 2024
The generic Mul for Scalar impl violated orphan rules, but used to be
accepted by rustc due to a bug. Replace the impl with separate concrete
impls for f32, i32, and u32.

See rust-lang/rust#124559 for more info.
@fmease fmease changed the title Tracking issue for future compatibility lint uncovered_param_in_projection Tracking issue for future-incompatibility lint uncovered_param_in_projection Sep 14, 2024
jdahlstrom added a commit to jdahlstrom/retrofire that referenced this issue Sep 18, 2024
The generic Mul for Scalar impl violated orphan rules, but used to be
accepted by rustc due to a bug. Replace the impl with separate concrete
impls for f32, i32, and u32.

See rust-lang/rust#124559 for more info.
jdahlstrom added a commit to jdahlstrom/retrofire that referenced this issue Sep 18, 2024
The generic Mul for Scalar impl violated orphan rules, but used to be
accepted by rustc due to a bug. Replace the impl with separate concrete
impls for f32, i32, and u32.

See rust-lang/rust#124559 for more info.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coherence Area: Coherence A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-traits Area: Trait system C-future-incompatibility Category: Future-incompatibility lints C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. L-uncovered_param_in_projection Lint: uncovered_param_in_projection T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants