Skip to content

Commit 20533a4

Browse files
committed
Auto merge of #57967 - eddyb:rmangle, r=<try>
Introduce Rust symbol mangling scheme. This is an implementation of a "feature-complete" Rust mangling scheme, in the vein of rust-lang/rfcs#2603 - but with some differences, see rust-lang/rfcs#2603 (comment) for details. The demangling implementation PR is rust-lang/rustc-demangle#23 (this PR already uses it via a git dependency, to allow testing). Discussion of the *design* of the mangling scheme should still happen on the RFC, but this PR's specific implementation details can be reviewed in parallel. <hr/> *Notes for reviewers*: * only the last 4 commits are specific to this branch, if necessary I can open a separate PR for everything else (it was meant to be its own small refactoring, but it got a bit out of hand) * the "TEMPORARY" commit is only there because it does some extra validation (comparing the demangling from `rustc-demangle` to the compiler's pretty-printing, adjusted slightly to produce the same output), that I would like to try on crater * there is the question of whether we should turn on the new mangling now, wait for tools to support it (I'm working on that), and/or have it under a `-Z` flag for now r? @nikomatsakis / @michaelwoerister cc @rust-lang/compiler
2 parents 5f60208 + bfb78ea commit 20533a4

File tree

144 files changed

+4941
-2772
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+4941
-2772
lines changed

Cargo.lock

+33-3
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,11 @@ dependencies = [
18771877
"getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
18781878
]
18791879

