Skip to content

Commit 985c57d

Browse files
committed
fallback default to None during parse late-bound lifetime
1 parent 2f19122 commit 985c57d

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

compiler/rustc_parse/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ parse_default_not_followed_by_item = `default` is not followed by an item
117117
.label = the `default` qualifier
118118
.note = only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
119119
120+
parse_default_parameter_in_binder = default parameter is not allowed in this binder
121+
120122
parse_do_catch_syntax_removed = found removed `do catch` syntax
121123
.note = following RFC #2388, the new non-placeholder syntax is `try`
122124
.suggestion = replace with the new syntax

compiler/rustc_parse/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2897,3 +2897,10 @@ pub(crate) struct TransposeDynOrImplSugg<'a> {
28972897
pub insertion_span: Span,
28982898
pub kw: &'a str,
28992899
}
2900+
2901+
#[derive(Diagnostic)]
2902+
#[diag(parse_default_parameter_in_binder)]
2903+
pub(crate) struct UnexpectedDefaultParameterInBinder {
2904+
#[primary_span]
2905+
pub span: Span,
2906+
}

compiler/rustc_parse/src/parser/ty.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::errors::{
44
self, DynAfterMut, ExpectedFnPathFoundFnKeyword, ExpectedMutOrConstInRawPointerType,
55
FnPointerCannotBeAsync, FnPointerCannotBeConst, FnPtrWithGenerics, FnPtrWithGenericsSugg,
66
InvalidDynKeyword, LifetimeAfterMut, NeedPlusAfterTraitObjectLifetime, NestedCVariadicType,
7-
ReturnTypesUseThinArrow,
7+
ReturnTypesUseThinArrow, UnexpectedDefaultParameterInBinder,
88
};
99
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
1010

@@ -14,8 +14,8 @@ use rustc_ast::token::{self, Delimiter, Token, TokenKind};
1414
use rustc_ast::util::case::Case;
1515
use rustc_ast::{
1616
self as ast, BareFnTy, BoundPolarity, FnRetTy, GenericBound, GenericBounds, GenericParam,
17-
Generics, Lifetime, MacCall, MutTy, Mutability, PolyTraitRef, TraitBoundModifier,
18-
TraitObjectSyntax, Ty, TyKind,
17+
GenericParamKind, Generics, Lifetime, MacCall, MutTy, Mutability, PolyTraitRef,
18+
TraitBoundModifier, TraitObjectSyntax, Ty, TyKind,
1919
};
2020
use rustc_errors::{Applicability, PResult};
2121
use rustc_span::symbol::{kw, sym, Ident};
@@ -1033,6 +1033,16 @@ impl<'a> Parser<'a> {
10331033
if self.eat_keyword(kw::For) {
10341034
self.expect_lt()?;
10351035
let params = self.parse_generic_params()?;
1036+
let params = params
1037+
.into_iter()
1038+
.map(|param| match param.kind {
1039+
GenericParamKind::Type { ref default } if let Some(ty) = default => {
1040+
self.sess.emit_err(UnexpectedDefaultParameterInBinder { span: ty.span });
1041+
GenericParam { kind: GenericParamKind::Type { default: None }, ..param }
1042+
}
1043+
_ => param,
1044+
})
1045+
.collect();
10361046
self.expect_gt()?;
10371047
// We rely on AST validation to rule out invalid cases: There must not be type
10381048
// parameters, and the lifetime parameters must not have bounds.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![allow(incomplete_features)]
2+
#![feature(non_lifetime_binders)]
3+
4+
type T = dyn for<V = A(&())> Fn(());
5+
//~^ ERROR default parameter is not allowed in this binder
6+
//~| ERROR late-bound type parameter not allowed on trait object types
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: default parameter is not allowed in this binder
2+
--> $DIR/issue-118697.rs:4:22
3+
|
4+
LL | type T = dyn for<V = A(&())> Fn(());
5+
| ^^^^^^
6+
7+
error: late-bound type parameter not allowed on trait object types
8+
--> $DIR/issue-118697.rs:4:18
9+
|
10+
LL | type T = dyn for<V = A(&())> Fn(());
11+
| ^
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)