diff options
| author | Michael Goulet <michael@errs.io> | 2022-10-22 20:18:16 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-10-22 20:29:40 +0000 |
| commit | c0cda2b2781a7cd66cc5d6672e390edfdbf7fc64 (patch) | |
| tree | 3d77098bb1f860e1d1e423512d8474e4b1d4108d | |
| parent | 289b2b8cf971b1adf132cb5b7f15368837c5e353 (diff) | |
| download | rust-c0cda2b2781a7cd66cc5d6672e390edfdbf7fc64.tar.gz rust-c0cda2b2781a7cd66cc5d6672e390edfdbf7fc64.zip | |
Pretty print lifetimes captured by RPIT
| -rw-r--r-- | compiler/rustc_middle/src/ty/print/pretty.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/impl-trait/hidden-lifetimes.stderr | 4 |
2 files changed, 18 insertions, 2 deletions
diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 0b06ccc19ec..2a229e04743 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -16,6 +16,7 @@ use rustc_session::cstore::{ExternCrate, ExternCrateSource}; use rustc_span::symbol::{kw, Ident, Symbol}; use rustc_target::abi::Size; use rustc_target::spec::abi::Abi; +use smallvec::SmallVec; use std::cell::Cell; use std::char; @@ -794,6 +795,7 @@ pub trait PrettyPrinter<'tcx>: let mut traits = FxIndexMap::default(); let mut fn_traits = FxIndexMap::default(); let mut is_sized = false; + let mut lifetimes = SmallVec::<[ty::Region<'tcx>; 1]>::new(); for predicate in bounds.transpose_iter().map(|e| e.map_bound(|(p, _)| *p)) { let predicate = predicate.subst(tcx, substs); @@ -825,6 +827,9 @@ pub trait PrettyPrinter<'tcx>: &mut fn_traits, ); } + ty::PredicateKind::TypeOutlives(outlives) => { + lifetimes.push(outlives.1); + } _ => {} } } @@ -978,6 +983,17 @@ pub trait PrettyPrinter<'tcx>: write!(self, "Sized")?; } + if let [re] = lifetimes.as_slice() + && re.is_static() + { + // Don't print a single static lifetime + } else { + for re in lifetimes { + write!(self, " + ")?; + self = self.print_region(re)?; + } + } + Ok(self) } diff --git a/src/test/ui/impl-trait/hidden-lifetimes.stderr b/src/test/ui/impl-trait/hidden-lifetimes.stderr index efc228de58b..de06ded7acd 100644 --- a/src/test/ui/impl-trait/hidden-lifetimes.stderr +++ b/src/test/ui/impl-trait/hidden-lifetimes.stderr @@ -1,4 +1,4 @@ -error[E0700]: hidden type for `impl Swap` captures lifetime that does not appear in bounds +error[E0700]: hidden type for `impl Swap + 'a` captures lifetime that does not appear in bounds --> $DIR/hidden-lifetimes.rs:29:5 | LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { @@ -11,7 +11,7 @@ help: to declare that the `impl Trait` captures `'b`, you can add an explicit `' LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + 'b { | ++++ -error[E0700]: hidden type for `impl Swap` captures lifetime that does not appear in bounds +error[E0700]: hidden type for `impl Swap + 'a` captures lifetime that does not appear in bounds --> $DIR/hidden-lifetimes.rs:46:5 | LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a { |
