diff options
| author | Waffle Maybe <waffle.lapkin@gmail.com> | 2022-01-04 13:21:56 +0300 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-01-09 12:21:33 +0300 |
| commit | 96b2f8ac3268f0aee4d10868f9e31a5f7b66641b (patch) | |
| tree | f5281af05c26e73fc83d79c33f1b52a5e7ffed18 | |
| parent | 268ae9a232372dcdff59830310d353d8539acb35 (diff) | |
| download | rust-96b2f8ac3268f0aee4d10868f9e31a5f7b66641b.tar.gz rust-96b2f8ac3268f0aee4d10868f9e31a5f7b66641b.zip | |
Apply suggestions from code review
Use "(associated) function" terminology instead of "method". Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
5 files changed, 27 insertions, 25 deletions
diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 6f119d5ab88..3e1605aabfd 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -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" diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs index c4c75434980..9f8053d4a4e 100644 --- a/compiler/rustc_middle/src/ty/trait_def.rs +++ b/compiler/rustc_middle/src/ty/trait_def.rs @@ -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]>>, } diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 50613ef7104..b95a2b6fa49 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -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(), } diff --git a/src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.rs b/src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.rs index 161e94273f8..1089e5f9c4a 100644 --- a/src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.rs +++ b/src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.rs @@ -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() {} diff --git a/src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.stderr b/src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.stderr index b5428cf3310..74a6dc8fec9 100644 --- a/src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.stderr +++ b/src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.stderr @@ -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(); |
