Skip to content

Commit 56ba260

Browse files
committed
Update test for equivalency to include region binders in object types, add new tests relating to HRTB, consolidate the unboxed_closures and overloaded_calls feature gates.
1 parent 7a846b8 commit 56ba260

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+531
-81
lines changed

src/doc/reference.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,11 +2513,6 @@ The currently implemented features of the reference compiler are:
25132513
closure as `once` is unlikely to be supported going forward. So
25142514
they are hidden behind this feature until they are to be removed.
25152515

2516-
* `overloaded_calls` - Allow implementing the `Fn*` family of traits on user
2517-
types, allowing overloading the call operator (`()`).
2518-
This feature may still undergo changes before being
2519-
stabilized.
2520-
25212516
* `phase` - Usage of the `#[phase]` attribute allows loading compiler plugins
25222517
for custom lints or syntax extensions. The implementation is
25232518
considered unwholesome and in need of overhaul, and it is not clear
@@ -2560,7 +2555,8 @@ The currently implemented features of the reference compiler are:
25602555
* `trace_macros` - Allows use of the `trace_macros` macro, which is a nasty
25612556
hack that will certainly be removed.
25622557

2563-
* `unboxed_closures` - A work in progress feature with many known bugs.
2558+
* `unboxed_closures` - Rust's new closure design, which is currently a work in
2559+
progress feature with many known bugs.
25642560

25652561
* `unsafe_destructor` - Allows use of the `#[unsafe_destructor]` attribute,
25662562
which is considered wildly unsafe and will be

src/librustc/middle/typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,11 +2264,11 @@ fn try_overloaded_call<'a>(fcx: &FnCtxt,
22642264
fcx.inh.method_map.borrow_mut().insert(method_call, method_callee);
22652265
write_call(fcx, call_expression, output_type);
22662266

