Skip to content

Commit 2a20073

Browse files
committed
Prohibit parenthesized params in bounds etc.
1 parent 63ecd6a commit 2a20073

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

Diff for: src/librustc_typeck/astconv.rs

+11
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
372372
self_ty: Ty<'tcx>)
373373
-> ty::TraitRef<'tcx>
374374
{
375+
self.prohibit_type_params(trait_ref.path.segments.split_last().unwrap().1);
376+
375377
let trait_def_id = self.trait_def_id(trait_ref);
376378
self.ast_path_to_mono_trait_ref(trait_ref.path.span,
377379
trait_def_id,
@@ -404,6 +406,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
404406

405407
debug!("ast_path_to_poly_trait_ref({:?}, def_id={:?})", trait_ref, trait_def_id);
406408

409+
self.prohibit_type_params(trait_ref.path.segments.split_last().unwrap().1);
410+
407411
let (substs, assoc_bindings) =
408412
self.create_substs_for_ast_trait_ref(trait_ref.path.span,
409413
trait_def_id,
@@ -625,6 +629,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
625629
dummy_self,
626630
&mut projection_bounds);
627631

632+
for trait_bound in trait_bounds[1..].iter() {
633+
// Sanity check for non-principal trait bounds
634+
self.instantiate_poly_trait_ref(trait_bound,
635+
dummy_self,
636+
&mut vec![]);
637+
}
638+
628639
let (auto_traits, trait_bounds) = split_auto_traits(tcx, &trait_bounds[1..]);
629640

630641
if !trait_bounds.is_empty() {

Diff for: src/librustc_typeck/check/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4495,7 +4495,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
44954495
(&data.lifetimes[..], &data.types[..], data.infer_types, &data.bindings[..])
44964496
}
44974497
Some(&hir::ParenthesizedParameters(_)) => {
4498-
span_bug!(span, "parenthesized parameters cannot appear in ExprPath");
4498+
AstConv::prohibit_parenthesized_params(self, &segment.as_ref().unwrap().0);
4499+
(&[][..], &[][..], true, &[][..])
44994500
}
45004501
None => (&[][..], &[][..], true, &[][..])
45014502
}

Diff for: src/test/compile-fail/issue-32995-2.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2017 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+
#![feature(conservative_impl_trait)]
12+
13+
fn main() {
14+
{ fn f<X: ::std::marker()::Send>() {} }
15+
//~^ ERROR parenthesized parameters may only be used with a trait
16+
17+
{ fn f() -> impl ::std::marker()::Send { } }
18+
//~^ ERROR parenthesized parameters may only be used with a trait
19+
}
20+
21+
#[derive(Clone)]
22+
struct X;
23+
24+
impl ::std::marker()::Copy for X {}
25+
//~^ ERROR parenthesized parameters may only be used with a trait

Diff for: src/test/compile-fail/issue-32995.rs

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ fn main() {
1717

1818
let b: ::std::boxed()::Box<_> = Box::new(1);
1919
//~^ ERROR parenthesized parameters may only be used with a trait
20+
21+
macro_rules! pathexpr {
22+
($p:path) => { $p }
23+
}
24+
25+
let p = pathexpr!(::std::str()::from_utf8)(b"foo").unwrap();
26+
//~^ ERROR parenthesized parameters may only be used with a trait
27+
28+
let p = pathexpr!(::std::str::from_utf8())(b"foo").unwrap();
29+
//~^ ERROR parenthesized parameters may only be used with a trait
30+
31+
let o : Box<::std::marker()::Send> = Box::new(1);
32+
//~^ ERROR parenthesized parameters may only be used with a trait
33+
34+
let o : Box<Send + ::std::marker()::Sync> = Box::new(1);
35+
//~^ ERROR parenthesized parameters may only be used with a trait
2036
}
2137

2238
fn foo<X:Default>() {

0 commit comments

Comments
 (0)