diff --git a/src/librustdoc/html/highlight/fixtures/decorations.html b/src/librustdoc/html/highlight/fixtures/decorations.html
new file mode 100644
index 000000000000..45f567880c9d
--- /dev/null
+++ b/src/librustdoc/html/highlight/fixtures/decorations.html
@@ -0,0 +1,2 @@
+let x = 1;
+let y = 2;
\ No newline at end of file
diff --git a/src/librustdoc/html/highlight/tests.rs b/src/librustdoc/html/highlight/tests.rs
index 3fa386dded9b..1fea7e983b44 100644
--- a/src/librustdoc/html/highlight/tests.rs
+++ b/src/librustdoc/html/highlight/tests.rs
@@ -1,6 +1,7 @@
-use super::write_code;
+use super::{write_code, DecorationInfo};
use crate::html::format::Buffer;
use expect_test::expect_file;
+use rustc_data_structures::fx::FxHashMap;
use rustc_span::create_default_session_globals_then;
use rustc_span::edition::Edition;
@@ -64,3 +65,17 @@ fn test_union_highlighting() {
expect_file!["fixtures/union.html"].assert_eq(&html.into_inner());
});
}
+
+#[test]
+fn test_decorations() {
+ create_default_session_globals_then(|| {
+ let src = "let x = 1;
+let y = 2;";
+ let mut decorations = FxHashMap::default();
+ decorations.insert("example", vec![(0, 10)]);
+
+ let mut html = Buffer::new();
+ write_code(&mut html, src, Edition::Edition2018, None, Some(DecorationInfo(decorations)));
+ expect_file!["fixtures/decorations.html"].assert_eq(&html.into_inner());
+ });
+}
diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs
index c75a42446200..776073db7f5a 100644
--- a/src/librustdoc/scrape_examples.rs
+++ b/src/librustdoc/scrape_examples.rs
@@ -149,9 +149,11 @@ where
}
};
- // We need to get the file the example originates in. If the call is contained
- // in a macro, then trace the span back to the macro source (rather than macro definition).
- let span = span.source_callsite();
+ // If this span comes from a macro expansion, then the source code may not actually show
+ // a use of the given item, so it would be a poor example. Hence, we skip all uses in macros.
+ if span.from_expansion() {
+ return;
+ }
// Save call site if the function resolves to a concrete definition
if let ty::FnDef(def_id, _) = ty.kind() {