I think there’s an episode of Star Trek TNG where Geordie creates a bot that he believes might be sentient. If it’s sentient, it has rights. But (of course) they need the bot to go on a mission that would require it to give it’s “life” to save the ship and crew.
I wish I could recall how the episode ends. Although I’m sure Picard found a way to save the sentient bot and the enterprise.