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

[type error] when wrongly destructing boxes of ints #105946

Closed
matthiaskrgr opened this issue Dec 20, 2022 · 7 comments · Fixed by #106499
Closed

[type error] when wrongly destructing boxes of ints #105946

matthiaskrgr opened this issue Dec 20, 2022 · 7 comments · Fixed by #106499
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Dec 20, 2022

Given the following code:

#![feature(box_syntax)]
#![feature(half_open_range_patterns_in_slices)]
fn main() {
    let [_y..] = [box 1, box 2];
}

The current output is:

error[E0425]: cannot find value `_y` in this scope
 --> 4a310255aac576a3d3d7ede99bff59ef38f2fb87.rs:4:10
  |
4 |     let [_y..] = [box 1, box 2];
  |          ^^ not found in this scope

error[E0527]: pattern requires 1 element but array has 2
 --> 4a310255aac576a3d3d7ede99bff59ef38f2fb87.rs:4:9
  |
4 |     let [_y..] = [box 1, box 2];
  |         ^^^^^^ expected 2 elements

error[E0029]: only `char` and numeric types are allowed in range patterns
 --> 4a310255aac576a3d3d7ede99bff59ef38f2fb87.rs:4:10
  |
4 |     let [_y..] = [box 1, box 2];
  |          ^^ this is of type `[type error]` but it should be `char` or numeric

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0029, E0425, E0527.
For more information about an error, try `rustc --explain E0029`.

We shouldn't show [type error] here.

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 20, 2022
@lcnr
Copy link
Contributor

lcnr commented Dec 20, 2022

without box_syntax

#![feature(half_open_range_patterns_in_slices)]
fn main() {
    let [_y..] = [Box::new(1), Box::new(2)];
}

theWhiteKn1ght added a commit to theWhiteKn1ght/rust that referenced this issue Dec 20, 2022
@matthiaskrgr
Copy link
Member Author

another one

fn digit() -> str {
	return {};
}
error[E0308]: mismatched types
 --> 0e1a330c6631176565a0f9d144ef565d69e68583.rs:2:9
  |
2 |     return {};
  |            ^^ expected `str`, found `()`

error[E0277]: the size for values of type `str` cannot be known at compilation time
 --> 0e1a330c6631176565a0f9d144ef565d69e68583.rs:1:15
  |
1 | fn digit() -> str {
  |               ^^^ doesn't have a size known at compile-time
2 |     return {};
  |            -- this returned value is of type `[type error]`
  |
  = help: the trait `Sized` is not implemented for `str`
  = note: the return type of a function must have a statically known size

@lyming2007
Copy link

What ideal output would you suggest? Should we remove the suggestion line like:

error[E0308]: mismatched types
 --> 0e1a330c6631176565a0f9d144ef565d69e68583.rs:2:9
  |
2 |     return {};
  |            ^^ expected `str`, found `()`

error[E0277]: the size for values of type `str` cannot be known at compilation time
 --> 0e1a330c6631176565a0f9d144ef565d69e68583.rs:1:15
  |
1 | fn digit() -> str {
  |               ^^^ doesn't have a size known at compile-time
2 |     return {};
  |
  = help: the trait `Sized` is not implemented for `str`
  = note: the return type of a function must have a statically known size

@compiler-errors
Copy link
Member

compiler-errors commented Dec 20, 2022

Ideally we should be checking that the return type is suggestable. If it's not suggestable, don't mention it.

@lyming2007
Copy link

@rustbot claim

@estebank
Copy link
Contributor

estebank commented Jan 2, 2023

I actually believe that neither the E0029 nor the E0277 should have been emitted. I would check explicitly for ty.references_error() and change the error to be err.delay_as_bug() (that way the error isn't printed out, but rustc will ICE if no other error is emitted, which should have happened).

@lyming2007
Copy link

I actually believe that neither the E0029 nor the E0277 should have been emitted. I would check explicitly for ty.references_error() and change the error to be err.delay_as_bug() (that way the error isn't printed out, but rustc will ICE if no other error is emitted, which should have happened).

The PR #106499 will prevent E0029 and E0277 from printing out after checking the type references.

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jan 6, 2023
…ebank

fix [type error] for error E0029 and E0277

check explicitly for the type references error
if ty.references_error() is true change the error to be err.delay_as_bug() and prevent the error E0029 and E0277 from emitting out this fix rust-lang#105946
@bors bors closed this as completed in 10dbcf0 Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants