Skip to content

Commit 63bc8d1

Browse files
committed
---
yaml --- r: 83924 b: refs/heads/dist-snap c: 3c0a162 h: refs/heads/master v: v3
1 parent 254527f commit 63bc8d1

File tree

10 files changed

+82
-722
lines changed

10 files changed

+82
-722
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 0983ebe5310d4eb6d289f636f7ed0536c08bbc0e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 908a22b62697fcb6c943527492158729dc762f10
9+
refs/heads/dist-snap: 3c0a1621b550936e862585667d8a58f7a2ab72c5
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/middle/borrowck/mod.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,13 @@ impl BorrowckCtxt {
538538

539539
move_data::MoveExpr(expr) => {
540540
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
541+
let suggestion = move_suggestion(self.tcx, expr_ty,
542+
"moved by default (use `copy` to override)");
541543
self.tcx.sess.span_note(
542544
expr.span,
543-
fmt!("`%s` moved here because it has type `%s`, \
544-
which is moved by default (use `copy` to override)",
545+
fmt!("`%s` moved here because it has type `%s`, which is %s",
545546
self.loan_path_to_str(moved_lp),
546-
expr_ty.user_string(self.tcx)));
547+
expr_ty.user_string(self.tcx), suggestion));
547548
}
548549

549550
move_data::MovePat(pat) => {
@@ -557,12 +558,28 @@ impl BorrowckCtxt {
557558
}
558559

559560
move_data::Captured(expr) => {
561+
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
562+
let suggestion = move_suggestion(self.tcx, expr_ty,
563+
"moved by default (make a copy and \
564+
capture that instead to override)");
560565
self.tcx.sess.span_note(
561566
expr.span,
562-
fmt!("`%s` moved into closure environment here \
563-
because its type is moved by default \
564-
(make a copy and capture that instead to override)",
565-
self.loan_path_to_str(moved_lp)));
567+
fmt!("`%s` moved into closure environment here because it \
568+
has type `%s`, which is %s",
569+
self.loan_path_to_str(moved_lp),
570+
expr_ty.user_string(self.tcx), suggestion));
571+
}
572+
}
573+
574+
fn move_suggestion(tcx: ty::ctxt, ty: ty::t, default_msg: &'static str)
575+
-> &'static str {
576+
match ty::get(ty).sty {
577+
ty::ty_closure(ref cty) if cty.sigil == ast::BorrowedSigil =>
578+
"a non-copyable stack closure (capture it in a new closure, \
579+
e.g. `|x| f(x)`, to override)",
580+
_ if !ty::type_is_copyable(tcx, ty) =>
581+
"non-copyable (perhaps you meant to use clone()?)",
582+
_ => default_msg,
566583
}
567584
}
568585
}

branches/dist-snap/src/librustc/middle/resolve.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,6 @@ pub struct NameBindings {
510510
value_def: Option<ValueNsDef>, //< Meaning in value namespace.
511511
}
512512

513-
/// Ways in which a trait can be referenced
514-
enum TraitReferenceType {
515-
TraitImplementation, // impl SomeTrait for T { ... }
516-
TraitDerivation, // trait T : SomeTrait { ... }
517-
TraitBoundingTypeParameter, // fn f<T:SomeTrait>() { ... }
518-
}
519-
520513
impl NameBindings {
521514
/// Creates a new module in this set of name bindings.
522515
pub fn define_module(@mut self,
@@ -3561,7 +3554,23 @@ impl Resolver {
35613554

35623555
// Resolve derived traits.
35633556
for traits.iter().advance |trt| {
3564-
self.resolve_trait_reference(*trt, visitor, TraitDerivation);
3557+
match self.resolve_path(trt.path, TypeNS, true,
3558+
visitor) {
3559+
None =>
3560+
self.session.span_err(trt.path.span,
3561+
"attempt to derive a \
3562+
nonexistent trait"),
3563+
Some(def) => {
3564+
// Write a mapping from the trait ID to the
3565+
// definition of the trait into the definition
3566+
// map.
3567+
3568+
debug!("(resolving trait) found trait def: \
3569+
%?", def);
3570+
3571+
self.record_def(trt.ref_id, def);
3572+
}
3573+
}
35653574
}
35663575

35673576
for (*methods).iter().advance |method| {
@@ -3812,31 +3821,22 @@ impl Resolver {
38123821
visitor: ResolveVisitor) {
38133822
match *type_parameter_bound {
38143823
TraitTyParamBound(tref) => {
3815-
self.resolve_trait_reference(tref, visitor, TraitBoundingTypeParameter)
3824+
self.resolve_trait_reference(tref, visitor)
38163825
}
38173826
RegionTyParamBound => {}
38183827
}
38193828
}
38203829

38213830
pub fn resolve_trait_reference(@mut self,
38223831
trait_reference: &trait_ref,
3823-
visitor: ResolveVisitor,
3824-
reference_type: TraitReferenceType) {
3832+
visitor: ResolveVisitor) {
38253833
match self.resolve_path(trait_reference.path, TypeNS, true, visitor) {
38263834
None => {
3827-
let path_str = self.idents_to_str(trait_reference.path.idents);
3828-
3829-
let usage_str = match reference_type {
3830-
TraitBoundingTypeParameter => "bound type parameter with",
3831-
TraitImplementation => "implement",
3832-
TraitDerivation => "derive"
3833-
};
3834-
3835-
let msg = fmt!("attempt to %s a nonexistent trait `%s`", usage_str, path_str);
3836-
self.session.span_err(trait_reference.path.span, msg);
3835+
let idents = self.idents_to_str(trait_reference.path.idents);
3836+
self.session.span_err(trait_reference.path.span,
3837+
fmt!("attempt to implement an unknown trait `%s`", idents));
38373838
}
38383839
Some(def) => {
3839-
debug!("(resolving trait) found trait def: %?", def);
38403840
self.record_def(trait_reference.ref_id, def);
38413841
}
38423842
}
@@ -3930,7 +3930,7 @@ impl Resolver {
39303930
let original_trait_refs;
39313931
match opt_trait_reference {
39323932
Some(trait_reference) => {
3933-
self.resolve_trait_reference(trait_reference, visitor, TraitImplementation);
3933+
self.resolve_trait_reference(trait_reference, visitor);
39343934

39353935
// Record the current set of trait references.
39363936
let mut new_trait_refs = ~[];

0 commit comments

Comments
 (0)