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 suggest restricting bound with unstable traits on stable and mention it's unstable on nightly #133522

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

estebank
Copy link
Contributor

On nightly, we mention the trait is unstable

error[E0277]: the trait bound `T: Unstable` is not satisfied
  --> $DIR/unstable-trait-suggestion.rs:13:9
   |
LL |     foo(t)
   |     --- ^ the trait `Unstable` is not implemented for `T`
   |     |
   |     required by a bound introduced by this call
   |
note: required by a bound in `foo`
  --> $DIR/unstable-trait-suggestion.rs:9:11
   |
LL | fn foo<T: Unstable>(_: T) {}
   |           ^^^^^^^^ required by this bound in `foo`
help: consider restricting type parameter `T` but it is an `unstable` trait
   |
LL | pub fn demo<T: Unstable>(t: T) {
   |              ++++++++++

On stable, we don't suggest the trait at all

error[E0277]: the trait bound `T: Unstable` is not satisfied
  --> $DIR/unstable-trait-suggestion.rs:13:9
   |
LL |     foo(t)
   |     --- ^ the trait `Unstable` is not implemented for `T`
   |     |
   |     required by a bound introduced by this call
   |
note: required by a bound in `foo`
  --> $DIR/unstable-trait-suggestion.rs:9:11
   |
LL | fn foo<T: Unstable>(_: T) {}
   |           ^^^^^^^^ required by this bound in `foo`

Fix #133511.

@rustbot
Copy link
Collaborator

rustbot commented Nov 27, 2024

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
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 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 27, 2024
@@ -6,7 +6,7 @@ LL | impl<A, B> FnOnce<A> for CachedFun<A, B>
|
note: required by a bound in `FnOnce`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
help: consider further restricting this bound
help: consider further restricting this bound but it is an `unstable` trait
Copy link
Member

Choose a reason for hiding this comment

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

nit: unstable is not a keyword, and "but" feels awkward here... maybe put it in parens and use "although" instead?

consider further restricting this bound (although this is an unstable trait)

Copy link
Member

Choose a reason for hiding this comment

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

maybe "although note that it is unstable" in the parentheses?

Copy link
Contributor

Choose a reason for hiding this comment

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

I also think the "it" here is a bit unclear, on first reading I thought "it" referred to T and was then thrown off by T being an unstable trait

Perhaps the trait could be named or something like "the new bound" or "the bound added below" be used instead?

Copy link
Member

Choose a reason for hiding this comment

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

the "it" is the trait, not really the bound

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"but note that the trait is unstable"?

Copy link
Member

Choose a reason for hiding this comment

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

sure, but if you're going to use "but" please still put it in parentheses or at least add a comma, since it's still a bit awkward grammatically

Copy link
Member

Choose a reason for hiding this comment

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

Drive-by comment: perhaps it would be easier if the types were explicitly named? For example:

error[E0277]: functions with the "rust-call" ABI must take a single non-self tuple argument
  --> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:31:5
   |
LL |     extern "rust-call" fn call_once(mut self, a: A) -> Self::Output {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Tuple` is not implemented for `A`
   |
help: consider adding the unstable trait `Tuple` to the bounds of `A`
   |
LL |     A: Eq + Hash + Clone + std::marker::Tuple,
   |                          ++++++++++++++++++++

Then the stability or non-stability can be added via the phrase "consider adding the trait Tuple to the bounds of A" / "consider adding the unstable trait Tuple to the bounds of A`".

Alternatively, it could be suggested via a separate note:

error[E0277]: functions with the "rust-call" ABI must take a single non-self tuple argument
  --> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:31:5
   |
LL |     extern "rust-call" fn call_once(mut self, a: A) -> Self::Output {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Tuple` is not implemented for `A`
   |
help: consider adding the trait `Tuple` to the bounds of `A`
   |
LL |     A: Eq + Hash + Clone + std::marker::Tuple,
   |                          ++++++++++++++++++++
note: the trait `Tuple` is unstable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to "help: consider restricting type parameter T with unstable trait Unstable".

On nightly, we mention the trait is unstable

```
error[E0277]: the trait bound `T: Unstable` is not satisfied
  --> $DIR/unstable-trait-suggestion.rs:13:9
   |
LL |     foo(t)
   |     --- ^ the trait `Unstable` is not implemented for `T`
   |     |
   |     required by a bound introduced by this call
   |
note: required by a bound in `foo`
  --> $DIR/unstable-trait-suggestion.rs:9:11
   |
LL | fn foo<T: Unstable>(_: T) {}
   |           ^^^^^^^^ required by this bound in `foo`
help: consider restricting type parameter `T` but it is an `unstable` trait
   |
LL | pub fn demo<T: Unstable>(t: T) {
   |              ++++++++++
```

On stable, we don't suggest the trait at all

```
error[E0277]: the trait bound `T: Unstable` is not satisfied
  --> $DIR/unstable-trait-suggestion.rs:13:9
   |
LL |     foo(t)
   |     --- ^ the trait `Unstable` is not implemented for `T`
   |     |
   |     required by a bound introduced by this call
   |
note: required by a bound in `foo`
  --> $DIR/unstable-trait-suggestion.rs:9:11
   |
LL | fn foo<T: Unstable>(_: T) {}
   |           ^^^^^^^^ required by this bound in `foo`
```
@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Nov 28, 2024
@@ -4,7 +4,7 @@ error[E0277]: the trait bound `C: Bar<5>` is not satisfied
LL | pub struct Structure<C: Tec> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar<5>` is not implemented for `C`
|
help: consider further restricting this bound
help: consider further restricting this bound with trait `Bar<5>`
Copy link
Member

Choose a reason for hiding this comment

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

Could you change this to use print_only_trait_name rather than printing the binder and the args?

I first of all don't think mentioning the name is really that useful, since it's already there in the suggestion, but if we're going to mention it at all, it's probably only worthwhile to suggest only the trait name.

Copy link
Member

Choose a reason for hiding this comment

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

Rendering the binder and substs runs the risk of printing a really overly long trait ref here, since we may have large types in the args.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could only mention the trait for unsafe ones (as I originally intended in the PR, to keep the diff small).

The only issue against using the "name only" is when we have more than one bound being suggested, but we have to handle that anyways...

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine either way, was just mentioning that it feels a bit redundant. Name only seems like a good compromise.

This test will break when `Step` gets stabilized, but punt until then.
@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Nov 28, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 28, 2024

This PR modifies tests/run-make/. If this PR is trying to port a Makefile
run-make test to use rmake.rs, please update the
run-make port tracking issue
so we can track our progress. You can either modify the tracking issue
directly, or you can comment on the tracking issue and link this PR.

cc @jieyouxu

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check-tidy failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/

# NOTE: intentionally uses python2 for x.py so we can test it still works.
# validate-toolstate only runs in our CI, so it's ok for it to only support python3.
ENV SCRIPT TIDY_PRINT_DIFF=1 python2.7 ../x.py test \
           --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint,cpp:fmt
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---
#13 2.797 Building wheels for collected packages: reuse
#13 2.798   Building wheel for reuse (pyproject.toml): started
#13 3.050   Building wheel for reuse (pyproject.toml): finished with status 'done'
#13 3.051   Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132720 sha256=026f3bb0f1aa8090b861fd0a0939cb1a782396d84c8aab7875096557d637a0f6
#13 3.051   Stored in directory: /tmp/pip-ephem-wheel-cache-gx1g54x1/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#13 3.055 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#13 3.457 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#13 3.458 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#13 3.986 Collecting virtualenv
#13 3.986 Collecting virtualenv
#13 4.027   Downloading virtualenv-20.28.0-py3-none-any.whl (4.3 MB)
#13 4.096      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.3/4.3 MB 64.1 MB/s eta 0:00:00
#13 4.152 Collecting platformdirs<5,>=3.9.1
#13 4.156   Downloading platformdirs-4.3.6-py3-none-any.whl (18 kB)
#13 4.175 Collecting distlib<1,>=0.3.7
#13 4.186      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 469.0/469.0 KB 88.1 MB/s eta 0:00:00
#13 4.220 Collecting filelock<4,>=3.12.2
#13 4.224   Downloading filelock-3.16.1-py3-none-any.whl (16 kB)
#13 4.224   Downloading filelock-3.16.1-py3-none-any.whl (16 kB)
#13 4.306 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#13 4.491 Successfully installed distlib-0.3.9 filelock-3.16.1 platformdirs-4.3.6 virtualenv-20.28.0
#13 DONE 4.6s

#14 [7/8] COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
#14 DONE 0.0s
---
DirectMap4k:      317376 kB
DirectMap2M:     8071168 kB
DirectMap1G:    10485760 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 python2.7 ../x.py test            --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint,cpp:fmt
+ TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint,cpp:fmt
    Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
WARN: currently no CI rustc builds have rustc debug assertions enabled. Please either set `rust.debug-assertions` to `false` if you want to use download CI rustc or set `rust.download-rustc` to `false`.
downloading https://static.rust-lang.org/dist/2024-10-16/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz
---
   Compiling tidy v0.1.0 (/checkout/src/tools/tidy)
    Finished `release` profile [optimized] target(s) in 30.36s
##[endgroup]
fmt check
Diff in /checkout/tests/run-make/missing-unstable-trait-bound/rmake.rs:14:
         .input("missing-bound.rs")
         .run_fail()
         .assert_stderr_not_contains("help: consider restricting type parameter `T`")
-        .assert_stderr_contains(r#"
+        .assert_stderr_contains(
   = note: required for `std::ops::Range<T>` to implement `Iterator`
   = note: required for `std::ops::Range<T>` to implement `Iterator`
-  = note: required for `std::ops::Range<T>` to implement `IntoIterator`"#);
+  = note: required for `std::ops::Range<T>` to implement `IntoIterator`"#,
 }
 
 
fmt error: Running `"/checkout/obj/build/x86_64-unknown-linux-gnu/rustfmt/bin/rustfmt" "--config-path" "/checkout" "--edition" "2021" "--unstable-features" "--skip-children" "--check" "/checkout/tests/run-make/native-link-modifier-whole-archive/native_lib_in_src.rs" "/checkout/tests/run-make/native-link-modifier-whole-archive/indirectly_linked.rs" "/checkout/tests/run-make/native-link-modifier-whole-archive/indirectly_linked_via_attr.rs" "/checkout/tests/run-make/native-link-modifier-whole-archive/directly_linked_test_minus_whole_archive.rs" "/checkout/tests/run-make/native-link-modifier-whole-archive/directly_linked_test_plus_whole_archive.rs" "/checkout/tests/run-make/native-link-modifier-whole-archive/directly_linked.rs" "/checkout/tests/run-make/native-link-modifier-whole-archive/rmake.rs" "/checkout/tests/run-make/native-link-modifier-whole-archive/rlib_with_cmdline_native_lib.rs" "/checkout/library/std/src/io/impls/tests.rs" "/checkout/tests/run-make/foreign-rust-exceptions/foo.rs" "/checkout/tests/run-make/foreign-rust-exceptions/bar.rs" "/checkout/tests/run-make/foreign-rust-exceptions/rmake.rs" "/checkout/tests/run-make/compressed-debuginfo/foo.rs" "/checkout/tests/run-make/compressed-debuginfo/rmake.rs" "/checkout/library/std/src/io/buffered/bufreader.rs" "/checkout/library/std/src/io/buffered/bufwriter.rs" "/checkout/library/std/src/io/buffered/linewritershim.rs" "/checkout/library/std/src/io/buffered/bufreader/buffer.rs" "/checkout/library/std/src/io/buffered/tests.rs" "/checkout/library/std/src/io/buffered/linewriter.rs" "/checkout/library/std/src/io/buffered/mod.rs" "/checkout/library/std/src/io/copy.rs" "/checkout/library/std/src/io/impls.rs" "/checkout/library/std/src/io/tests.rs" "/checkout/tests/run-make/extern-fn-generic/test.rs" "/checkout/tests/run-make/extern-fn-generic/rmake.rs" "/checkout/tests/run-make/extern-fn-generic/testcrate.rs" "/checkout/library/std/src/io/util/tests.rs" "/checkout/library/std/src/io/stdio/tests.rs" "/checkout/library/std/src/io/mod.rs" "/checkout/library/std/src/io/util.rs" "/checkout/library/std/src/f32.rs" "/checkout/tests/run-make/extern-fn-reachable/dylib.rs" "/checkout/tests/run-make/panic-abort-eh_frame/foo.rs" "/checkout/tests/run-make/panic-abort-eh_frame/rmake.rs" "/checkout/library/std/src/thread/current.rs" "/checkout/library/std/src/thread/local.rs" "/checkout/tests/run-make/incr-test-moved-file/main.rs" "/checkout/tests/run-make/incr-test-moved-file/rmake.rs" "/checkout/library/std/src/thread/local/tests.rs" "/checkout/library/std/src/thread/local/dynamic_tests.rs" "/checkout/library/std/src/thread/scoped.rs" "/checkout/library/std/src/thread/spawnhook.rs" "/checkout/library/std/src/thread/tests.rs" "/checkout/library/std/src/thread/mod.rs" "/checkout/tests/run-make/return-non-c-like-enum-from-c/rmake.rs" "/checkout/tests/run-make/return-non-c-like-enum-from-c/nonclike.rs" "/checkout/tests/run-make/no-input-file/rmake.rs" "/checkout/tests/run-make/missing-unstable-trait-bound/missing-bound.rs" "/checkout/tests/run-make/missing-unstable-trait-bound/rmake.rs" "/checkout/tests/run-make/mixing-formats/bar2.rs" "/checkout/tests/run-make/mixing-formats/foo.rs" "/checkout/tests/run-make/mixing-formats/bar1.rs" "/checkout/tests/run-make/mixing-formats/baz2.rs" "/checkout/tests/run-make/mixing-formats/rmake.rs" "/checkout/tests/run-make/mixing-formats/baz.rs" "/checkout/tests/run-make/doctests-keep-binaries-2024/rmake.rs" "/checkout/tests/run-make/doctests-keep-binaries-2024/t.rs" "/checkout/tests/run-make/CURRENT_RUSTC_VERSION/main.rs" "/checkout/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs" "/checkout/tests/run-make/CURRENT_RUSTC_VERSION/stable.rs" "/checkout/tests/run-make/panic-impl-transitive/panic-impl-provider.rs" "/checkout/tests/run-make/panic-impl-transitive/panic-impl-consumer.rs" "/checkout/library/std/src/io/stdio.rs"` failed.
If you're running `tidy`, try again with `--bless`. Or, if you just want to format code, run `./x.py fmt` instead.
  local time: Thu Nov 28 19:44:32 UTC 2024
  network time: Thu, 28 Nov 2024 19:44:32 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stable rustc 1.82 suggests using an unstable trait
7 participants