Skip to content

Commit 0c8e886

Browse files
committed
Rust: fix QLdoc examples
1 parent 0157c16 commit 0c8e886

File tree

1 file changed

+69
-27
lines changed

1 file changed

+69
-27
lines changed

rust/schema/annotations.py

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,8 @@ class _:
644644
An inline assembly expression. For example:
645645
```rust
646646
unsafe {
647-
builtin # asm(_);
647+
#[inline(always)]
648+
builtin # asm("cmp {0}, {1}", in(reg) a, in(reg) b);
648649
}
649650
```
650651
"""
@@ -932,8 +933,13 @@ class _:
932933
933934
For example:
934935
```rust
935-
<T as Iterator>::Item
936-
// ^^^^
936+
fn process_cloneable<T>(iter: T)
937+
where
938+
T: Iterator<Item: Clone>
939+
// ^^^^^^^^^^^
940+
{
941+
// ...
942+
}
937943
```
938944
"""
939945

@@ -959,8 +965,13 @@ class _:
959965
960966
For example:
961967
```rust
962-
for <'a> |x: &'a u32 | x
963-
// ^^^^^^
968+
let print_any = for<T: std::fmt::Debug> |x: T| {
969+
// ^^^^^^^^^^^^^^^^^^^^^^^
970+
println!("{:?}", x);
971+
};
972+
973+
print_any(42);
974+
print_any("hello");
964975
```
965976
"""
966977

@@ -1135,8 +1146,13 @@ class _:
11351146
11361147
For example:
11371148
```rust
1138-
for <'a> fn(&'a str)
1139-
// ^^^^^
1149+
fn foo<T>(value: T)
1150+
where
1151+
T: for<'a> Fn(&'a str) -> &'a str
1152+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1153+
{
1154+
// ...
1155+
}
11401156
```
11411157
"""
11421158

@@ -1311,8 +1327,8 @@ class _:
13111327
13121328
For example:
13131329
```rust
1314-
Foo<'a>
1315-
// ^^
1330+
let text: Text<'a>;
1331+
// ^^
13161332
```
13171333
"""
13181334

@@ -1399,6 +1415,9 @@ class _:
13991415
14001416
For example:
14011417
```rust
1418+
macro_rules! macro_type {
1419+
() => { i32 };
1420+
}
14021421
type T = macro_type!();
14031422
// ^^^^^^^^^^^^^
14041423
```
@@ -1445,8 +1464,13 @@ class _:
14451464
14461465
For example:
14471466
```rust
1448-
#[cfg(feature = "foo")]
1449-
// ^^^^^^^^^^^^^^^
1467+
#[unsafe(lint::name = "reason_for_bypass")]
1468+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1469+
#[deprecated(since = "1.2.0", note = "Use bar instead", unsafe=true)]
1470+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1471+
fn foo() {
1472+
// ...
1473+
}
14501474
```
14511475
"""
14521476

@@ -1578,8 +1602,8 @@ class _:
15781602
"""
15791603
A path referring to a type. For example:
15801604
```rust
1581-
let x: (i32);
1582-
// ^^^
1605+
type X = std::collections::HashMap<i32, i32>;
1606+
type Y = X::Item;
15831607
```
15841608
"""
15851609

