Skip to content

Commit a12a4dd

Browse files
committed
auto merge of #16537 : jakub-/rust/use-mod-manual, r=alexcrichton
2 parents 921240e + 7606f58 commit a12a4dd

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/doc/rust.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,9 @@ use_decl : "pub" ? "use" [ path "as" ident
924924
925925
path_glob : ident [ "::" [ path_glob
926926
| '*' ] ] ?
927-
| '{' ident [ ',' ident ] * '}' ;
927+
| '{' path_item [ ',' path_item ] * '}' ;
928+
929+
path_item : ident | "mod" ;
928930
~~~~
929931

930932
A _use declaration_ creates one or more local name bindings synonymous
@@ -943,14 +945,18 @@ Use declarations support a number of convenient shortcuts:
943945
* Simultaneously binding a list of paths differing only in their final element,
944946
using the glob-like brace syntax `use a::b::{c,d,e,f};`
945947
* Binding all paths matching a given prefix, using the asterisk wildcard syntax `use a::b::*;`
948+
* Simultaneously binding a list of paths differing only in their final element
949+
and their immediate parent module, using the `mod` keyword, such as `use a::b::{mod, c, d};`
946950

947951
An example of `use` declarations:
948952

949953
~~~~
950954
use std::iter::range_step;
951955
use std::option::{Some, None};
956+
use std::collections::hashmap::{mod, HashMap};
952957
953958
# fn foo<T>(_: T){}
959+
# fn bar(map: HashMap<String, uint>, set: hashmap::HashSet<String>){}
954960
955961
fn main() {
956962
// Equivalent to 'std::iter::range_step(0u, 10u, 2u);'
@@ -959,6 +965,11 @@ fn main() {
959965
// Equivalent to 'foo(vec![std::option::Some(1.0f64),
960966
// std::option::None]);'
961967
foo(vec![Some(1.0f64), None]);
968+
969+
// Both `hash` and `HashMap` are in scope.
970+
let map = HashMap::new();
971+
let set = hashmap::HashSet::new();
972+
bar(map, set);
962973
}
963974
~~~~
964975

0 commit comments

Comments
 (0)