Skip to content

elaborate: avoid projections with unconstrained bound regions #136303

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

Closed
wants to merge 3 commits into from

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Jan 30, 2025

Should only do this for where-bounds and item bounds. Gonna rewrite later I think.

This means we'll no longer need to support unconstrained regions in implied bounds, see lcnr/random-rust-snippets#15. This fixes

trait Super {
    type SAssoc;
}
trait Trait<'a>: Super<SAssoc = <Self as Trait<'a>>::TAssoc> {
    type TAssoc;
}

fn test<'a, T: 'a>() {}

fn unconstrained_lt<'arg, T: for<'a> Trait<'a>>(x: &'arg <T as Super>::SAssoc) {
    test::<'arg, <T as Super>::SAssoc>();
}

but breaks

trait Super {
    type SAssoc;
}
trait Trait<'a>: Super<SAssoc = <Self as Trait<'a>>::TAssoc> {
    type TAssoc;
}

fn test<'a, T: 'a>() {}

fn unconstrained_lt<'arg, T: for<'a> Trait<'a, TAssoc = usize>>(x: <T as Super>::SAssoc) -> usize {
    x
}

r? @compiler-errors

lcnr added 3 commits January 30, 2025 16:37

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jan 30, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Jan 30, 2025

@bors try

@bors
Copy link
Collaborator

bors commented Jan 30, 2025

⌛ Trying commit d6f2c89 with merge a3dffdb...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 30, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
… r=<try>

elaborate: avoid projections with unconstrained bound regions

Should only do this for where-bounds and item bounds. Gonna rewrite later I think.

This means we'll no longer need to support unconstrained regions in implied bounds, see lcnr/random-rust-snippets#15. This fixes
```rust
trait Super {
    type SAssoc;
}
trait Trait<'a>: Super<SAssoc = <Self as Trait<'a>>::TAssoc> {
    type TAssoc;
}

fn test<'a, T: 'a>() {}

fn unconstrained_lt<'arg, T: for<'a> Trait<'a>>(x: &'arg <T as Super>::SAssoc) {
    test::<'arg, <T as Super>::SAssoc>();
}
```
but breaks
```rust
trait Super {
    type SAssoc;
}
trait Trait<'a>: Super<SAssoc = <Self as Trait<'a>>::TAssoc> {
    type TAssoc;
}

fn test<'a, T: 'a>() {}

fn unconstrained_lt<'arg, T: for<'a> Trait<'a, TAssoc = usize>>(x: <T as Super>::SAssoc) -> usize {
    x
}
```

r? `@compiler-errors`
@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
#21 exporting to docker image format
#21 sending tarball 28.4s done
#21 DONE 43.5s
##[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-18]
debug: `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` configured.
---
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-18', '--enable-llvm-link-shared', '--set', 'rust.randomize-layout=true', '--set', 'rust.thin-lto-import-instr-limit=10', '--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', 'rust.lld=false', '--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-18/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.randomize-layout := True
configure: rust.thin-lto-import-instr-limit := 10
---
Saved the actual stderr to "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/nll/issue-54189/issue-54189.stderr"
diff of stderr:

12    |
13    = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
- error: aborting due to 2 previous errors
+ error[E0308]: mismatched types
+   --> $DIR/issue-54189.rs:1:44
+    |
+    |
+ LL | fn bug() -> impl for <'r> Fn() -> &'r () { || { &() } }
+    |                                            ^^^^^^^^^^ one type is more general than the other
+    = note: expected reference `&()`
+    = note: expected reference `&()`
+               found reference `&'r ()`
- For more information about this error, try `rustc --explain E0582`.
+ error: aborting due to 3 previous errors
+ 
+ Some errors have detailed explanations: E0308, E0582.
---
-   --> /checkout/tests/ui/nll/issue-54189.rs:1:44
+ error[E0308]: mismatched types
+   --> $DIR/issue-54189.rs:1:44
+    |
+ LL | fn bug() -> impl for <'r> Fn() -> &'r () { || { &() } }
+    |                                            ^^^^^^^^^^ one type is more general than the other
+    = note: expected reference `&()`
+    = note: expected reference `&()`
+               found reference `&'r ()`
+ 
+ Some errors have detailed explanations: E0308, E0582.
+ For more information about an error, try `rustc --explain E0308`.



The actual stderr differed from the expected stderr.
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args nll/issue-54189.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/nll/issue-54189.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" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--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/nll/issue-54189" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers"
--- stderr -------------------------------
--- stderr -------------------------------
error[E0582]: binding for associated type `Output` references lifetime `'r`, which does not appear in the trait input types
   |
   |
LL | fn bug() -> impl for <'r> Fn() -> &'r () { || { &() } }


error[E0582]: binding for associated type `Output` references lifetime `'r`, which does not appear in the trait input types
   |
   |
