Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
49044d0
Add support for trait associated items
GuillaumeGomez Jan 20, 2025
f1649a4
Better handling of paths in link to def feature
GuillaumeGomez Jan 26, 2025
1a6d636
Update to last rustc_hir Visitor changes
GuillaumeGomez Jan 26, 2025
d528a49
Fix panic if an item does not have a body
GuillaumeGomez May 4, 2025
25e767b
Ignore impl associated types in jump to def feature
GuillaumeGomez Aug 10, 2025
15f6d2e
rustdoc: Move HTML-specific attr rendering code into HTML rendering mod
fmease Sep 13, 2025
e9b2c4f
avoid violating `slice::from_raw_parts` safety contract in `Vec::extr…
petrosagg May 15, 2025
739e899
Add proper name mangling for pattern types
oli-obk Jun 11, 2025
58c7505
Make `render_example_with_highlighting` return an `impl fmt::Display`
yotamofek Sep 22, 2025
aaff372
Remove `Tooltip::None` variant, use `Option::None`
yotamofek Sep 22, 2025
e697f20
Remove unused param from `write_header`
yotamofek Sep 22, 2025
5673449
feature: Implement vec_try_remove
BenjaminBrienen Sep 24, 2025
137d4ea
BTreeMap: Don't leak allocators when initializing nodes
cammeresi Sep 20, 2025
88e7977
rustdoc: Slightly clean up attr rendering
fmease Sep 13, 2025
d7d7725
rustdoc: Fully escape link section and export name
fmease Sep 13, 2025
85c193a
rustdoc: hide `#[repr(...)]` if it isn't part of the public ABI
fmease May 17, 2025
185ae69
add doc for `NonZero*` const creation
cptpiepmatz Sep 25, 2025
a39d513
Rollup merge of #116882 - fmease:rustdoc-generalized-priv-repr-heuris…
matthiaskrgr Sep 25, 2025
a028b7a
Rollup merge of #135771 - GuillaumeGomez:jump-to-def-perf, r=fmease
matthiaskrgr Sep 25, 2025
e3f7626
Rollup merge of #141032 - petrosagg:extract-if-ub, r=joboet
matthiaskrgr Sep 25, 2025
958d143
Rollup merge of #142401 - oli-obk:pattern-mango, r=petrochenkov
matthiaskrgr Sep 25, 2025
fea9196
Rollup merge of #146293 - BenjaminBrienen:try_remove, r=joboet
matthiaskrgr Sep 25, 2025
83cf8f9
Rollup merge of #146859 - cammeresi:btree-alloc-20250920, r=joboet
matthiaskrgr Sep 25, 2025
781f71a
Rollup merge of #146924 - cptpiepmatz:doc-nonzero-const-creation, r=j…
matthiaskrgr Sep 25, 2025
c6d0059
Rollup merge of #146933 - yotamofek:pr/rustdoc/highlight_no_write_str…
matthiaskrgr Sep 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add proper name mangling for pattern types
  • Loading branch information
