rust icon indicating copy to clipboard operation
rust copied to clipboard

Split refining_impl_trait lint into _reachable, _internal variants

Open tmandry opened this issue 1 year ago • 15 comments

As discussed in https://github.com/rust-lang/rust/issues/119535#issuecomment-1909352040:

We discussed this today in triage and developed a consensus to:

  • Add a separate lint against impls that refine a return type defined with RPITIT even when the trait is not crate public.
  • Place that in a lint group along with the analogous crate public lint.
  • Create an issue to solicit feedback on these lints (or perhaps two separate ones).
  • Have the warnings displayed with each lint reference this issue in a similar manner to how we do that today with the required Self: '0' bound on GATs.
  • Make a note to review this feedback on 2-3 release cycles.

This points users to https://github.com/rust-lang/rust/issues/121718 to leave feedback.

tmandry avatar Feb 28 '24 01:02 tmandry

r? @Nadrieril

rustbot has assigned @Nadrieril. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

rustbot avatar Feb 28 '24 01:02 rustbot

Nominating for lang team discussion. We discussed this lint previously as part of #119535, leading to the consensus described in https://github.com/rust-lang/rust/issues/119535#issuecomment-1909352040.

This PR implements that consensus, but I'd like feedback on the lint naming and documentation. See the tests for examples of the lints that are added.

@rustbot label I-lang-nominated

tmandry avatar Feb 28 '24 01:02 tmandry

r? @compiler-errors

tmandry avatar Feb 28 '24 01:02 tmandry

The job x86_64-gnu-llvm-16 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#12 writing image sha256:208e32678afb38d19a0b5e9bf791d5510d7e6b9da5478fac9afdbc08e90a304d done
#12 naming to docker.io/library/rust-ci done
#12 DONE 10.2s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-16]
##[group]Clock drift check
  local time: Wed Feb 28 01:17:13 UTC 2024
  network time: Wed, 28 Feb 2024 01:17:13 GMT
  network time: Wed, 28 Feb 2024 01:17:13 GMT
##[endgroup]
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-16', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'build.optimized-compiler-builtins', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-16/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
failures:

---- [ui] tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs#next stdout ----

error in revision `next`: /checkout/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs:15: unexpected warning: '15:5: 15:24: impl trait in impl method signature does not match trait method signature [refining_impl_trait_internal]'
error in revision `next`: 1 unexpected errors found, 0 expected errors not found
status: exit status: 0
status: exit status: 0
command: RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--cfg" "next" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.next" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.next/auxiliary" "-Znext-solver" "--edition=2021"
    Error {
        line_num: 15,
        kind: Some(
            Warning,
            Warning,
        ),
        msg: "15:5: 15:24: impl trait in impl method signature does not match trait method signature [refining_impl_trait_internal]",
]

thread '[ui] tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs#next' panicked at src/tools/compiletest/src/runtest.rs:1845:13:
explicit panic

rust-log-analyzer avatar Feb 28 '24 01:02 rust-log-analyzer

There's also a test failing with the new trait solver that looks like a bug (normalizing-self-auto-trait-issue-109924.rs gives a refinement error when it shouldn't).

Yeah, this is a new solver bug. Just add the warning in the UI test //[next]~^ WARN ..... and I can fix it later in a separate PR.

compiler-errors avatar Feb 28 '24 14:02 compiler-errors

The job x86_64-gnu-llvm-16 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#12 writing image sha256:ea04c0fba79163740966d65e071839f1033025396a3348e6ff4aa39bea37af93 done
#12 naming to docker.io/library/rust-ci done
#12 DONE 10.1s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-16]
##[group]Clock drift check
  local time: Tue Mar  5 22:16:06 UTC 2024
  network time: Tue, 05 Mar 2024 22:16:06 GMT
  network time: Tue, 05 Mar 2024 22:16:06 GMT
##[endgroup]
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-16', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'build.optimized-compiler-builtins', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-16/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
##[endgroup]
Testing GCC stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling y v0.1.0 (/checkout/compiler/rustc_codegen_gcc/build_system)
    Finished release [optimized] target(s) in 1.24s
     Running `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-codegen/x86_64-unknown-linux-gnu/release/y test --use-system-gcc --use-backend gcc --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/cg_gcc --release --no-default-features --mini-tests --std-tests`
