Skip to content

Commit 4ee4fc4

Browse files
committed
Remove feature gated examples from the reference
Fixes rust-lang#24573
1 parent a81ce5f commit 4ee4fc4

File tree

1 file changed

+7
-165
lines changed

1 file changed

+7
-165
lines changed

src/doc/reference.md

Lines changed: 7 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -973,28 +973,6 @@ Use declarations support a number of convenient shortcuts:
973973
and their immediate parent module, using the `self` keyword, such as
974974
`use a::b::{self, c, d};`
975975

976-
An example of `use` declarations:
977-
978-
```
979-
# #![feature(core)]
980-
use std::option::Option::{Some, None};
981-
use std::collections::hash_map::{self, HashMap};
982-
983-
fn foo<T>(_: T){}
984-
fn bar(map1: HashMap<String, usize>, map2: hash_map::HashMap<String, usize>){}
985-
986-
fn main() {
987-
// Equivalent to 'foo(vec![std::option::Option::Some(1.0f64),
988-
// std::option::Option::None]);'
989-
foo(vec![Some(1.0f64), None]);
990-
991-
// Both `hash_map` and `HashMap` are in scope.
992-
let map1 = HashMap::new();
993-
let map2 = hash_map::HashMap::new();
994-
bar(map1, map2);
995-
}
996-
```
997-
998976
Like items, `use` declarations are private to the containing module, by
999977
default. Also like items, a `use` declaration can be public, if qualified by
1000978
the `pub` keyword. Such a `use` declaration serves to _re-export_ a name. A
@@ -1030,35 +1008,6 @@ parent modules respectively. All rules regarding accessing declared modules in
10301008
`use` declarations applies to both module declarations and `extern crate`
10311009
declarations.
10321010

1033-
An example of what will and will not work for `use` items:
1034-
1035-
```
1036-
# #![feature(core)]
1037-
# #![allow(unused_imports)]
1038-
use foo::core::iter; // good: foo is at the root of the crate
1039-
use foo::baz::foobaz; // good: foo is at the root of the crate
1040-
1041-
mod foo {
1042-
extern crate core;
1043-
1044-
use foo::core::iter; // good: foo is at crate root
1045-
// use core::iter; // bad: core is not at the crate root
1046-
use self::baz::foobaz; // good: self refers to module 'foo'
1047-
use foo::bar::foobar; // good: foo is at crate root
1048-
1049-
pub mod bar {
1050-
pub fn foobar() { }
1051-
}
1052-
1053-
pub mod baz {
1054-
use super::bar::foobar; // good: super refers to module 'foo'
1055-
pub fn foobaz() { }
1056-
}
1057-
}
1058-
1059-
fn main() {}
1060-
```
1061-
10621011
### Functions
10631012

