Skip to content

Commit ab4dbab

Browse files
committed
---
yaml --- r: 114527 b: refs/heads/master c: 30bf73f h: refs/heads/master i: 114525: 86d6f4f 114523: 559f0aa 114519: 93859e1 114511: 89b582a 114495: eba572b v: v3
1 parent 8e5a818 commit ab4dbab

File tree

16 files changed

+282
-41
lines changed

16 files changed

+282
-41
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 926504c8853458dcde5f4ab66a10e11a6fcda2e7
2+
refs/heads/master: 30bf73fd789ad1414284f59b005e85304ff963ad
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ec0258a381b88b5574e3f8ce72ae553ac3a574b7
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17

trunk/src/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ let ys = xs;
11061106
11071107
xs = Nil;
11081108
1109-
// `xs` can be used again
1109+
// `xs` can't be used again
11101110
~~~
11111111

11121112
A destructor call will only occur for a variable that has not been moved from,

trunk/src/librustc/middle/check_match.rs

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,18 @@ fn default(cx: &MatchCheckCtxt, r: &[@Pat]) -> Option<Vec<@Pat> > {
863863

864864
fn check_local(cx: &mut MatchCheckCtxt, loc: &Local) {
865865
visit::walk_local(cx, loc, ());
866-
if is_refutable(cx, loc.pat) {
867-
cx.tcx.sess.span_err(loc.pat.span,
868-
"refutable pattern in local binding");
866+
867+
let name = match loc.source {
868+
LocalLet => "local",
869+
LocalFor => "`for` loop"
870+
};
871+
872+
let mut spans = vec![];
873+
find_refutable(cx, loc.pat, &mut spans);
874+
875+
for span in spans.iter() {
876+
cx.tcx.sess.span_err(*span,
877+
format!("refutable pattern in {} binding", name).as_slice());
869878
}
870879

871880
// Check legality of move bindings.
@@ -879,53 +888,65 @@ fn check_fn(cx: &mut MatchCheckCtxt,
879888
sp: Span) {
880889
visit::walk_fn(cx, kind, decl, body, sp, ());
881890
for input in decl.inputs.iter() {
882-
if is_refutable(cx, input.pat) {
883-
cx.tcx.sess.span_err(input.pat.span,
891+
let mut spans = vec![];
892+
find_refutable(cx, input.pat, &mut spans);
893+
894+
for span in spans.iter() {
895+
cx.tcx.sess.span_err(*span,
884896
"refutable pattern in function argument");
885897
}
886898
}
887899
}
888900

889-
fn is_refutable(cx: &MatchCheckCtxt, pat: &Pat) -> bool {
901+
fn find_refutable(cx: &MatchCheckCtxt, pat: &Pat, spans: &mut Vec<Span>) {
902+
macro_rules! this_pattern {
903+
() => {
904+
{
905+
spans.push(pat.span);
906+
return
907+
}
908+
}
909+
}
890910
let opt_def = cx.tcx.def_map.borrow().find_copy(&pat.id);
891911
match opt_def {
892912
Some(DefVariant(enum_id, _, _)) => {
893913
if ty::enum_variants(cx.tcx, enum_id).len() != 1u {
894-
return true;
914+
this_pattern!()
895915
}
896916
}
897-
Some(DefStatic(..)) => return true,
917+
Some(DefStatic(..)) => this_pattern!(),
898918
_ => ()
899919
}
900920

901921
match pat.node {
902922
PatUniq(sub) | PatRegion(sub) | PatIdent(_, _, Some(sub)) => {
903-
is_refutable(cx, sub)
923+
find_refutable(cx, sub, spans)
904924
}
905-
PatWild | PatWildMulti | PatIdent(_, _, None) => { false }
925+
PatWild | PatWildMulti | PatIdent(_, _, None) => {}
906926
PatLit(lit) => {
907927
match lit.node {
908928
ExprLit(lit) => {
909929
match lit.node {
910-
LitNil => false, // `()`
911-
_ => true,
930+
LitNil => {} // `()`
931+
_ => this_pattern!(),
912932
}
913933
}
914-
_ => true,
934+
_ => this_pattern!(),
915935
}
916936
}
917-
PatRange(_, _) => { true }
937+
PatRange(_, _) => { this_pattern!() }
918938
PatStruct(_, ref fields, _) => {
919-
fields.iter().any(|f| is_refutable(cx, f.pat))
920-
}
921-
PatTup(ref elts) => {
922-
elts.iter().any(|elt| is_refutable(cx, *elt))
939+
for f in fields.iter() {
940+
find_refutable(cx, f.pat, spans);
941+
}
923942
}
924-
PatEnum(_, Some(ref args)) => {
925-
args.iter().any(|a| is_refutable(cx, *a))
943+
PatTup(ref elts) | PatEnum(_, Some(ref elts))=> {
944+
for elt in elts.iter() {
945+
find_refutable(cx, *elt, spans)
946+
}
926947
}
927-
PatEnum(_,_) => { false }
928-
PatVec(..) => { true }
948+
PatEnum(_,_) => {}
949+
PatVec(..) => { this_pattern!() }
929950
}
930951
}
931952

trunk/src/librustc/middle/privacy.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,23 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
297297
}
298298
}
299299

300+
ast::ItemTy(ref ty, _) if public_first => {
301+
match ty.node {
302+
ast::TyPath(_, _, id) => {
303+
match self.tcx.def_map.borrow().get_copy(&id) {
304+
ast::DefPrimTy(..) => {},
305+
def => {
306+
let did = def_id_of_def(def);
307+
if is_local(did) {
308+
self.exported_items.insert(did.node);
309+
}
310+
}
311+
}
312+
}
313+
_ => {}
314+
}
315+
}
316+
300317
_ => {}
301318
}
302319

trunk/src/libstd/str.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,25 @@ Unicode string manipulation (`str` type)
1616
1717
Rust's string type is one of the core primitive types of the language. While
1818
represented by the name `str`, the name `str` is not actually a valid type in
19-
Rust. Each string must also be decorated with its ownership. This means that
20-
there is one common kind of string in Rust:
19+
Rust. Each string must also be decorated with a pointer. `String` is used
20+
for an owned string, so there is only one commonly-used `str` type in Rust:
21+
`&str`.
2122
22-
* `&str` - This is the borrowed string type. This type of string can only be
23-
created from the other kind of string. As the name "borrowed"
24-
implies, this type of string is owned elsewhere, and this string
25-
cannot be moved out of.
23+
`&str` is the borrowed string type. This type of string can only be created
24+
from other strings, unless it is a static string (see below). As the word
25+
"borrowed" implies, this type of string is owned elsewhere, and this string
26+
cannot be moved out of.
2627
27-
As an example, here's the one kind of string.
28+
As an example, here's some code that uses a string.
2829
2930
```rust
3031
fn main() {
3132
let borrowed_string = "This string is borrowed with the 'static lifetime";
3233
}
3334
```
3435
35-
From the example above, you can see that Rust has 1 different kind of string
36-
literal. The "borrowed literal" is akin to C's concept of a static string.
36+
From the example above, you can see that Rust's string literals have the
37+
`'static` lifetime. This is akin to C's concept of a static string.
3738
3839
String literals are allocated statically in the rodata of the
3940
executable/library. The string then has the type `&'static str` meaning that
@@ -509,7 +510,7 @@ pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> {
509510
Section: MaybeOwned
510511
*/
511512

512-
/// A MaybeOwned is a string that can hold either a String or a &str.
513+
/// A `MaybeOwned` is a string that can hold either a `String` or a `&str`.
513514
/// This can be useful as an optimization when an allocation is sometimes
514515
/// needed but not always.
515516
pub enum MaybeOwned<'a> {
@@ -519,7 +520,7 @@ pub enum MaybeOwned<'a> {
519520
Owned(String)
520521
}
521522

522-
/// SendStr is a specialization of `MaybeOwned` to be sendable
523+
/// `SendStr` is a specialization of `MaybeOwned` to be sendable
523524
pub type SendStr = MaybeOwned<'static>;
524525

525526
impl<'a> MaybeOwned<'a> {

trunk/src/libsyntax/ast.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,14 @@ pub enum Stmt_ {
417417
StmtMac(Mac, bool),
418418
}
419419

420+
/// Where a local declaration came from: either a true `let ... =
421+
/// ...;`, or one desugared from the pattern of a for loop.
422+
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
423+
pub enum LocalSource {
424+
LocalLet,
425+
LocalFor,
426+
}
427+
420428
// FIXME (pending discussion of #1697, #2178...): local should really be
421429
// a refinement on pat.
422430
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
@@ -427,6 +435,7 @@ pub struct Local {
427435
pub init: Option<@Expr>,
428436
pub id: NodeId,
429437
pub span: Span,
438+
pub source: LocalSource,
430439
}
431440

432441
pub type Decl = Spanned<Decl_>;

trunk/src/libsyntax/ext/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
439439
init: Some(ex),
440440
id: ast::DUMMY_NODE_ID,
441441
span: sp,
442+
source: ast::LocalLet,
442443
};
443444
let decl = respan(sp, ast::DeclLocal(local));
444445
@respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID))
@@ -462,6 +463,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
462463
init: Some(ex),
463464
id: ast::DUMMY_NODE_ID,
464465
span: sp,
466+
source: ast::LocalLet,
465467
};
466468
let decl = respan(sp, ast::DeclLocal(local));
467469
@respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID))

trunk/src/libsyntax/ext/expand.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,17 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
147147
// ['<ident>:] loop {
148148
// match i.next() {
149149
// None => break,
150-
// Some(<src_pat>) => <src_loop_block>
150+
// Some(mut value) => {
151+
// let <src_pat> = value;
152+
// <src_loop_block>
153+
// }
151154
// }
152155
// }
153156
// }
154157
// }
158+
//
159+
// (The use of the `let` is to give better error messages
160+
// when the pattern is refutable.)
155161

156162
let local_ident = token::gensym_ident("__i"); // FIXME #13573
157163
let next_ident = fld.cx.ident_of("next");
@@ -167,11 +173,33 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
167173
fld.cx.arm(span, vec!(none_pat), break_expr)
168174
};
169175

170-
// `Some(<src_pat>) => <src_loop_block>`
176+
// let <src_pat> = value;
177+
let value_ident = token::gensym_ident("__value");
178+
// this is careful to use src_pat.span so that error
179+
// messages point exact at that.
180+
let local = @ast::Local {
181+
ty: fld.cx.ty_infer(src_pat.span),
182+
pat: src_pat,
183+
init: Some(fld.cx.expr_ident(src_pat.span, value_ident)),
184+
id: ast::DUMMY_NODE_ID,
185+
span: src_pat.span,
186+
source: ast::LocalFor
187+
};
188+
let local = codemap::respan(src_pat.span, ast::DeclLocal(local));
189+
let local = @codemap::respan(span, ast::StmtDecl(@local, ast::DUMMY_NODE_ID));
190+
191+
// { let ...; <src_loop_block> }
192+
let block = fld.cx.block(span, vec![local],
193+
Some(fld.cx.expr_block(src_loop_block)));
194+
195+
// `Some(mut value) => { ... }`
196+
// Note the _'s in the name will stop any unused mutability warnings.
197+
let value_pat = fld.cx.pat_ident_binding_mode(span, value_ident,
198+
ast::BindByValue(ast::MutMutable));
171199
let some_arm =
172200
fld.cx.arm(span,
173-
vec!(fld.cx.pat_enum(span, some_path, vec!(src_pat))),
174-
fld.cx.expr_block(src_loop_block));
201+
vec!(fld.cx.pat_enum(span, some_path, vec!(value_pat))),
202+
fld.cx.expr_block(block));
175203

176204
// `match i.next() { ... }`
177205
let match_expr = {
@@ -669,7 +697,8 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
669697
pat: pat,
670698
init: init,
671699
id: id,
672-
span: span
700+
span: span,
701+
source: source,
673702
} = **local;
674703
// expand the pat (it might contain exprs... #:(o)>
675704
let expanded_pat = fld.fold_pat(pat);
@@ -703,6 +732,7 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
703732
init: new_init_opt,
704733
id: id,
705734
span: span,
735+
source: source
706736
};
707737
SmallVector::one(@Spanned {
708738
node: StmtDecl(@Spanned {

trunk/src/libsyntax/fold.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ pub trait Folder {
288288
pat: self.fold_pat(l.pat),
289289
init: l.init.map(|e| self.fold_expr(e)),
290290
span: self.new_span(l.span),
291+
source: l.source,
291292
}
292293
}
293294

trunk/src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use ast::{Ident, NormalFn, Inherited, Item, Item_, ItemStatic};
3434
use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl};
3535
use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, Lit, Lit_};
3636
use ast::{LitBool, LitFloat, LitFloatUnsuffixed, LitInt, LitChar};
37-
use ast::{LitIntUnsuffixed, LitNil, LitStr, LitUint, Local};
37+
use ast::{LitIntUnsuffixed, LitNil, LitStr, LitUint, Local, LocalLet};
3838
use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, Matcher, MatchNonterminal};
3939
use ast::{MatchSeq, MatchTok, Method, MutTy, BiMul, Mutability};
4040
use ast::{NamedField, UnNeg, NoReturn, UnNot, P, Pat, PatEnum};
@@ -3034,6 +3034,7 @@ impl<'a> Parser<'a> {
30343034
init: init,
30353035
id: ast::DUMMY_NODE_ID,
30363036
span: mk_sp(lo, self.last_span.hi),
3037+
source: LocalLet,
30373038
}
30383039
}
30393040

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type="lib"]
12+
#![deny(warnings)]
13+
14+
pub use src::aliases::B;
15+
pub use src::hidden_core::make;
16+
17+
mod src {
18+
pub mod aliases {
19+
use super::hidden_core::A;
20+
pub type B = A<f32>;
21+
}
22+
23+
pub mod hidden_core {
24+
use super::aliases::B;
25+
26+
pub struct A<T>;
27+
28+
pub fn make() -> B { A }
29+
30+
impl<T> A<T> {
31+
pub fn foo(&mut self) { println!("called foo"); }
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)