Skip to content

Commit 9ba2423

Browse files
committed
Contextual only tests
2 parents c03c902 + 857a6cc commit 9ba2423

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ symbols! {
6161
Mod: "mod",
6262
Move: "move",
6363
Mut: "mut",
64-
Only: "only",
6564
Pub: "pub",
6665
Ref: "ref",
6766
Return: "return",
@@ -130,6 +129,7 @@ symbols! {
130129
ContractRequires: "contract_requires",
131130
Default: "default",
132131
MacroRules: "macro_rules",
132+
Only: "only",
133133
Raw: "raw",
134134
Reuse: "reuse",
135135
Safe: "safe",

tests/ui/trait-bounds/only-bound.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,37 @@ trait InheritedOnly: OnlyPointeeSized {
5050
}
5151
}
5252

53+
54+
55+
fn only(){
56+
let only = 0u32;
57+
}
58+
59+
mod a{
60+
#[allow(non_camel_case_types)]
61+
struct only {}
62+
}
63+
64+
mod b {
65+
use std::marker::{MetaSized, PointeeSized};
66+
67+
#[allow(non_camel_case_types)]
68+
trait only: only PointeeSized {
69+
fn foo(&self) {
70+
size_of_val(self);
71+
//~^ ERROR the size for values of type `Self` cannot be known
72+
}
73+
}
74+
}
75+
76+
mod only{
77+
pub trait Alpha {}
78+
}
79+
80+
// In the below context, rust will attempt to look for `Alpha` in the crate root, not in a module
81+
// `only`
82+
//fn alpha<T: only::Alpha>(){
83+
//}
84+
85+
5386
fn main() {}

tests/ui/trait-bounds/only-bound.stderr

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ LL | size_of_val(&self);
7777
LL | size_of_val(&mut self);
7878
| ++++
7979

80-
error: aborting due to 7 previous errors
80+
error[E0277]: the size for values of type `Self` cannot be known
81+
--> $DIR/only-bound.rs:70:25
82+
|
83+
LL | size_of_val(self);
84+
| ----------- ^^^^ the trait `MetaSized` is not implemented for `Self`
85+
| |
86+
| required by a bound introduced by this call
87+
|
88+
= note: the trait bound `Self: MetaSized` is not satisfied
89+
note: required by a bound in `std::mem::size_of_val`
90+
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
91+
help: consider borrowing here
92+
|
93+
LL | size_of_val(&self);
94+
| +
95+
LL | size_of_val(&mut self);
96+
| ++++
97+
98+
error: aborting due to 8 previous errors
8199

82100
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)