Skip to content

Commit

Permalink
Update test for equivalency to include region binders in object types…
Browse files Browse the repository at this point in the history
…, add new tests relating to HRTB, consolidate the `unboxed_closures` and `overloaded_calls` feature gates.
  • Loading branch information
nikomatsakis committed Nov 18, 2014
1 parent 7a846b8 commit 56ba260
Show file tree
Hide file tree
Showing 48 changed files with 531 additions and 81 deletions.
8 changes: 2 additions & 6 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2513,11 +2513,6 @@ The currently implemented features of the reference compiler are:
closure as `once` is unlikely to be supported going forward. So
they are hidden behind this feature until they are to be removed.

* `overloaded_calls` - Allow implementing the `Fn*` family of traits on user
types, allowing overloading the call operator (`()`).
This feature may still undergo changes before being
stabilized.

* `phase` - Usage of the `#[phase]` attribute allows loading compiler plugins
for custom lints or syntax extensions. The implementation is
considered unwholesome and in need of overhaul, and it is not clear
Expand Down Expand Up @@ -2560,7 +2555,8 @@ The currently implemented features of the reference compiler are:
* `trace_macros` - Allows use of the `trace_macros` macro, which is a nasty
hack that will certainly be removed.

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

* `unsafe_destructor` - Allows use of the `#[unsafe_destructor]` attribute,
which is considered wildly unsafe and will be
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2264,11 +2264,11 @@ fn try_overloaded_call<'a>(fcx: &FnCtxt,
fcx.inh.method_map.borrow_mut().insert(method_call, method_callee);
write_call(fcx, call_expression, output_type);

if !fcx.tcx().sess.features.borrow().overloaded_calls {
if !fcx.tcx().sess.features.borrow().unboxed_closures {
span_err!(fcx.tcx().sess, call_expression.span, E0056,
"overloaded calls are experimental");
span_help!(fcx.tcx().sess, call_expression.span,
"add `#![feature(overloaded_calls)]` to \
"add `#![feature(unboxed_closures)]` to \
the crate attributes to enable");
}

Expand Down
7 changes: 3 additions & 4 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
("quote", Active),
("linkage", Active),
("struct_inherit", Removed),
("overloaded_calls", Active),

("quad_precision_float", Removed),

Expand Down Expand Up @@ -101,7 +100,7 @@ enum Status {
/// A set of features to be used by later passes.
pub struct Features {
pub default_type_params: bool,
pub overloaded_calls: bool,
pub unboxed_closures: bool,
pub rustc_diagnostic_macros: bool,
pub import_shadowing: bool,
pub visible_private_types: bool,
Expand All @@ -112,7 +111,7 @@ impl Features {
pub fn new() -> Features {
Features {
default_type_params: false,
overloaded_calls: false,
unboxed_closures: false,
rustc_diagnostic_macros: false,
import_shadowing: false,
visible_private_types: false,
Expand Down Expand Up @@ -458,7 +457,7 @@ pub fn check_crate(span_handler: &SpanHandler, krate: &ast::Crate) -> (Features,

(Features {
default_type_params: cx.has_feature("default_type_params"),
overloaded_calls: cx.has_feature("overloaded_calls"),
unboxed_closures: cx.has_feature("unboxed_closures"),
rustc_diagnostic_macros: cx.has_feature("rustc_diagnostic_macros"),
import_shadowing: cx.has_feature("import_shadowing"),
visible_private_types: cx.has_feature("visible_private_types"),
Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/issue-18711.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(unboxed_closures, overloaded_calls)]
#![feature(unboxed_closures)]
#![crate_type = "rlib"]

pub fn inner<F>(f: F) -> F {
Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/unboxed-closures-cross-crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(unboxed_closures, overloaded_calls)]
#![feature(unboxed_closures)]

#[inline]
pub fn has_closures() -> uint {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-reverse-complement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

// ignore-android see #10393 #13206

#![feature(slicing_syntax, unboxed_closures, overloaded_calls)]
#![feature(slicing_syntax, unboxed_closures)]

extern crate libc;

Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-spectralnorm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
// no-pretty-expanded FIXME #15189

#![allow(non_snake_case)]
#![feature(unboxed_closures, overloaded_calls)]
#![feature(unboxed_closures)]

use std::iter::AdditiveIterator;
use std::mem;
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/borrowck-overloaded-call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(overloaded_calls)]
#![feature(unboxed_closures)]

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

Expand Down
60 changes: 60 additions & 0 deletions src/test/compile-fail/hrtb-higher-ranker-supertraits-transitive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test HRTB supertraits with several levels of expansion required.

trait Foo<'tcx>
{
fn foo(&'tcx self) -> &'tcx int;
}

trait Bar<'ccx>
: for<'tcx> Foo<'tcx>
{
fn bar(&'ccx self) -> &'ccx int;
}

trait Baz
: for<'ccx> Bar<'ccx>
{
fn dummy(&self);
}

trait Qux
: Bar<'static>
{
fn dummy(&self);
}

fn want_foo_for_any_tcx<F>(f: &F)
where F : for<'tcx> Foo<'tcx>
{
}

fn want_bar_for_any_ccx<B>(b: &B)
where B : for<'ccx> Bar<'ccx>
{
}

fn want_baz<B>(b: &B)
where B : Baz
{
want_foo_for_any_tcx(b);
want_bar_for_any_ccx(b);
}

fn want_qux<B>(b: &B)
where B : Qux
{
want_foo_for_any_tcx(b);
want_bar_for_any_ccx(b); //~ ERROR not implemented
}

fn main() {}
58 changes: 58 additions & 0 deletions src/test/compile-fail/hrtb-higher-ranker-supertraits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test a trait (`Bar`) with a higher-ranked supertrait.

trait Foo<'tcx>
{
fn foo(&'tcx self) -> &'tcx int;
}

trait Bar<'ccx>
: for<'tcx> Foo<'tcx>
{
fn bar(&'ccx self) -> &'ccx int;
}

fn want_foo_for_some_tcx<'x,F>(f: &'x F)
where F : Foo<'x>
{
want_foo_for_some_tcx(f);
want_foo_for_any_tcx(f); //~ ERROR not implemented
}

fn want_foo_for_any_tcx<F>(f: &F)
where F : for<'tcx> Foo<'tcx>
{
want_foo_for_some_tcx(f);
want_foo_for_any_tcx(f);
}

fn want_bar_for_some_ccx<'x,B>(b: &B)
where B : Bar<'x>
{
want_foo_for_some_tcx(b);
want_foo_for_any_tcx(b);

want_bar_for_some_ccx(b);
want_bar_for_any_ccx(b); //~ ERROR not implemented
}

fn want_bar_for_any_ccx<B>(b: &B)
where B : for<'ccx> Bar<'ccx>
{
want_foo_for_some_tcx(b);
want_foo_for_any_tcx(b);

want_bar_for_some_ccx(b);
want_bar_for_any_ccx(b);
}

fn main() {}
35 changes: 35 additions & 0 deletions src/test/compile-fail/hrtb-identity-fn-borrows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test that the `'a` in the where clause correctly links the region
// of the output to the region of the input.

trait FnLike<A,R> {
fn call(&self, arg: A) -> R;
}

fn call_repeatedly<F>(f: F)
where F : for<'a> FnLike<&'a int, &'a int>
{
// Result is stored: cannot re-assign `x`
let mut x = 3;
let y = f.call(&x);
x = 5; //~ ERROR cannot assign

// Result is not stored: can re-assign `x`
let mut x = 3;
f.call(&x);
f.call(&x);
f.call(&x);
x = 5;
}

fn main() {
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-15094.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(overloaded_calls)]
#![feature(unboxed_closures)]

use std::{fmt, ops};

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-18532.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// when a type error or unconstrained type variable propagates
// into it.

#![feature(overloaded_calls)]
#![feature(unboxed_closures)]

fn main() {
(return)((),());
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/overloaded-calls-bad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(overloaded_calls)]
#![feature(unboxed_closures)]

use std::ops::FnMut;

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/overloaded-calls-nontuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(overloaded_calls)]
#![feature(unboxed_closures)]

use std::ops::FnMut;

Expand Down
43 changes: 43 additions & 0 deletions src/test/compile-fail/stage0-clone-contravariant-lifetime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// A zero-dependency test that covers some basic traits, default
// methods, etc. When mucking about with basic type system stuff I
// often encounter problems in the iterator trait, so it's useful to
// have hanging around. -nmatsakis

// error-pattern: requires `start` lang_item

#![no_std]
#![feature(lang_items)]

#[lang = "sized"]
pub trait Sized for Sized? {
// Empty.
}

pub mod std {
pub mod clone {
pub trait Clone {
fn clone(&self) -> Self;
}
}
}

pub struct ContravariantLifetime<'a>;

impl <'a> ::std::clone::Clone for ContravariantLifetime<'a> {
#[inline]
fn clone(&self) -> ContravariantLifetime<'a> {
match *self { ContravariantLifetime => ContravariantLifetime, }
}
}

fn main() { }
40 changes: 40 additions & 0 deletions src/test/compile-fail/stage0-cmp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.


// A zero-dependency test that covers some basic traits, default
// methods, etc. When mucking about with basic type system stuff I
// often encounter problems in the iterator trait, so it's useful to
// have hanging around. -nmatsakis

// error-pattern: requires `start` lang_item

#![no_std]
#![feature(lang_items)]

#[lang = "sized"]
pub trait Sized for Sized? {
// Empty.
}

#[unstable = "Definition may change slightly after trait reform"]
pub trait PartialEq for Sized? {
/// This method tests for `self` and `other` values to be equal, and is used by `==`.
fn eq(&self, other: &Self) -> bool;
}

#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
#[unstable = "Trait is unstable."]
impl<'a, Sized? T: PartialEq> PartialEq for &'a T {
#[inline]
fn eq(&self, other: & &'a T) -> bool { PartialEq::eq(*self, *other) }
}

fn main() { }
Loading

1 comment on commit 56ba260

@nikomatsakis
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=pcwalton p=1

Please sign in to comment.