Skip to content

Tuple issue #41081

Closed
Closed
@wind2412

Description

@wind2412

I defined a tuple: let tuple: ((u8, u32),(u8, u32)) = ((1, 45), (2, 100));
And I have a tool to look up its type:

#![feature(core_intrinsics)]

fn type_of<T>(_: T) {
	println!("{}", unsafe { std::intrinsics::type_name::<T>() });
}
//p.s. from stack overflow

So I can get the type of the tuple: type_of(tuple.0); and it turns out to be (u8, u32).Right.
According to convention, I can use tuple.0.0 to get the first u8 value. Because type_of(tuple.0) is (u8, u32). But when I use tuple.0, I get:

error: unexpected token: `0.0`
  --> test_tuple.rs:38:16
   |
38 | 	type_of(tuple.0.0);		
   | 	              ^^^
   |
help: try parenthesizing the first index
   | 	type_of(tuple.(tuple.0).0);	 

error[E0061]: this function takes 1 parameter but 0 parameters were supplied
  --> test_tuple.rs:38:2
   |
3  |   fn type_of<T>(_: T) {
   |  _- starting here...
4  | | 	println!("{}", unsafe { std::intrinsics::type_name::<T>() });
5  | | }
   | |_- ...ending here: defined here
...
38 |   	type_of(tuple.0.0);		
   |    ^^^^^^^^^^^^^^^^^^ expected 1 parameter

error: aborting due to previous error

A little weird of this wrong message... It tells us Rust recognized it as tuple.(0.0)...
And I do as the "help"'s advice, type_of(tuple.(tuple.0).3) and then get another wrong msg...

error: unexpected token: `(`
  --> test_tuple.rs:39:16
   |
39 | 	type_of(tuple.(tuple.0).3);		
   | 	              ^

error: aborting due to 2 previous errors

But I use (tuple.0).0 is okay...

If it's not made deliberately, hope you can fix this syntax instead of (tuple.0).0 and make the help message better~;)

Besides,

>rustc --version
rustc 1.18.0-nightly (2564711e8 2017-04-04)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions