Skip to content

Do not permit type parameters on builtin bounds. #21549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1834,8 +1834,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<T>
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());
}
}
_ => {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ register_diagnostics! {
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 }
Expand Down
27 changes: 27 additions & 0 deletions src/test/compile-fail/typeck-builtin-bound-type-parameters.rs
Original file line number Diff line number Diff line change
@@ -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 <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.

fn foo1<T:Copy<U>, U>(x: T) {}
//~^ ERROR: builtin bounds do not require arguments, 1 given

trait Trait: Copy<Send> {}
//~^ ERROR: builtin bounds do not require arguments, 1 given

struct MyStruct1<T: Copy<T>>;
//~^ 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() {
}