Skip to content

Commit 332f83b

Browse files
committed
---
yaml --- r: 216293 b: refs/heads/stable c: 7f78887 h: refs/heads/master i: 216291: 011290d v: v3
1 parent c63398c commit 332f83b

7 files changed

+168
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ refs/heads/tmp: 378a370ff2057afeb1eae86eb6e78c476866a4a6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: a5286998df566e736b32f6795bfc3803bdaf453d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 3d9b5d04242567648800c5594695f147c6bca05b
32+
refs/heads/stable: 7f7888754745696467d6ba8f93ce2b9e50c10b3b
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375

branches/stable/src/test/compile-fail/impl-type-where-trait-has-method.rs renamed to branches/stable/src/test/compile-fail/associated-const-impl-wrong-type.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
trait Foo {
12-
fn bar(&self);
11+
use std::marker::MarkerTrait;
12+
13+
trait Foo: MarkerTrait {
14+
const BAR: u32;
1315
}
1416

15-
impl Foo for u32 {
16-
//~^ ERROR not all trait items implemented, missing: `bar`
17-
type bar = u64;
18-
//~^ ERROR item `bar` is an associated type, which doesn't match its trait `Foo`
17+
struct SignedBar;
18+
19+
impl Foo for SignedBar {
20+
const BAR: i32 = -1;
21+
//~^ ERROR E0326
1922
}
2023

21-
fn main () {}
24+
fn main() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
#![deny(non_upper_case_globals)]
12+
#![allow(dead_code)]
13+
14+
struct Foo;
15+
16+
impl Foo {
17+
const not_upper: bool = true;
18+
}
19+
//~^^ ERROR associated constant `not_upper` should have an upper case name such as `NOT_UPPER`
20+
21+
fn main() {}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
trait Foo {
12+
fn bar(&self);
13+
const MY_CONST: u32;
14+
}
15+
16+
pub struct FooConstForMethod;
17+
18+
impl Foo for FooConstForMethod {
19+
//~^ ERROR E0046
20+
const bar: u64 = 1;
21+
//~^ ERROR E0323
22+
const MY_CONST: u32 = 1;
23+
}
24+
25+
pub struct FooMethodForConst;
26+
27+
impl Foo for FooMethodForConst {
28+
//~^ ERROR E0046
29+
fn bar(&self) {}
30+
fn MY_CONST() {}
31+
//~^ ERROR E0324
32+
}
33+
34+
pub struct FooTypeForMethod;
35+
36+
impl Foo for FooTypeForMethod {
37+
//~^ ERROR E0046
38+
type bar = u64;
39+
//~^ ERROR E0325
40+
const MY_CONST: u32 = 1;
41+
}
42+
43+
fn main () {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
#![deny(dead_code)]
12+
13+
const GLOBAL_BAR: u32 = 1;
14+
15+
struct Foo;
16+
17+
impl Foo {
18+
const BAR: u32 = GLOBAL_BAR;
19+
}
20+
21+
fn main() {
22+
let _: u32 = Foo::BAR;
23+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
use std::marker::MarkerTrait;
12+
13+
struct MyType;
14+
15+
impl MyType {
16+
const IMPL_IS_INHERENT: bool = true;
17+
}
18+
19+
trait MyTrait: MarkerTrait {
20+
const IMPL_IS_INHERENT: bool;
21+
const IMPL_IS_ON_TRAIT: bool;
22+
}
23+
24+
impl MyTrait for MyType {
25+
const IMPL_IS_INHERENT: bool = false;
26+
const IMPL_IS_ON_TRAIT: bool = true;
27+
}
28+
29+
fn main() {
30+
// Check that the inherent impl is used before the trait, but that the trait
31+
// can still be accessed.
32+
assert!(<MyType>::IMPL_IS_INHERENT);
33+
assert!(!<MyType as MyTrait>::IMPL_IS_INHERENT);
34+
assert!(<MyType>::IMPL_IS_ON_TRAIT);
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
use std::marker::MarkerTrait;
12+
13+
// The main purpose of this test is to ensure that different impls of the same
14+
// trait can refer to each other without setting off the static recursion check
15+
// (as long as there's no actual recursion).
16+
17+
trait Foo: MarkerTrait {
18+
const BAR: u32;
19+
}
20+
21+
struct IsFoo1;
22+
23+
impl Foo for IsFoo1 {
24+
const BAR: u32 = 1;
25+
}
26+
27+
struct IsFoo2;
28+
29+
impl Foo for IsFoo2 {
30+
const BAR: u32 = <IsFoo1 as Foo>::BAR;
31+
}
32+
33+
fn main() {
34+
assert_eq!(<IsFoo1>::BAR, <IsFoo2 as Foo>::BAR);
35+
}

0 commit comments

Comments
 (0)