LL | fn bug() -> impl for <'r> Fn() -> &'r () { || { &() } }
   |
   |
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0308]: mismatched types
##[error]  --> /checkout/tests/ui/nll/issue-54189.rs:1:44
   |
   |
LL | fn bug() -> impl for <'r> Fn() -> &'r () { || { &() } }
   |                                            ^^^^^^^^^^ one type is more general than the other
   = note: expected reference `&()`
   = note: expected reference `&()`
              found reference `&'r ()`
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0308, E0582.
For more information about an error, try `rustc --explain E0308`.
For more information about an error, try `rustc --explain E0308`.
------------------------------------------


---- [ui] tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.rs stdout ----
Saved the actual stderr to "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/traits/object/elaborated-predicates-unconstrained-late-bound/elaborated-predicates-unconstrained-late-bound.stderr"
diff of stderr:

- error[E0582]: binding for associated type `T` references lifetime `'a`, which does not appear in the trait input types
+ error[E0191]: the value of the associated type `T` in `B` must be specified
3    |
3    |
- LL | trait A<T>: B<T = T> {}
-    |               ----- due to this supertrait
+ LL |     type T;
+    |     ------ `T` defined here
6 ...
7 LL |         Erase::<dyn for<'a> A<&'a _>>(x.as_str())
-    |                     ^^^^^^^^^^^^^^^^
+    |                     ^^^^^^^^^^^^^^^^ help: specify the associated type: `for<'a> A<&'a _, T = Type>`
10 error: aborting due to 1 previous error
11 

- For more information about this error, try `rustc --explain E0582`.
---
To only update this specific test, also pass `--test-args traits/object/elaborated-predicates-unconstrained-late-bound.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.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" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--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/traits/object/elaborated-predicates-unconstrained-late-bound" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers"
--- stderr -------------------------------
error[E0191]: the value of the associated type `T` in `B` must be specified
##[error]  --> /checkout/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.rs:19:21
   |
   |
LL |     type T;
   |     ------ `T` defined here
...
LL |         Erase::<dyn for<'a> A<&'a _>>(x.as_str())
   |                     ^^^^^^^^^^^^^^^^ help: specify the associated type: `for<'a> A<&'a _, T = Type>`
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0191`.
------------------------------------------
------------------------------------------


---- [ui] tests/ui/wf/ice-wf-missing-span-in-error-130012.rs stdout ----
Saved the actual stderr to "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/wf/ice-wf-missing-span-in-error-130012/ice-wf-missing-span-in-error-130012.stderr"


26 LL | impl<F: for<'b> Fun<Assoc = &'b ()>> MyTrait for F {}
28 
- error[E0308]: mismatched types
- error[E0308]: mismatched types
+ error[E0271]: type mismatch resolving `<Self as Fun>::Assoc == &()`
+    = note:    expected reference `&()`
+            found associated type `<Self as Fun>::Assoc`
+            found associated type `<Self as Fun>::Assoc`
+    = help: consider constraining the associated type `<Self as Fun>::Assoc` to `&()`
+ note: required by a bound in `MyTrait`
+   --> $DIR/ice-wf-missing-span-in-error-130012.rs:9:28
+    |
+    |
+ LL | trait MyTrait: for<'a> Fun<Assoc = &'a ()> {}
+    |                            ^^^^^^^^^^^^^^ required by this bound in `MyTrait`
+ 
+ error[E0271]: type mismatch resolving `<F as Fun>::Assoc == &()`
31    |
31    |
32 LL | impl<F: for<'b> Fun<Assoc = &'b ()>> MyTrait for F {}
-    |                                                  ^ lifetime mismatch
+    |                                                  ^ expected `&()`, found associated type
34    |
-    = note: expected reference `&()`
-    = note: expected reference `&()`
-               found reference `&'b ()`
+    = note:    expected reference `&()`
+            found associated type `<F as Fun>::Assoc`
+ note: required for `F` to implement `MyTrait`
+    |
+    |
+ LL | impl<F: for<'b> Fun<Assoc = &'b ()>> MyTrait for F {}
+    |                     |
+    |                     unsatisfied trait bound introduced here
+    |                     unsatisfied trait bound introduced here
+ help: consider constraining the associated type `<F as Fun>::Assoc` to `&()`
+    |
+ LL | impl<F: for<'b> Fun<Assoc = &'b (), Assoc = &()>> MyTrait for F {}
37 
- error: aborting due to 5 previous errors
+ error: aborting due to 6 previous errors
39 
---

