Skip to content

Commit fdd2523

Browse files
committed
Use underlying symbol whenever we string-ify DefPathData
Converting an `Ident` to a string will cause us to try to guess if the identifier is 'raw', potentially inserting a 'r#' prefix. However, all of the existing code that string-ifys `DefPathData` is expecting to be working with a `Symbol`, which never has a `r#` suffix. This was causing Rustdoc to generate links containing `r#` for structs/traits with raw identifiers (e.g. `r#struct`), leading to broken links when the actual html files were generated without the `r#` suffix.
1 parent 5e98189 commit fdd2523

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

src/librustc/hir/map/definitions.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl DefPath {
211211
let mut s = String::with_capacity(self.data.len() * 16);
212212

213213
for component in &self.data {
214-
write!(s, "::{}[{}]", component.data.as_ident(), component.disambiguator).unwrap();
214+
write!(s, "::{}[{}]", component.data.as_ident().name, component.disambiguator).unwrap();
215215
}
216216

217217
s
@@ -230,9 +230,10 @@ impl DefPath {
230230

231231
for component in &self.data {
232232
if component.disambiguator == 0 {
233-
write!(s, "::{}", component.data.as_ident()).unwrap();
233+
write!(s, "::{}", component.data.as_ident().name).unwrap();
234234
} else {
235-
write!(s, "{}[{}]", component.data.as_ident(), component.disambiguator).unwrap();
235+
write!(s, "{}[{}]", component.data.as_ident().name, component.disambiguator)
236+
.unwrap();
236237
}
237238
}
238239

@@ -250,9 +251,10 @@ impl DefPath {
250251
opt_delimiter.map(|d| s.push(d));
251252
opt_delimiter = Some('-');
252253
if component.disambiguator == 0 {
253-
write!(s, "{}", component.data.as_ident()).unwrap();
254+
write!(s, "{}", component.data.as_ident().name).unwrap();
254255
} else {
255-
write!(s, "{}[{}]", component.data.as_ident(), component.disambiguator).unwrap();
256+
write!(s, "{}[{}]", component.data.as_ident().name, component.disambiguator)
257+
.unwrap();
256258
}
257259
}
258260
s
@@ -568,6 +570,6 @@ impl DefPathData {
568570
}
569571

570572
pub fn to_string(&self) -> String {
571-
self.as_ident().to_string()
573+
self.as_ident().name.to_string()
572574
}
573575
}

src/librustc/ty/print/obsolete.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ impl DefPathBasedNames<'tcx> {
186186
// foo::bar::ItemName::
187187
for part in self.tcx.def_path(def_id).data {
188188
if self.omit_disambiguators {
189-
write!(output, "{}::", part.data.as_ident()).unwrap();
189+
write!(output, "{}::", part.data.as_ident().name).unwrap();
190190
} else {
191-
write!(output, "{}[{}]::", part.data.as_ident(), part.disambiguator).unwrap();
191+
write!(output, "{}[{}]::", part.data.as_ident().name, part.disambiguator).unwrap();
192192
}
193193
}
194194

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub mod r#try {
2+
// @has raw_idents/try/struct.struct.html
3+
pub struct r#struct;
4+
5+
pub trait r#trait {}
6+
}

src/test/rustdoc/raw_idents.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// aux-build:raw-foreign.rs
2+
// build-aux-docs
3+
4+
extern crate raw_foreign;
5+
6+
// has 'raw_idents/trait.MyTrait.html' '//a[@href="../raw_foreign/try/trait.trait.html"]' 'trait'
7+
// has 'raw_idents/trait.MyTrait.html' '//a[@href="../raw_foreign/try/struct.struct.html"]' 'struct'
8+
pub trait MyTrait {
9+
fn foo<T>() where T: raw_foreign::r#try::r#trait {}
10+
}
11+
12+
impl MyTrait for raw_foreign::r#try::r#struct {
13+
fn foo<T>() where T: raw_foreign::r#try::r#trait {}
14+
}

0 commit comments

Comments
 (0)