1880+
[[package]]
1881+
name = "punycode"
1882+
version = "0.4.0"
1883+
source = "registry+https://github.com/rust-lang/crates.io-index"
1884+
18801885
[[package]]
18811886
name = "quick-error"
18821887
version = "1.2.2"
@@ -2361,6 +2366,11 @@ dependencies = [
23612366
name = "rustc-demangle"
23622367
version = "0.1.10"
23632368
source = "registry+https://github.com/rust-lang/crates.io-index"
2369+
2370+
[[package]]
2371+
name = "rustc-demangle"
2372+
version = "0.1.13"
2373+
source = "git+https://github.com/eddyb/rustc-demangle?rev=20d5bcc9bcea0d9413540916dd5f9fdadc7012f7#20d5bcc9bcea0d9413540916dd5f9fdadc7012f7"
23642374
dependencies = [
23652375
"compiler_builtins 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
23662376
"rustc-std-workspace-core 1.0.0",
@@ -2487,7 +2497,7 @@ dependencies = [
24872497
"cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
24882498
"memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
24892499
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
2490-
"rustc-demangle 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
2500+
"rustc-demangle 0.1.13 (git+https://github.com/eddyb/rustc-demangle?rev=20d5bcc9bcea0d9413540916dd5f9fdadc7012f7)",
24912501
"rustc_llvm 0.0.0",
24922502
]
24932503

@@ -2503,7 +2513,7 @@ dependencies = [
25032513
"memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
25042514
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
25052515
"rustc 0.0.0",
2506-
"rustc-demangle 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
2516+
"rustc-demangle 0.1.13 (git+https://github.com/eddyb/rustc-demangle?rev=20d5bcc9bcea0d9413540916dd5f9fdadc7012f7)",
25072517
"rustc_allocator 0.0.0",
25082518
"rustc_apfloat 0.0.0",
25092519
"rustc_codegen_utils 0.0.0",
@@ -2524,12 +2534,15 @@ version = "0.0.0"
25242534
dependencies = [
25252535
"flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
25262536
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
2537+
"punycode 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
25272538
"rustc 0.0.0",
2539+
"rustc-demangle 0.1.13 (git+https://github.com/eddyb/rustc-demangle?rev=20d5bcc9bcea0d9413540916dd5f9fdadc7012f7)",
25282540
"rustc_data_structures 0.0.0",
25292541
"rustc_incremental 0.0.0",
25302542
"rustc_metadata 0.0.0",
25312543
"rustc_mir 0.0.0",
25322544
"rustc_target 0.0.0",
2545+
"std-mangle-rs 0.1.0 (git+https://github.com/michaelwoerister/std-mangle-rs?rev=2336dcdfcc91db3cdda18eda73aca488773ac6fc)",
25332546
"syntax 0.0.0",
25342547
"syntax_pos 0.0.0",
25352548
]
@@ -3081,14 +3094,22 @@ dependencies = [
30813094
"panic_unwind 0.0.0",
30823095
"profiler_builtins 0.0.0",
30833096
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
3084-
"rustc-demangle 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
3097+
"rustc-demangle 0.1.13 (git+https://github.com/eddyb/rustc-demangle?rev=20d5bcc9bcea0d9413540916dd5f9fdadc7012f7)",
30853098
"rustc_asan 0.0.0",
30863099
"rustc_lsan 0.0.0",
30873100
"rustc_msan 0.0.0",
30883101
"rustc_tsan 0.0.0",
30893102
"unwind 0.0.0",
30903103
]
30913104

3105+
[[package]]
3106+
name = "std-mangle-rs"
3107+
version = "0.1.0"
3108+
source = "git+https://github.com/michaelwoerister/std-mangle-rs?rev=2336dcdfcc91db3cdda18eda73aca488773ac6fc#2336dcdfcc91db3cdda18eda73aca488773ac6fc"
3109+
dependencies = [
3110+
"unic-idna-punycode 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
3111+
]
3112+
30923113
[[package]]
30933114
name = "string_cache"
30943115
version = "0.7.3"
@@ -3548,6 +3569,11 @@ name = "ucd-util"
35483569
version = "0.1.3"
35493570
source = "registry+https://github.com/rust-lang/crates.io-index"
35503571

3572+
[[package]]
3573+
name = "unic-idna-punycode"
3574+
version = "0.7.0"
3575+
source = "registry+https://github.com/rust-lang/crates.io-index"
3576+
35513577
[[package]]
35523578
name = "unicode-bidi"
35533579
version = "0.3.4"
@@ -3939,6 +3965,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
39393965
"checksum proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)" = "926d0604475349f463fe44130aae73f2294b5309ab2ca0310b998bd334ef191f"
39403966
"checksum pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d6fdf85cda6cadfae5428a54661d431330b312bc767ddbc57adbedc24da66e32"
39413967
"checksum pulldown-cmark 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eef52fac62d0ea7b9b4dc7da092aa64ea7ec3d90af6679422d3d7e0e14b6ee15"
3968+
"checksum punycode 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6ddd112cca70a4d30883b2d21568a1d376ff8be4758649f64f973c6845128ad3"
39423969
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
39433970
"checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45"
39443971
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
@@ -3980,6 +4007,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
39804007
"checksum rustc-ap-syntax 306.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1adc189e5e4500a4167b9afa04e67067f40d0039e0e05870c977bebb561f065a"
39814008
"checksum rustc-ap-syntax_pos 306.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4d42c430dbb0be4377bfe6aa5099074c63ac8796b24098562c2e2154aecc5652"
39824009
"checksum rustc-demangle 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "82ae957aa1b3055d8e086486723c0ccd3d7b8fa190ae8fa2e35543b6171c810e"
4010+
"checksum rustc-demangle 0.1.13 (git+https://github.com/eddyb/rustc-demangle?rev=20d5bcc9bcea0d9413540916dd5f9fdadc7012f7)" = "<none>"
39834011
"checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8"
39844012
"checksum rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c6d5a683c6ba4ed37959097e88d71c9e8e26659a3cb5be8b389078e7ad45306"
39854013
"checksum rustc-rayon-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40f06724db71e18d68b3b946fdf890ca8c921d9edccc1404fdfdb537b0d12649"
@@ -4007,6 +4035,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
40074035
"checksum smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b73ea3738b47563803ef814925e69be00799a8c07420be8b996f8e98fb2336db"
40084036
"checksum socket2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d11a52082057d87cb5caa31ad812f4504b97ab44732cd8359df2e9ff9f48e7"
40094037
"checksum stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ffbc596e092fe5f598b12ef46cc03754085ac2f4d8c739ad61c4ae266cc3b3fa"
4038+
"checksum std-mangle-rs 0.1.0 (git+https://github.com/michaelwoerister/std-mangle-rs?rev=2336dcdfcc91db3cdda18eda73aca488773ac6fc)" = "<none>"
40104039
"checksum string_cache 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25d70109977172b127fe834e5449e5ab1740b9ba49fa18a2020f509174f25423"
40114040
"checksum string_cache_codegen 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "35293b05cf1494e8ddd042a7df6756bf18d07f42d234f32e71dce8a7aabb0191"
40124041
"checksum string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc"
@@ -4044,6 +4073,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
40444073
"checksum toml-query 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6854664bfc6df0360c695480836ee90e2d0c965f06db291d10be9344792d43e8"
40454074
"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
40464075
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
4076+
"checksum unic-idna-punycode 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b0366615c248bc56ea5ceafe6f71a682f6591e653b1ce61814999302617b8c0"
40474077
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
40484078
"checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25"
40494079
"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1"

src/librustc/dep_graph/dep_node.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for DefId {
721721
}
722722

723723
fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
724-
tcx.item_path_str(*self)
724+
tcx.def_path_str(*self)
725725
}
726726
}
727727

@@ -733,7 +733,7 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for DefIndex {
733733
}
734734

735735
fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
736-
tcx.item_path_str(DefId::local(*self))
736+
tcx.def_path_str(DefId::local(*self))
737737
}
738738
}
739739