Note: some mismatched output was normalized before being compared
-   --> /checkout/tests/ui/wf/ice-wf-missing-span-in-error-130012.rs:9:28
-   --> /checkout/tests/ui/wf/ice-wf-missing-span-in-error-130012.rs:14:38
+ error[E0271]: type mismatch resolving `<Self as Fun>::Assoc == &()`
+    = note:    expected reference `&()`
+            found associated type `<Self as Fun>::Assoc`
+            found associated type `<Self as Fun>::Assoc`
+    = help: consider constraining the associated type `<Self as Fun>::Assoc` to `&()`
+ note: required by a bound in `MyTrait`
+   --> $DIR/ice-wf-missing-span-in-error-130012.rs:9:28
+    |
+    |
+ LL | trait MyTrait: for<'a> Fun<Assoc = &'a ()> {}
+    |                            ^^^^^^^^^^^^^^ required by this bound in `MyTrait`
+ 
+ error[E0271]: type mismatch resolving `<F as Fun>::Assoc == &()`
+    |                                                  ^ expected `&()`, found associated type
+    = note:    expected reference `&()`
+            found associated type `<F as Fun>::Assoc`
+ note: required for `F` to implement `MyTrait`
+    |
+    |
+ LL | impl<F: for<'b> Fun<Assoc = &'b ()>> MyTrait for F {}
+    |                     |
+    |                     unsatisfied trait bound introduced here
+    |                     unsatisfied trait bound introduced here
+ help: consider constraining the associated type `<F as Fun>::Assoc` to `&()`
+    |
+ LL | impl<F: for<'b> Fun<Assoc = &'b (), Assoc = &()>> MyTrait for F {}
+ error: aborting due to 6 previous errors
+ Some errors have detailed explanations: E0271, E0582.
+ For more information about an error, try `rustc --explain E0271`.



The actual stderr differed from the expected stderr.
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args wf/ice-wf-missing-span-in-error-130012.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/wf/ice-wf-missing-span-in-error-130012.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" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--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/wf/ice-wf-missing-span-in-error-130012" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers"
--- stderr -------------------------------
--- stderr -------------------------------
error[E0582]: binding for associated type `Assoc` references lifetime `'a`, which does not appear in the trait input types
   |
   |
LL | trait MyTrait: for<'a> Fun<Assoc = &'a ()> {}


error[E0582]: binding for associated type `Assoc` references lifetime `'a`, which does not appear in the trait input types
   |
   |
LL | trait MyTrait: for<'a> Fun<Assoc = &'a ()> {}
   |
   |
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0582]: binding for associated type `Assoc` references lifetime `'a`, which does not appear in the trait input types
   |
   |
LL | trait MyTrait: for<'a> Fun<Assoc = &'a ()> {}
   |
   |
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0582]: binding for associated type `Assoc` references lifetime `'b`, which does not appear in the trait input types
   |
   |
LL | impl<F: for<'b> Fun<Assoc = &'b ()>> MyTrait for F {}


error[E0271]: type mismatch resolving `<Self as Fun>::Assoc == &()`
   = note:    expected reference `&()`
           found associated type `<Self as Fun>::Assoc`
           found associated type `<Self as Fun>::Assoc`
   = help: consider constraining the associated type `<Self as Fun>::Assoc` to `&()`
note: required by a bound in `MyTrait`
  --> /checkout/tests/ui/wf/ice-wf-missing-span-in-error-130012.rs:9:28
   |
   |
LL | trait MyTrait: for<'a> Fun<Assoc = &'a ()> {}
   |                            ^^^^^^^^^^^^^^ required by this bound in `MyTrait`

error[E0271]: type mismatch resolving `<F as Fun>::Assoc == &()`
   |
   |
LL | impl<F: for<'b> Fun<Assoc = &'b ()>> MyTrait for F {}
   |                                                  ^ expected `&()`, found associated type
   = note:    expected reference `&()`
   = note:    expected reference `&()`
           found associated type `<F as Fun>::Assoc`
note: required for `F` to implement `MyTrait`
   |
   |
LL | impl<F: for<'b> Fun<Assoc = &'b ()>> MyTrait for F {}
   |                     |
   |                     unsatisfied trait bound introduced here
   |                     unsatisfied trait bound introduced here
help: consider constraining the associated type `<F as Fun>::Assoc` to `&()`
   |
LL | impl<F: for<'b> Fun<Assoc = &'b (), Assoc = &()>> MyTrait for F {}

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0271, E0582.

@bors
Copy link
Collaborator

bors commented Jan 30, 2025

☀️ Try build successful - checks-actions
Build commit: a3dffdb (a3dffdb3a32d0dedc198f9de7d43173f3eb6727b)

@lcnr
Copy link
Contributor Author

lcnr commented Jan 31, 2025

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-136303 created and queued.
🤖 Automatically detected try build a3dffdb
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 31, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-136303 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-136303 is completed!
📊 209 regressed and 2 fixed (576018 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Feb 1, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Feb 3, 2025

there are at least 3 actual regressions here:

  • gat-lending-iterator
  • gluon_salsa
  • polars-core

That makes me really unhappy :/

@compiler-errors
Copy link
Member

@rustbot author -- should we close this now that we decided that we're gonna allow these projections? 🤔

@rustbot rustbot 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 Feb 6, 2025
@lcnr lcnr closed this Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

None yet

6 participants