oli-obk committed Sep 23, 2025
commit 739e89980f2c5602851c9271fd61f7381007e87a
14 changes: 6 additions & 8 deletions compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,16 @@ impl<'tcx> V0SymbolMangler<'tcx> {
fn print_pat(&mut self, pat: ty::Pattern<'tcx>) -> Result<(), std::fmt::Error> {
Ok(match *pat {
ty::PatternKind::Range { start, end } => {
let consts = [start, end];
for ct in consts {
Ty::new_array_with_const_len(self.tcx, self.tcx.types.unit, ct).print(self)?;
}
self.push("R");
self.print_const(start)?;
self.print_const(end)?;
}
ty::PatternKind::Or(patterns) => {
self.push("O");
for pat in patterns {
self.print_pat(pat)?;
}
self.push("E");
}
})
}
Expand Down Expand Up @@ -498,12 +499,9 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> {
}

ty::Pat(ty, pat) => {
// HACK: Represent as tuple until we have something better.
// HACK: constants are used in arrays, even if the types don't match.
self.push("T");
self.push("W");
ty.print(self)?;
self.print_pat(pat)?;
self.push("E");
}

ty::Array(ty, len) => {
Expand Down
28 changes: 28 additions & 0 deletions src/doc/rustc/src/symbol-mangling/v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ A *placeholder* may occur in circumstances where a type or const value is not re
[mut-ptr-type]: #mut-ptr-type
[fn-type]: #fn-type
[dyn-trait-type]: #dyn-trait-type
[pattern-type]: #pattern-type

> type → \
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *[basic-type]* \
Expand All @@ -722,6 +723,7 @@ A *placeholder* may occur in circumstances where a type or const value is not re
> &nbsp;&nbsp; | *[mut-ptr-type]* \
> &nbsp;&nbsp; | *[fn-type]* \
> &nbsp;&nbsp; | *[dyn-trait-type]* \
> &nbsp;&nbsp; | *[pattern-type]* \
> &nbsp;&nbsp; | *[path]* \
> &nbsp;&nbsp; | *[backref]*

Expand Down Expand Up @@ -830,6 +832,23 @@ Remaining primitives are encoded as a crate production, e.g. `C4f128`.
[fn-sig]: #fn-sig
[abi]: #abi

* `W` — A [pattern-type][pattern-tpye] `u32 is 0..100`.
> <span id="pattern-type">pattern-type</span> → `W` *[pattern-kind]*
>
> <span id="pattern-kind">pattern-kind</span> → \
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *[range-pattern-kind]* \
> &nbsp;&nbsp; *[or-pattern-kind]*
>
> <span id="range-pattern-kind">range-pattern-kind</span> → `R` *[const]* *[const]*
>
> <span id="or-pattern-kind">or-pattern-kind</span> → `O` *[pattern-kind]* `E`

While or patterns can be nested in theory, in practice this does not happen and they are instead flattened.

Range patterns have a start and end constant that are both included in the range.
The end must be larger than the start (there can be no wraparound). To emulate wraparound,
you need to use an or pattern of the two ranges to the upper limit and from the lower limit.

* `D` — A [trait object][reference-trait-object] `dyn Trait<Assoc=X> + Send + 'a`.

> <span id="dyn-trait-type">dyn-trait-type</span> → `D` *[dyn-bounds]* *[lifetime]*
Expand Down Expand Up @@ -1139,6 +1158,7 @@ The following is a summary of all of the productions of the symbol grammar.
> &nbsp;&nbsp; | *[mut-ptr-type]* \
> &nbsp;&nbsp; | *[fn-type]* \
> &nbsp;&nbsp; | *[dyn-trait-type]* \
> &nbsp;&nbsp; | *[pattern-type]* \
> &nbsp;&nbsp; | *[path]* \
> &nbsp;&nbsp; | *[backref]*
>
Expand All @@ -1152,6 +1172,14 @@ The following is a summary of all of the productions of the symbol grammar.
> [mut-ptr-type] → `O` *[type]* \
> [fn-type] → `F` *[fn-sig]* \
> [dyn-trait-type] → `D` *[dyn-bounds]* *[lifetime]*
> [pattern-type] → `W` *[pattern-kind]*
>
> [pattern-kind] → \
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *[range-pattern-kind]* \
> &nbsp;&nbsp; *[or-pattern-kind]*
>
> [range-pattern-kind] -> `R` *[const]* *[const]* \
> [or-pattern-kind] -> `O` *[pattern-kind]* `E` \
>
> [namespace] → *[lower]* | *[upper]*
>
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen-llvm/pattern_type_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn bar() {
// CHECK: call pattern_type_symbols::foo::<u32>
// CHECK: call void @_RINvC[[CRATE_IDENT:[a-zA-Z0-9]{12}]]_20pattern_type_symbols3foomEB2_
foo::<u32>();
// CHECK: call pattern_type_symbols::foo::<(u32, [(); 0], [(); 999999999])>
// CHECK: call void @_RINvC[[CRATE_IDENT]]_20pattern_type_symbols3fooTmAum0_Aum3b9ac9ff_EEB2_
// CHECK: call pattern_type_symbols::foo::<u32 is 0..=999999999>
// CHECK: call void @_RINvC[[CRATE_IDENT]]_20pattern_type_symbols3fooWmRm0_m3b9ac9ff_EB2_
foo::<NanoU32>();
}
Loading