Ai
4 Star 8 Fork 2

Gitee 极速下载/CodeQL

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/github/codeql
克隆/下载
annotations.py 41.61 KB
一键复制 编辑 原始数据 按行查看 历史
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591
from misc.codegen.lib.schemadefs import *
from .ast import *
class LabelableExpr(Expr):
"""
The base class for expressions that can be labeled (`LoopExpr`, `ForExpr`, `WhileExpr` or `BlockExpr`).
"""
label: optional[Label] | child
class LoopingExpr(LabelableExpr):
"""
The base class for expressions that loop (`LoopExpr`, `ForExpr` or `WhileExpr`).
"""
loop_body: optional["BlockExpr"] | child
@annotate(TypeItem, replace_bases={AstNode: Item})
class _:
"""
An item that defines a type. Either a `Struct`, `Enum`, or `Union`.
"""
derive_macro_expansions: list[MacroItems] | child | rust.detach
attrs: list["Attr"] | child
generic_param_list: optional["GenericParamList"] | child
name: optional["Name"] | child
visibility: optional["Visibility"] | child
where_clause: optional["WhereClause"] | child
@annotate(Module)
@rust.doc_test_signature(None)
class _:
"""
A module declaration. For example:
```rust
mod foo;
```
```rust
mod bar {
pub fn baz() {}
}
```
"""
@annotate(Expr, cfg=True)
class _:
"""
The base class for expressions.
"""
@annotate(Pat, cfg=True)
class _:
"""
The base class for patterns.
"""
@annotate(Label)
class _:
"""
A label. For example:
```rust
'label: loop {
println!("Hello, world (once)!");
break 'label;
};
```
"""
@annotate(Stmt)
class _:
"""
The base class for statements.
"""
@annotate(TypeRepr)
class _:
"""
The base class for type references.
```rust
let x: i32;
let y: Vec<i32>;
let z: Option<i32>;
```
"""
@annotate(Path)
class _:
"""
A path. For example:
```rust
use some_crate::some_module::some_item;
foo::bar;
```
"""
segment: _ | ql.db_table_name("path_segments_") | doc("last segment of this path")
@annotate(GenericArgList)
class _:
"""
The base class for generic arguments.
```rust
x.foo::<u32, u64>(42);
```
"""
@annotate(Function)
@rust.doc_test_signature(None)
class _:
"""
A function declaration. For example
```rust
fn foo(x: u32) -> u64 {(x + 1).into()}
```
A function declaration within a trait might not have a body:
```rust
trait Trait {
fn bar();
}
```
"""
class PathExprBase(Expr):
"""
A path expression or a variable access in a formatting template. See `PathExpr` and `FormatTemplateVariableAccess` for further details.
"""
@annotate(
PathExpr, replace_bases={Expr: PathExprBase}, add_bases=(PathAstNode,), cfg=True
)
@qltest.test_with(Path)
class _:
"""
A path expression. For example:
```rust
let x = variable;
let x = foo::bar;
let y = <T>::foo;
let z = <TypeRepr as Trait>::foo;
```
"""
path: drop
@annotate(IfExpr, cfg=True)
class _:
"""
An `if` expression. For example:
```rust
if x == 42 {
println!("that's the answer");
}
```
```rust
let y = if x > 0 {
1
} else {
0
};
```
"""
@annotate(LetExpr, cfg=True)
@rust.doc_test_signature("(maybe_some: Option<String>) -> ()")
class _:
"""
A `let` expression. For example:
```rust
if let Some(x) = maybe_some {
println!("{}", x);
}
```
"""
@annotate(BlockExpr, replace_bases={Expr: LabelableExpr}, cfg=True)
class _:
"""
A block expression. For example:
```rust
{
let x = 42;
}
```
```rust
'label: {
let x = 42;
x
}
```
"""
label: drop
@annotate(LoopExpr, replace_bases={Expr: LoopingExpr}, cfg=True)
class _:
"""
A loop expression. For example:
```rust
loop {
println!("Hello, world (again)!");
};
```
```rust
'label: loop {
println!("Hello, world (once)!");
break 'label;
};
```
```rust
let mut x = 0;
loop {
if x < 10 {
x += 1;
} else {
break;
}
};
```
"""
label: drop
loop_body: drop
@annotate(CallExpr, cfg=True)
class _:
"""
NOTE: Consider using `Call` instead, as that excludes call expressions that are
instantiations of tuple structs and tuple variants.
A call expression. For example:
```rust
foo(42);
foo::<u32, u64>(42);
foo[0](42);
Option::Some(42); // tuple variant instantiation
```
"""
@annotate(MethodCallExpr, cfg=True)
class _:
"""
NOTE: Consider using `MethodCall` instead, as that also includes calls to methods using
call syntax (such as `Foo::method(x)`), operation syntax (such as `x + y`), and
indexing syntax (such as `x[y]`).
A method call expression. For example:
```rust
x.foo(42);
x.foo::<u32, u64>(42);
```
"""
@annotate(MatchArm)
@rust.doc_test_signature("(x: i32)")
class _:
"""
A match arm. For example:
```rust
match x {
Option::Some(y) => y,
Option::None => 0,
};
```
```rust
match x {
Some(y) if y != 0 => 1 / y,
_ => 0,
};
```
"""
@annotate(MatchExpr, cfg=True)
@rust.doc_test_signature("(x: i32) -> i32")
class _:
"""
A match expression. For example:
```rust
match x {
Option::Some(y) => y,
Option::None => 0,
}
```
```rust
match x {
Some(y) if y != 0 => 1 / y,
_ => 0,
}
```
"""
scrutinee: _ | doc(
"scrutinee (the expression being matched) of this match expression"
)
@annotate(ContinueExpr, cfg=True)
class _:
"""
A continue expression. For example:
```rust
loop {
if not_ready() {
continue;
}
}
```
```rust
'label: loop {
if not_ready() {
continue 'label;
}
}
```
"""
@annotate(BreakExpr, cfg=True)
class _:
"""
A break expression. For example:
```rust
loop {
if not_ready() {
break;
}
}
```
```rust
let x = 'label: loop {
if done() {
break 'label 42;
}
};
```
```rust
let x = 'label: {
if exit() {
break 'label 42;
}
0;
};
```
"""
@annotate(ReturnExpr, cfg=True)
@rust.doc_test_signature(None)
class _:
"""
A return expression. For example:
```rust
fn some_value() -> i32 {
return 42;
}
```
```rust
fn no_value() -> () {
return;
}
```
"""
@annotate(BecomeExpr, cfg=True)
@rust.doc_test_signature(None)
class _:
"""
A `become` expression. For example:
```rust
fn fact_a(n: i32, a: i32) -> i32 {
if n == 0 {
a
} else {
become fact_a(n - 1, n * a)
}
}
```
"""
@annotate(YieldExpr, cfg=True)
class _:
"""
A `yield` expression. For example:
```rust
let one = #[coroutine]
|| {
yield 1;
};
```
"""
@annotate(YeetExpr, cfg=True)
class _:
"""
A `yeet` expression. For example:
```rust
if x < size {
do yeet "index out of bounds";
}
```
"""
@annotate(StructExprField)
class _:
"""
A field in a struct expression. For example `a: 1` in:
```rust
Foo { a: 1, b: 2 };
```
"""
@annotate(StructExpr, add_bases=(PathAstNode,), cfg=True)
class _:
"""
A struct expression. For example:
```rust
let first = Foo { a: 1, b: 2 };
let second = Foo { a: 2, ..first };
let n = Foo { a: 1, b: 2 }.b;
Foo { a: m, .. } = second;
```
"""
path: drop
@annotate(FieldExpr, cfg=True)
class _:
"""
A field access expression. For example:
```rust
x.foo
```
"""
@annotate(AwaitExpr, cfg=True)
class _:
"""
An `await` expression. For example:
```rust
async {
let x = foo().await;
x
}
```
"""
@annotate(CastExpr, cfg=True)
class _:
"""
A type cast expression. For example:
```rust
value as u64;
```
"""
@annotate(RefExpr, cfg=True)
class _:
"""
A reference expression. For example:
```rust
let ref_const = &foo;
let ref_mut = &mut foo;
let raw_const: &mut i32 = &raw const foo;
let raw_mut: &mut i32 = &raw mut foo;
```
"""
@annotate(PrefixExpr, cfg=True)
class _:
"""
A unary operation expression. For example:
```rust
let x = -42;
let y = !true;
let z = *ptr;
```
"""
@annotate(BinaryExpr, cfg=True)
class _:
"""
A binary operation expression. For example:
```rust
x + y;
x && y;
x <= y;
x = y;
x += y;
```
"""
@annotate(RangeExpr, cfg=True)
class _:
"""
A range expression. For example:
```rust
let x = 1..=10;
let x = 1..10;
let x = 10..;
let x = ..10;
let x = ..=10;
let x = ..;
```
"""
@annotate(IndexExpr, cfg=True)
class _:
"""
An index expression. For example:
```rust
list[42];
list[42] = 1;
```
"""
@annotate(ClosureExpr)
class _:
"""
A closure expression. For example:
```rust
|x| x + 1;
move |x: i32| -> i32 { x + 1 };
async |x: i32, y| x + y;
#[coroutine]
|x| yield x;
#[coroutine]
static |x| yield x;
for<T: std::fmt::Debug> |x: T| {
println!("{:?}", x);
};
```
"""
@annotate(TupleExpr, cfg=True)
class _:
"""
A tuple expression. For example:
```rust
let tuple = (1, "one");
let n = (2, "two").0;
let (a, b) = tuple;
```
"""
@annotate(ArrayExprInternal)
@ql.internal
@qltest.skip
class _:
pass
class ArrayExpr(Expr):
"""
The base class for array expressions. For example:
```rust
[1, 2, 3];
[1; 10];
```
"""
exprs: list[Expr] | child
attrs: list[Attr] | child
@synth.from_class(ArrayExprInternal)
class ArrayListExpr(ArrayExpr):
"""
An array expression with a list of elements. For example:
```rust
[1, 2, 3];
```
"""
__cfg__ = True
@synth.from_class(ArrayExprInternal)
class ArrayRepeatExpr(ArrayExpr):
"""
An array expression with a repeat operand and a repeat length. For example:
```rust
[1; 10];
```
"""
__cfg__ = True
repeat_operand: Expr | child
repeat_length: Expr | child
@annotate(LiteralExpr, cfg=True)
class _:
"""
A literal expression. For example:
```rust
42;
42.0;
"Hello, world!";
b"Hello, world!";
'x';
b'x';
r"Hello, world!";
true;
```
"""
@annotate(UnderscoreExpr, cfg=True)
class _:
"""
An underscore expression. For example:
```rust
_ = 42;
```
"""
@annotate(OffsetOfExpr, cfg=True)
class _:
"""
An `offset_of` expression. For example:
```rust
builtin # offset_of(Struct, field);
```
"""
@annotate(AsmExpr, cfg=True)
class _:
"""
An inline assembly expression. For example:
```rust
unsafe {
#[inline(always)]
builtin # asm("cmp {0}, {1}", in(reg) a, in(reg) b);
}
```
"""
@annotate(LetStmt, cfg=True)
class _:
"""
A let statement. For example:
```rust
let x = 42;
let x: i32 = 42;
let x: i32;
let x;
let (x, y) = (1, 2);
let Some(x) = std::env::var("FOO") else {
return;
};
```
"""
@annotate(ExprStmt)
class _:
"""
An expression statement. For example:
```rust
start();
finish();
use std::env;
```
"""
@annotate(WildcardPat, cfg=True)
class _:
"""
A wildcard pattern. For example:
```rust
let _ = 42;
```
"""
@annotate(TuplePat, cfg=True)
class _:
"""
A tuple pattern. For example:
```rust
let (x, y) = (1, 2);
let (a, b, .., z) = (1, 2, 3, 4, 5);
```
"""
@annotate(OrPat, cfg=True)
class _:
"""
An or pattern. For example:
```rust
match x {
Option::Some(y) | Option::None => 0,
}
```
"""
@annotate(StructPatField)
class _:
"""
A field in a struct pattern. For example `a: 1` in:
```rust
let Foo { a: 1, b: 2 } = foo;
```
"""
@annotate(StructPat, add_bases=(PathAstNode,), cfg=True)
class _:
"""
A struct pattern. For example:
```rust
match x {
Foo { a: 1, b: 2 } => "ok",
Foo { .. } => "fail",
}
```
"""
path: drop
@annotate(RangePat, cfg=True)
class _:
"""
A range pattern. For example:
```rust
match x {
..15 => "too cold",
16..=25 => "just right",
26.. => "too hot",
}
```
"""
@annotate(SlicePat, cfg=True)
class _:
"""
A slice pattern. For example:
```rust
match x {
[1, 2, 3, 4, 5] => "ok",
[1, 2, ..] => "fail",
[x, y, .., z, 7] => "fail",
}
```
"""
@annotate(PathPat, add_bases=(PathAstNode,), cfg=True)
@qltest.test_with(Path)
class _:
"""
A path pattern. For example:
```rust
match x {
Foo::Bar => "ok",
_ => "fail",
}
```
"""
path: drop
@annotate(LiteralPat, cfg=True)
class _:
"""
A literal pattern. For example:
```rust
match x {
42 => "ok",
_ => "fail",
}
```
"""
@annotate(IdentPat, cfg=True)
class _:
"""
A binding pattern. For example:
```rust
match x {
Option::Some(y) => y,
Option::None => 0,
};
```
```rust
match x {
y@Option::Some(_) => y,
Option::None => 0,
};
```
"""
@annotate(TupleStructPat, add_bases=(PathAstNode,), cfg=True)
class _:
"""
A tuple struct pattern. For example:
```rust
match x {
Tuple("a", 1, 2, 3) => "great",
Tuple(.., 3) => "fine",
Tuple(..) => "fail",
};
```
"""
path: drop
@annotate(RefPat, cfg=True)
class _:
"""
A reference pattern. For example:
```rust
match x {
&mut Option::Some(y) => y,
&Option::None => 0,
};
```
"""
@annotate(BoxPat, cfg=True)
class _:
"""
A box pattern. For example:
```rust
match x {
box Option::Some(y) => y,
box Option::None => 0,
};
```
"""
@annotate(ConstBlockPat, cfg=True)
class _:
"""
A const block pattern. For example:
```rust
match x {
const { 1 + 2 + 3 } => "ok",
_ => "fail",
};
```
"""
@annotate(Abi)
class _:
"""
An ABI specification for an extern function or block.
For example:
```rust
extern "C" fn foo() {}
// ^^^
```
"""
@annotate(ArgList)
class _:
"""
A list of arguments in a function or method call.
For example:
```rust
foo(1, 2, 3);
// ^^^^^^^^^
```
"""
@annotate(ArrayTypeRepr)
class _:
"""
An array type representation.
For example:
```rust
let arr: [i32; 4];
// ^^^^^^^^
```
"""
@annotate(AssocItem, replace_bases={AstNode: Item})
class _:
"""
An associated item in a `Trait` or `Impl`.
For example:
```rust
trait T {fn foo(&self);}
// ^^^^^^^^^^^^^
```
"""
@annotate(AssocItemList)
@qltest.test_with(Trait)
class _:
"""
A list of `AssocItem` elements, as appearing in a `Trait` or `Impl`.
"""
@annotate(AssocTypeArg)
class _:
"""
An associated type argument in a path.
For example:
```rust
fn process_cloneable<T>(iter: T)
where
T: Iterator<Item: Clone>
// ^^^^^^^^^^^
{
// ...
}
```
"""
@annotate(Attr)
class _:
"""
An attribute applied to an item.
For example:
```rust
#[derive(Debug)]
//^^^^^^^^^^^^^
struct S;
```
"""
@annotate(ForBinder)
class _:
"""
A for binder, specifying lifetime or type parameters for a closure or a type.
For example:
```rust
let print_any = for<T: std::fmt::Debug> |x: T| {
// ^^^^^^^^^^^^^^^^^^^^^^^
println!("{:?}", x);
};
print_any(42);
print_any("hello");
```
"""
@annotate(Const, replace_bases={Item: None})
class _:
"""
A constant item declaration.
For example:
```rust
const X: i32 = 42;
```
"""
has_implementation: (
predicate
| doc("this constant has an implementation")
| desc(
"""
This is the same as `hasBody` for source code, but for library code (for which we always skip
the body), this will hold when the body was present in the original code.
"""
)
| rust.detach
)
@annotate(ConstArg)
class _:
"""
A constant argument in a generic argument list.
For example:
```rust
Foo::<3>
// ^
```
"""
@annotate(ConstParam)
class _:
"""
A constant parameter in a generic parameter list.
For example:
```rust
struct Foo <const N: usize>;
// ^^^^^^^^^^^^^^
```
"""
@annotate(DynTraitTypeRepr)
class _:
"""
A dynamic trait object type.
For example:
```rust
let x: &dyn Debug;
// ^^^^^^^^^
```
"""
@annotate(Enum, replace_bases={Item: None})
class _:
"""
An enum declaration.
For example:
```rust
enum E {A, B(i32), C {x: i32}}
```
"""
attrs: drop
generic_param_list: drop
name: drop
visibility: drop
where_clause: drop
@annotate(ExternBlock)
class _:
"""
An extern block containing foreign function declarations.
For example:
```rust
extern "C" {
fn foo();
}
```
"""
@annotate(ExternCrate)
class _:
"""
An extern crate declaration.
For example:
```rust
extern crate serde;
```
"""
@annotate(ExternItem, replace_bases={AstNode: Item})
class _:
"""
An item inside an extern block.
For example:
```rust
extern "C" {
fn foo();
static BAR: i32;
}
```
"""
@annotate(ExternItemList)
class _:
"""
A list of items inside an extern block.
For example:
```rust
extern "C" {
fn foo();
static BAR: i32;
}
```
"""
@annotate(FieldList)
class _:
"""
A list of fields in a struct or enum variant.
For example:
```rust
struct S {x: i32, y: i32}
// ^^^^^^^^^^^^^^^^
enum E {A(i32, i32)}
// ^^^^^^^^^^^^^
```
"""
@annotate(FnPtrTypeRepr)
class _:
"""
A function pointer type.
For example:
```rust
let f: fn(i32) -> i32;
// ^^^^^^^^^^^^^^
```
"""
@annotate(ForExpr, replace_bases={Expr: LoopingExpr}, cfg=True)
class _:
"""
A for loop expression.
For example:
```rust
for x in 0..10 {
println!("{}", x);
}
```
"""
label: drop
loop_body: drop
@annotate(ForTypeRepr)
class _:
"""
A function pointer type with a `for` modifier.
For example:
```rust
type RefOp<X> = for<'a> fn(&'a X) -> &'a X;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
```
"""
@annotate(FormatArgsArg, cfg=True)
@qltest.test_with(FormatArgsExpr)
class _:
"""
A FormatArgsArg. For example the `"world"` in:
```rust
format_args!("Hello, {}!", "world")
```
"""
@annotate(FormatArgsExpr, cfg=True)
class _:
"""
A FormatArgsExpr. For example:
```rust
format_args!("no args");
format_args!("{} foo {:?}", 1, 2);
format_args!("{b} foo {a:?}", a=1, b=2);
let (x, y) = (1, 42);
format_args!("{x}, {y}");
```
"""
formats: list["Format"] | child | synth
@annotate(GenericArg)
class _:
"""
A generic argument in a generic argument list.
For example:
```rust
Foo:: <u32, 3, 'a>
// ^^^^^^^^^^^
```
"""
@annotate(GenericParam)
class _:
"""
A generic parameter in a generic parameter list.
For example:
```rust
fn foo<T, U>(t: T, u: U) {}
// ^ ^
```
"""
@annotate(GenericParamList)
class _:
"""
A list of generic parameters. For example:
```rust
fn f<A, B>(a: A, b: B) {}
// ^^^^^^
type Foo<T1, T2> = (T1, T2);
// ^^^^^^^^
```
"""
@annotate(Impl)
class _:
"""
An `impl`` block.
For example:
```rust
impl MyTrait for MyType {
fn foo(&self) {}
}
```
"""
@annotate(ImplTraitTypeRepr)
class _:
"""
An `impl Trait` type.
For example:
```rust
fn foo() -> impl Iterator<Item = i32> { 0..10 }
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
```
"""
@annotate(InferTypeRepr)
class _:
"""
An inferred type (`_`).
For example:
```rust
let x: _ = 42;
// ^
```
"""
@annotate(Item, add_bases=(Addressable,))
class _:
"""
An item such as a function, struct, enum, etc.
For example:
```rust
fn foo() {}
struct S;
enum E {}
```
"""
attribute_macro_expansion: optional[MacroItems] | child | rust.detach
@annotate(ItemList)
class _:
"""
A list of items in a module or block.
For example:
```rust
mod m {
fn foo() {}
struct S;
}
```
"""
@annotate(LetElse)
class _:
"""
An else block in a let-else statement.
For example:
```rust
let Some(x) = opt else {
return;
};
// ^^^^^^
```
"""
@annotate(Lifetime)
class _:
"""
A lifetime annotation.
For example:
```rust
fn foo<'a>(x: &'a str) {}
// ^^ ^^
```
"""
@annotate(LifetimeArg)
class _:
"""
A lifetime argument in a generic argument list.
For example:
```rust
let text: Text<'a>;
// ^^
```
"""
@annotate(LifetimeParam)
class _:
"""
A lifetime parameter in a generic parameter list.
For example:
```rust
fn foo<'a>(x: &'a str) {}
// ^^
```
"""
@annotate(MacroCall, cfg=True, replace_bases={Item: None})
class _:
"""
A macro invocation.
For example:
```rust
println!("Hello, world!");
```
"""
macro_call_expansion: optional[AstNode] | child | rust.detach
@annotate(MacroItems)
@rust.doc_test_signature(None)
class _:
"""
A sequence of items generated by a macro. For example:
```rust
mod foo{
include!("common_definitions.rs");
#[an_attribute_macro]
fn foo() {
println!("Hello, world!");
}
#[derive(Debug)]
struct Bar;
}
```
"""
@annotate(MacroRules)
class _:
"""
A macro definition using the `macro_rules!` syntax.
```rust
macro_rules! my_macro {
() => {
println!("This is a macro!");
};
}
```
"""
class MacroBlockExpr(Expr):
"""
A sequence of statements generated by a `MacroCall`. For example:
```rust
macro_rules! my_macro {
() => {
let mut x = 40;
x += 2;
x
};
}
my_macro!(); // this macro expands to a sequence of statements (and an expression)
```
"""
__cfg__ = True
statements: list[Stmt] | child
tail_expr: optional[Expr] | child
@annotate(MacroTypeRepr)
class _:
"""
A type produced by a macro.
For example:
```rust
macro_rules! macro_type {
() => { i32 };
}
type T = macro_type!();
// ^^^^^^^^^^^^^
```
"""
@annotate(MatchArmList)
class _:
"""
A list of arms in a match expression.
For example:
```rust
match x {
1 => "one",
2 => "two",
_ => "other",
}
// ^^^^^^^^^^^
```
"""
@annotate(MatchGuard)
class _:
"""
A guard condition in a match arm.
For example:
```rust
match x {
y if y > 0 => "positive",
// ^^^^^^^
_ => "non-positive",
}
```
"""
@annotate(Meta)
class _:
"""
A meta item in an attribute.
For example:
```rust
#[unsafe(lint::name = "reason_for_bypass")]
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#[deprecated(since = "1.2.0", note = "Use bar instead", unsafe=true)]
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
fn foo() {
// ...
}
```
"""
@annotate(Name, cfg=True)
class _:
"""
An identifier name.
For example:
```rust
let foo = 1;
// ^^^
```
"""
@annotate(NameRef)
class _:
"""
A reference to a name.
For example:
```rust
foo();
//^^^
```
"""
@annotate(NeverTypeRepr)
class _:
"""
The never type `!`.
For example:
```rust
fn foo() -> ! { panic!() }
// ^
```
"""
class ParamBase(AstNode):
"""
A normal parameter, `Param`, or a self parameter `SelfParam`.
"""
attrs: list["Attr"] | child
type_repr: optional["TypeRepr"] | child
@annotate(ParamBase, cfg=True)
class _:
pass
@annotate(Param, replace_bases={AstNode: ParamBase}, cfg=True)
class _:
"""
A parameter in a function or method. For example `x` in:
```rust
fn new(x: T) -> Foo<T> {
// ...
}
```
"""
attrs: drop
type_repr: drop
@annotate(ParenExpr)
class _:
"""
A parenthesized expression.
For example:
```rust
(x + y)
```
"""
@annotate(ParenPat)
class _:
"""
A parenthesized pattern.
For example:
```rust
let (x) = 1;
// ^^^
```
"""
@annotate(ParenTypeRepr)
class _:
"""
A parenthesized type.
For example:
```rust
let x: (i32);
// ^^^^^
```
"""
@annotate(PathSegment)
@qltest.test_with(Path)
class _:
"""
A path segment, which is one part of a whole path.
For example:
- `HashMap`
- `HashMap<K, V>`
- `Fn(i32) -> i32`
- `widgets(..)`
- `<T as Iterator>`
"""
type_repr: optional["TypeRepr"] | child | rust.detach
trait_type_repr: optional["PathTypeRepr"] | child | rust.detach
@annotate(PathTypeRepr)
@qltest.test_with(Path)
class _:
"""
A path referring to a type. For example:
```rust
type X = std::collections::HashMap<i32, i32>;
type Y = X::Item;
```
"""
@annotate(PtrTypeRepr)
class _:
"""
A pointer type.
For example:
```rust
let p: *const i32;
let q: *mut i32;
// ^^^^^^^^^
```
"""
@annotate(StructExprFieldList)
class _:
"""
A list of fields in a struct expression.
For example:
```rust
Foo { a: 1, b: 2 }
// ^^^^^^^^^^^
```
"""
@annotate(StructField)
class _:
"""
A field in a struct declaration.
For example:
```rust
struct S { x: i32 }
// ^^^^^^^
```
"""
@annotate(StructFieldList)
class _:
"""
A list of fields in a struct declaration.
For example:
```rust
struct S { x: i32, y: i32 }
// ^^^^^^^^^^^^^^^
```
"""
@annotate(StructPatFieldList)
class _:
"""
A list of fields in a struct pattern.
For example:
```rust
let Foo { a, b } = foo;
// ^^^^^
```
"""
@annotate(RefTypeRepr)
class _:
"""
A reference type.
For example:
```rust
let r: &i32;
let m: &mut i32;
// ^^^^^^^^
```
"""
@annotate(Rename)
class _:
"""
A rename in a use declaration.
For example:
```rust
use foo as bar;
// ^^^^^^
```
"""
@annotate(RestPat, cfg=True)
class _:
"""
A rest pattern (`..`) in a tuple, slice, or struct pattern.
For example:
```rust
let (a, .., z) = (1, 2, 3);
// ^^
```
"""
@annotate(RetTypeRepr)
class _:
"""
A return type in a function signature.
For example:
```rust
fn foo() -> i32 { 0 }
// ^^^^^^
```
"""
@annotate(ReturnTypeSyntax)
class _:
"""
A return type notation `(..)` to reference or bound the type returned by a trait method
For example:
```rust
struct ReverseWidgets<F: Factory<widgets(..): DoubleEndedIterator>> {
factory: F,
}
impl<F> Factory for ReverseWidgets<F>
where
F: Factory<widgets(..): DoubleEndedIterator>,
{
fn widgets(&self) -> impl Iterator<Item = Widget> {
self.factory.widgets().rev()
}
}
```
"""
@annotate(SelfParam, replace_bases={AstNode: ParamBase}, cfg=True)
@rust.doc_test_signature(None)
class _:
"""
A `self` parameter. For example `self` in:
```rust
struct X;
impl X {
fn one(&self) {}
fn two(&mut self) {}
fn three(self) {}
fn four(mut self) {}
fn five<'a>(&'a self) {}
}
```
"""
attrs: drop
type_repr: drop
@annotate(SliceTypeRepr)
class _:
"""
A slice type.
For example:
```rust
let s: &[i32];
// ^^^^^
```
"""
@annotate(SourceFile)
class _:
"""
A source file.
For example:
```rust
// main.rs
fn main() {}
```
"""
@annotate(Static, replace_bases={Item: None})
class _:
"""
A static item declaration.
For example:
```rust
static X: i32 = 42;
```
"""
@annotate(StmtList)
class _:
"""
A list of statements in a block, with an optional tail expression at the
end that determines the block's value.
For example:
```rust
{
let x = 1;
let y = 2;
x + y
}
// ^^^^^^^^^
```
"""
statements: (
_
| doc("statements of this statement list")
| desc(
"""
The statements of a `StmtList` do not include any tail expression, which
can be accessed with predicates such as `getTailExpr`.
"""
)
)
tail_expr: (
_
| doc("tail expression of this statement list")
| desc(
"""
The tail expression is the expression at the end of a block, that
determines the block's value.
"""
)
)
@annotate(Struct, replace_bases={Item: None})
class _:
"""
A Struct. For example:
```rust
struct Point {
x: i32,
y: i32,
}
```
"""
field_list: _ | ql.db_table_name("struct_field_lists_")
attrs: drop
generic_param_list: drop
name: drop
visibility: drop
where_clause: drop
@annotate(TokenTree)
class _:
"""
A token tree in a macro definition or invocation.
For example:
```rust
println!("{} {}!", "Hello", "world");
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
```rust
macro_rules! foo { ($x:expr) => { $x + 1 }; }
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
"""
@annotate(Trait)
@rust.doc_test_signature(None)
class _:
"""
A Trait. For example:
```
trait Frobinizable {
type Frobinator;
type Result: Copy;
fn frobinize_with(&mut self, frobinator: &Self::Frobinator) -> Result;
}
pub trait Foo<T: Frobinizable> where T::Frobinator: Eq {}
```
"""
@annotate(TraitAlias)
class _:
"""
A trait alias.
For example:
```rust
trait Foo = Bar + Baz;
```
"""
@annotate(TryExpr, cfg=True)
class _:
"""
A try expression using the `?` operator.
For example:
```rust
let x = foo()?;
// ^
```
"""
@annotate(TupleField)
class _:
"""
A field in a tuple struct or tuple variant.
For example:
```rust
struct S(i32, String);
// ^^^ ^^^^^^
```
"""
@annotate(TupleFieldList)
class _:
"""
A list of fields in a tuple struct or tuple variant.
For example:
```rust
struct S(i32, String);
// ^^^^^^^^^^^^^
```
"""
@annotate(TupleTypeRepr)
class _:
"""
A tuple type.
For example:
```rust
let t: (i32, String);
// ^^^^^^^^^^^^^
```
"""
@annotate(TypeAlias, replace_bases={Item: None})
class _:
"""
A type alias. For example:
```rust
type Point = (u8, u8);
trait Trait {
type Output;
// ^^^^^^^^^^^
}
```
"""
@annotate(TypeArg)
class _:
"""
A type argument in a generic argument list.
For example:
```rust
Foo::<u32>
// ^^^
```
"""
@annotate(TypeBound)
class _:
"""
A type bound in a trait or generic parameter.
For example:
```rust
fn foo<T: Debug>(t: T) {}
// ^^^^^
fn bar(value: impl for<'a> From<&'a str>) {}
// ^^^^^^^^^^^^^^^^^^^^^
```
"""
@annotate(TypeBoundList)
class _:
"""
A list of type bounds.
For example:
```rust
fn foo<T: Debug + Clone>(t: T) {}
// ^^^^^^^^^^^^^
```
"""
@annotate(TypeParam)
class _:
"""
A type parameter in a generic parameter list.
For example:
```rust
fn foo<T>(t: T) {}
// ^
```
"""
@annotate(Union, replace_bases={Item: None})
class _:
"""
A union declaration.
For example:
```rust
union U { f1: u32, f2: f32 }
```
"""
attrs: drop
generic_param_list: drop
name: drop
visibility: drop
where_clause: drop
@annotate(Use)
class _:
"""
A `use` statement. For example:
```rust
use std::collections::HashMap;
```
"""
@annotate(UseTree)
class _:
"""
A `use` tree, that is, the part after the `use` keyword in a `use` statement. For example:
```rust
use std::collections::HashMap;
use std::collections::*;
use std::collections::HashMap as MyHashMap;
use std::collections::{self, HashMap, HashSet};
```
"""
@annotate(UseTreeList)
class _:
"""
A list of use trees in a use declaration.
For example:
```rust
use std::{fs, io};
// ^^^^^^^^
```
"""
@annotate(Variant, replace_bases={AstNode: Addressable})
class _:
"""
A variant in an enum declaration.
For example:
```rust
enum E { A, B(i32), C { x: i32 } }
// ^ ^^^^^^ ^^^^^^^^^^^^
```
"""
@annotate(VariantList)
class _:
"""
A list of variants in an enum declaration.
For example:
```rust
enum E { A, B, C }
// ^^^^^^^^^^^
```
"""
@annotate(Visibility)
class _:
"""
A visibility modifier.
For example:
```rust
pub struct S;
//^^^
```
"""
@annotate(WhereClause)
class _:
"""
A where clause in a generic declaration.
For example:
```rust
fn foo<T>(t: T) where T: Debug {}
// ^^^^^^^^^^^^^^
```
"""
@annotate(WherePred)
class _:
"""
A predicate in a where clause.
For example:
```rust
fn foo<T, U>(t: T, u: U) where T: Debug, U: Clone {}
// ^^^^^^^^ ^^^^^^^^
fn bar<T>(value: T) where for<'a> T: From<&'a str> {}
// ^^^^^^^^^^^^^^^^^^^^^^^^
```
"""
@annotate(WhileExpr, replace_bases={Expr: LoopingExpr}, cfg=True)
class _:
"""
A while loop expression.
For example:
```rust
while x < 10 {
x += 1;
}
```
"""
label: drop
loop_body: drop
@annotate(Function, add_bases=[Callable], replace_bases={Item: None})
class _:
param_list: drop
attrs: drop
has_implementation: (
predicate
| doc("this function has an implementation")
| desc(
"""
This is the same as `hasBody` for source code, but for library code (for which we always skip
the body), this will hold when the body was present in the original code.
"""
)
| rust.detach
)
@annotate(ClosureExpr, add_bases=[Callable])
class _:
param_list: drop
attrs: drop
@synth.on_arguments(parent="FormatArgsExpr", index=int, kind=int)
@qltest.test_with(FormatArgsExpr)
class FormatTemplateVariableAccess(PathExprBase):
pass
@synth.on_arguments(parent=FormatArgsExpr, index=int, text=string, offset=int)
@qltest.test_with(FormatArgsExpr)
class Format(Locatable):
"""
A format element in a formatting template. For example the `{}` in:
```rust
println!("Hello {}", "world");
```
or the `{value:#width$.precision$}` in:
```rust
println!("Value {value:#width$.precision$}");
```
"""
parent: FormatArgsExpr
index: int
argument_ref: (
optional["FormatArgument"]
| child
| desc(
"""
For example `name` and `0` in:
```rust
let name = "Alice";
println!("{name} in wonderland");
println!("{0} in wonderland", name);
```
"""
)
)
width_argument: (
optional["FormatArgument"]
| child
| desc(
"""
For example `width` and `1` in:
```rust
let width = 6;
println!("{:width$}", PI);
println!("{:1$}", PI, width);
```
"""
)
)
precision_argument: (
optional["FormatArgument"]
| child
| desc(
"""
For example `prec` and `1` in:
```rust
let prec = 6;
println!("{:.prec$}", PI);
println!("{:.1$}", PI, prec);
```
"""
)
)
@synth.on_arguments(
parent=FormatArgsExpr,
index=int,
kind=int,
name=string,
positional=boolean,
offset=int,
)
@qltest.test_with(FormatArgsExpr)
class FormatArgument(Locatable):
"""
An argument in a format element in a formatting template. For example the `width`, `precision`, and `value` in:
```rust
println!("Value {value:#width$.precision$}");
```
or the `0`, `1` and `2` in:
```rust
println!("Value {0:#1$.2$}", value, width, precision);
```
"""
parent: Format
variable: optional[FormatTemplateVariableAccess] | child
@annotate(MacroDef)
class _:
"""
A Rust 2.0 style declarative macro definition.
For example:
```rust
pub macro vec_of_two($element:expr) {
vec![$element, $element]
}
```
"""
@annotate(MacroExpr, cfg=True)
class _:
"""
A macro expression, representing the invocation of a macro that produces an expression.
For example:
```rust
let y = vec![1, 2, 3];
```
"""
@annotate(MacroPat, cfg=True)
class _:
"""
A macro pattern, representing the invocation of a macro that produces a pattern.
For example:
```rust
macro_rules! my_macro {
() => {
Ok(_)
};
}
match x {
my_macro!() => "matched",
// ^^^^^^^^^^^
_ => "not matched",
}
```
"""
@annotate(ParamList)
class _:
"""
A list of parameters in a function, method, or closure declaration.
For example:
```rust
fn foo(x: i32, y: i32) {}
// ^^^^^^^^^^^^^
```
"""
@annotate(AsmDirSpec)
class _:
"""
An inline assembly direction specifier.
For example:
```rust
use core::arch::asm;
asm!("mov {input:x}, {input:x}", output = out(reg) x, input = in(reg) y);
// ^^^ ^^
```
"""
@annotate(AsmOperandExpr)
class _:
"""
An operand expression in an inline assembly block.
For example:
```rust
use core::arch::asm;
asm!("mov {0}, {1}", out(reg) x, in(reg) y);
// ^ ^
```
"""
@annotate(AsmOption)
class _:
"""
An option in an inline assembly block.
For example:
```rust
use core::arch::asm;
asm!("", options(nostack, nomem));
// ^^^^^^^^^^^^^^^^
```
"""
@annotate(AsmRegSpec)
class _:
"""
A register specification in an inline assembly block.
For example:
```rust
use core::arch::asm;
asm!("mov {0}, {1}", out("eax") x, in(EBX) y);
// ^^^ ^^^
```
"""
@annotate(AsmClobberAbi)
class _:
"""
A clobbered ABI in an inline assembly block.
For example:
```rust
use core::arch::asm;
asm!("", clobber_abi("C"));
// ^^^^^^^^^^^^^^^^
```
"""
@annotate(AsmConst)
class _:
"""
A constant operand in an inline assembly block.
For example:
```rust
use core::arch::asm;
asm!("mov eax, {const}", const 42);
// ^^^^^^^
```
"""
@annotate(AsmLabel)
class _:
"""
A label in an inline assembly block.
For example:
```rust
use core::arch::asm;
asm!(
"jmp {}",
label { println!("Jumped from asm!"); }
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
);
```
"""
@annotate(AsmOperandNamed)
class _:
"""
A named operand in an inline assembly block.
For example:
```rust
use core::arch::asm;
asm!("mov {0:x}, {input:x}", out(reg) x, input = in(reg) y);
// ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
```
"""
@annotate(AsmOptionsList)
class _:
"""
A list of options in an inline assembly block.
For example:
```rust
use core::arch::asm;
asm!("", options(nostack, nomem));
// ^^^^^^^^^^^^^^^^
```
"""
@annotate(AsmRegOperand)
class _:
"""
A register operand in an inline assembly block.
For example:
```rust
use core::arch::asm;
asm!("mov {0}, {1}", out(reg) x, in(reg) y);
// ^ ^
```
"""
@annotate(AsmSym)
class _:
"""
A symbol operand in an inline assembly block.
For example:
```rust
use core::arch::asm;
asm!("call {sym}", sym = sym my_function);
// ^^^^^^^^^^^^^^^^^^^^^^
```
"""
@annotate(UseBoundGenericArgs)
class _:
"""
A use<..> bound to control which generic parameters are captured by an impl Trait return type.
For example:
```rust
pub fn hello<'a, T, const N: usize>() -> impl Sized + use<'a, T, N> { 0 }
// ^^^^^^^^
```
"""
@annotate(ParenthesizedArgList)
class _:
"""
A parenthesized argument list as used in function traits.
For example:
```rust
fn call_with_42<F>(f: F) -> i32
where
F: Fn(i32, String) -> i32,
// ^^^^^^^^^^^
{
f(42, "Don't panic".to_string())
}
```
"""
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/mirrors/CodeQL.git
git@gitee.com:mirrors/CodeQL.git
mirrors
CodeQL
CodeQL
main

搜索帮助