Elon Musk is unveiling the Tesla Model 3 today. If you're planning to buy one, you’re probably feeling pretty good about yourself. Not only will you have a sweet ride, but you’ll be doing something good for the environment! No gasoline-powered sports cars to get you through your midlife crisis, thank you very much. You care about global warming.

But how green is a Tesla, really? Devonshire Research Group, an investment firm that specializes in valuing tech companies, dug into the data and concluded that Tesla's environmental benefits may be more hyped than warranted. Devonshire isn’t saying that Tesla is pulling a Volkswagen, or that its cars are spewing greenhouse gases from invisible tailpipes. It’s arguing that Teslas (and, by extension, all electric vehicles) create pollution and carbon emissions in other ways. Each stage of an EV's life has environmental impacts, and while they aren't as obvious as a tailpipe pumping out fumes, that doesn't make them any less damaging.

Let's start with the basics. Your electric car doesn’t need gas, but it still might get its energy from burning carbon. It depends on how your local grid generates electricity. “If you use coal-fired power plants to produce the electricity, then all-electrics don’t even look that much better than a traditional vehicle in terms of greenhouse gases,” says Virginia McConnell, an economist at the environmental research firm Resources for the Future. But if your local grid incorporates a fair amount of renewable solar and wind energy, like California, your electric vehicle is pretty clean.

Of course, gasoline doesn't exist in a vacuum, either: Refining, processing, and transporting gas add emissions that car owners must factor into their overall carbon footprint, the so-called "well-to-wheel" tally. It takes as much energy to produce a gallon of gasoline as a Model S consumes in 20 miles of driving, according to Department of Energy data. When you add all those extra expenditures up, "an electric car like the Model S has almost four times lower CO 2 per mile than an equivalent gas-powered car,” says a Tesla spokesperson. So while the emissions argument is tantalizing for gas guzzlers, the average numbers still come out in favor of electric vehicles.

Beyond Emissions

The math gets trickier, though, when you include other forms of environmental damage. Electric cars need to be light, which means they include a lot of high-performing metals. The lithium in the batteries, for example, is super light and conductive—that’s how you get a lot of energy without adding a lot of weight. Other, rare metals are sprinkled throughout the car, mostly in the magnets that are in everything from the headlights to the on-board electronics.

But those rare metals come from somewhere—often, from environmentally destructive mines. It’s not just Tesla, of course. All electric vehicles rely on parts with similar environmental issues. Even solar panels depend on rare metals that have to be dug out of the earth and processed in less-than-green ways, says David Abraham, author of the book The Elements of Power. (Disclosure: I helped edit some chapters of the book.)

We can’t look at mining as an over-there thing and at Tesla as an over-here thing. They’re intricately linked. David Abraham

Rare metals only exist in tiny quantities and inconvenient places—so you have to move a lot of earth to get just a little bit. In the Jiangxi rare earth mine in China, Abraham writes, workers dig eight-foot holes and pour ammonium sulfate into them to dissolve the sandy clay. Then they haul out bags of muck and pass it through several acid baths; what’s left is baked in a kiln, leaving behind the rare earths required by everything from our phones to our Teslas.

At this mine, those rare earths amounted to 0.2 percent of what gets pulled out of the ground. The other 99.8 percent—now contaminated with toxic chemicals—is dumped back into the environment. That damage is difficult to quantify, just like the impact of oil drilling.

And, as in every stage of the process, mining has hidden emissions. Jiangxi has it relatively easy because it’s digging up clay, but many mines rely on rock-crushing equipment with astronomical energy bills, as well as coal-fired furnaces for the final baking stages. Those spew a lot of carbon dioxide in the atmosphere in the process of refining a material destined for your zero-emissions car. In fact, manufacturing an electric vehicle generates more carbon emissions than building a conventional car, mostly because of its battery, the Union of Concerned Scientists has found.

“We’re shifting pollution, and in the process we’re hoping that it doesn’t have the environmental impact,” says Abraham. He believes that when you add all the environmental impacts, they still come out in favor of electric vehicles. (The Union of Concerned Scientists agrees; it found that even when you add in emissions from battery manufacturing, EVs generate half the emissions of a conventional car over the course of its life.) Still, consumers and investors should understand what it takes to make the materials that enable their green choices. “I don’t think there’s been much discussion of that,” Abraham says. “We can’t look at mining as an over-there thing and at Tesla as an over-here thing. They’re intricately linked.”

Overall, “the greenhouse-gas-emissions footprint of electric vehicles can be pretty high on the front end, as they’re being built,” says McConnell. “And so you need to get a lot of benefits on the other side, when you use it.” And after you're done using it.

Life After Death

Now let’s fast-forward 15 years, to when your Tesla Model 3 is on its last legs. Where is the battery going to go? The good news is: not to a landfill. “It has not been accepted for a battery that comes out of a car to go to a landfill for decades,” says electric car advocate Chelsea Sexton. Instead, “battery recyclers are piloting technologies to recover a lot of materials from those batteries,” says Shanika Amarakoon, a researcher at the firm Abt Associates who partnered with the Environmental Protection Agency to write a report on the impacts of lithium-ion batteries in electric cars.

A Tesla battery is big—the pack in the Model S tops half a ton, far bigger than anything most e-recycling outfits take—so coming up with an efficient and cost-effective recycling process will take some work, and only a few companies specialize in recycling lithium batteries right now. “The challenge that we have with recycling these rare metals is enormous,” Abraham says, “because the products that we have now use metals in such a small quantity that it’s not economic to recycle.”

But that could change when there are million of electric vehicles on US roads and millions of old batteries to recycle. “The more batteries that are out there, in various devices, the more interest there is in figuring out how to recycle them or to recapture rare earth metals [from them],” Sexton says. Plus, used electric car batteries can still be useful for energy storage, whether in a single building or as part of grids that incorporate more solar and wind. That can help offset the environmental costs of making the batteries in the first place.

According to Tesla's spokesperson, the company already recycles all battery packs returned to it and plans to do more. As the battery market grows—driven by investments like Tesla’s upcoming Gigafactory—its greater numbers will drive up recycling efficiencies and reduce impact on the environment.

You can’t judge Tesla, or any other electric car, in a vacuum. You must compare it to the status quo.

OK, so an electric vehicle contributes a fair bit of pollution and greenhouse gases to the world. But you know what else does? A gasoline-powered car. Even though they don’t have batteries, conventional automobiles can contain plenty of the same problematic rare metals that electric cars do. (Remember those magnets?) You can’t judge Tesla, or any other electric car, in a vacuum. You must compare it to the status quo. And that status quo has many of the same problems—plus the carbon emissions and air pollution generated by traditional gas guzzlers.

“We need to invest in the science of understanding the impacts of the products that we’re making,” Abraham says. Still, that doesn’t mean we should stop making those products—or that you shouldn’t buy one. “The hope is that if you’re getting people to buy a lot of electric vehicles, you’re going to push on the technology too,” McConnell says. “You don’t get that unless you have some market interest in it.” The Tesla Model 3 you’re dreaming of isn’t perfect. But it may still push our society and economy in the right direction.

UPDATE 16:28 ET 3/31/16: This story has been changed to update attribution of Tesla's statements.