Skip to content

Commit 96b2f8a

Browse files
Apply suggestions from code review
Use "(associated) function" terminology instead of "method". Co-authored-by: Daniel Henry-Mantilla <[email protected]>
1 parent 268ae9a commit 96b2f8a

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
678678
from method dispatch when the receiver is an array, for compatibility in editions < 2021."
679679
),
680680
rustc_attr!(
681-
rustc_must_implement_one_of, Normal, template!(List: "method1, method2, ..."), ErrorFollowing,
681+
rustc_must_implement_one_of, Normal, template!(List: "function1, function2, ..."), ErrorFollowing,
682682
"the `#[rustc_must_implement_one_of]` attribute is used to change minimal complete \
683683
definition of a trait, it's currently in experimental form and should be changed before \
684684
being exposed outside of the std"

compiler/rustc_middle/src/ty/trait_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct TraitDef {
4545
/// recomputed all the time.
4646
pub def_path_hash: DefPathHash,
4747

48-
/// List of methods from `#[rustc_must_implement_one_of]` attribute one of which
48+
/// List of functions from `#[rustc_must_implement_one_of]` attribute one of which
4949
/// must be implemented.
5050
pub must_implement_one_of: Option<Box<[Ident]>>,
5151
}

compiler/rustc_typeck/src/collect.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1253,15 +1253,17 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
12531253
.map(|item| item.ident().ok_or(item.span()))
12541254
.collect::<Result<Box<[_]>, _>>()
12551255
.map_err(|span| {
1256-
tcx.sess.struct_span_err(span, "must be an identifier of a method").emit();
1256+
tcx.sess
1257+
.struct_span_err(span, "must be a name of an associated function")
1258+
.emit();
12571259
})
12581260
.ok()
12591261
.zip(Some(attr.span)),
12601262
// Error is reported by `rustc_attr!`
12611263
None => None,
12621264
})
12631265
// Check that all arguments of `#[rustc_must_implement_one_of]` reference
1264-
// methods in the trait with default implementations
1266+
// functions in the trait with default implementations
12651267
.and_then(|(list, attr_span)| {
12661268
let errors = list.iter().filter_map(|ident| {
12671269
let item = items.iter().find(|item| item.ident == *ident);
@@ -1272,7 +1274,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
12721274
tcx.sess
12731275
.struct_span_err(
12741276
item.span,
1275-
"This method doesn't have a default implementation",
1277+
"This function doesn't have a default implementation",
12761278
)
12771279
.span_note(attr_span, "required by this annotation")
12781280
.emit();
@@ -1284,16 +1286,16 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
12841286
}
12851287
Some(item) => tcx
12861288
.sess
1287-
.struct_span_err(item.span, "Not a method")
1289+
.struct_span_err(item.span, "Not a function")
12881290
.span_note(attr_span, "required by this annotation")
12891291
.note(
12901292
"All `#[rustc_must_implement_one_of]` arguments \
1291-
must be method identifiers",
1293+
must be associated function names",
12921294
)
12931295
.emit(),
12941296
None => tcx
12951297
.sess
1296-
.struct_span_err(ident.span, "Method not found in this trait")
1298+
.struct_span_err(ident.span, "Function not found in this trait")
12971299
.emit(),
12981300
}
12991301

src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#![feature(rustc_attrs)]
22

33
#[rustc_must_implement_one_of(a, b)]
4-
//~^ Method not found in this trait
5-
//~| Method not found in this trait
4+
//~^ Function not found in this trait
5+
//~| Function not found in this trait
66
trait Tr0 {}
77

88
#[rustc_must_implement_one_of(a, b)]
9-
//~^ Method not found in this trait
9+
//~^ Function not found in this trait
1010
trait Tr1 {
1111
fn a() {}
1212
}
@@ -23,16 +23,16 @@ trait Tr3 {}
2323

2424
#[rustc_must_implement_one_of(A, B)]
2525
trait Tr4 {
26-
const A: u8 = 1; //~ Not a method
26+
const A: u8 = 1; //~ Not a function
2727

28-
type B; //~ Not a method
28+
type B; //~ Not a function
2929
}
3030

3131
#[rustc_must_implement_one_of(a, b)]
3232
trait Tr5 {
33-
fn a(); //~ This method doesn't have a default implementation
33+
fn a(); //~ This function doesn't have a default implementation
3434

35-
fn b(); //~ This method doesn't have a default implementation
35+
fn b(); //~ This function doesn't have a default implementation
3636
}
3737

3838
fn main() {}

src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ error: malformed `rustc_must_implement_one_of` attribute input
22
--> $DIR/rustc_must_implement_one_of_misuse.rs:20:1
33
|
44
LL | #[rustc_must_implement_one_of]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_must_implement_one_of(method1, method2, ...)]`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_must_implement_one_of(function1, function2, ...)]`
66

7-
error: Method not found in this trait
7+
error: Function not found in this trait
88
--> $DIR/rustc_must_implement_one_of_misuse.rs:3:31
99
|
1010
LL | #[rustc_must_implement_one_of(a, b)]
1111
| ^
1212

13-
error: Method not found in this trait
13+
error: Function not found in this trait
1414
--> $DIR/rustc_must_implement_one_of_misuse.rs:3:34
1515
|
1616
LL | #[rustc_must_implement_one_of(a, b)]
1717
| ^
1818

19-
error: Method not found in this trait
19+
error: Function not found in this trait
2020
--> $DIR/rustc_must_implement_one_of_misuse.rs:8:34
2121
|
2222
LL | #[rustc_must_implement_one_of(a, b)]
@@ -28,7 +28,7 @@ error: the `#[rustc_must_implement_one_of]` attribute must be used with at least
2828
LL | #[rustc_must_implement_one_of(a)]
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3030

31-
error: Not a method
31+
error: Not a function
3232
--> $DIR/rustc_must_implement_one_of_misuse.rs:26:5
3333
|
3434
LL | const A: u8 = 1;
@@ -39,9 +39,9 @@ note: required by this annotation
3939
|
4040
LL | #[rustc_must_implement_one_of(A, B)]
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42-
= note: All `#[rustc_must_implement_one_of]` arguments must be method identifiers
42+
= note: All `#[rustc_must_implement_one_of]` arguments must be associated function names
4343

44-
error: Not a method
44+
error: Not a function
4545
--> $DIR/rustc_must_implement_one_of_misuse.rs:28:5
4646
|
4747
LL | type B;
@@ -52,9 +52,9 @@ note: required by this annotation
5252
|
5353
LL | #[rustc_must_implement_one_of(A, B)]
5454
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55-
= note: All `#[rustc_must_implement_one_of]` arguments must be method identifiers
55+
= note: All `#[rustc_must_implement_one_of]` arguments must be associated function names
5656

57-
error: This method doesn't have a default implementation
57+
error: This function doesn't have a default implementation
5858
--> $DIR/rustc_must_implement_one_of_misuse.rs:33:5
5959
|
6060
LL | fn a();
@@ -66,7 +66,7 @@ note: required by this annotation
6666
LL | #[rustc_must_implement_one_of(a, b)]
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6868

69-
error: This method doesn't have a default implementation
69+
error: This function doesn't have a default implementation
7070
--> $DIR/rustc_must_implement_one_of_misuse.rs:35:5
7171
|
7272
LL | fn b();

0 commit comments

Comments
 (0)