From 3ebdbac2651cd21f2efda8d3b381ed396d7bb725 Mon Sep 17 00:00:00 2001 From: Ahmed Charles Date: Sat, 24 Jan 2015 09:53:05 -0800 Subject: [PATCH] Do not permit type parameters on builtin bounds. --- src/librustc_typeck/astconv.rs | 10 +++++-- src/librustc_typeck/diagnostics.rs | 3 ++- .../typeck-builtin-bound-type-parameters.rs | 27 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/test/compile-fail/typeck-builtin-bound-type-parameters.rs diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index afdc414c163..bb27918075d 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1847,8 +1847,14 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt, if ty::try_add_builtin_trait(tcx, trait_did, &mut builtin_bounds) { - // FIXME(#20302) -- we should check for things like Copy - continue; // success + let segments = &b.trait_ref.path.segments; + let parameters = &segments[segments.len() - 1].parameters; + if parameters.is_empty() { + continue; // success + } + span_err!(tcx.sess, b.trait_ref.path.span, E0316, + "builtin bounds do not require arguments, {} given", + parameters.types().len()); } } _ => { diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 17cf92d39d8..82334eb253b 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -171,7 +171,8 @@ E0247, // found module name used as a type E0248, // found value name used as a type E0249, // expected constant expr for array length - E0250 // expected constant expr for array length + E0250, // expected constant expr for array length + E0316 // wrong number of type arguments to a built-in trait } __build_diagnostic_array! { DIAGNOSTICS } diff --git a/src/test/compile-fail/typeck-builtin-bound-type-parameters.rs b/src/test/compile-fail/typeck-builtin-bound-type-parameters.rs new file mode 100644 index 00000000000..3914fb96a0d --- /dev/null +++ b/src/test/compile-fail/typeck-builtin-bound-type-parameters.rs @@ -0,0 +1,27 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn foo1, U>(x: T) {} +//~^ ERROR: builtin bounds do not require arguments, 1 given + +trait Trait: Copy {} +//~^ ERROR: builtin bounds do not require arguments, 1 given + +struct MyStruct1>; +//~^ ERROR: builtin bounds do not require arguments, 1 given + +struct MyStruct2<'a, T: Copy<'a>>; +//~^ ERROR: builtin bounds do not require arguments, 1 given + +fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} +//~^ ERROR: builtin bounds do not require arguments, 1 given + +fn main() { +} -- GitLab