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

[WIP] Enforce may-define-must-define for ATPITs #123046

Conversation

compiler-errors
Copy link
Member

Putting this up in an incomplete state because I've got some concerns

r? oli-obk

@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 Mar 25, 2024
@@ -78,6 +82,24 @@ impl<'tcx> RegionInferenceContext<'tcx> {
}
}
}

if !infcx.tcx.is_typeck_child(anchor.to_def_id()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Specifically, we can't enforce this on typeck children because it would mean that the given code fails:

trait Foo {
  type Assoc;
  fn foo() -> Self::Assoc;
}

impl Foo for () {
  type Assoc = impl Sized;
  fn foo() -> Self::Assoc {
    let x = || {};
    //      ^^^^^ <- this body doesn't define `Self::Assoc`, even though it could.
    ""
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have thoughts either, @aliemjay? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't remember if this landed, but I once had a commit where opaques from children got copied into their parents during borrowck. Then we could stop looking at children entirely. Well, modulo opaques that are only mentioned in the signature of children, but... oh we don't have ATPIT tests for that, do we

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't collect opaques for typeck children anyways:

trait Foo {
  type Assoc;
  fn foo();
}

impl Foo for () {
  type Assoc = impl Sized;
  fn foo() {
    let x = || -> Self::Assoc {
        ""
    };
  }
}
error[E0308]: mismatched types
  --> src/lib.rs:12:9
   |
9  |   type Assoc = impl Sized;
   |                ---------- the expected opaque type
...
12 |         ""
   |         ^^ expected opaque type, found `&str`
   |
   = note: expected opaque type `<() as Foo>::Assoc`
                found reference `&'static str`

Copy link
Member Author

@compiler-errors compiler-errors Mar 25, 2024

Choose a reason for hiding this comment

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

And I don't think we want to -- since if we don't, then we only need to check that the typeck root defines the given opaques.

@@ -42,12 +43,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// Check that all opaque types have the same region parameters if they have the same
/// non-region parameters. This is necessary because within the new solver we perform various query operations
/// modulo regions, and thus could unsoundly select some impls that don't hold.
fn check_unique(
fn check_unique_and_defined(
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: comment

@@ -78,6 +82,24 @@ impl<'tcx> RegionInferenceContext<'tcx> {
}
}
}

if !infcx.tcx.is_typeck_child(anchor.to_def_id()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have thoughts either, @aliemjay? 🤔

@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
#16 exporting to docker image format
#16 sending tarball 29.3s done
#16 DONE 35.0s
##[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-17]
---
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-17', '--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', '--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-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
error: /checkout/tests/ui/generic-associated-types/issue-87258_a.rs:17: unexpected error: '17:26: 17:37: method must define opaque type'

error: 1 unexpected errors found, 0 expected errors not found
status: exit status: 1
command: RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/generic-associated-types/issue-87258_a.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" "--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/generic-associated-types/issue-87258_a" "-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/generic-associated-types/issue-87258_a/auxiliary"
    Error {
        line_num: 17,
        kind: Some(
            Error,

@bors
Copy link
Contributor

bors commented Mar 28, 2024

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

@compiler-errors
Copy link
Member Author

OK well I'm never actually gonna work on this. Sorry @oli-obk, feel free to take over 🫡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Development

Successfully merging this pull request may close these issues.

5 participants