Skip to content
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

Don't ICE for late-bound consts across AnonConstBoundary #109105

Merged
merged 1 commit into from
Mar 14, 2023
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
14 changes: 7 additions & 7 deletions compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,25 +1427,25 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
if let ResolvedArg::LateBound(..) = def && crossed_anon_const {
let use_span = self.tcx.hir().span(hir_id);
let def_span = self.tcx.def_span(param_def_id);
match self.tcx.def_kind(param_def_id) {
let guar = match self.tcx.def_kind(param_def_id) {
DefKind::ConstParam => {
self.tcx.sess.emit_err(errors::CannotCaptureLateBoundInAnonConst::Const {
use_span,
def_span,
});
})
}
DefKind::TyParam => {
self.tcx.sess.emit_err(errors::CannotCaptureLateBoundInAnonConst::Type {
use_span,
def_span,
});
})
}
_ => unreachable!(),
}
return;
};
self.map.defs.insert(hir_id, ResolvedArg::Error(guar));
} else {
self.map.defs.insert(hir_id, def);
}

self.map.defs.insert(hir_id, def);
return;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/ui/traits/non_lifetime_binders/capture-late-ct-in-anon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![feature(non_lifetime_binders)]
//~^ WARN the feature `non_lifetime_binders` is incomplete

fn b()
where
for<const C: usize> [(); C]: Copy,
//~^ ERROR cannot capture late-bound const parameter in a constant
{
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/capture-late-ct-in-anon.rs:1:12
|
LL | #![feature(non_lifetime_binders)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
= note: `#[warn(incomplete_features)]` on by default

error: cannot capture late-bound const parameter in a constant
--> $DIR/capture-late-ct-in-anon.rs:6:30
|
LL | for<const C: usize> [(); C]: Copy,
| -------------- ^
| |
| parameter defined here

error: aborting due to previous error; 1 warning emitted