Skip to content

Commit ac6cab0

Browse files
author
Keegan McAllister
committed
borrowck/README.md: Fix display of code on GitHub
1 parent 160cf96 commit ac6cab0

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/librustc_borrowck/borrowck/README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Here `x` represents some variable, `LV.f` is a field reference,
5353
and `*LV` is a pointer dereference. There is no auto-deref or other
5454
niceties. This means that if you have a type like:
5555

56-
```text
56+
```rust
5757
struct S { f: uint }
5858
```
5959

@@ -82,13 +82,13 @@ SD = struct S<'LT...> { (f: TY)... }
8282

8383
Now, imagine we had a program like this:
8484

85-
```text
85+
```rust
8686
struct Foo { f: uint, g: uint }
8787
...
8888
'a: {
89-
let mut x: Box<Foo> = ...;
90-
let y = &mut (*x).f;
91-
x = ...;
89+
let mut x: Box<Foo> = ...;
90+
let y = &mut (*x).f;
91+
x = ...;
9292
}
9393
```
9494

@@ -507,7 +507,7 @@ specify that the lifetime of the loan must be less than the lifetime
507507
of the `&Ty` pointer. In simple cases, this clause is redundant, since
508508
the `LIFETIME()` function will already enforce the required rule:
509509

510-
```
510+
```rust
511511
fn foo(point: &'a Point) -> &'static f32 {
512512
&point.x // Error
513513
}
@@ -517,7 +517,7 @@ The above example fails to compile both because of clause (1) above
517517
but also by the basic `LIFETIME()` check. However, in more advanced
518518
examples involving multiple nested pointers, clause (1) is needed:
519519

520-
```
520+
```rust
521521
fn foo(point: &'a &'b mut Point) -> &'b f32 {
522522
&point.x // Error
523523
}
@@ -536,7 +536,7 @@ which is only `'a`, not `'b`. Hence this example yields an error.
536536
As a final twist, consider the case of two nested *immutable*
537537
pointers, rather than a mutable pointer within an immutable one:
538538

539-
```
539+
```rust
540540
fn foo(point: &'a &'b Point) -> &'b f32 {
541541
&point.x // OK
542542
}
@@ -558,7 +558,7 @@ The rules pertaining to `LIFETIME` exist to ensure that we don't
558558
create a borrowed pointer that outlives the memory it points at. So
559559
`LIFETIME` prevents a function like this:
560560

561-
```
561+
```rust
562562
fn get_1<'a>() -> &'a int {
563563
let x = 1;
564564
&x
@@ -578,7 +578,7 @@ after we return and hence the remaining code in `'a` cannot possibly
578578
mutate it. This distinction is important for type checking functions
579579
like this one:
580580

581-
```
581+
```rust
582582
fn inc_and_get<'a>(p: &'a mut Point) -> &'a int {
583583
p.x += 1;
584584
&p.x
@@ -631,7 +631,7 @@ maximum of `LT'`.
631631

632632
Here is a concrete example of a bug this rule prevents:
633633

634-
```
634+
```rust
635635
// Test region-reborrow-from-shorter-mut-ref.rs:
636636
fn copy_pointer<'a,'b,T>(x: &'a mut &'b mut T) -> &'b mut T {
637637
&mut **p // ERROR due to clause (1)
@@ -659,7 +659,7 @@ ways to violate the rules is to move the base pointer to a new name
659659
and access it via that new name, thus bypassing the restrictions on
660660
the old name. Here is an example:
661661

662-
```
662+
```rust
663663
// src/test/compile-fail/borrowck-move-mut-base-ptr.rs
664664
fn foo(t0: &mut int) {
665665
let p: &int = &*t0; // Freezes `*t0`
@@ -679,7 +679,7 @@ danger is to mutably borrow the base path. This can lead to two bad
679679
scenarios. The most obvious is that the mutable borrow itself becomes
680680
another path to access the same data, as shown here:
681681

682-
```
682+
```rust
683683
// src/test/compile-fail/borrowck-mut-borrow-of-mut-base-ptr.rs
684684
fn foo<'a>(mut t0: &'a mut int,
685685
mut t1: &'a mut int) {
@@ -700,7 +700,7 @@ of `t0`. Hence the claim `&mut t0` is illegal.
700700
Another danger with an `&mut` pointer is that we could swap the `t0`
701701
value away to create a new path:
702702

703-
```
703+
```rust
704704
// src/test/compile-fail/borrowck-swap-mut-base-ptr.rs
705705
fn foo<'a>(mut t0: &'a mut int,
706706
mut t1: &'a mut int) {
@@ -718,7 +718,7 @@ careful to ensure this example is still illegal.
718718
referent is claimed, even freezing the base pointer can be dangerous,
719719
as shown in the following example:
720720

721-
```
721+
```rust
722722
// src/test/compile-fail/borrowck-borrow-of-mut-base-ptr.rs
723723
fn foo<'a>(mut t0: &'a mut int,
724724
mut t1: &'a mut int) {
@@ -741,7 +741,7 @@ which is clearly unsound.
741741
However, it is not always unsafe to freeze the base pointer. In
742742
particular, if the referent is frozen, there is no harm in it:
743743

744-
```
744+
```rust
745745
// src/test/run-pass/borrowck-borrow-of-mut-base-ptr-safe.rs
746746
fn foo<'a>(mut t0: &'a mut int,
747747
mut t1: &'a mut int) {
@@ -757,7 +757,7 @@ thing `t2` can be used for is to further freeze `*t0`, which is
757757
already frozen. In particular, we cannot assign to `*t0` through the
758758
new alias `t2`, as demonstrated in this test case:
759759

760-
```
760+
```rust
761761
// src/test/run-pass/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs
762762
fn foo(t0: & &mut int) {
763763
let t1 = t0;
@@ -830,7 +830,7 @@ moves/uninitializations of the variable that is being used.
830830

831831
Let's look at a simple example:
832832

833-
```
833+
```rust
834834
fn foo(a: Box<int>) {
835835
let b: Box<int>; // Gen bit 0.
836836

0 commit comments

Comments
 (0)