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

Make some report and emit errors take DefIds instead of BodyIds #108945

Merged

Conversation

spastorino
Copy link
Member

Breaking off from #108915

r? @compiler-errors

@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 9, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2023

Some changes occurred in need_type_info.rs

cc @lcnr

@spastorino
Copy link
Member Author

This patches gives 3Fs, unsure why but it seems we are losing some inference info for diagnostics ...

failures:

---- [ui] tests/ui/lazy-type-alias-impl-trait/branches3.rs stdout ----
diff of stderr:

1	error[E0282]: type annotations needed
-	  --> $DIR/branches3.rs:8:10
+	  --> $DIR/branches3.rs:8:13
3	   |
4	LL |         |s| s.len()
-	   |          ^  - type must be known at this point
-	   |
-	help: consider giving this closure parameter an explicit type
-	   |
-	LL |         |s: /* Type */| s.len()
-	   |           ++++++++++++
+	   |             ^ cannot infer type
11	
12	error[E0282]: type annotations needed
-	  --> $DIR/branches3.rs:15:10
+	  --> $DIR/branches3.rs:15:13
14	   |
15	LL |         |s| s.len()
-	   |          ^  - type must be known at this point
-	   |
-	help: consider giving this closure parameter an explicit type
-	   |
-	LL |         |s: /* Type */| s.len()
-	   |           ++++++++++++
+	   |             ^ cannot infer type
22	
23	error[E0282]: type annotations needed
-	  --> $DIR/branches3.rs:23:10
+	  --> $DIR/branches3.rs:23:13
25	   |
26	LL |         |s| s.len()
-	   |          ^  - type must be known at this point
-	   |
-	help: consider giving this closure parameter an explicit type
-	   |
-	LL |         |s: /* Type */| s.len()
-	   |           ++++++++++++
+	   |             ^ cannot infer type
33	
34	error[E0282]: type annotations needed
-	  --> $DIR/branches3.rs:30:10
+	  --> $DIR/branches3.rs:30:13
36	   |
37	LL |         |s| s.len()
-	   |          ^  - type must be known at this point
-	   |
-	help: consider giving this closure parameter an explicit type
-	   |
-	LL |         |s: /* Type */| s.len()
-	   |           ++++++++++++
+	   |             ^ cannot infer type
44	
45	error: aborting due to 4 previous errors
46	


The actual stderr differed from the expected stderr.
Actual stderr saved to /home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/test/ui/lazy-type-alias-impl-trait/branches3/branches3.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args lazy-type-alias-impl-trait/branches3.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/stage1/bin/rustc" "/home/gh-spastorino/rust3/tests/ui/lazy-type-alias-impl-trait/branches3.rs" "-Zthreads=1" "--target=aarch64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--remap-path-prefix=/home/gh-spastorino/rust3/tests/ui=fake-test-src-base" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/test/ui/lazy-type-alias-impl-trait/branches3" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/test/ui/lazy-type-alias-impl-trait/branches3/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0282]: type annotations needed
  --> fake-test-src-base/lazy-type-alias-impl-trait/branches3.rs:8:13
   |
LL |         |s| s.len() //~ ERROR type annotations needed
   |             ^ cannot infer type

error[E0282]: type annotations needed
  --> fake-test-src-base/lazy-type-alias-impl-trait/branches3.rs:15:13
   |
LL |         |s| s.len() //~ ERROR type annotations needed
   |             ^ cannot infer type

error[E0282]: type annotations needed
  --> fake-test-src-base/lazy-type-alias-impl-trait/branches3.rs:23:13
   |
LL |         |s| s.len() //~ ERROR type annotations needed
   |             ^ cannot infer type

error[E0282]: type annotations needed
  --> fake-test-src-base/lazy-type-alias-impl-trait/branches3.rs:30:13
   |
LL |         |s| s.len() //~ ERROR type annotations needed
   |             ^ cannot infer type

error: aborting due to 4 previous errors

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


---- [ui] tests/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-2.rs stdout ----
diff of stderr:

