Skip to content

Commit d3d14d6

Browse files
author
wickerwaka
committed
Added cfail test
Changed error to 'use of trait `{}` as a struct constructor'
1 parent f5776f8 commit d3d14d6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: src/librustc/middle/typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4000,7 +4000,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
40004000
}
40014001
Some(def::DefTrait(def_id)) => {
40024002
span_err!(tcx.sess, path.span, E0159,
4003-
"`{}` is a trait not a structure",
4003+
"use of trait `{}` as a struct constructor",
40044004
pprust::path_to_string(path));
40054005
check_struct_fields_on_error(fcx,
40064006
id,

Diff for: src/test/compile-fail/trait-as-struct-constructor.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 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+
trait TraitNotAStruct { }
12+
13+
fn main() {
14+
TraitNotAStruct{ value: 0 };
15+
//~^ ERROR: use of trait `TraitNotAStruct` as a struct constructor [E0159]
16+
}
17+

0 commit comments

Comments
 (0)