mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-06 08:36:52 -04:00
Emit fatal on defaults for generic params in binders if with nested defs
This commit is contained in:
@@ -2220,14 +2220,19 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
|
||||
// since later compiler stages cannot handle them (and shouldn't need to be able to).
|
||||
let default = default
|
||||
.as_ref()
|
||||
.filter(|_| match source {
|
||||
.filter(|anon_const| match source {
|
||||
hir::GenericParamSource::Generics => true,
|
||||
hir::GenericParamSource::Binder => {
|
||||
self.dcx().emit_err(errors::GenericParamDefaultInBinder {
|
||||
span: param.span(),
|
||||
});
|
||||
|
||||
false
|
||||
let err = errors::GenericParamDefaultInBinder { span: param.span() };
|
||||
if expr::WillCreateDefIdsVisitor
|
||||
.visit_expr(&anon_const.value)
|
||||
.is_break()
|
||||
{
|
||||
self.dcx().emit_fatal(err)
|
||||
} else {
|
||||
self.dcx().emit_err(err);
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
.map(|def| self.lower_anon_const_to_const_arg_and_alloc(def));
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
//@ known-bug: #123629
|
||||
#![feature(generic_assert)]
|
||||
|
||||
fn foo()
|
||||
where
|
||||
for<const N: usize = { assert!(u) }> ():,
|
||||
{
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
#![feature(generic_assert)]
|
||||
|
||||
fn foo()
|
||||
where
|
||||
for<const N: usize = { assert!(u) }> ():,
|
||||
//~^ ERROR cannot find value `u` in this scope
|
||||
//~^^ ERROR only lifetime parameters can be used in this context
|
||||
//~^^^ ERROR defaults for generic parameters are not allowed in `for<...>` binders
|
||||
{
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
error[E0425]: cannot find value `u` in this scope
|
||||
--> $DIR/bad-defaults-for-generic-param-in-binder-123629.rs:5:36
|
||||
|
|
||||
LL | for<const N: usize = { assert!(u) }> ():,
|
||||
| ^ not found in this scope
|
||||
|
||||
error[E0658]: only lifetime parameters can be used in this context
|
||||
--> $DIR/bad-defaults-for-generic-param-in-binder-123629.rs:5:15
|
||||
|
|
||||
LL | for<const N: usize = { assert!(u) }> ():,
|
||||
| ^
|
||||
|
|
||||
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
|
||||
= help: add `#![feature(non_lifetime_binders)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error: defaults for generic parameters are not allowed in `for<...>` binders
|
||||
--> $DIR/bad-defaults-for-generic-param-in-binder-123629.rs:5:9
|
||||
|
|
||||
LL | for<const N: usize = { assert!(u) }> ():,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0425, E0658.
|
||||
For more information about an error, try `rustc --explain E0425`.
|
||||
Reference in New Issue
Block a user