2267-
if !fcx.tcx().sess.features.borrow().overloaded_calls {
2267+
if !fcx.tcx().sess.features.borrow().unboxed_closures {
22682268
span_err!(fcx.tcx().sess, call_expression.span, E0056,
22692269
"overloaded calls are experimental");
22702270
span_help!(fcx.tcx().sess, call_expression.span,
2271-
"add `#![feature(overloaded_calls)]` to \
2271+
"add `#![feature(unboxed_closures)]` to \
22722272
the crate attributes to enable");
22732273
}
22742274

src/libsyntax/feature_gate.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
5858
("quote", Active),
5959
("linkage", Active),
6060
("struct_inherit", Removed),
61-
("overloaded_calls", Active),
6261

6362
("quad_precision_float", Removed),
6463

@@ -101,7 +100,7 @@ enum Status {
101100
/// A set of features to be used by later passes.
102101
pub struct Features {
103102
pub default_type_params: bool,
104-
pub overloaded_calls: bool,
103+
pub unboxed_closures: bool,
105104
pub rustc_diagnostic_macros: bool,
106105
pub import_shadowing: bool,
107106
pub visible_private_types: bool,
@@ -112,7 +111,7 @@ impl Features {
112111
pub fn new() -> Features {
113112
Features {
114113
default_type_params: false,
115-
overloaded_calls: false,
114+
unboxed_closures: false,
116115
rustc_diagnostic_macros: false,
117116
import_shadowing: false,
118117
visible_private_types: false,
@@ -458,7 +457,7 @@ pub fn check_crate(span_handler: &SpanHandler, krate: &ast::Crate) -> (Features,
458457

459458
(Features {
460459
default_type_params: cx.has_feature("default_type_params"),
461-
overloaded_calls: cx.has_feature("overloaded_calls"),
460+
unboxed_closures: cx.has_feature("unboxed_closures"),
462461
rustc_diagnostic_macros: cx.has_feature("rustc_diagnostic_macros"),
463462
import_shadowing: cx.has_feature("import_shadowing"),
464463
visible_private_types: cx.has_feature("visible_private_types"),

src/test/auxiliary/issue-18711.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(unboxed_closures, overloaded_calls)]
11+
#![feature(unboxed_closures)]
1212
#![crate_type = "rlib"]
1313

1414
pub fn inner<F>(f: F) -> F {

src/test/auxiliary/unboxed-closures-cross-crate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(unboxed_closures, overloaded_calls)]
11+
#![feature(unboxed_closures)]
1212

1313
#[inline]
1414
pub fn has_closures() -> uint {

src/test/bench/shootout-reverse-complement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
// ignore-android see #10393 #13206
4242

43-
#![feature(slicing_syntax, unboxed_closures, overloaded_calls)]
43+
#![feature(slicing_syntax, unboxed_closures)]
4444

4545
extern crate libc;
4646

src/test/bench/shootout-spectralnorm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
// no-pretty-expanded FIXME #15189
4242

4343
#![allow(non_snake_case)]
44-
#![feature(unboxed_closures, overloaded_calls)]
44+
#![feature(unboxed_closures)]
4545

4646
use std::iter::AdditiveIterator;
4747
use std::mem;

src/test/compile-fail/borrowck-overloaded-call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(overloaded_calls)]
11+
#![feature(unboxed_closures)]
1212

1313
use std::ops::{Fn, FnMut, FnOnce};
1414

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
// Test HRTB supertraits with several levels of expansion required.
12+
13+
trait Foo<'tcx>
14+
{
15+
fn foo(&'tcx self) -> &'tcx int;
16+
}
17+
18+
trait Bar<'ccx>
19+
: for<'tcx> Foo<'tcx>
20+
{
21+
fn bar(&'ccx self) -> &'ccx int;
22+
}
23+
24+
trait Baz
25+
: for<'ccx> Bar<'ccx>
26+
{
27+
fn dummy(&self);
28+
}
29+
30+
trait Qux
31+
: Bar<'static>
32+
{
33+
fn dummy(&self);
34+
}
35+
36+
fn want_foo_for_any_tcx<F>(f: &F)
37+
where F : for<'tcx> Foo<'tcx>
38+
{
39+
}
40+
41+
fn want_bar_for_any_ccx<B>(b: &B)
42+
where B : for<'ccx> Bar<'ccx>
43+
{
44+
}
45+
46+
fn want_baz<B>(b: &B)
47+
where B : Baz
48+
{
49+
want_foo_for_any_tcx(b);
50+
want_bar_for_any_ccx(b);
51+
}
52+
53+
fn want_qux<B>(b: &B)
54+
where B : Qux
55+
{
56+
want_foo_for_any_tcx(b);
57+
want_bar_for_any_ccx(b); //~ ERROR not implemented
58+
}
59+
60+
fn main() {}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
// Test a trait (`Bar`) with a higher-ranked supertrait.
12+
13+
trait Foo<'tcx>
14+
{
15+
fn foo(&'tcx self) -> &'tcx int;
16+
}
17+
18+
trait Bar<'ccx>
19+
: for<'tcx> Foo<'tcx>
20+
{
21+
fn bar(&'ccx self) -> &'ccx int;
22+
}
23+
24+
fn want_foo_for_some_tcx<'x,F>(f: &'x F)
25+
where F : Foo<'x>
26+
{
27+
want_foo_for_some_tcx(f);
28+
want_foo_for_any_tcx(f); //~ ERROR not implemented
29+
}
30+
31+
fn want_foo_for_any_tcx<F>(f: &F)
32+
where F : for<'tcx> Foo<'tcx>
33+
{
34+
want_foo_for_some_tcx(f);
35+
want_foo_for_any_tcx(f);
36+
}
37+
38+
fn want_bar_for_some_ccx<'x,B>(b: &B)
39+
where B : Bar<'x>
40+
{
41+
want_foo_for_some_tcx(b);
42+
want_foo_for_any_tcx(b);
43+
44+
want_bar_for_some_ccx(b);
45+
want_bar_for_any_ccx(b); //~ ERROR not implemented
46+
}
47+
48+
fn want_bar_for_any_ccx<B>(b: &B)
49+
where B : for<'ccx> Bar<'ccx>
50+
{
51+
want_foo_for_some_tcx(b);
52+
want_foo_for_any_tcx(b);
53+
54+
want_bar_for_some_ccx(b);
55+
want_bar_for_any_ccx(b);
56+
}
57+
58+
fn main() {}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
// Test that the `'a` in the where clause correctly links the region
12+
// of the output to the region of the input.
13+
14+
trait FnLike<A,R> {
15+
fn call(&self, arg: A) -> R;
16+
}
17+
18+
fn call_repeatedly<F>(f: F)
19+
where F : for<'a> FnLike<&'a int, &'a int>
20+
{
21+
// Result is stored: cannot re-assign `x`
22+
let mut x = 3;
23+
let y = f.call(&x);
24+
x = 5; //~ ERROR cannot assign
25+
26+
// Result is not stored: can re-assign `x`
27+
let mut x = 3;
28+
f.call(&x);
29+
f.call(&x);
30+
f.call(&x);
31+
x = 5;
32+
}
33+
34+
fn main() {
35+
}

src/test/compile-fail/issue-15094.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(overloaded_calls)]
11+
#![feature(unboxed_closures)]
1212

1313
use std::{fmt, ops};
1414

src/test/compile-fail/issue-18532.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// when a type error or unconstrained type variable propagates
1313
// into it.
1414

15-
#![feature(overloaded_calls)]
15+
#![feature(unboxed_closures)]
1616

1717
fn main() {
1818
(return)((),());

src/test/compile-fail/overloaded-calls-bad.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(overloaded_calls)]
11+
#![feature(unboxed_closures)]
1212

1313
use std::ops::FnMut;
1414

src/test/compile-fail/overloaded-calls-nontuple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(overloaded_calls)]
11+
#![feature(unboxed_closures)]
1212

1313
use std::ops::FnMut;
1414

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
// A zero-dependency test that covers some basic traits, default
12+
// methods, etc. When mucking about with basic type system stuff I
13+
// often encounter problems in the iterator trait, so it's useful to
14+
// have hanging around. -nmatsakis
15+
16+
// error-pattern: requires `start` lang_item
17+
18+
#![no_std]
19+
#![feature(lang_items)]
20+
21+
#[lang = "sized"]
22+
pub trait Sized for Sized? {
23+
// Empty.
24+
}
25+
26+
pub mod std {
27+
pub mod clone {
28+
pub trait Clone {
29+
fn clone(&self) -> Self;
30+
}
31+
}
32+
}
33+
34+
pub struct ContravariantLifetime<'a>;
35+
36+
impl <'a> ::std::clone::Clone for ContravariantLifetime<'a> {
37+
#[inline]
38+
fn clone(&self) -> ContravariantLifetime<'a> {
39+
match *self { ContravariantLifetime => ContravariantLifetime, }
40+
}
41+
}
42+
43+
fn main() { }

src/test/compile-fail/stage0-cmp.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
12+
// A zero-dependency test that covers some basic traits, default
13+
// methods, etc. When mucking about with basic type system stuff I
14+
// often encounter problems in the iterator trait, so it's useful to
15+
// have hanging around. -nmatsakis
16+
17+
// error-pattern: requires `start` lang_item
18+
19+
#![no_std]
20+
#![feature(lang_items)]
21+
22+
#[lang = "sized"]
23+
pub trait Sized for Sized? {
24+
// Empty.
25+
}
26+
27+
#[unstable = "Definition may change slightly after trait reform"]
28+
pub trait PartialEq for Sized? {
29+
/// This method tests for `self` and `other` values to be equal, and is used by `==`.
30+
fn eq(&self, other: &Self) -> bool;
31+
}
32+
33+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
34+
#[unstable = "Trait is unstable."]
35+
impl<'a, Sized? T: PartialEq> PartialEq for &'a T {
36+
#[inline]
37+
fn eq(&self, other: & &'a T) -> bool { PartialEq::eq(*self, *other) }
38+
}
39+
40+
fn main() { }

0 commit comments

Comments
 (0)