diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb
index e088303801..106810072b 100644
--- a/lib/rdoc/markup/to_html_crossref.rb
+++ b/lib/rdoc/markup/to_html_crossref.rb
@@ -159,6 +159,12 @@ def link(name, text, code = true, rdoc_ref: false)
ref = @cross_reference.resolve name, text if name
+ # Non-text source files (C, Ruby, etc.) don't get HTML pages generated,
+ # so don't auto-link to them. Explicit rdoc-ref: links are still allowed.
+ if !rdoc_ref && RDoc::TopLevel === ref && !ref.text?
+ return text
+ end
+
case ref
when String then
if rdoc_ref && @warn_missing_rdoc_ref
diff --git a/test/rdoc/markup/to_html_crossref_test.rb b/test/rdoc/markup/to_html_crossref_test.rb
index 802acb7063..ff243fc9e0 100644
--- a/test/rdoc/markup/to_html_crossref_test.rb
+++ b/test/rdoc/markup/to_html_crossref_test.rb
@@ -387,6 +387,25 @@ def test_to_html_CROSSREF_email_hyperlink_all
assert_equal 'first.last@example.com', result
end
+ def test_convert_CROSSREF_c_file_not_autolinked
+ # C files are not text files, so they don't get HTML pages generated.
+ # Auto cross-references to them should not produce links.
+ c_file = @store.add_file 'array.c'
+ c_file.parser = RDoc::Parser::C
+
+ result = @to.convert 'array.c'
+ assert_equal para("array.c"), result
+ end
+
+ def test_convert_RDOCLINK_rdoc_ref_c_file_linked
+ # Explicit rdoc-ref: links to non-text files should still work.
+ c_file = @store.add_file 'array.c'
+ c_file.parser = RDoc::Parser::C
+
+ result = @to.convert 'rdoc-ref:array.c'
+ assert_equal para("array.c"), result
+ end
+
def test_link
assert_equal 'n', @to.link('n', 'n')