-	error[E0282]: type annotations needed for `Option<T>`
-	  --> $DIR/unboxed-closures-failed-recursive-fn-2.rs:8:9
+	error[E0282]: type annotations needed
+	  --> $DIR/unboxed-closures-failed-recursive-fn-2.rs:17:32
3	   |
-	LL |     let mut closure0 = None;
-	   |         ^^^^^^^^^^^^
-	...
7	LL |                         return c();
-	   |                                --- type must be known at this point
-	   |
-	help: consider giving `closure0` an explicit type, where the placeholders `_` are specified
-	   |
-	LL |     let mut closure0: Option<T> = None;
-	   |                     +++++++++++
+	   |                                ^^^ cannot infer type
14	
15	error: aborting due to previous error
16	


The actual stderr differed from the expected stderr.
Actual stderr saved to /home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-2/unboxed-closures-failed-recursive-fn-2.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args unboxed-closures/unboxed-closures-failed-recursive-fn-2.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/stage1/bin/rustc" "/home/gh-spastorino/rust3/tests/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-2.rs" "-Zthreads=1" "--target=aarch64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--remap-path-prefix=/home/gh-spastorino/rust3/tests/ui=fake-test-src-base" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-2" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-2/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0282]: type annotations needed
  --> fake-test-src-base/unboxed-closures/unboxed-closures-failed-recursive-fn-2.rs:17:32
   |
LL |                         return c();
   |                                ^^^ cannot infer type

error: aborting due to previous error

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


---- [ui] tests/ui/type-alias-impl-trait/closures_in_branches.rs stdout ----
diff of stderr:

1	error[E0282]: type annotations needed
-	  --> $DIR/closures_in_branches.rs:7:10
+	  --> $DIR/closures_in_branches.rs:7:13
3	   |
4	LL |         |x| x.len()
-	   |          ^  - type must be known at this point
-	   |
-	help: consider giving this closure parameter an explicit type
-	   |
-	LL |         |x: /* Type */| x.len()
-	   |           ++++++++++++
+	   |             ^ cannot infer type
11	
12	error[E0282]: type annotations needed
-	  --> $DIR/closures_in_branches.rs:21:10
+	  --> $DIR/closures_in_branches.rs:21:13
14	   |
15	LL |         |x| x.len()
-	   |          ^  - type must be known at this point
-	   |
-	help: consider giving this closure parameter an explicit type
-	   |
-	LL |         |x: /* Type */| x.len()
-	   |           ++++++++++++
+	   |             ^ cannot infer type
22	
23	error: aborting due to 2 previous errors
24	


The actual stderr differed from the expected stderr.
Actual stderr saved to /home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/test/ui/type-alias-impl-trait/closures_in_branches/closures_in_branches.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args type-alias-impl-trait/closures_in_branches.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/stage1/bin/rustc" "/home/gh-spastorino/rust3/tests/ui/type-alias-impl-trait/closures_in_branches.rs" "-Zthreads=1" "--target=aarch64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--remap-path-prefix=/home/gh-spastorino/rust3/tests/ui=fake-test-src-base" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/test/ui/type-alias-impl-trait/closures_in_branches" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/home/gh-spastorino/rust3/build/aarch64-unknown-linux-gnu/test/ui/type-alias-impl-trait/closures_in_branches/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0282]: type annotations needed
  --> fake-test-src-base/type-alias-impl-trait/closures_in_branches.rs:7:13
   |
LL |         |x| x.len() //~ ERROR type annotations needed
   |             ^ cannot infer type

error[E0282]: type annotations needed
  --> fake-test-src-base/type-alias-impl-trait/closures_in_branches.rs:21:13
   |
LL |         |x| x.len() //~ ERROR type annotations needed
   |             ^ cannot infer type

error: aborting due to 2 previous errors

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



failures:
    [ui] tests/ui/lazy-type-alias-impl-trait/branches3.rs
    [ui] tests/ui/type-alias-impl-trait/closures_in_branches.rs
    [ui] tests/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-2.rs

test result: FAILED. 4 passed; 3 failed; 14577 ignored; 0 measured; 0 filtered out; finished in 0.19s

@spastorino spastorino force-pushed the pass-def-id-instead-of-using-hir-id branch from 215320e to 0d1674e Compare March 9, 2023 19:38
@spastorino spastorino force-pushed the pass-def-id-instead-of-using-hir-id branch from 0d1674e to 2f480fa Compare March 9, 2023 20:44
@spastorino spastorino force-pushed the pass-def-id-instead-of-using-hir-id branch from 2f480fa to 5b99723 Compare March 9, 2023 20:53
@spastorino
Copy link
Member Author

