Skip to content

Commit 3ebdbac

Browse files
ahmedcharlesflaper87
authored andcommitted
Do not permit type parameters on builtin bounds.
1 parent dcc6ce2 commit 3ebdbac

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,8 +1847,14 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
18471847
if ty::try_add_builtin_trait(tcx,
18481848
trait_did,
18491849
&mut builtin_bounds) {
1850-
// FIXME(#20302) -- we should check for things like Copy<T>
1851-
continue; // success
1850+
let segments = &b.trait_ref.path.segments;
1851+
let parameters = &segments[segments.len() - 1].parameters;
1852+
if parameters.is_empty() {
1853+
continue; // success
1854+
}
1855+
span_err!(tcx.sess, b.trait_ref.path.span, E0316,
1856+
"builtin bounds do not require arguments, {} given",
1857+
parameters.types().len());
18521858
}
18531859
}
18541860
_ => {

src/librustc_typeck/diagnostics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ register_diagnostics! {
171171
E0247, // found module name used as a type
172172
E0248, // found value name used as a type
173173
E0249, // expected constant expr for array length
174-
E0250 // expected constant expr for array length
174+
E0250, // expected constant expr for array length
175+
E0316 // wrong number of type arguments to a built-in trait
175176
}
176177

177178
__build_diagnostic_array! { DIAGNOSTICS }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2015 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+
fn foo1<T:Copy<U>, U>(x: T) {}
12+
//~^ ERROR: builtin bounds do not require arguments, 1 given
13+
14+
trait Trait: Copy<Send> {}
15+
//~^ ERROR: builtin bounds do not require arguments, 1 given
16+
17+
struct MyStruct1<T: Copy<T>>;
18+
//~^ ERROR: builtin bounds do not require arguments, 1 given
19+
20+
struct MyStruct2<'a, T: Copy<'a>>;
21+
//~^ ERROR: builtin bounds do not require arguments, 1 given
22+
23+
fn foo2<'a, T:Copy<'a, U>, U>(x: T) {}
24+
//~^ ERROR: builtin bounds do not require arguments, 1 given
25+
26+
fn main() {
27+
}

0 commit comments

Comments
 (0)