10588: internal: Parse const trait bounds r=Veykril a=Veykril

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10582
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-10-19 12:32:30 +00:00 committed by GitHub
commit dfa355b431
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 19 deletions

4
Cargo.lock generated
View file

@ -1763,9 +1763,9 @@ dependencies = [
[[package]] [[package]]
name = "ungrammar" name = "ungrammar"
version = "1.14.8" version = "1.14.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "403c1892ad46cacffb28c73550172999c6c75f70ca9c97bcafc8ce99d6421529" checksum = "66be59c2fd880e3d76d1a6cf6d34114008f1d8af2748d4ad9d39ea712f14fda9"
[[package]] [[package]]
name = "unicase" name = "unicase"

View file

@ -19,7 +19,8 @@ miniz_oxide.opt-level = 3
[profile.release] [profile.release]
incremental = true incremental = true
debug = 0 # Set this to 1 or 2 to get more useful backtraces in debugger. # Set this to 1 or 2 to get more useful backtraces in debugger.
debug = 0
[patch.'crates-io'] [patch.'crates-io']
# rowan = { path = "../rowan" } # rowan = { path = "../rowan" }

View file

@ -100,7 +100,7 @@ fn lifetime_bounds(p: &mut Parser) {
} }
// test type_param_bounds // test type_param_bounds
// struct S<T: 'a + ?Sized + (Copy)>; // struct S<T: 'a + ?Sized + (Copy) + ~const Drop>;
pub(super) fn bounds(p: &mut Parser) { pub(super) fn bounds(p: &mut Parser) {
assert!(p.at(T![:])); assert!(p.at(T![:]));
p.bump(T![:]); p.bump(T![:]);
@ -124,14 +124,24 @@ pub(super) fn bounds_without_colon_m(p: &mut Parser, marker: Marker) -> Complete
fn type_bound(p: &mut Parser) -> bool { fn type_bound(p: &mut Parser) -> bool {
let m = p.start(); let m = p.start();
let has_paren = p.eat(T!['(']); let has_paren = p.eat(T!['(']);
p.eat(T![?]);
match p.current() { match p.current() {
LIFETIME_IDENT => lifetime(p), LIFETIME_IDENT => lifetime(p),
T![for] => types::for_type(p, false), T![for] => types::for_type(p, false),
_ if paths::is_use_path_start(p) => types::path_type_(p, false), current => {
_ => { match current {
m.abandon(p); T![?] => p.bump_any(),
return false; T![~] => {
p.bump_any();
p.expect(T![const]);
}
_ => (),
}
if paths::is_use_path_start(p) {
types::path_type_(p, false);
} else {
m.abandon(p);
return false;
}
} }
} }
if has_paren { if has_paren {

View file

@ -29,7 +29,7 @@ rayon = "1"
expect-test = "1.2.0-pre.1" expect-test = "1.2.0-pre.1"
proc-macro2 = "1.0.8" proc-macro2 = "1.0.8"
quote = "1.0.2" quote = "1.0.2"
ungrammar = "=1.14.8" ungrammar = "=1.14.9"
test_utils = { path = "../test_utils" } test_utils = { path = "../test_utils" }
sourcegen = { path = "../sourcegen" } sourcegen = { path = "../sourcegen" }

View file

@ -1271,6 +1271,8 @@ pub struct TypeBound {
impl TypeBound { impl TypeBound {
pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) } pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) } pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
pub fn tilde_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![~]) }
pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) } pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
} }

View file

@ -536,6 +536,7 @@ impl Field {
"?" => "question_mark", "?" => "question_mark",
"," => "comma", "," => "comma",
"|" => "pipe", "|" => "pipe",
"~" => "tilde",
_ => name, _ => name,
}; };
format_ident!("{}_token", name) format_ident!("{}_token", name)

View file

@ -1,17 +1,17 @@
SOURCE_FILE@0..35 SOURCE_FILE@0..49
STRUCT@0..34 STRUCT@0..48
STRUCT_KW@0..6 "struct" STRUCT_KW@0..6 "struct"
WHITESPACE@6..7 " " WHITESPACE@6..7 " "
NAME@7..8 NAME@7..8
IDENT@7..8 "S" IDENT@7..8 "S"
GENERIC_PARAM_LIST@8..33 GENERIC_PARAM_LIST@8..47
L_ANGLE@8..9 "<" L_ANGLE@8..9 "<"
TYPE_PARAM@9..32 TYPE_PARAM@9..46
NAME@9..10 NAME@9..10
IDENT@9..10 "T" IDENT@9..10 "T"
COLON@10..11 ":" COLON@10..11 ":"
WHITESPACE@11..12 " " WHITESPACE@11..12 " "
TYPE_BOUND_LIST@12..32 TYPE_BOUND_LIST@12..46
TYPE_BOUND@12..14 TYPE_BOUND@12..14
LIFETIME@12..14 LIFETIME@12..14
LIFETIME_IDENT@12..14 "'a" LIFETIME_IDENT@12..14 "'a"
@ -36,6 +36,18 @@ SOURCE_FILE@0..35
NAME_REF@27..31 NAME_REF@27..31
IDENT@27..31 "Copy" IDENT@27..31 "Copy"
R_PAREN@31..32 ")" R_PAREN@31..32 ")"
R_ANGLE@32..33 ">" WHITESPACE@32..33 " "
SEMICOLON@33..34 ";" PLUS@33..34 "+"
WHITESPACE@34..35 "\n" WHITESPACE@34..35 " "
TYPE_BOUND@35..46
TILDE@35..36 "~"
CONST_KW@36..41 "const"
WHITESPACE@41..42 " "
PATH_TYPE@42..46
PATH@42..46
PATH_SEGMENT@42..46
NAME_REF@42..46
IDENT@42..46 "Drop"
R_ANGLE@46..47 ">"
SEMICOLON@47..48 ";"
WHITESPACE@48..49 "\n"

View file

@ -1 +1 @@
struct S<T: 'a + ?Sized + (Copy)>; struct S<T: 'a + ?Sized + (Copy) + ~const Drop>;