Skip to content

Commit bc409cb

Browse files
committed
rollup merge of #23117: japaric/default-impl
fixes #23080 r? @nikomatsakis cc @flaper87
2 parents 3c2c516 + 8a391dd commit bc409cb

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

src/librustc_typeck/check/wf.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
118118

119119
self.check_variances_for_type_defn(item, ast_generics);
120120
}
121-
ast::ItemTrait(_, ref ast_generics, _, _) => {
121+
ast::ItemTrait(_, ref ast_generics, _, ref items) => {
122122
let trait_predicates =
123123
ty::lookup_predicates(ccx.tcx, local_def(item.id));
124124
reject_non_type_param_bounds(
@@ -127,6 +127,14 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
127127
&trait_predicates);
128128
self.check_variances(item, ast_generics, &trait_predicates,
129129
self.tcx().lang_items.phantom_fn());
130+
if ty::trait_has_default_impl(ccx.tcx, local_def(item.id)) {
131+
if !items.is_empty() {
132+
ccx.tcx.sess.span_err(
133+
item.span,
134+
"traits with default impls (`e.g. unsafe impl Trait for ..`) must \
135+
have no methods or associated items")
136+
}
137+
}
130138
}
131139
_ => {}
132140
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
// ignore-tidy-linelength
12+
13+
#![feature(optin_builtin_traits)]
14+
15+
use std::marker::MarkerTrait;
16+
17+
unsafe trait Trait: MarkerTrait {
18+
//~^ error: traits with default impls (`e.g. unsafe impl Trait for ..`) must have no methods or associated items
19+
type Output;
20+
}
21+
22+
unsafe impl Trait for .. {}
23+
24+
fn call_method<T: Trait>(x: T) {}
25+
26+
fn main() {
27+
// ICE
28+
call_method(());
29+
}

src/test/compile-fail/issue-23080.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
// ignore-tidy-linelength
12+
13+
#![feature(optin_builtin_traits)]
14+
15+
unsafe trait Trait {
16+
//~^ error: traits with default impls (`e.g. unsafe impl Trait for ..`) must have no methods or associated items
17+
fn method(&self) {
18+
println!("Hello");
19+
}
20+
}
21+
22+
unsafe impl Trait for .. {}
23+
24+
fn call_method<T: Trait>(x: T) {
25+
x.method();
26+
}
27+
28+
fn main() {
29+
// ICE
30+
call_method(());
31+
}

0 commit comments

Comments
 (0)