Skip to content

Commit

Permalink
implement review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ezrashaw committed Apr 14, 2023
1 parent ecf2a9b commit b506d96
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 3 additions & 2 deletions compiler/rustc_trait_selection/src/traits/outlives_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> {
let ty = self.resolve_vars_if_possible(ty);
let ty = OpportunisticRegionResolver::new(self).fold_ty(ty);

// We must avoid processing constrained lifetime variables in implied
// We must avoid processing unconstrained lifetime variables in implied
// bounds. See #110161 for context.
assert!(!ty.has_non_region_infer());
if ty.needs_infer() {
self.tcx.sess.delay_span_bug(
self.tcx.source_span_untracked(body_id),
self.tcx.def_span(body_id),
"skipped implied_outlives_bounds due to unconstrained lifetimes",
);
return vec![];
Expand Down
12 changes: 7 additions & 5 deletions tests/ui/implied-bounds/issue-110161.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@

// compile-flags: --crate-type=lib

trait Trait {
trait LtTrait {
type Ty;
}

// erroneous `Ty` impl
impl Trait for () {
impl LtTrait for () {
//~^ ERROR not all trait items implemented, missing: `Ty` [E0046]
}

// `'lt` is not constrained by the erroneous `Ty`
impl<'lt, T> Trait for Box<T>
impl<'lt, T> LtTrait for Box<T>
where
T: Trait<Ty = &'lt ()>,
T: LtTrait<Ty = &'lt ()>,
{
type Ty = &'lt ();
}

// unconstrained lifetime appears in implied bounds
fn test(_: <Box<()> as Trait>::Ty) {}
fn test(_: <Box<()> as LtTrait>::Ty) {}

fn test2<'x>(_: &'x <Box<()> as LtTrait>::Ty) {}
4 changes: 2 additions & 2 deletions tests/ui/implied-bounds/issue-110161.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ error[E0046]: not all trait items implemented, missing: `Ty`
LL | type Ty;
| ------- `Ty` from trait
...
LL | impl Trait for () {
| ^^^^^^^^^^^^^^^^^ missing `Ty` in implementation
LL | impl LtTrait for () {
| ^^^^^^^^^^^^^^^^^^^ missing `Ty` in implementation

error: aborting due to previous error

Expand Down

0 comments on commit b506d96

Please sign in to comment.