Carding, that is police stopping of pedestrians on the street, and asking for identification and other information, is in the news again. (Note, if you are stopped I urge you always to be polite with police regardless of your legal rights. Unless you actually have something problematic on your person cooperate fully. If you have something problematic then politely say "I believe I do not have to answer any questions or show you what I have on me. I refuse to answer any questions or show you what I have on me. May I go now?" If they arrest you the police then have to justify their actions)
Toronto Police insist carding is lawful. And in a narrow sense they are quite correct.
In general, the police can ask you any questions they want but you do not have to talk to them, show them your identification or answer their questions. The police are in no better position legally than anyone else - I am entitled to ask people on the street questions and they are entitled to ignore me.
The problem is that when a uniformed police officer asks questions most people (reasonably) assume they must answer.
People's uncertainty about their right to not answer questions is made worse by the police making implicitly threatening remarks such as:
i. What are you trying to hide!
ii. What do you have in your pocket!
iii. Do I have to take you to the Police Station?!
If someone reasonably believes they have no choice but to answer questions and are not free to go then they are detained. And detention leads to a host of issues that probably render carding unlawful.
If, as a factual matter, police detain an individual as part of carding - something that is very possible - then constitutional issues arise. Random detention breaches constitutional rights. There are legal rights arising on detention. These constitutional breaches may be permissible but only if the police show, among other things, that such breaches are reasonable limits prescribed by law. Such is possible but not likely.
Of course most people who are carded have a brief police interaction and no charges are laid. They have no reason to raise the legality of the interaction. People who are charged (say with drug offences) have reason to argue the legality but seldom present as sympathetic.
As a result carding (legal or not) may not receive a full analysis by the court.