diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py
index 93d7a3519..253849b92 100644
--- a/sphinx/builders/html.py
+++ b/sphinx/builders/html.py
@@ -968,7 +968,8 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
if 'includehidden' not in kwds:
kwds['includehidden'] = False
toctree = self.env.get_toctree_for(docname, self, collapse, **kwds)
- self.fix_refuris(toctree)
+ if toctree is not None:
+ self.fix_refuris(toctree)
return self.render_partial(toctree)['fragment']
def assemble_doctree(self):
diff --git a/tests/roots/test-toctree-empty/_templates/localtoc.html b/tests/roots/test-toctree-empty/_templates/localtoc.html
new file mode 100644
index 000000000..0fd913922
--- /dev/null
+++ b/tests/roots/test-toctree-empty/_templates/localtoc.html
@@ -0,0 +1,2 @@
+{# This will call toctree unconditionally, whether there is a local or global toc #}
+{{ toctree() }}
diff --git a/tests/roots/test-toctree-empty/conf.py b/tests/roots/test-toctree-empty/conf.py
new file mode 100644
index 000000000..dac85eb9a
--- /dev/null
+++ b/tests/roots/test-toctree-empty/conf.py
@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+
+master_doc = 'index'
+html_theme = 'classic'
+exclude_patterns = ['_build']
+templates_path = ['_templates']
diff --git a/tests/roots/test-toctree-empty/index.rst b/tests/roots/test-toctree-empty/index.rst
new file mode 100644
index 000000000..0b97a60fc
--- /dev/null
+++ b/tests/roots/test-toctree-empty/index.rst
@@ -0,0 +1,4 @@
+test-toctree-empty
+==================
+
+.. toctree::
diff --git a/tests/test_toctree.py b/tests/test_toctree.py
index 276ef7977..18910197f 100644
--- a/tests/test_toctree.py
+++ b/tests/test_toctree.py
@@ -26,3 +26,12 @@ def test_relations(app, status, warning):
assert app.builder.relations['qux/qux_1'] == ['qux/index', 'qux/index', 'qux/qux_2']
assert app.builder.relations['qux/qux_2'] == ['qux/index', 'qux/qux_1', None]
assert 'quux' not in app.builder.relations
+
+
+@pytest.mark.sphinx('singlehtml', testroot='toctree-empty')
+def test_singlehtml_toctree(app, status, warning):
+ app.builder.build_all()
+ try:
+ app.builder._get_local_toctree('index')
+ except AttributeError:
+ pytest.fail('Unexpected AttributeError in app.builder.fix_refuris')