10641013
A _function item_ defines a sequence of [statements](#statements) and an
@@ -1378,16 +1327,13 @@ a = Animal::Cat;
13781327
Enumeration constructors can have either named or unnamed fields:
13791328

13801329
```
1381-
# #![feature(struct_variant)]
1382-
# fn main() {
13831330
enum Animal {
13841331
Dog (String, f64),
13851332
Cat { name: String, weight: f64 }
13861333
}
13871334
13881335
let mut a: Animal = Animal::Dog("Cocoa".to_string(), 37.2);
13891336
a = Animal::Cat { name: "Spotty".to_string(), weight: 2.7 };
1390-
# }
13911337
```
13921338

13931339
In this example, `Cat` is a _struct-like enum variant_,
@@ -1727,17 +1673,6 @@ Functions within external blocks are declared in the same way as other Rust
17271673
functions, with the exception that they may not have a body and are instead
17281674
terminated by a semicolon.
17291675

1730-
```
1731-
# #![feature(libc)]
1732-
extern crate libc;
1733-
use libc::{c_char, FILE};
1734-
1735-
extern {
1736-
fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE;
1737-
}
1738-
# fn main() {}
1739-
```
1740-
17411676
Functions within external blocks may be called by Rust code, just like
17421677
functions defined in Rust. The Rust compiler automatically translates between
17431678
the Rust ABI and the foreign ABI.
@@ -2339,7 +2274,7 @@ considered a full-fledged language feature.
23392274

23402275
For this reason, Rust recognizes a special crate-level attribute of the form:
23412276

2342-
```{.ignore}
2277+
```ignore
23432278
#![feature(feature1, feature2, feature3)]
23442279
```
23452280

@@ -3241,55 +3176,17 @@ expression.
32413176

32423177
In a pattern whose head expression has an `enum` type, a placeholder (`_`)
32433178
stands for a *single* data field, whereas a wildcard `..` stands for *all* the
3244-
fields of a particular variant. For example:
3245-
3246-
```
3247-
#![feature(box_patterns)]
3248-
#![feature(box_syntax)]
3249-
enum List<X> { Nil, Cons(X, Box<List<X>>) }
3250-
3251-
fn main() {
3252-
let x: List<i32> = List::Cons(10, box List::Cons(11, box List::Nil));
3253-
3254-
match x {
3255-
List::Cons(_, box List::Nil) => panic!("singleton list"),
3256-
List::Cons(..) => return,
3257-
List::Nil => panic!("empty list")
3258-
}
3259-
}
3260-
```
3261-
3262-
The first pattern matches lists constructed by applying `Cons` to any head
3263-
value, and a tail value of `box Nil`. The second pattern matches _any_ list
3264-
constructed with `Cons`, ignoring the values of its arguments. The difference
3265-
between `_` and `..` is that the pattern `C(_)` is only type-correct if `C` has
3266-
exactly one argument, while the pattern `C(..)` is type-correct for any enum
3267-
variant `C`, regardless of how many arguments `C` has.
3179+
fields of a particular variant. The difference between `_` and `..` is that the
3180+
pattern `C(_)` is only type-correct if `C` has exactly one argument, while the
3181+
pattern `C(..)` is type-correct for any enum variant `C`, regardless of how
3182+
many arguments `C` has.
32683183

32693184
Used inside an array pattern, `..` stands for any number of elements, when the
32703185
`advanced_slice_patterns` feature gate is turned on. This wildcard can be used
32713186
at most once for a given array, which implies that it cannot be used to
32723187
specifically match elements that are at an unknown distance from both ends of a
32733188
array, like `[.., 42, ..]`. If preceded by a variable name, it will bind the
3274-
corresponding slice to the variable. Example:
3275-
3276-
```
3277-
# #![feature(advanced_slice_patterns, slice_patterns)]
3278-
fn is_symmetric(list: &[u32]) -> bool {
3279-
match list {
3280-
[] | [_] => true,
3281-
[x, inside.., y] if x == y => is_symmetric(inside),
3282-
_ => false
3283-
}
3284-
}
3285-
3286-
fn main() {
3287-
let sym = &[0, 1, 4, 2, 4, 1, 0];
3288-
let not_sym = &[0, 1, 7, 2, 4, 1, 0];
3289-
assert!(is_symmetric(sym));
3290-
assert!(!is_symmetric(not_sym));
3291-
}
3292-
```
3189+
corresponding slice to the variable.
32933190

32943191
A `match` behaves differently depending on whether or not the head expression
32953192
is an [lvalue or an rvalue](#lvalues,-rvalues-and-temporaries). If the head
@@ -3305,68 +3202,13 @@ possible, it is preferable to match on lvalues, as the lifetime of these
33053202
matches inherits the lifetime of the lvalue, rather than being restricted to
33063203
the inside of the match.
33073204

3308-
An example of a `match` expression:
3309-
3310-
```
3311-
#![feature(box_patterns)]
3312-
#![feature(box_syntax)]
3313-
# fn process_pair(a: i32, b: i32) { }
3314-
# fn process_ten() { }
3315-
3316-
enum List<X> { Nil, Cons(X, Box<List<X>>) }
3317-
3318-
fn main() {
3319-
let x: List<i32> = List::Cons(10, box List::Cons(11, box List::Nil));
3320-
3321-
match x {
3322-
List::Cons(a, box List::Cons(b, _)) => {
3323-
process_pair(a, b);
3324-
}
3325-
List::Cons(10, _) => {
3326-
process_ten();
3327-
}
3328-
List::Nil => {
3329-
return;
3330-
}
3331-
_ => {
3332-
panic!();
3333-
}
3334-
}
3335-
}
3336-
```
3337-
33383205
Patterns that bind variables default to binding to a copy or move of the
33393206
matched value (depending on the matched value's type). This can be changed to
33403207
bind to a reference by using the `ref` keyword, or to a mutable reference using
33413208
`ref mut`.
33423209

33433210
Subpatterns can also be bound to variables by the use of the syntax `variable @
3344-
subpattern`. For example:
3345-
3346-
```
3347-
#![feature(box_patterns)]
3348-
#![feature(box_syntax)]
3349-
3350-
enum List { Nil, Cons(u32, Box<List>) }
3351-
3352-
fn is_sorted(list: &List) -> bool {
3353-
match *list {
3354-
List::Nil | List::Cons(_, box List::Nil) => true,
3355-
List::Cons(x, ref r @ box List::Cons(_, _)) => {
3356-
match *r {
3357-
box List::Cons(y, _) => (x <= y) && is_sorted(&**r),
3358-
_ => panic!()
3359-
}
3360-
}
3361-
}
3362-
}
3363-
3364-
fn main() {
3365-
let a = List::Cons(6, box List::Cons(7, box List::Cons(42, box List::Nil)));
3366-
assert!(is_sorted(&a));
3367-
}
3368-
3369-
```
3211+
subpattern`.
33703212

33713213
Patterns can also dereference pointers by using the `&`, `&mut` and `box`
33723214
symbols, as appropriate. For example, these two matches on `x: &i32` are

0 commit comments

Comments
 (0)