I want the right margin of TOC to be straight. Instead of this Latex violates the bound (Pic. 1). If babel is commented out (with the last \addcontentsline), the result is still buggy (Pic. 2). Apparently, some of the words could be carried over to the next lines even without hyphenation.

Here is the minimal working example.

```
\documentclass{book}
\usepackage[russian]{babel}
\usepackage[titles]{tocloft}

\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\cftsetrmarg{4cm}

\begin{document}
  \tableofcontents

  \addcontentsline{toc}{chapter}{Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted  Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted }

  \addcontentsline{toc}{chapter}{Blossom blossom blossom blossom blossom blossom test test test blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom}

  \addcontentsline{toc}{chapter}{Bbbbbbb bbbbbbbbbb bbbbbbb bbbbbbbbbb bbbbbb}

  \addcontentsline{toc}{chapter}{Численные исследования разработанных алгоритмов}

\end{document}

```

![Pic. 1](https://i.stack.imgur.com/859RD.png)

**Picture 1 (above).**

![Pic. 2](https://i.stack.imgur.com/wh5lk.png)

**Picture 2 (above).**

**UPDATE.**

The proposed solutions partially solved the problem. The remaining problems are shown on the Picture 3. The corresponding code is:

```
\documentclass{book}
\usepackage[english]{babel}
\usepackage[titles]{tocloft}

% Compulsory settings
\textwidth=170mm
\cftsetrmarg{6.35cm}

% Adviced (but not working) options
\renewcommand{\cftchapleader}{\penalty5000 \cftdotfill{\cftdotsep}}
\emergencystretch=10em
\sloppy

\begin{document}
  \tableofcontents

  \addcontentsline{toc}{chapter}{This line just demonstrates the right bound. Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted  Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted }

  \addcontentsline{toc}{chapter}{Thisline demonstratesdemonstrates thewidthof posbbbbbbbbbbbbbbblegaps. Thisline demonstrates thewidthof possiblegaps.}

  \addcontentsline{toc}{chapter}{Parameter parmeter parameter parammmeter Fibre Channel}

\end{document}

```

![Pic. 3](https://i.stack.imgur.com/g219A.png)

**Picture 3 (above).**