Apply suggestions from code review

Use "(associated) function" terminology instead of "method".

Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
This commit is contained in:
Waffle Maybe 2022-01-04 13:21:56 +03:00 committed by Maybe Waffle
parent 268ae9a232
commit 96b2f8ac32
5 changed files with 27 additions and 25 deletions

View file

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

View file

@ -45,7 +45,7 @@ pub struct TraitDef {
/// recomputed all the time.
pub def_path_hash: DefPathHash,
/// List of methods from `#[rustc_must_implement_one_of]` attribute one of which
/// List of functions from `#[rustc_must_implement_one_of]` attribute one of which
/// must be implemented.
pub must_implement_one_of: Option<Box<[Ident]>>,
}

View file

@ -1253,7 +1253,9 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
.map(|item| item.ident().ok_or(item.span()))
.collect::<Result<Box<[_]>, _>>()
.map_err(|span| {
tcx.sess.struct_span_err(span, "must be an identifier of a method").emit();
tcx.sess
.struct_span_err(span, "must be a name of an associated function")
.emit();
})
.ok()
.zip(Some(attr.span)),
@ -1261,7 +1263,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
None => None,
})
// Check that all arguments of `#[rustc_must_implement_one_of]` reference
// methods in the trait with default implementations
// functions in the trait with default implementations
.and_then(|(list, attr_span)| {
let errors = list.iter().filter_map(|ident| {
let item = items.iter().find(|item| item.ident == *ident);
@ -1272,7 +1274,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
tcx.sess
.struct_span_err(
item.span,
"This method doesn't have a default implementation",
"This function doesn't have a default implementation",
)
.span_note(attr_span, "required by this annotation")
.emit();
@ -1284,16 +1286,16 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
}
Some(item) => tcx
.sess
.struct_span_err(item.span, "Not a method")
.struct_span_err(item.span, "Not a function")
.span_note(attr_span, "required by this annotation")
.note(
"All `#[rustc_must_implement_one_of]` arguments \
must be method identifiers",
must be associated function names",
)
.emit(),
None => tcx
.sess
.struct_span_err(ident.span, "Method not found in this trait")
.struct_span_err(ident.span, "Function not found in this trait")
.emit(),
}

View file

@ -1,12 +1,12 @@
#![feature(rustc_attrs)]
#[rustc_must_implement_one_of(a, b)]
//~^ Method not found in this trait
//~| Method not found in this trait
//~^ Function not found in this trait
//~| Function not found in this trait
trait Tr0 {}
#[rustc_must_implement_one_of(a, b)]
//~^ Method not found in this trait
//~^ Function not found in this trait
trait Tr1 {
fn a() {}
}
@ -23,16 +23,16 @@ trait Tr3 {}
#[rustc_must_implement_one_of(A, B)]
trait Tr4 {
const A: u8 = 1; //~ Not a method
const A: u8 = 1; //~ Not a function
type B; //~ Not a method
type B; //~ Not a function
}
#[rustc_must_implement_one_of(a, b)]
trait Tr5 {
fn a(); //~ This method doesn't have a default implementation
fn a(); //~ This function doesn't have a default implementation
fn b(); //~ This method doesn't have a default implementation
fn b(); //~ This function doesn't have a default implementation
}
fn main() {}

View file

@ -2,21 +2,21 @@ error: malformed `rustc_must_implement_one_of` attribute input
--> $DIR/rustc_must_implement_one_of_misuse.rs:20:1
|
LL | #[rustc_must_implement_one_of]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_must_implement_one_of(method1, method2, ...)]`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_must_implement_one_of(function1, function2, ...)]`
error: Method not found in this trait
error: Function not found in this trait
--> $DIR/rustc_must_implement_one_of_misuse.rs:3:31
|
LL | #[rustc_must_implement_one_of(a, b)]
| ^
error: Method not found in this trait
error: Function not found in this trait
--> $DIR/rustc_must_implement_one_of_misuse.rs:3:34
|
LL | #[rustc_must_implement_one_of(a, b)]
| ^
error: Method not found in this trait
error: Function not found in this trait
--> $DIR/rustc_must_implement_one_of_misuse.rs:8:34
|
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
LL | #[rustc_must_implement_one_of(a)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Not a method
error: Not a function
--> $DIR/rustc_must_implement_one_of_misuse.rs:26:5
|
LL | const A: u8 = 1;
@ -39,9 +39,9 @@ note: required by this annotation
|
LL | #[rustc_must_implement_one_of(A, B)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: All `#[rustc_must_implement_one_of]` arguments must be method identifiers
= note: All `#[rustc_must_implement_one_of]` arguments must be associated function names
error: Not a method
error: Not a function
--> $DIR/rustc_must_implement_one_of_misuse.rs:28:5
|
LL | type B;
@ -52,9 +52,9 @@ note: required by this annotation
|
LL | #[rustc_must_implement_one_of(A, B)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: All `#[rustc_must_implement_one_of]` arguments must be method identifiers
= note: All `#[rustc_must_implement_one_of]` arguments must be associated function names
error: This method doesn't have a default implementation
error: This function doesn't have a default implementation
--> $DIR/rustc_must_implement_one_of_misuse.rs:33:5
|
LL | fn a();
@ -66,7 +66,7 @@ note: required by this annotation
LL | #[rustc_must_implement_one_of(a, b)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: This method doesn't have a default implementation
error: This function doesn't have a default implementation
--> $DIR/rustc_must_implement_one_of_misuse.rs:35:5
|
LL | fn b();