A man has been charged with selling drugs to Mac Miller before he died.
The rapper overdosed in September last year.
Prosecutors in Los Angeles say he thought he'd been sold a painkiller called oxycodone - but it had actually been laced with fentanyl, a powerful drug that is fifty times more potent than heroin.
Cameron James Pettit, who's 28 and from LA, has been arrested on suspicion of distributing a controlled substance.
Mac Miller, whose real name was Malcolm McCormick, was 26 when he died.
The coroner found fentanyl, cocaine and alcohol in his body and concluded he'd accidentally taken an overdose.
Prosecutors say their evidence against Cameron James Pettit includes messages he sent after the body was discovered.
He told a friend: "Most likely I will die in jail."
The news agency Reuters is reporting that Pettit has appeared for a brief hearing in court and is now being held in custody until the trial.
If he's found guilty he could spend 20 years behind bars.
Mac had always been open about his issues with substance abuse - and was arrested for drink driving in May 2018.
Addiction was a big theme on his final album, Swimming, which was nominated for a Grammy after his death.
He was also coming out of a high-profile relationship, and break up, with Ariana Grande.
They met in 2012 and performed together at the One Love Manchester concert in 2017.
In an interview with Vogue earlier this year she described him as "the best person ever" who "didn't deserve the demons he had".
"You have no idea how many times I warned him that that would happen and fought that fight, for how many years of our friendship, of our relationship", she added.
Throughout his career, Mac collaborated with the likes of Kendrick Lamar and Pharrell Williams.
He put out his first mixtape when he was 15 under the name EZ Mac, but it was his 2010 release KIDS that got him a record deal.
He also starred in an MTV reality series in 2013 which followed him and a group of friends after he moved to Los Angeles to pursue his career.
Snoop Dog, Wiz Khalifa, Shawn Mendes and Chance the Rapper all paid tribute to him after he died.