8000 Account for late-bound lifetimes in generics by cjgillot · Pull Request #103448 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Account for late-bound lifetimes in generics #103448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Do not print single ::<'_> for fn items.
  • Loading branch information
cjgillot committed Oct 26, 2022
commit 6a874c54c75a291c6d152ef6fb95af5b278c06a1
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {

fn path_generic_args(
mut self,
_: bool,
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
args: &[GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
fn path_generic_args(
self,
_: bool,
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
_args: &[GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ impl<'tcx> LateContext<'tcx> {

fn path_generic_args(
self,
_: bool,
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
_args: &[GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ fn foo(&self) -> Self::T { String::new() }

fn format_generic_args(self, args: &[ty::GenericArg<'tcx>]) -> String {
FmtPrinter::new(self, hir::def::Namespace::TypeNS)
.path_generic_args(Ok, args)
.path_generic_args(true, Ok, args)
.expect("could not write to `String`.")
.into_buffer()
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/ty/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::ty::{self, DefIdTree, Ty, TyCtxt};

use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sso::SsoHashSet;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};

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

fn path_generic_args(
self,
forbid_lifetime_elision: bool,
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
args: &[GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error>;
Expand Down Expand Up @@ -150,7 +152,12 @@ pub trait Printer<'tcx>: Sized {
_ => {
if !generics.params.is_empty() && substs.len() >= generics.count() {
let args = generics.own_substs_no_defaults(self.tcx(), substs);
let forbid_elision = !matches!(
self.tcx().def_kind(def_id),
DefKind::Fn | DefKind::AssocFn
);
return self.path_generic_args(
forbid_elision,
|cx| cx.print_def_path(def_id, parent_substs),
args,
);
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1845,12 +1845,18 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {

fn path_generic_args(
mut self,
forbid_lifetime_elision: bool,
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
args: &[GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> {
self = print_prefix(self)?;

if args.first().is_some() {
let all_elided = args.iter().all(|arg| match arg.unpack() {
ty::GenericArgKind::Lifetime(lt) => !lt.has_name(),
_ => false,
});

if !args.is_empty() && (forbid_lifetime_elision || self.tcx.sess.verbose() || !all_elided) {
if self.in_value {
write!(self, "::")?;
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_symbol_mangling/src/legacy.rs
Or A3DB iginal file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
}
fn path_generic_args(
mut self,
_: bool,
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
args: &[GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
// polymorphization is enabled) and this isn't an inherent impl.
if impl_trait_ref.is_some() && substs.iter().any(|a| a.has_non_region_param()) {
self = self.path_generic_args(
false,
|this| {
this.path_append_ns(
|cx| cx.print_def_path(parent_def_id, &[]),
Expand Down Expand Up @@ -808,6 +809,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {

fn path_generic_args(
mut self,
_: bool,
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
args: &[GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let _: fn(&mut &isize, &mut &isize) = a;
| ^ one type is more general than the other
|
= note: expected fn pointer `for<'a, 'b, 'c, 'd> fn(&'a mut &'b isize, &'c mut &'d isize)`
found fn item `for<'a, 'b> fn(&'a mut &isize, &'b mut &isize) {a::<'_, '_>}`
found fn item `for<'a, 'b> fn(&'a mut &isize, &'b mut &isize) {a}`

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let _: fn(&mut &isize, &mut &isize, &mut &isize) = a;
| ^ one type is more general than the other
|
= note: expected fn pointer `for<'a, 'b, 'c, 'd, 'e, 'f> fn(&'a mut &'b isize, &'c mut &'d isize, &'e mut &'f isize)`
found fn item `for<'a, 'b, 'c> fn(&'a mut &isize, &'b mut &isize, &'c mut &isize) {a::<'_, '_, '_>}`
found fn item `for<'a, 'b, 'c> fn(&'a mut &isize, &'b mut &isize, &'c mut &isize) {a}`

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/regions/regions-lifetime-bounds-on-fns.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let _: fn(&mut &isize, &mut &isize) = a;
| ^ one type is more general than the other
|
= note: expected fn pointer `for<'a, 'b, 'c, 'd> fn(&'a mut &'b isize, &'c mut &'d isize)`
found fn item `for<'a, 'b> fn(&'a mut &isize, &'b mut &isize) {a::<'_, '_>}`
found fn item `for<'a, 'b> fn(& 4826 ;'a mut &isize, &'b mut &isize) {a}`

error: aborting due to previous error

Expand Down
0