Skip to content

Commit 6a874c5

Browse files
committed
Do not print single ::<'_> for fn items.
1 parent 20ecbf5 commit 6a874c5

File tree

11 files changed

+24
-5
lines changed

11 files changed

+24
-5
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
135135

136136
fn path_generic_args(
137137
mut self,
138+
_: bool,
138139
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
139140
args: &[GenericArg<'tcx>],
140141
) -> Result<Self::Path, Self::Error> {

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
574574
}
575575
fn path_generic_args(
576576
self,
577+
_: bool,
577578
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
578579
_args: &[GenericArg<'tcx>],
579580
) -> Result<Self::Path, Self::Error> {

compiler/rustc_lint/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ impl<'tcx> LateContext<'tcx> {
12321232

12331233
fn path_generic_args(
12341234
self,
1235+
_: bool,
12351236
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
12361237
_args: &[GenericArg<'tcx>],
12371238
) -> Result<Self::Path, Self::Error> {

compiler/rustc_middle/src/ty/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ fn foo(&self) -> Self::T { String::new() }
985985

986986
fn format_generic_args(self, args: &[ty::GenericArg<'tcx>]) -> String {
987987
FmtPrinter::new(self, hir::def::Namespace::TypeNS)
988-
.path_generic_args(Ok, args)
988+
.path_generic_args(true, Ok, args)
989989
.expect("could not write to `String`.")
990990
.into_buffer()
991991
}

compiler/rustc_middle/src/ty/print/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::ty::{self, DefIdTree, Ty, TyCtxt};
33

44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_data_structures::sso::SsoHashSet;
6+
use rustc_hir::def::DefKind;
67
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
78
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
89

@@ -92,6 +93,7 @@ pub trait Printer<'tcx>: Sized {
9293

9394
fn path_generic_args(
9495
self,
96+
forbid_lifetime_elision: bool,
9597
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
9698
args: &[GenericArg<'tcx>],
9799
) -> Result<Self::Path, Self::Error>;
@@ -150,7 +152,12 @@ pub trait Printer<'tcx>: Sized {
150152
_ => {
151153
if !generics.params.is_empty() && substs.len() >= generics.count() {
152154
let args = generics.own_substs_no_defaults(self.tcx(), substs);
155+
let forbid_elision = !matches!(
156+
self.tcx().def_kind(def_id),
157+
DefKind::Fn | DefKind::AssocFn
158+
);
153159
return self.path_generic_args(
160+
forbid_elision,
154161
|cx| cx.print_def_path(def_id, parent_substs),
155162
args,
156163
);

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,12 +1845,18 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
18451845

18461846
fn path_generic_args(
18471847
mut self,
1848+
forbid_lifetime_elision: bool,
18481849
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
18491850
args: &[GenericArg<'tcx>],
18501851
) -> Result<Self::Path, Self::Error> {
18511852
self = print_prefix(self)?;
18521853

1853-
if args.first().is_some() {
1854+
let all_elided = args.iter().all(|arg| match arg.unpack() {
1855+
ty::GenericArgKind::Lifetime(lt) => !lt.has_name(),
1856+
_ => false,
1857+
});
1858+
1859+
if !args.is_empty() && (forbid_lifetime_elision || self.tcx.sess.verbose() || !all_elided) {
18541860
if self.in_value {
18551861
write!(self, "::")?;
18561862
}

compiler/rustc_symbol_mangling/src/legacy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
350350
}
351351
fn path_generic_args(
352352
mut self,
353+
_: bool,
353354
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
354355
args: &[GenericArg<'tcx>],
355356
) -> Result<Self::Path, Self::Error> {

compiler/rustc_symbol_mangling/src/v0.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
303303
// polymorphization is enabled) and this isn't an inherent impl.
304304
if impl_trait_ref.is_some() && substs.iter().any(|a| a.has_non_region_param()) {
305305
self = self.path_generic_args(
306+
false,
306307
|this| {
307308
this.path_append_ns(
308309
|cx| cx.print_def_path(parent_def_id, &[]),
@@ -808,6 +809,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
808809

809810
fn path_generic_args(
810811
mut self,
812+
_: bool,
811813
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
812814
args: &[GenericArg<'tcx>],
813815
) -> Result<Self::Path, Self::Error> {

src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let _: fn(&mut &isize, &mut &isize) = a;
55
| ^ one type is more general than the other
66
|
77
= note: expected fn pointer `for<'a, 'b, 'c, 'd> fn(&'a mut &'b isize, &'c mut &'d isize)`
8-
found fn item `for<'a, 'b> fn(&'a mut &isize, &'b mut &isize) {a::<'_, '_>}`
8+
found fn item `for<'a, 'b> fn(&'a mut &isize, &'b mut &isize) {a}`
99

1010
error: aborting due to previous error
1111

src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let _: fn(&mut &isize, &mut &isize, &mut &isize) = a;
55
| ^ one type is more general than the other
66
|
77
= note: expected fn pointer `for<'a, 'b, 'c, 'd, 'e, 'f> fn(&'a mut &'b isize, &'c mut &'d isize, &'e mut &'f isize)`
8-
found fn item `for<'a, 'b, 'c> fn(&'a mut &isize, &'b mut &isize, &'c mut &isize) {a::<'_, '_, '_>}`
8+
found fn item `for<'a, 'b, 'c> fn(&'a mut &isize, &'b mut &isize, &'c mut &isize) {a}`
99

1010
error: aborting due to previous error
1111

0 commit comments

Comments
 (0)