Skip to content
Open
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
11 changes: 9 additions & 2 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
use rustc_ast::{self as ast, AttrVec, NodeId, PatKind, attr, token};
use rustc_ast::{self as ast, AttrVec, GenericBound, NodeId, PatKind, attr, token};
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute, Features};
use rustc_session::Session;
use rustc_session::parse::{feature_err, feature_warn};
Expand Down Expand Up @@ -152,7 +152,14 @@ impl<'a> PostExpansionVisitor<'a> {
for param in params {
if !param.bounds.is_empty() {
let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();
self.sess.dcx().emit_err(errors::ForbiddenBound { spans });
if param.bounds.iter().any(|bound| matches!(bound, GenericBound::Trait(_))) {
// Issue #149695
// Abort immediately otherwise items defined in complex bounds will be lowered into HIR,
// which will cause ICEs when errors of the items visit unlowered parents.
self.sess.dcx().emit_fatal(errors::ForbiddenBound { spans });
} else {
self.sess.dcx().emit_err(errors::ForbiddenBound { spans });
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/ui/closures/binder/bounds-on-closure-type-binders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ fn main() {
// Regression test for issue #119067
let _ = for<T: Trait> || -> () {};
//~^ ERROR bounds cannot be used in this context
//~| ERROR late-bound type parameter not allowed on closures
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,5 @@ error: bounds cannot be used in this context
LL | let _ = for<T: Trait> || -> () {};
| ^^^^^

error: late-bound type parameter not allowed on closures
--> $DIR/bounds-on-closure-type-binders.rs:11:17
|
LL | let _ = for<T: Trait> || -> () {};
| ^

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

11 changes: 11 additions & 0 deletions tests/ui/traits/non_lifetime_binders/bad-bounds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@ edition 2024

#![feature(non_lifetime_binders)]
fn produce() -> for<A: A<{ //~ ERROR expected trait, found type parameter `A`
//~^ ERROR bounds cannot be used in this context
#[derive(Hash)]
enum A {}
struct A<A>; //~ ERROR the name `A` is defined multiple times
}>> Trait {} //~ ERROR cannot find trait `Trait` in this scope

fn main() {}
46 changes: 46 additions & 0 deletions tests/ui/traits/non_lifetime_binders/bad-bounds.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
error[E0428]: the name `A` is defined multiple times
--> $DIR/bad-bounds.rs:8:5
|
LL | enum A {}
| ------ previous definition of the type `A` here
LL | struct A<A>;
| ^^^^^^^^^^^^ `A` redefined here
|
= note: `A` must be defined only once in the type namespace of this block

error[E0404]: expected trait, found type parameter `A`
--> $DIR/bad-bounds.rs:4:24
|
LL | fn produce() -> for<A: A<{
| _____________________-__^
| | |
| | found this type parameter
LL | |
LL | | #[derive(Hash)]
LL | | enum A {}
LL | | struct A<A>;
LL | | }>> Trait {}
| |__^ not a trait

error[E0405]: cannot find trait `Trait` in this scope
--> $DIR/bad-bounds.rs:9:5
|
LL | }>> Trait {}
| ^^^^^ not found in this scope

error: bounds cannot be used in this context
--> $DIR/bad-bounds.rs:4:24
|
LL | fn produce() -> for<A: A<{
| ________________________^
LL | |
LL | | #[derive(Hash)]
LL | | enum A {}
LL | | struct A<A>;
LL | | }>> Trait {}
| |__^

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0404, E0405, E0428.
For more information about an error, try `rustc --explain E0404`.
Loading