@@ -2187,14 +2211,12 @@ class FormatArgument(Locatable):
21872211
@annotate(MacroDef)
21882212
class _:
21892213
"""
2190-
A macro definition using the `macro_rules!` or similar syntax.
2214+
A Rust 2.0 style declarative macro definition.
21912215
21922216
For example:
21932217
```rust
2194-
macro_rules! my_macro {
2195-
() => {
2196-
println!("This is a macro!");
2197-
};
2218+
pub macro vec_of_two($element:expr) {
2219+
vec![$element, $element]
21982220
}
21992221
```
22002222
"""
@@ -2219,8 +2241,14 @@ class _:
22192241
22202242
For example:
22212243
```rust
2244+
macro_rules! my_macro {
2245+
() => {
2246+
Ok(_)
2247+
};
2248+
}
22222249
match x {
22232250
my_macro!() => "matched",
2251+
// ^^^^^^^^^^^
22242252
_ => "not matched",
22252253
}
22262254
```
@@ -2243,12 +2271,13 @@ class _:
22432271
@annotate(AsmDirSpec)
22442272
class _:
22452273
"""
2246-
An inline assembly directive specification.
2274+
An inline assembly direction specifier.
22472275
22482276
For example:
22492277
```rust
2250-
asm!("nop");
2251-
// ^^^^^
2278+
use core::arch::asm;
2279+
asm!("mov {input:x}, {input:x}", output = out(reg) x, input = in(reg) y);
2280+
// ^^^ ^^
22522281
```
22532282
"""
22542283

@@ -2260,6 +2289,7 @@ class _:
22602289
22612290
For example:
22622291
```rust
2292+
use core::arch::asm;
22632293
asm!("mov {0}, {1}", out(reg) x, in(reg) y);
22642294
// ^ ^
22652295
```
@@ -2273,6 +2303,7 @@ class _:
22732303
22742304
For example:
22752305
```rust
2306+
use core::arch::asm;
22762307
asm!("", options(nostack, nomem));
22772308
// ^^^^^^^^^^^^^^^^
22782309
```
@@ -2286,8 +2317,9 @@ class _:
22862317
22872318
For example:
22882319
```rust
2289-
asm!("mov {0}, {1}", out("eax") x, in("ebx") y);
2290-
// ^^^ ^^^
2320+
use core::arch::asm;
2321+
asm!("mov {0}, {1}", out("eax") x, in(EBX) y);
2322+
// ^^^ ^^^
22912323
```
22922324
"""
22932325

@@ -2299,6 +2331,7 @@ class _:
22992331
23002332
For example:
23012333
```rust
2334+
use core::arch::asm;
23022335
asm!("", clobber_abi("C"));
23032336
// ^^^^^^^^^^^^^^^^
23042337
```
@@ -2312,6 +2345,7 @@ class _:
23122345
23132346
For example:
23142347
```rust
2348+
use core::arch::asm;
23152349
asm!("mov eax, {const}", const 42);
23162350
// ^^^^^^^
23172351
```
@@ -2325,8 +2359,12 @@ class _:
23252359
23262360
For example:
23272361
```rust
2328-
asm!("jmp {label}", label = sym my_label);
2329-
// ^^^^^^^^^^^^^^^^^^^^^^
2362+
use core::arch::asm;
2363+
asm!(
2364+
"jmp {}",
2365+
label { println!("Jumped from asm!"); }
2366+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2367+
);
23302368
```
23312369
"""
23322370

@@ -2338,8 +2376,9 @@ class _:
23382376
23392377
For example:
23402378
```rust
2341-
asm!("mov {out}, {in}", out = out(reg) x, in = in(reg) y);
2342-
// ^^^^^ ^^^^
2379+
use core::arch::asm;
2380+
asm!("mov {0:x}, {input:x}", out(reg) x, input = in(reg) y);
2381+
// ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
23432382
```
23442383
"""
23452384

@@ -2351,6 +2390,7 @@ class _:
23512390
23522391
For example:
23532392
```rust
2393+
use core::arch::asm;
23542394
asm!("", options(nostack, nomem));
23552395
// ^^^^^^^^^^^^^^^^
23562396
```
@@ -2364,6 +2404,7 @@ class _:
23642404
23652405
For example:
23662406
```rust
2407+
use core::arch::asm;
23672408
asm!("mov {0}, {1}", out(reg) x, in(reg) y);
23682409
// ^ ^
23692410
```
@@ -2377,6 +2418,7 @@ class _:
23772418
23782419
For example:
23792420
```rust
2421+
use core::arch::asm;
23802422
asm!("call {sym}", sym = sym my_function);
23812423
// ^^^^^^^^^^^^^^^^^^^^^^
23822424
```

0 commit comments

Comments
 (0)