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

Add #[defines] attribute and require it for all type-alias-impl-trait sites that register a hidden type #128440

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

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jul 31, 2024

Instead of relying on the signature of items to decide whether they are constraining an opaque type, the opaque types that the item constrains must be explicitly listed.

A previous version of this PR used an actual attribute, but had to keep the resolved DefIds in a side table.

Now we just lower to fields in the AST that have no surface syntax, instead a builtin attribute macro fills in those fields where applicable.

Note that for convenience referencing opaque types in associated types from associated methods on the same impl will not require an attribute. If that causes problems #[defines()] can be used to overwrite the default of searching for opaques in the signature.

One wart of this design is that closures and static items do not have generics. So since I stored the opaques in the generics of functions, consts and methods, I needed to add a custom field to closures and statics to track this information. It's not really worse than the work that had to be done for the attribute/side-table based design, just something to be aware of.

@oli-obk oli-obk added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 31, 2024
@rust-log-analyzer

This comment has been minimized.

@petrochenkov petrochenkov self-assigned this Jul 31, 2024
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 31, 2024
@bors
Copy link
Contributor

bors commented Aug 1, 2024

☔ The latest upstream changes (presumably #128481) made this pull request unmergeable. Please resolve the merge conflicts.

@petrochenkov

This comment was marked as resolved.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2024
@petrochenkov petrochenkov removed their assignment Aug 14, 2024
@petrochenkov

This comment was marked as resolved.

@traviscross traviscross added the F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` label Aug 23, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 4, 2024
…ler-errors

Avoid `opaque type not constrained` errors in the presence of other errors

pulled out of rust-lang#128440

These errors carry no new information if the opaque type was actually used in a constraining (but erroneous) way somewhere.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 4, 2024
Rollup merge of rust-lang#133850 - oli-obk:push-xryukktpyooq, r=compiler-errors

Avoid `opaque type not constrained` errors in the presence of other errors

pulled out of rust-lang#128440

These errors carry no new information if the opaque type was actually used in a constraining (but erroneous) way somewhere.
@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Dec 10, 2024
@rust-log-analyzer

This comment has been minimized.

@bors

This comment was marked as resolved.

@oli-obk oli-obk removed the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Feb 25, 2025
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the defines branch 2 times, most recently from 0b8b995 to 573d6ce Compare February 25, 2025 09:43
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Feb 26, 2025
Comment on lines -824 to +826
if !rustc_feature::encode_cross_crate(attr.name_or_empty()) {
if let hir::Attribute::Parsed(p) = attr {
should_encode = p.encode_cross_crate();
} else if !rustc_feature::encode_cross_crate(attr.name_or_empty()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jdonszelmann what do you think about this? There's probably more opportunity for simplifying things, since name_or_empty is always empty for parsed attrs, but that should be its own PR

@oli-obk oli-obk marked this pull request as ready for review February 26, 2025 10:46
@rustbot
Copy link
Collaborator

rustbot commented Feb 26, 2025

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@oli-obk
Copy link
Contributor Author

oli-obk commented Feb 26, 2025

r? @lcnr maybe?

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic label Feb 26, 2025
@rustbot
Copy link
Collaborator

rustbot commented Feb 26, 2025

rustc_error_messages was changed

cc @davidtwco, @compiler-errors, @TaKO8Ki

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test now lives in tests/ui/type-alias-impl-trait/path_resolution_taint.rs

@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)
info: removing rustup binaries
info: rustup is uninstalled
##[group]Image checksum input
mingw-check-tidy
# We use the ghcr base image because ghcr doesn't have a rate limit
# and the mingw-check-tidy job doesn't cache docker images in CI.
FROM ghcr.io/rust-lang/ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
  g++ \
  make \
---

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,cpp
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---
#12 3.671 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
#12 4.218 Collecting virtualenv
#12 4.275   Downloading virtualenv-20.29.2-py3-none-any.whl (4.3 MB)
#12 4.540      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.3/4.3 MB 16.3 MB/s eta 0:00:00
#12 4.601 Collecting platformdirs<5,>=3.9.1
#12 4.612   Downloading platformdirs-4.3.6-py3-none-any.whl (18 kB)
#12 4.636 Collecting distlib<1,>=0.3.7
#12 4.662      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 469.0/469.0 KB 32.6 MB/s eta 0:00:00
#12 4.703 Collecting filelock<4,>=3.12.2
#12 4.713   Downloading filelock-3.17.0-py3-none-any.whl (16 kB)
#12 4.713   Downloading filelock-3.17.0-py3-none-any.whl (16 kB)
#12 4.793 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#12 4.975 Successfully installed distlib-0.3.9 filelock-3.17.0 platformdirs-4.3.6 virtualenv-20.29.2
#12 DONE 5.1s

#13 [7/8] COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
#13 DONE 0.0s
---
DirectMap4k:      114624 kB
DirectMap2M:     8273920 kB
DirectMap1G:    10485760 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 python2.7 ../x.py test            --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
+ TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
    Finished `dev` profile [unoptimized] target(s) in 0.05s
##[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/2025-02-18/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz
---
##[endgroup]
fmt check
fmt: checked 5856 files
tidy check
tidy error: /checkout/compiler/rustc_hir_analysis/messages.ftl: message `hir_analysis_tait_forward_compat` is not used
removing old virtual environment
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'venv'
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'virtualenv'
Requirement already satisfied: pip in ./build/venv/lib/python3.10/site-packages (25.0.1)
All checks passed!
checking python file formatting
28 files already formatted
checking C++ file formatting
checking C++ file formatting
some tidy checks failed
Command has failed. Rerun with -v to see more details.
  local time: Wed Feb 26 12:05:36 UTC 2025
  network time: Wed, 26 Feb 2025 12:05:36 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-attributes Area: Attributes (`#[…]`, `#![…]`) A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
Development

Successfully merging this pull request may close these issues.

9 participants