Filter orphan rules based on imports, fixes #10294 and #10420.