src/librustc/hir/def_id.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl DefId {
249249
if self.is_local() && self.index == CRATE_DEF_INDEX {
250250
format!("top-level module")
251251
} else {
252-
format!("module `{}`", tcx.item_path_str(*self))
252+
format!("module `{}`", tcx.def_path_str(*self))
253253
}
254254
}
255255
}

src/librustc/hir/map/definitions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -660,13 +660,13 @@ impl DefPathData {
660660
return name
661661
}
662662
// note that this does not show up in user printouts
663-
CrateRoot => "{{root}}",
663+
CrateRoot => "{{crate}}",
664664
Impl => "{{impl}}",
665-
Misc => "{{?}}",
665+
Misc => "{{misc}}",
666666
ClosureExpr => "{{closure}}",
667667
StructCtor => "{{constructor}}",
668668
AnonConst => "{{constant}}",
669-
ImplTrait => "{{impl-Trait}}",
669+
ImplTrait => "{{opaque}}",
670670
};
671671

672672
Symbol::intern(s).as_interned_str()

src/librustc/hir/map/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,8 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
11891189
// the user-friendly path, otherwise fall back to stringifying DefPath.
11901190
::ty::tls::with_opt(|tcx| {
11911191
if let Some(tcx) = tcx {
1192-
tcx.node_path_str(id)
1192+
let def_id = map.local_def_id(id);
1193+
tcx.def_path_str(def_id)
11931194
} else if let Some(path) = map.def_path_from_id(id) {
11941195
path.data.into_iter().map(|elem| {
11951196
elem.data.to_string()

src/librustc/infer/error_reporting/mod.rs

+114-15
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
224224
self.hir().span(node),
225225
),
226226
_ => (
227-
format!("the lifetime {} as defined on", fr.bound_region),
227+
format!("the lifetime {} as defined on", region),
228228
cm.def_span(self.hir().span(node)),
229229
),
230230
},
@@ -445,17 +445,109 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
445445
terr: &TypeError<'tcx>,
446446
sp: Span,
447447
) {
448+
use hir::def_id::CrateNum;
449+
use hir::map::DisambiguatedDefPathData;
450+
use ty::print::Printer;
451+
use ty::subst::Kind;
452+
453+
struct AbsolutePathPrinter<'a, 'gcx, 'tcx> {
454+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
455+
}
456+
457+
struct NonTrivialPath;
458+
459+
impl<'gcx, 'tcx> Printer<'gcx, 'tcx> for AbsolutePathPrinter<'_, 'gcx, 'tcx> {
460+
type Error = NonTrivialPath;
461+
462+
type Path = Vec<String>;
463+
type Region = !;
464+
type Type = !;
465+
type DynExistential = !;
466+
467+
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'gcx, 'tcx> {
468+
self.tcx
469+
}
470+
471+
fn print_region(
472+
self,
473+
_region: ty::Region<'_>,
474+
) -> Result<Self::Region, Self::Error> {
475+
Err(NonTrivialPath)
476+
}
477+
478+
fn print_type(
479+
self,
480+
_ty: Ty<'tcx>,
481+
) -> Result<Self::Type, Self::Error> {
482+
Err(NonTrivialPath)
483+
}
484+
485+
fn print_dyn_existential(
486+
self,
487+
_predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
488+
) -> Result<Self::DynExistential, Self::Error> {
489+
Err(NonTrivialPath)
490+
}
491+
492+
fn path_crate(
493+
self,
494+
cnum: CrateNum,
495+
) -> Result<Self::Path, Self::Error> {
496+
Ok(vec![self.tcx.original_crate_name(cnum).to_string()])
497+
}
498+
fn path_qualified(
499+
self,
500+
_self_ty: Ty<'tcx>,
501+
_trait_ref: Option<ty::TraitRef<'tcx>>,
502+
) -> Result<Self::Path, Self::Error> {
503+
Err(NonTrivialPath)
504+
}
505+
506+
fn path_append_impl(
507+
self,
508+
_print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
509+
_disambiguated_data: &DisambiguatedDefPathData,
510+
_self_ty: Ty<'tcx>,
511+
_trait_ref: Option<ty::TraitRef<'tcx>>,
512+
) -> Result<Self::Path, Self::Error> {
513+
Err(NonTrivialPath)
514+
}
515+
fn path_append(
516+
self,
517+
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
518+
disambiguated_data: &DisambiguatedDefPathData,
519+
) -> Result<Self::Path, Self::Error> {
520+
let mut path = print_prefix(self)?;
521+
path.push(disambiguated_data.data.as_interned_str().to_string());
522+
Ok(path)
523+
}
524+
fn path_generic_args(
525+
self,
526+
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
527+
_args: &[Kind<'tcx>],
528+
) -> Result<Self::Path, Self::Error> {
529+
print_prefix(self)
530+
}
531+
}
532+
448533
let report_path_match = |err: &mut DiagnosticBuilder<'_>, did1: DefId, did2: DefId| {
449534
// Only external crates, if either is from a local
450535
// module we could have false positives
451536
if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate {
452-
let exp_path = self.tcx.item_path_str(did1);
453-
let found_path = self.tcx.item_path_str(did2);
454-
let exp_abs_path = self.tcx.absolute_item_path_str(did1);
455-
let found_abs_path = self.tcx.absolute_item_path_str(did2);
537+
let abs_path = |def_id| {
538+
AbsolutePathPrinter { tcx: self.tcx }
539+
.print_def_path(def_id, &[])
540+
};
541+
456542
// We compare strings because DefPath can be different
457543
// for imported and non-imported crates
458-
if exp_path == found_path || exp_abs_path == found_abs_path {
544+
let same_path = || -> Result<_, NonTrivialPath> {
545+
Ok(
546+
self.tcx.def_path_str(did1) == self.tcx.def_path_str(did2) ||
547+
abs_path(did1)? == abs_path(did2)?
548+
)
549+
};
550+
if same_path().unwrap_or(false) {
459551
let crate_name = self.tcx.crate_name(did1.krate);
460552
err.span_note(
461553
sp,
@@ -650,7 +742,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
650742
return Some(());
651743
}
652744
if let &ty::Adt(def, _) = &ta.sty {
653-
let path_ = self.tcx.item_path_str(def.did.clone());
745+
let path_ = self.tcx.def_path_str(def.did.clone());
654746
if path_ == other_path {
655747
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);
656748
return Some(());
@@ -675,7 +767,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
675767
}
676768

677769
/// For generic types with parameters with defaults, remove the parameters corresponding to
678-
/// the defaults. This repeats a lot of the logic found in `PrintContext::parameterized`.
770+
/// the defaults. This repeats a lot of the logic found in `ty::print::pretty`.
679771
fn strip_generic_default_params(
680772
&self,
681773
def_id: DefId,
@@ -740,11 +832,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
740832
mutbl: hir::Mutability,
741833
s: &mut DiagnosticStyledString,
742834
) {
743-
let r = &r.to_string();
835+
let mut r = r.to_string();
836+
if r == "'_" {
837+
r.clear();
838+
} else {
839+
r.push(' ');
840+
}
744841
s.push_highlighted(format!(
745-
"&{}{}{}",
842+
"&{}{}",
746843
r,
747-
if r == "" { "" } else { " " },
748844
if mutbl == hir::MutMutable { "mut " } else { "" }
749845
));
750846
s.push_normal(ty.to_string());
@@ -755,8 +851,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
755851
let sub_no_defaults_1 = self.strip_generic_default_params(def1.did, sub1);
756852
let sub_no_defaults_2 = self.strip_generic_default_params(def2.did, sub2);
757853
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
758-
let path1 = self.tcx.item_path_str(def1.did.clone());
759-
let path2 = self.tcx.item_path_str(def2.did.clone());
854+
let path1 = self.tcx.def_path_str(def1.did.clone());
855+
let path2 = self.tcx.def_path_str(def2.did.clone());
760856
if def1.did == def2.did {
761857
// Easy case. Replace same types with `_` to shorten the output and highlight
762858
// the differing ones.
@@ -1011,7 +1107,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10111107
if exp_is_struct && &exp_found.expected == ret_ty.skip_binder() {
10121108
let message = format!(
10131109
"did you mean `{}(/* fields */)`?",
1014-
self.tcx.item_path_str(def_id)
1110+
self.tcx.def_path_str(def_id)
10151111
);
10161112
diag.span_label(span, message);
10171113
}
@@ -1423,7 +1519,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14231519
var_origin: RegionVariableOrigin,
14241520
) -> DiagnosticBuilder<'tcx> {
14251521
let br_string = |br: ty::BoundRegion| {
1426-
let mut s = br.to_string();
1522+
let mut s = match br {
1523+
ty::BrNamed(_, name) => name.to_string(),
1524+
_ => String::new(),
1525+
};
14271526
if !s.is_empty() {
14281527
s.push_str(" ");
14291528
}

0 commit comments

Comments
 (0)