Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 16 additions & 3 deletions compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1842,13 +1842,26 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
.iter()
.map(|param| generic_param_def_as_bound_arg(param)),
);
bound_vars.extend(
// `resolve_bound_vars` is computed per HIR owner. `visit_early_late`
// records this associated function's binder before walking its signature,
// so reuse that in-progress binder instead of recursively querying `fn_sig`.
let fn_bound_vars = if assoc_fn.def_id == constraint.hir_id.owner.to_def_id() {
let fn_hir_id =
self.tcx.local_def_id_to_hir_id(assoc_fn.def_id.expect_local());
self.rbv
.late_bound_vars
.get(&fn_hir_id.local_id)
.expect("late-bound vars for the current function were not recorded")
.clone()
} else {
self.tcx
.fn_sig(assoc_fn.def_id)
.instantiate_identity()
.skip_norm_wip()
.bound_vars(),
);
.bound_vars()
.to_vec()
};
bound_vars.extend(fn_bound_vars);
bound_vars
} else {
self.tcx
Expand Down
20 changes: 13 additions & 7 deletions compiler/rustc_lint/src/impl_trait_overcaptures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,12 @@ where
match arg {
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(def_id))
| ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id)) => {
added.push(def_id);
let unique = self.in_scope_parameters.insert(def_id, ParamKind::Late);
assert_eq!(unique, None);
// Return type notation introduces a binder containing the referenced
// function's own bound parameters. For self-referential RTN, these may
// already be present as `Free` entries from the enclosing signature.
// Temporarily shadow them as `Late` and restore them when leaving.
let previous = self.in_scope_parameters.insert(def_id, ParamKind::Late);
added.push((def_id, previous));
Comment thread
oli-obk marked this conversation as resolved.
}
_ => {
self.tcx.dcx().span_delayed_bug(
Expand All @@ -231,10 +234,13 @@ where

t.super_visit_with(self);

// And remove them. The `shift_remove` should be `O(1)` since we're popping
// them off from the end.
for arg in added.into_iter().rev() {
self.in_scope_parameters.shift_remove(&arg);
// Restore the previous scope entries, removing newly added parameters.
for (arg, previous) in added.into_iter().rev() {
if let Some(previous) = previous {
self.in_scope_parameters.insert(arg, previous);
} else {
self.in_scope_parameters.shift_remove(&arg);
}
}
}

Expand Down
8 changes: 0 additions & 8 deletions tests/crashes/133613.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//@ check-pass

#![feature(return_type_notation)]

trait IntFactory {
fn stream(self) -> impl IntFactory<stream(..): Send>;
//~^ ERROR cycle detected when resolving lifetimes for `IntFactory::stream`
}

fn main() {}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ needs-rustc-debug-assertions

#![feature(return_type_notation)]

// This unrelated item forces error recovery. Keep more lifetime parameters
// here than the anonymous lifetimes introduced by the function so that using
// this item's bound variables cannot accidentally hide an out-of-bounds access.
struct Wrapper<'a, 'b, 'c, 'd>();
//~^ ERROR parameter `'a` is never used
//~| ERROR parameter `'b` is never used
//~| ERROR parameter `'c` is never used
//~| ERROR parameter `'d` is never used

trait IntFactory {
fn stream(&self) -> impl IntFactory<stream(..): IntFactory<stream(..): Send>>;
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error[E0392]: lifetime parameter `'a` is never used
--> $DIR/nested-rtn-error-recovery-issue-133613.rs:8:16
|
LL | struct Wrapper<'a, 'b, 'c, 'd>();
| ^^ unused lifetime parameter
|
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`

error[E0392]: lifetime parameter `'b` is never used
--> $DIR/nested-rtn-error-recovery-issue-133613.rs:8:20
|
LL | struct Wrapper<'a, 'b, 'c, 'd>();
| ^^ unused lifetime parameter
|
= help: consider removing `'b`, referring to it in a field, or using a marker such as `PhantomData`

error[E0392]: lifetime parameter `'c` is never used
--> $DIR/nested-rtn-error-recovery-issue-133613.rs:8:24
|
LL | struct Wrapper<'a, 'b, 'c, 'd>();
| ^^ unused lifetime parameter
|
= help: consider removing `'c`, referring to it in a field, or using a marker such as `PhantomData`

error[E0392]: lifetime parameter `'d` is never used
--> $DIR/nested-rtn-error-recovery-issue-133613.rs:8:28
|
LL | struct Wrapper<'a, 'b, 'c, 'd>();
| ^^ unused lifetime parameter
|
= help: consider removing `'d`, referring to it in a field, or using a marker such as `PhantomData`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0392`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ check-pass

#![feature(return_type_notation)]
#![allow(dead_code)]

struct A<const B: usize>;

trait C {
fn d(&self) -> impl C<d(..):>;
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/ui/impl-trait/in-trait/return-type-notation.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//@ check-pass

#![allow(incomplete_features)]
#![feature(return_type_notation)]

trait IntFactory {
fn stream(&self) -> impl IntFactory<stream(..): IntFactory<stream(..): Send> + Send>;
//~^ ERROR cycle detected when resolving lifetimes for `IntFactory::stream`
}

pub fn main() {}
19 changes: 0 additions & 19 deletions tests/ui/impl-trait/in-trait/return-type-notation.stderr

This file was deleted.

4 changes: 2 additions & 2 deletions tests/ui/parallel-rustc/fn-sig-cycle-ice-154560.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Regression test for ICE from issue #154056.

//@ ignore-parallel-frontend query cycle + ICE
//@ check-pass

#![feature(min_generic_const_args)]
#![feature(return_type_notation)]

trait IntFactory {
fn stream(&self) -> impl IntFactory<stream(..): Send>;
//~^ ERROR cycle detected when resolving lifetimes for `IntFactory::stream`
}

trait SendIntFactory: IntFactory<stream(..): Send> + Send {}

fn main() {}
19 changes: 0 additions & 19 deletions tests/ui/parallel-rustc/fn-sig-cycle-ice-154560.stderr

This file was deleted.

Loading