You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ rustc -
<anon>:2:13: 2:28 error: ambiguous associated type; specify the type using the syntax `<f32 as Trait>::consts` [E0223]
<anon>:2 let i = f32::consts::PI;
^~~~~~~~~~~~~~~
error: aborting due to previous error
on rust 1.0 stable and 1.1 stable
using the full path std::f32::consts::PI; works. The compilation error looks wrong (why is f32 an associated type)?
Yes, I probably haven't made myself very clear in the description above.
I've noted that fully specifying the path works, but I still think "ambiguous associated type" referring to f32 is a confusing error message (I can't blame the person asking the SO question for interpreting it as "f32 is an associated type and defined in two or more traits" none of which is true).
That's true. The message should read something like "no associated type consts found" (at least this seems to be the case here). It would also help if rustc would output a list of implemented Traits that have the ambiguous associated type whenever this happens.
error[E0223]: ambiguous associated type
--> <anon>:2:17
|
2 | let _ = f32::consts::PI;
| ^^^^^^^^^^^^^^^ ambiguous associated type
|
= note: specify the type using the syntax `<f32 as Trait>::consts`
The consts in the number type modules should probably be moved to associated constants. I believe we're mostly on board with this, but there's not currently an issue to my knowledge.
I ran into this today. I was reading the docs for f32 and all the examples use f32::consts::PI, so color me surprised when attempting to use that results in an associated type error (???).
Of course, the examples also use std::f32; at the top, but that's a pretty dang non-local effect and not something you are looking for right away, and of course the error doesn't point you in anywhere near that direction.
It would probably be best if there were not two different things named f32 here, but I suppose that ship has sailed.
At a minimum, the ambiguous associated type, specify the type using the syntax <f32 as Trait>::consts error message is totally bogus and should be improved
Activity
jonas-schievink commentedon Jul 3, 2015
You're using the type
f32, not the module, so rustc tries to resolveconstsas an associated type. If you put ause std::f32somewhere, it works.pfalabella commentedon Jul 3, 2015
Yes, I probably haven't made myself very clear in the description above.
I've noted that fully specifying the path works, but I still think "ambiguous associated type" referring to f32 is a confusing error message (I can't blame the person asking the SO question for interpreting it as "f32 is an associated type and defined in two or more traits" none of which is true).
jonas-schievink commentedon Jul 3, 2015
That's true. The message should read something like "no associated type
constsfound" (at least this seems to be the case here). It would also help if rustc would output a list of implemented Traits that have the ambiguous associated type whenever this happens.bluss commentedon Jul 3, 2015
Rustc is underlining all of
f32::consts::PI, and it should call it an associated item, not just type.steveklabnik commentedon Nov 29, 2016
Triage, with the new errors:
ouch 😦
Mark-Simulacrum commentedon Jun 1, 2017
The consts in the number type modules should probably be moved to associated constants. I believe we're mostly on board with this, but there's not currently an issue to my knowledge.
abique commentedon Dec 25, 2017
I'm running into this error, this is quite ridiculous to have so much troubles just to use PI.
agrif commentedon Sep 14, 2018
I ran into this today. I was reading the docs for
f32and all the examples usef32::consts::PI, so color me surprised when attempting to use that results in an associated type error (???).Of course, the examples also
use std::f32;at the top, but that's a pretty dang non-local effect and not something you are looking for right away, and of course the error doesn't point you in anywhere near that direction.It would probably be best if there were not two different things named
f32here, but I suppose that ship has sailed.eminence commentedon Sep 14, 2018
At a minimum, the
ambiguous associated type, specify the type using the syntax <f32 as Trait>::constserror message is totally bogus and should be improvedRollup merge of rust-lang#60045 - estebank:suggest-std, r=petrochenkov
Rollup merge of rust-lang#60045 - estebank:suggest-std, r=petrochenkov
Rollup merge of rust-lang#60045 - estebank:suggest-std, r=petrochenkov
AliAbdullah1999 commentedon Dec 9, 2019
can anyone guide me in this
AliAbdullah1999 commentedon Dec 9, 2019
105 | let v_02 = ::create_vehicle{
| ^ expected one of
.,::,;,?, or an operator here//i talked about this error above