Skip to content

Commit 769aa0a

Browse files
committed
Remove the double auto-ref on arrays/strings as receivers
Part of rust-lang#18469 [breaking-change] A receiver will only ever get a single auto-reference. Previously arrays and strings would get two, e.g., [T] would be auto-ref'ed to &&[T]. This is usually apparent when a trait is implemented for `&[T]` and has a method takes self by reference. The usual solution is to implement the trait for `[T]` (the DST form).
1 parent 0669a43 commit 769aa0a

File tree

6 files changed

+22
-76
lines changed

6 files changed

+22
-76
lines changed

src/libgraphviz/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl<'a> LabelText<'a> {
440440
/// Renders text as string suitable for a label in a .dot file.
441441
pub fn escape(&self) -> String {
442442
match self {
443-
&LabelStr(ref s) => s.escape_default(),
443+
&LabelStr(ref s) => (&**s).escape_default(),
444444
&EscStr(ref s) => LabelText::escape_str(s.as_slice()),
445445
}
446446
}
@@ -453,7 +453,7 @@ impl<'a> LabelText<'a> {
453453
match self {
454454
EscStr(s) => s,
455455
LabelStr(s) => if s.contains_char('\\') {
456-
s.escape_default().into_cow()
456+
(&*s).escape_default().into_cow()
457457
} else {
458458
s
459459
},

src/librustc_typeck/check/method/probe.rs

+1-23
Original file line numberDiff line numberDiff line change
@@ -628,17 +628,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
628628
None => {}
629629
}
630630

631-
match self.pick_autorefd_method(step) {
632-
Some(result) => return Some(result),
633-
None => {}
634-
}
635-
636-
// FIXME -- Super hack. For DST types, we will convert to
637-
// &&[T] or &&str, as part of a kind of legacy lookup scheme.
638-
match step.self_ty.sty {
639-
ty::ty_str | ty::ty_vec(_, None) => self.pick_autorefrefd_method(step),
640-
_ => None
641-
}
631+
self.pick_autorefd_method(step)
642632
}
643633

644634
fn pick_by_value_method(&mut self,
@@ -681,18 +671,6 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
681671
|m,r| ty::mk_rptr(tcx, r, ty::mt {ty:step.self_ty, mutbl:m}))
682672
}
683673

684-
fn pick_autorefrefd_method(&mut self,
685-
step: &CandidateStep<'tcx>)
686-
-> Option<PickResult<'tcx>>
687-
{
688-
let tcx = self.tcx();
689-
self.search_mutabilities(
690-
|m| AutoRef(m, box AutoRef(m, box step.adjustment.clone())),
691-
|m,r| ty::mk_rptr(tcx, r, ty::mt { ty: ty::mk_rptr(tcx, r, ty::mt { ty:step.self_ty,
692-
mutbl:m}),
693-
mutbl: m }))
694-
}
695-
696674
fn search_mutabilities<F, G>(&mut self,
697675
mut mk_adjustment: F,
698676
mut mk_autoref_ty: G)

src/libstd/ascii.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'a> fmt::Show for Ascii {
170170

171171
/// Trait for converting into an ascii type.
172172
#[experimental = "may be replaced by generic conversion traits"]
173-
pub trait AsciiCast<T> {
173+
pub trait AsciiCast<T> for Sized? {
174174
/// Convert to an ascii type, panic on non-ASCII input.
175175
#[inline]
176176
fn to_ascii(&self) -> T {
@@ -196,10 +196,10 @@ pub trait AsciiCast<T> {
196196
}
197197

198198
#[experimental = "may be replaced by generic conversion traits"]
199-
impl<'a> AsciiCast<&'a[Ascii]> for &'a [u8] {
199+
impl<'a> AsciiCast<&'a[Ascii]> for [u8] {
200200
#[inline]
201201
unsafe fn to_ascii_nocheck(&self) -> &'a[Ascii] {
202-
mem::transmute(*self)
202+
mem::transmute(self)
203203
}
204204

205205
#[inline]
@@ -212,10 +212,10 @@ impl<'a> AsciiCast<&'a[Ascii]> for &'a [u8] {
212212
}
213213

214214
#[experimental = "may be replaced by generic conversion traits"]
215-
impl<'a> AsciiCast<&'a [Ascii]> for &'a str {
215+
impl<'a> AsciiCast<&'a [Ascii]> for str {
216216
#[inline]
217217
unsafe fn to_ascii_nocheck(&self) -> &'a [Ascii] {
218-
mem::transmute(*self)
218+
mem::transmute(self)
219219
}
220220

221221
#[inline]

src/test/compile-fail/auto-ref-slice-plus-ref.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-14 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -12,18 +12,27 @@
1212
fn main() {
1313

1414
// Testing that method lookup does not automatically borrow
15-
// vectors to slices then automatically create a &mut self
16-
// reference. That would allow creating a mutable pointer to a
17-
// temporary, which would be a source of confusion
15+
// vectors to slices then automatically create a self reference.
1816

1917
let mut a = vec!(0);
2018
a.test_mut(); //~ ERROR does not implement any method in scope named `test_mut`
19+
a.test(); //~ ERROR does not implement any method in scope named `test`
20+
21+
([1]).test(); //~ ERROR does not implement any method in scope named `test`
22+
(&[1]).test(); //~ ERROR does not implement any method in scope named `test`
2123
}
2224

2325
trait MyIter {
2426
fn test_mut(&mut self);
27+
fn test(&self);
2528
}
2629

2730
impl<'a> MyIter for &'a [int] {
2831
fn test_mut(&mut self) { }
32+
fn test(&self) { }
33+
}
34+
35+
impl<'a> MyIter for &'a str {
36+
fn test_mut(&mut self) { }
37+
fn test(&self) { }
2938
}

src/test/run-pass/assignability-trait.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-4 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -51,8 +51,6 @@ pub fn main() {
5151

5252
// Now try it with a type that *needs* to be borrowed
5353
let z = [0,1,2,3];
54-
// Call a method
55-
z.iterate(|y| { assert!(z[*y as uint] == *y); true });
5654
// Call a parameterized function
5755
assert_eq!(length::<int, &[int]>(&z), z.len());
5856
}

src/test/run-pass/auto-ref-slice-plus-ref.rs

-39
This file was deleted.

0 commit comments

Comments
 (0)