Using system GCC
Using system GCC
[BUILD] example
[AOT] mini_core_hello_world
/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/cg_gcc/mini_core_hello_world
abc
---

error: impl trait in impl method signature does not match trait method signature
##[error]  --> lint_example.rs:10:29
   |
6  |     fn as_display(&self) -> impl Display;
   |                             ------------ return type from trait method defined here
10 |     fn as_display(&self) -> Self {
   |                             ^^^^
   |
   |
   = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
   = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
  --> lint_example.rs:1:9
   |
   |
1  | #![deny(refining_impl_trait)]
   |         ^^^^^^^^^^^^^^^^^^^
   = note: `#[deny(refining_impl_trait_reachable)]` implied by `#[deny(refining_impl_trait)]`
   |
   |
10 |     fn as_display(&self) -> impl std::fmt::Display {


warning: unused variable: `x`
##[warning]  --> lint_example.rs:18:9
##[warning]  --> lint_example.rs:18:9
   |
18 |     let x: &str = "".as_display();
   |         ^ help: if this is intentional, prefix it with an underscore: `_x`
   = note: `#[warn(unused_variables)]` on by default


error: aborting due to 1 previous error; 1 warning emitted
error: aborting due to 1 previous error; 1 warning emitted


warning: lint group `refining-impl-trait` is missing from the GROUP_DESCRIPTIONS list
If this is a new lint group, please update the GROUP_DESCRIPTIONS in src/tools/lint-docs/src/groups.rs
Rustbook (x86_64-unknown-linux-gnu) - rustc
Rustbook (x86_64-unknown-linux-gnu) - cargo
Rustbook (x86_64-unknown-linux-gnu) - clippy
Rustbook (x86_64-unknown-linux-gnu) - embedded-book
---
 finished in 1.513 seconds
##[endgroup]
Generating lint docs (x86_64-unknown-linux-gnu)
##[group]Running stage2 lint-docs (x86_64-unknown-linux-gnu)
error: failed to test example in lint docs for `refining_impl_trait_reachable` in /checkout/compiler/rustc_lint_defs/src/builtin.rs:4313: lint docs should start with the text "The `refining_impl_trait_reachable` lint" to introduce the lint
This error was generated by the lint-docs tool.
This tool extracts documentation for lints from the source code and places
This tool extracts documentation for lints from the source code and places
them in the rustc book. See the declare_lint! documentation
https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/macro.declare_lint.html


To re-run these tests, run: ./x.py test --keep-stage=0 src/tools/lint-docs
The --keep-stage flag should be used if you have already built the compiler

Build completed unsuccessfully in 0:32:58
  local time: Tue Mar  5 22:49:38 UTC 2024
  network time: Tue, 05 Mar 2024 22:49:38 GMT

rust-log-analyzer avatar Mar 05 '24 22:03 rust-log-analyzer

Rebased and improved docs and tests; the PR should be ready now.

tmandry avatar Mar 05 '24 22:03 tmandry

The job x86_64-gnu-llvm-16 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#12 writing image sha256:ff05940f84a6f56c9a6f16ac81c703c3745a484acea2342d016d13b2b9d10a7a done
#12 naming to docker.io/library/rust-ci done
#12 DONE 10.1s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-16]
##[group]Clock drift check
  local time: Tue Mar  5 22:55:23 UTC 2024
  network time: Tue, 05 Mar 2024 22:55:23 GMT
  network time: Tue, 05 Mar 2024 22:55:23 GMT
##[endgroup]
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-16', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'build.optimized-compiler-builtins', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-16/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
##[endgroup]
Testing GCC stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling y v0.1.0 (/checkout/compiler/rustc_codegen_gcc/build_system)
    Finished release [optimized] target(s) in 1.23s
     Running `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-codegen/x86_64-unknown-linux-gnu/release/y test --use-system-gcc --use-backend gcc --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/cg_gcc --release --no-default-features --mini-tests --std-tests`
Using system GCC
Using system GCC
[BUILD] example
[AOT] mini_core_hello_world
/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/cg_gcc/mini_core_hello_world
abc
---

error: impl trait in impl method signature does not match trait method signature
##[error]  --> lint_example.rs:10:29
   |
6  |     fn as_display(&self) -> impl Display;
   |                             ------------ return type from trait method defined here
10 |     fn as_display(&self) -> Self {
   |                             ^^^^
   |
   |
   = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
   = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
  --> lint_example.rs:1:9
   |
   |
1  | #![deny(refining_impl_trait)]
   |         ^^^^^^^^^^^^^^^^^^^
   = note: `#[deny(refining_impl_trait_reachable)]` implied by `#[deny(refining_impl_trait)]`
   |
   |
10 |     fn as_display(&self) -> impl std::fmt::Display {


warning: unused variable: `x`
##[warning]  --> lint_example.rs:18:9
##[warning]  --> lint_example.rs:18:9
   |
18 |     let x: &str = "".as_display();
   |         ^ help: if this is intentional, prefix it with an underscore: `_x`
   = note: `#[warn(unused_variables)]` on by default


error: aborting due to 1 previous error; 1 warning emitted
error: aborting due to 1 previous error; 1 warning emitted


warning: lint group `refining-impl-trait` is missing from the GROUP_DESCRIPTIONS list
If this is a new lint group, please update the GROUP_DESCRIPTIONS in src/tools/lint-docs/src/groups.rs
Rustbook (x86_64-unknown-linux-gnu) - rustc
Rustbook (x86_64-unknown-linux-gnu) - cargo
Rustbook (x86_64-unknown-linux-gnu) - clippy
Rustbook (x86_64-unknown-linux-gnu) - embedded-book
---
 finished in 1.515 seconds
##[endgroup]
Generating lint docs (x86_64-unknown-linux-gnu)
##[group]Running stage2 lint-docs (x86_64-unknown-linux-gnu)
error: failed to test example in lint docs for `refining_impl_trait_reachable` in /checkout/compiler/rustc_lint_defs/src/builtin.rs:4313: lint docs should start with the text "The `refining_impl_trait_reachable` lint" to introduce the lint
This error was generated by the lint-docs tool.
This tool extracts documentation for lints from the source code and places
This tool extracts documentation for lints from the source code and places
them in the rustc book. See the declare_lint! documentation
https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/macro.declare_lint.html


To re-run these tests, run: ./x.py test --keep-stage=0 src/tools/lint-docs
The --keep-stage flag should be used if you have already built the compiler

Build completed unsuccessfully in 0:32:57
  local time: Tue Mar  5 23:28:55 UTC 2024
  network time: Tue, 05 Mar 2024 23:28:55 GMT

rust-log-analyzer avatar Mar 05 '24 23:03 rust-log-analyzer

@rustbot label +T-lang -T-compiler

pnkfelix avatar Mar 06 '24 16:03 pnkfelix

@rfcbot fcp merge

We discussed this in today's meeting and agreed that this split looked like what we asked for, with the intent being to gain more specific feedback. We decided to do an FCP.

nikomatsakis avatar Mar 06 '24 16:03 nikomatsakis

Team member @nikomatsakis has proposed to merge this. The next step is review by the rest of the tagged team members:

  • [ ] @joshtriplett
  • [x] @nikomatsakis
  • [x] @pnkfelix
  • [x] @scottmcm
  • [x] @tmandry

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. See this document for info about what commands tagged team members can give me.

rfcbot avatar Mar 06 '24 16:03 rfcbot

@rfcbot fcp merge

This is what we asked for, thanks! (T-lang meeting concluded we will nonetheless drive this via fcp)

pnkfelix avatar Mar 06 '24 16:03 pnkfelix

yay race conditions.

@rfcbot fcp reviewed

pnkfelix avatar Mar 06 '24 16:03 pnkfelix

:bell: This is now entering its final comment period, as per the review above. :bell:

rfcbot avatar Mar 06 '24 17:03 rfcbot

@rustbot labels -I-lang-nominated

As mentioned above, we discussed this and it's now in FCP. Let's unnominate.

traviscross avatar Mar 06 '24 17:03 traviscross

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

rfcbot avatar Mar 16 '24 17:03 rfcbot

@bors r+

compiler-errors avatar Mar 16 '24 17:03 compiler-errors

:pushpin: Commit c121a26ab978681db9133865089a67a3d9723eda has been approved by compiler-errors

It is now in the queue for this repository.

bors avatar Mar 16 '24 17:03 bors