I am forwarding feature request reported in the Debian BTS:
The rst-compile function assumes the current buffer is the "master"
source file for a reST document. When using the ..include::
directive, this is not necessarily the case.
In AuCTeX, a similar problem is solved by supporting a file-local
variable TeX-Master, which contains a string referring to the master
file. I suggest the rst-compile function be similar extended to use
the reST-master file-local variable (if set), falling back on the
current behaviour (if not set).
An advantageous side effect is that files with a generic .txt
extension (or no extension) could be made to automatically use
rst-mode instead of the generic text-mode with the following elisp
(adapted from scheme48):
(put 'reST-master 'safe-local-variable t)
(when (and (boundp 'reST-master) reST-master)