This should be ready now modulo that in FnCtxt we have body_id: LocalDefId and in Inherited we have body_def_id: LocalDefId. In general I think I'd prefer the latter, given that a field called body_id may be seen as containing BodyId. Can rename FnCtxt field if you guys prefer so.

@compiler-errors
Copy link
Member

You can rename body_id in FnCtxt to body_def_id in a follow-up PR. Not sure if I prefer body_def_id or body_id strongly.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 9, 2023

📌 Commit 5b99723 has been approved by compiler-errors

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Mar 9, 2023

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 9, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 10, 2023
…cjgillot

Remove `body_def_id` from `Inherited`

We can just use the body id from the obligation cause.

Follow-up to rust-lang#108945, only my commit is relevant.

r? `@cjgillot` cc `@spastorino`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 10, 2023
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#108879 (Unconstrained terms should account for infer vars being equated)
 - rust-lang#108936 (Rustdoc: don't hide anonymous reexport)
 - rust-lang#108940 (Add myself to compiler reviewers list)
 - rust-lang#108945 (Make some report and emit errors take DefIds instead of BodyIds)
 - rust-lang#108946 (Document the resulting values produced when using `From<bool>` on floats)
 - rust-lang#108956 (Make ptr::from_ref and ptr::from_mut in rust-lang#106116 const.)
 - rust-lang#108960 (Remove `body_def_id` from `Inherited`)
 - rust-lang#108963 (only call git on git checkouts during bootstrap)
 - rust-lang#108964 (Fix the docs for pointer method with_metadata_of)

Failed merges:

 - rust-lang#108950 (Directly construct Inherited in typeck.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit afd8558 into rust-lang:master Mar 10, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 10, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 14, 2023
…r-errors

Remove some direct calls to local_def_id_to_hir_id on diagnostics

Was playing with `tests/ui/impl-trait/in-trait/default-body-with-rpit.rs` and was able to remove some ICEs. Still getting ...

```
error[E0277]: `impl Future<Output = Foo::{opaque#0}>` is not a future
  --> tests/ui/impl-trait/in-trait/default-body-with-rpit.rs:10:28
   |
10 |     async fn baz(&self) -> impl Debug {
   |                            ^^^^^^^^^^ `impl Future<Output = Foo::{opaque#0}>` is not a future
   |
   = help: the trait `Future` is not implemented for `impl Future<Output = Foo::{opaque#0}>`
   = note: impl Future<Output = Foo::{opaque#0}> must be a future or must implement `IntoFuture` to be awaited
note: required by a bound in `Foo::{opaque#1}`
  --> tests/ui/impl-trait/in-trait/default-body-with-rpit.rs:10:28
   |
10 |     async fn baz(&self) -> impl Debug {
   |                            ^^^^^^^^^^ required by this bound in `Foo::{opaque#1}`

error[E0277]: the size for values of type `impl Future<Output = Foo::{opaque#0}>` cannot be known at compilation time
  --> tests/ui/impl-trait/in-trait/default-body-with-rpit.rs:10:28
   |
10 |     async fn baz(&self) -> impl Debug {
   |                            ^^^^^^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `Sized` is not implemented for `impl Future<Output = Foo::{opaque#0}>`
note: required by a bound in `Foo::{opaque#1}`
  --> tests/ui/impl-trait/in-trait/default-body-with-rpit.rs:10:28
   |
10 |     async fn baz(&self) -> impl Debug {
   |                            ^^^^^^^^^^ required by this bound in `Foo::{opaque#1}`

error: internal compiler error: compiler/rustc_hir_typeck/src/closure.rs:724:18: async fn generator return type not an inference variable: Foo::{opaque#1}<'_>
  --> tests/ui/impl-trait/in-trait/default-body-with-rpit.rs:10:39
   |
10 |       async fn baz(&self) -> impl Debug {
   |  _______________________________________^
11 | |         ""
12 | |     }
   | |_____^
```

But I guess this is a little bit of progress anyway.

This one goes on top of rust-lang#108700 and rust-lang#108945
r? `@compiler-errors`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants