Skip to content

Commit 673b9d9

Browse files
committed
---
yaml --- r: 212917 b: refs/heads/master c: 22b6a5d h: refs/heads/master i: 212915: eb282b2 v: v3
1 parent d344814 commit 673b9d9

File tree

15 files changed

+85
-204
lines changed

15 files changed

+85
-204
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: 4806210db9148f008a317db5235bc0e5a5e3b48e
2+
refs/heads/master: 22b6a5dc2acb4fd83fa3d90d1a04128c252aedd2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
55
refs/heads/try: 1864973ae17213c5a58c4dd3f9af6d1b6c7d2e05

trunk/src/doc/reference.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -928,21 +928,20 @@ A _generic function_ allows one or more _parameterized types_ to appear in its
928928
signature. Each type parameter must be explicitly declared, in an
929929
angle-bracket-enclosed, comma-separated list following the function name.
930930

931-
```{.ignore}
932-
fn iter<T, F>(seq: &[T], f: F) where T: Copy, F: Fn(T) {
933-
for elt in seq { f(*elt); }
934-
}
935-
fn map<T, U, F>(seq: &[T], f: F) -> Vec<U> where T: Copy, U: Copy, F: Fn(T) -> U {
936-
let mut acc = vec![];
937-
for elt in seq { acc.push(f(*elt)); }
938-
acc
939-
}
931+
```rust,ignore
932+
// foo is generic over A and B
933+
934+
fn foo<A, B>(x: A, y: B) {
940935
```
941936

942937
Inside the function signature and body, the name of the type parameter can be
943938
used as a type name. [Trait](#traits) bounds can be specified for type parameters
944939
to allow methods with that trait to be called on values of that type. This is
945-
specified using the `where` syntax, as in the above example.
940+
specified using the `where` syntax:
941+
942+
```rust,ignore
943+
fn foo<T>(x: T) where T: Debug {
944+
```
946945

947946
When a generic function is referenced, its type is instantiated based on the
948947
context of the reference. For example, calling the `iter` function defined

trunk/src/doc/trpl/closures.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ let y = &mut num;
120120
```
121121

122122
If your closure requires it, however, Rust will take ownership and move
123-
the environment instead. This doesn’t work:
123+
the environment instead:
124124

125125
```rust,ignore
126126
let nums = vec![1, 2, 3];
@@ -130,7 +130,7 @@ let takes_nums = || nums;
130130
println!("{:?}", nums);
131131
```
132132

133-
We get this error:
133+
This gives us:
134134

135135
```text
136136
note: `nums` moved into closure environment here because it has type

trunk/src/doc/trpl/rust-inside-other-languages.md

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,10 @@ threads = []
6666
5_000_000.times do
6767
count += 1
6868
end
69-
70-
count
7169
end
7270
end
7371

74-
threads.each do |t|
75-
puts "Thread finished with count=#{t.value}"
76-
end
72+
threads.each { |t| t.join }
7773
puts "done!"
7874
```
7975

@@ -107,26 +103,50 @@ use std::thread;
107103
fn process() {
108104
let handles: Vec<_> = (0..10).map(|_| {
109105
thread::spawn(|| {
110-
let mut x = 0;
106+
let mut _x = 0;
111107
for _ in (0..5_000_000) {
112-
x += 1
108+
_x += 1
113109
}
114-
x
115110
})
116111
}).collect();
117112

118113
for h in handles {
119-
println!("Thread finished with count={}",
120-
h.join().map_err(|_| "Could not join a thread!").unwrap());
114+
h.join().ok().expect("Could not join a thread!");
121115
}
122-
println!("done!");
123116
}
124117
```
125118

126119
Some of this should look familiar from previous examples. We spin up ten
127120
threads, collecting them into a `handles` vector. Inside of each thread, we
128-
loop five million times, and add one to `x` each time. Finally, we join on
129-
each thread.
121+
loop five million times, and add one to `_x` each time. Why the underscore?
122+
Well, if we remove it and compile:
123+
124+
```bash
125+
$ cargo build
126+
Compiling embed v0.1.0 (file:///home/steve/src/embed)
127+
src/lib.rs:3:1: 16:2 warning: function is never used: `process`, #[warn(dead_code)] on by default
128+
src/lib.rs:3 fn process() {
129+
src/lib.rs:4 let handles: Vec<_> = (0..10).map(|_| {
130+
src/lib.rs:5 thread::spawn(|| {
131+
src/lib.rs:6 let mut x = 0;
132+
src/lib.rs:7 for _ in (0..5_000_000) {
133+
src/lib.rs:8 x += 1
134+
...
135+
src/lib.rs:6:17: 6:22 warning: variable `x` is assigned to, but never used, #[warn(unused_variables)] on by default
136+
src/lib.rs:6 let mut x = 0;
137+
^~~~~
138+
```
139+
140+
That first warning is because we are building a library. If we had a test
141+
for this function, the warning would go away. But for now, it’s never
142+
called.
143+
144+
The second is related to `x` versus `_x`. Because we never actually _do_
145+
anything with `x`, we get a warning about it. In our case, that’s perfectly
146+
okay, as we’re just trying to waste CPU cycles. Prefixing `x` with the
147+
underscore removes the warning.
148+
149+
Finally, we join on each thread.
130150
131151
Right now, however, this is a Rust library, and it doesn’t expose anything
132152
that’s callable from C. If we tried to hook this up to another language right

trunk/src/doc/trpl/trait-objects.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,7 @@ let y = TraitObject {
300300
// y.method();
301301
(y.vtable.method)(y.data);
302302
```
303+
304+
If `b` or `y` were owning trait objects (`Box<Foo>`), there would be a
305+
`(b.vtable.destructor)(b.data)` (respectively `y`) call when they went out of
306+
scope.

trunk/src/libcore/str/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,10 @@ impl<'a, P: Pattern<'a>> SplitInternal<'a, P> {
638638

639639
generate_pattern_iterators! {
640640
forward:
641-
#[doc="Created with the method `.split()`."]
641+
/// Created with the method `.split()`.
642642
struct Split;
643643
reverse:
644-
#[doc="Created with the method `.rsplit()`."]
644+
/// Created with the method `.rsplit()`.
645645
struct RSplit;
646646
stability:
647647
#[stable(feature = "rust1", since = "1.0.0")]
@@ -652,10 +652,10 @@ generate_pattern_iterators! {
652652

653653
generate_pattern_iterators! {
654654
forward:
655-
#[doc="Created with the method `.split_terminator()`."]
655+
/// Created with the method `.split_terminator()`.
656656
struct SplitTerminator;
657657
reverse:
658-
#[doc="Created with the method `.rsplit_terminator()`."]
658+
/// Created with the method `.rsplit_terminator()`.
659659
struct RSplitTerminator;
660660
stability:
661661
#[stable(feature = "rust1", since = "1.0.0")]
@@ -698,10 +698,10 @@ impl<'a, P: Pattern<'a>> SplitNInternal<'a, P> {
698698

699699
generate_pattern_iterators! {
700700
forward:
701-
#[doc="Created with the method `.splitn()`."]
701+
/// Created with the method `.splitn()`.
702702
struct SplitN;
703703
reverse:
704-
#[doc="Created with the method `.rsplitn()`."]
704+
/// Created with the method `.rsplitn()`.
705705
struct RSplitN;
706706
stability:
707707
#[stable(feature = "rust1", since = "1.0.0")]
@@ -732,10 +732,10 @@ impl<'a, P: Pattern<'a>> MatchIndicesInternal<'a, P> {
732732

733733
generate_pattern_iterators! {
734734
forward:
735-
#[doc="Created with the method `.match_indices()`."]
735+
/// Created with the method `.match_indices()`.
736736
struct MatchIndices;
737737
reverse:
738-
#[doc="Created with the method `.rmatch_indices()`."]
738+
/// Created with the method `.rmatch_indices()`.
739739
struct RMatchIndices;
740740
stability:
741741
#[unstable(feature = "core",
@@ -773,10 +773,10 @@ impl<'a, P: Pattern<'a>> MatchesInternal<'a, P> {
773773

774774
generate_pattern_iterators! {
775775
forward:
776-
#[doc="Created with the method `.matches()`."]
776+
/// Created with the method `.matches()`.
777777
struct Matches;
778778
reverse:
779-
#[doc="Created with the method `.rmatches()`."]
779+
/// Created with the method `.rmatches()`.
780780
struct RMatches;
781781
stability:
782782
#[unstable(feature = "core", reason = "type got recently added")]

trunk/src/liblibc/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,7 @@ pub use funcs::bsd43::*;
146146
#[link(name = "m")]
147147
extern {}
148148

149-
// When compiling rust with musl, statically include libc.a in liblibc.rlib.
150-
// A cargo build of the libc crate will therefore automatically pick up the
151-
// libc.a symbols because liblibc is transitively linked to by the stdlib.
152-
#[cfg(all(target_env = "musl", not(feature = "cargo-build"), not(test)))]
149+
#[cfg(all(target_env = "musl", not(test)))]
153150
#[link(name = "c", kind = "static")]
154151
extern {}
155152

trunk/src/librustc/middle/traits/project.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,19 +389,15 @@ fn opt_normalize_projection_type<'a,'b,'tcx>(
389389
}
390390
}
391391
Ok(ProjectedTy::NoProgress(projected_ty)) => {
392-
debug!("normalize_projection_type: projected_ty={} no progress",
393-
projected_ty.repr(selcx.tcx()));
394392
Some(Normalized {
395393
value: projected_ty,
396394
obligations: vec!()
397395
})
398396
}
399397
Err(ProjectionTyError::TooManyCandidates) => {
400-
debug!("normalize_projection_type: too many candidates");
401398
None
402399
}
403400
Err(ProjectionTyError::TraitSelectionError(_)) => {
404-
debug!("normalize_projection_type: ERROR");
405401
// if we got an error processing the `T as Trait` part,
406402
// just return `ty::err` but add the obligation `T :
407403
// Trait`, which when processed will cause the error to be

trunk/src/librustc_back/sha2.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,6 @@ pub struct Sha256 {
482482

483483
impl Sha256 {
484484
/// Construct a new instance of a SHA-256 digest.
485-
/// Do not – under any circumstances – use this where timing attacks might be possible!
486485
pub fn new() -> Sha256 {
487486
Sha256 {
488487
engine: Engine256::new(&H256)

trunk/src/librustc_typeck/check/method/probe.rs

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,10 @@ struct Candidate<'tcx> {
5959
}
6060

6161
enum CandidateKind<'tcx> {
62-
InherentImplCandidate(/* Impl */ ast::DefId, subst::Substs<'tcx>,
63-
/* Normalize obligations */ Vec<traits::PredicateObligation<'tcx>>),
62+
InherentImplCandidate(/* Impl */ ast::DefId, subst::Substs<'tcx>),
6463
ObjectCandidate(/* Trait */ ast::DefId, /* method_num */ usize, /* vtable index */ usize),
6564
ExtensionImplCandidate(/* Impl */ ast::DefId, ty::TraitRef<'tcx>,
66-
subst::Substs<'tcx>, ItemIndex,
67-
/* Normalize obligations */ Vec<traits::PredicateObligation<'tcx>>),
65+
subst::Substs<'tcx>, ItemIndex),
6866
ClosureCandidate(/* Trait */ ast::DefId, ItemIndex),
6967
WhereClauseCandidate(ty::PolyTraitRef<'tcx>, ItemIndex),
7068
ProjectionCandidate(ast::DefId, ItemIndex),
@@ -400,24 +398,16 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
400398
}
401399

402400
let (impl_ty, impl_substs) = self.impl_ty_and_substs(impl_def_id);
403-
let impl_ty = impl_ty.subst(self.tcx(), &impl_substs);
401+
let impl_ty = self.fcx.instantiate_type_scheme(self.span, &impl_substs, &impl_ty);
404402

405403
// Determine the receiver type that the method itself expects.
406-
let xform_self_ty = self.xform_self_ty(&item, impl_ty, &impl_substs);
407-
408-
// We can't use normalize_associated_types_in as it will pollute the
409-
// fcx's fulfillment context after this probe is over.
410-
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
411-
let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx);
412-
let traits::Normalized { value: xform_self_ty, obligations } =
413-
traits::normalize(selcx, cause, &xform_self_ty);
414-
debug!("assemble_inherent_impl_probe: xform_self_ty = {:?}",
415-
xform_self_ty.repr(self.tcx()));
404+
let xform_self_ty =
405+
self.xform_self_ty(&item, impl_ty, &impl_substs);
416406

417407
self.inherent_candidates.push(Candidate {
418408
xform_self_ty: xform_self_ty,
419409
item: item,
420-
kind: InherentImplCandidate(impl_def_id, impl_substs, obligations)
410+
kind: InherentImplCandidate(impl_def_id, impl_substs)
421411
});
422412
}
423413

@@ -663,24 +653,12 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
663653
impl_trait_ref.self_ty(),
664654
impl_trait_ref.substs);
665655

666-
// Normalize the receiver. We can't use normalize_associated_types_in
667-
// as it will pollute the fcx's fulfillment context after this probe
668-
// is over.
669-
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
670-
let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx);
671-
let traits::Normalized { value: xform_self_ty, obligations } =
672-
traits::normalize(selcx, cause, &xform_self_ty);
673-
674656
debug!("xform_self_ty={}", xform_self_ty.repr(self.tcx()));
675657

676658
self.extension_candidates.push(Candidate {
677659
xform_self_ty: xform_self_ty,
678660
item: item.clone(),
679-
kind: ExtensionImplCandidate(impl_def_id,
680-
impl_trait_ref,
681-
impl_substs,
682-
item_index,
683-
obligations)
661+
kind: ExtensionImplCandidate(impl_def_id, impl_trait_ref, impl_substs, item_index)
684662
});
685663
});
686664
}
@@ -1048,8 +1026,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
10481026
// match as well (or at least may match, sometimes we
10491027
// don't have enough information to fully evaluate).
10501028
match probe.kind {
1051-
InherentImplCandidate(impl_def_id, ref substs, ref ref_obligations) |
1052-
ExtensionImplCandidate(impl_def_id, _, ref substs, _, ref ref_obligations) => {
1029+
InherentImplCandidate(impl_def_id, ref substs) |
1030+
ExtensionImplCandidate(impl_def_id, _, ref substs, _) => {
10531031
let selcx = &mut traits::SelectionContext::new(self.infcx(), self.fcx);
10541032
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
10551033

@@ -1068,10 +1046,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
10681046
debug!("impl_obligations={}", obligations.repr(self.tcx()));
10691047

10701048
// Evaluate those obligations to see if they might possibly hold.
1071-
obligations.iter()
1072-
.chain(norm_obligations.iter()).chain(ref_obligations.iter())
1073-
.all(|o| selcx.evaluate_obligation(o))
1074-
1049+
obligations.iter().all(|o| selcx.evaluate_obligation(o)) &&
1050+
norm_obligations.iter().all(|o| selcx.evaluate_obligation(o))
10751051
}
10761052

10771053
ProjectionCandidate(..) |
@@ -1305,13 +1281,13 @@ impl<'tcx> Candidate<'tcx> {
13051281
Pick {
13061282
item: self.item.clone(),
13071283
kind: match self.kind {
1308-
InherentImplCandidate(def_id, _, _) => {
1284+
InherentImplCandidate(def_id, _) => {
13091285
InherentImplPick(def_id)
13101286
}
13111287
ObjectCandidate(def_id, item_num, real_index) => {
13121288
ObjectPick(def_id, item_num, real_index)
13131289
}
1314-
ExtensionImplCandidate(def_id, _, _, index, _) => {
1290+
ExtensionImplCandidate(def_id, _, _, index) => {
13151291
ExtensionImplPick(def_id, index)
13161292
}
13171293
ClosureCandidate(trait_def_id, index) => {
@@ -1339,9 +1315,9 @@ impl<'tcx> Candidate<'tcx> {
13391315

13401316
fn to_source(&self) -> CandidateSource {
13411317
match self.kind {
1342-
InherentImplCandidate(def_id, _, _) => ImplSource(def_id),
1318+
InherentImplCandidate(def_id, _) => ImplSource(def_id),
13431319
ObjectCandidate(def_id, _, _) => TraitSource(def_id),
1344-
ExtensionImplCandidate(def_id, _, _, _, _) => ImplSource(def_id),
1320+
ExtensionImplCandidate(def_id, _, _, _) => ImplSource(def_id),
13451321
ClosureCandidate(trait_def_id, _) => TraitSource(trait_def_id),
13461322
WhereClauseCandidate(ref trait_ref, _) => TraitSource(trait_ref.def_id()),
13471323
ProjectionCandidate(trait_def_id, _) => TraitSource(trait_def_id),
@@ -1359,7 +1335,7 @@ impl<'tcx> Candidate<'tcx> {
13591335
ClosureCandidate(trait_def_id, item_num) => {
13601336
Some((trait_def_id, item_num))
13611337
}
1362-
ExtensionImplCandidate(_, ref trait_ref, _, item_num, _) => {
1338+
ExtensionImplCandidate(_, ref trait_ref, _, item_num) => {
13631339
Some((trait_ref.def_id, item_num))
13641340
}
13651341
WhereClauseCandidate(ref trait_ref, item_num) => {
@@ -1383,14 +1359,13 @@ impl<'tcx> Repr<'tcx> for Candidate<'tcx> {
13831359
impl<'tcx> Repr<'tcx> for CandidateKind<'tcx> {
13841360
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
13851361
match *self {
1386-
InherentImplCandidate(ref a, ref b, ref c) =>
1387-
format!("InherentImplCandidate({},{},{})", a.repr(tcx), b.repr(tcx),
1388-
c.repr(tcx)),
1362+
InherentImplCandidate(ref a, ref b) =>
1363+
format!("InherentImplCandidate({},{})", a.repr(tcx), b.repr(tcx)),
13891364
ObjectCandidate(a, b, c) =>
13901365
format!("ObjectCandidate({},{},{})", a.repr(tcx), b, c),
1391-
ExtensionImplCandidate(ref a, ref b, ref c, ref d, ref e) =>
1392-
format!("ExtensionImplCandidate({},{},{},{},{})", a.repr(tcx), b.repr(tcx),
1393-
c.repr(tcx), d, e.repr(tcx)),
1366+
ExtensionImplCandidate(ref a, ref b, ref c, ref d) =>
1367+
format!("ExtensionImplCandidate({},{},{},{})", a.repr(tcx), b.repr(tcx),
1368+
c.repr(tcx), d),
13941369
ClosureCandidate(ref a, ref b) =>
13951370
format!("ClosureCandidate({},{})", a.repr(tcx), b),
13961371
WhereClauseCandidate(ref a, ref b) =>

0 commit comments

Comments
 (0)