Skip to content

Commit

Permalink
fallback default to None during parse late-bound lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Dec 17, 2023
1 parent 2f19122 commit 985c57d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ parse_default_not_followed_by_item = `default` is not followed by an item
.label = the `default` qualifier
.note = only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
parse_default_parameter_in_binder = default parameter is not allowed in this binder
parse_do_catch_syntax_removed = found removed `do catch` syntax
.note = following RFC #2388, the new non-placeholder syntax is `try`
.suggestion = replace with the new syntax
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2897,3 +2897,10 @@ pub(crate) struct TransposeDynOrImplSugg<'a> {
pub insertion_span: Span,
pub kw: &'a str,
}

#[derive(Diagnostic)]
#[diag(parse_default_parameter_in_binder)]
pub(crate) struct UnexpectedDefaultParameterInBinder {
#[primary_span]
pub span: Span,
}
16 changes: 13 additions & 3 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::errors::{
self, DynAfterMut, ExpectedFnPathFoundFnKeyword, ExpectedMutOrConstInRawPointerType,
FnPointerCannotBeAsync, FnPointerCannotBeConst, FnPtrWithGenerics, FnPtrWithGenericsSugg,
InvalidDynKeyword, LifetimeAfterMut, NeedPlusAfterTraitObjectLifetime, NestedCVariadicType,
ReturnTypesUseThinArrow,
ReturnTypesUseThinArrow, UnexpectedDefaultParameterInBinder,
};
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};

Expand All @@ -14,8 +14,8 @@ use rustc_ast::token::{self, Delimiter, Token, TokenKind};
use rustc_ast::util::case::Case;
use rustc_ast::{
self as ast, BareFnTy, BoundPolarity, FnRetTy, GenericBound, GenericBounds, GenericParam,
Generics, Lifetime, MacCall, MutTy, Mutability, PolyTraitRef, TraitBoundModifier,
TraitObjectSyntax, Ty, TyKind,
GenericParamKind, Generics, Lifetime, MacCall, MutTy, Mutability, PolyTraitRef,
TraitBoundModifier, TraitObjectSyntax, Ty, TyKind,
};
use rustc_errors::{Applicability, PResult};
use rustc_span::symbol::{kw, sym, Ident};
Expand Down Expand Up @@ -1033,6 +1033,16 @@ impl<'a> Parser<'a> {
if self.eat_keyword(kw::For) {
self.expect_lt()?;
let params = self.parse_generic_params()?;
let params = params
.into_iter()
.map(|param| match param.kind {
GenericParamKind::Type { ref default } if let Some(ty) = default => {
self.sess.emit_err(UnexpectedDefaultParameterInBinder { span: ty.span });
GenericParam { kind: GenericParamKind::Type { default: None }, ..param }
}
_ => param,
})
.collect();
self.expect_gt()?;
// We rely on AST validation to rule out invalid cases: There must not be type
// parameters, and the lifetime parameters must not have bounds.
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/traits/non_lifetime_binders/issue-118697.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![allow(incomplete_features)]
#![feature(non_lifetime_binders)]

type T = dyn for<V = A(&())> Fn(());
//~^ ERROR default parameter is not allowed in this binder
//~| ERROR late-bound type parameter not allowed on trait object types

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/traits/non_lifetime_binders/issue-118697.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: default parameter is not allowed in this binder
--> $DIR/issue-118697.rs:4:22
|
LL | type T = dyn for<V = A(&())> Fn(());
| ^^^^^^

error: late-bound type parameter not allowed on trait object types
--> $DIR/issue-118697.rs:4:18
|
LL | type T = dyn for<V = A(&())> Fn(());
| ^

error: aborting due to 2 previous errors

0 comments on commit 985c57d

Please sign in to comment.