mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-10 05:53:10 +00:00
Merge #10776
10776: fix: Remove validation of `super` in use paths r=Veykril a=lnicola Fixes #10770 Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
9f1e26c3f9
@ -245,8 +245,6 @@ fn validate_range_expr(expr: ast::RangeExpr, errors: &mut Vec<SyntaxError>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxError>) {
|
fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxError>) {
|
||||||
use ast::PathSegmentKind;
|
|
||||||
|
|
||||||
let path = segment.parent_path();
|
let path = segment.parent_path();
|
||||||
let is_path_start = segment.coloncolon_token().is_none() && path.qualifier().is_none();
|
let is_path_start = segment.coloncolon_token().is_none() && path.qualifier().is_none();
|
||||||
|
|
||||||
@ -264,26 +262,6 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxErro
|
|||||||
token.text_range(),
|
token.text_range(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else if let Some(token) = segment.super_token() {
|
|
||||||
if segment.coloncolon_token().is_some() || !all_supers(&path) {
|
|
||||||
errors.push(SyntaxError::new(
|
|
||||||
"The `super` keyword may only be preceded by other `super`s",
|
|
||||||
token.text_range(),
|
|
||||||
));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut curr_path = path;
|
|
||||||
while let Some(prefix) = use_prefix(curr_path) {
|
|
||||||
if !all_supers(&prefix) {
|
|
||||||
errors.push(SyntaxError::new(
|
|
||||||
"The `super` keyword may only be preceded by other `super`s",
|
|
||||||
token.text_range(),
|
|
||||||
));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
curr_path = prefix;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn use_prefix(mut path: ast::Path) -> Option<ast::Path> {
|
fn use_prefix(mut path: ast::Path) -> Option<ast::Path> {
|
||||||
@ -305,23 +283,6 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxErro
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_supers(path: &ast::Path) -> bool {
|
|
||||||
let segment = match path.segment() {
|
|
||||||
Some(it) => it,
|
|
||||||
None => return false,
|
|
||||||
};
|
|
||||||
|
|
||||||
if segment.kind() != Some(PathSegmentKind::SuperKw) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(ref subpath) = path.qualifier() {
|
|
||||||
return all_supers(subpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_trait_object_ref_ty(ty: ast::RefType, errors: &mut Vec<SyntaxError>) {
|
fn validate_trait_object_ref_ty(ty: ast::RefType, errors: &mut Vec<SyntaxError>) {
|
||||||
|
@ -1,75 +0,0 @@
|
|||||||
SOURCE_FILE@0..67
|
|
||||||
USE@0..12
|
|
||||||
USE_KW@0..3 "use"
|
|
||||||
WHITESPACE@3..4 " "
|
|
||||||
USE_TREE@4..11
|
|
||||||
PATH@4..11
|
|
||||||
PATH_SEGMENT@4..11
|
|
||||||
COLON2@4..6 "::"
|
|
||||||
NAME_REF@6..11
|
|
||||||
SUPER_KW@6..11 "super"
|
|
||||||
SEMICOLON@11..12 ";"
|
|
||||||
WHITESPACE@12..13 "\n"
|
|
||||||
USE@13..26
|
|
||||||
USE_KW@13..16 "use"
|
|
||||||
WHITESPACE@16..17 " "
|
|
||||||
USE_TREE@17..25
|
|
||||||
PATH@17..25
|
|
||||||
PATH@17..18
|
|
||||||
PATH_SEGMENT@17..18
|
|
||||||
NAME_REF@17..18
|
|
||||||
IDENT@17..18 "a"
|
|
||||||
COLON2@18..20 "::"
|
|
||||||
PATH_SEGMENT@20..25
|
|
||||||
NAME_REF@20..25
|
|
||||||
SUPER_KW@20..25 "super"
|
|
||||||
SEMICOLON@25..26 ";"
|
|
||||||
WHITESPACE@26..27 "\n"
|
|
||||||
USE@27..47
|
|
||||||
USE_KW@27..30 "use"
|
|
||||||
WHITESPACE@30..31 " "
|
|
||||||
USE_TREE@31..46
|
|
||||||
PATH@31..46
|
|
||||||
PATH@31..39
|
|
||||||
PATH@31..36
|
|
||||||
PATH_SEGMENT@31..36
|
|
||||||
NAME_REF@31..36
|
|
||||||
SUPER_KW@31..36 "super"
|
|
||||||
COLON2@36..38 "::"
|
|
||||||
PATH_SEGMENT@38..39
|
|
||||||
NAME_REF@38..39
|
|
||||||
IDENT@38..39 "a"
|
|
||||||
COLON2@39..41 "::"
|
|
||||||
PATH_SEGMENT@41..46
|
|
||||||
NAME_REF@41..46
|
|
||||||
SUPER_KW@41..46 "super"
|
|
||||||
SEMICOLON@46..47 ";"
|
|
||||||
WHITESPACE@47..48 "\n"
|
|
||||||
USE@48..66
|
|
||||||
USE_KW@48..51 "use"
|
|
||||||
WHITESPACE@51..52 " "
|
|
||||||
USE_TREE@52..65
|
|
||||||
PATH@52..53
|
|
||||||
PATH_SEGMENT@52..53
|
|
||||||
NAME_REF@52..53
|
|
||||||
IDENT@52..53 "a"
|
|
||||||
COLON2@53..55 "::"
|
|
||||||
USE_TREE_LIST@55..65
|
|
||||||
L_CURLY@55..56 "{"
|
|
||||||
USE_TREE@56..64
|
|
||||||
PATH@56..64
|
|
||||||
PATH@56..61
|
|
||||||
PATH_SEGMENT@56..61
|
|
||||||
NAME_REF@56..61
|
|
||||||
SUPER_KW@56..61 "super"
|
|
||||||
COLON2@61..63 "::"
|
|
||||||
PATH_SEGMENT@63..64
|
|
||||||
NAME_REF@63..64
|
|
||||||
IDENT@63..64 "b"
|
|
||||||
R_CURLY@64..65 "}"
|
|
||||||
SEMICOLON@65..66 ";"
|
|
||||||
WHITESPACE@66..67 "\n"
|
|
||||||
error 6..11: The `super` keyword may only be preceded by other `super`s
|
|
||||||
error 20..25: The `super` keyword may only be preceded by other `super`s
|
|
||||||
error 41..46: The `super` keyword may only be preceded by other `super`s
|
|
||||||
error 56..61: The `super` keyword may only be preceded by other `super`s
|
|
@ -1,4 +0,0 @@
|
|||||||
use ::super;
|
|
||||||
use a::super;
|
|
||||||
use super::a::super;
|
|
||||||
use a::{super::b};
|
|
Loading…
Reference in New Issue
Block a user