Skip to content

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

@matthiaskrgr

Description

@matthiaskrgr
Member

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.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Dec 20, 2022
lcnr

lcnr commented on Dec 20, 2022

@lcnr
Contributor

without box_syntax

#![feature(half_open_range_patterns_in_slices)]
fn main() {
    let [_y..] = [Box::new(1), Box::new(2)];
}
added a commit that references this issue on Dec 20, 2022
matthiaskrgr

matthiaskrgr commented on Dec 20, 2022

@matthiaskrgr
MemberAuthor

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

lyming2007 commented on Dec 20, 2022

@lyming2007

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

compiler-errors commented on Dec 20, 2022

@compiler-errors
Member

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

lyming2007

lyming2007 commented on Dec 20, 2022

@lyming2007

@rustbot claim

estebank

estebank commented on Jan 2, 2023

@estebank
Contributor

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

lyming2007 commented on Jan 5, 2023

@lyming2007

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.

added a commit that references this issue on Jan 6, 2023
a8f7ec2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @lyming2007@matthiaskrgr@estebank@compiler-errors@lcnr

    Issue actions

      [type error] when wrongly destructing boxes of ints · Issue #105946 · rust-lang/rust