Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Use "(associated) function" terminology instead of "method".

Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
  • Loading branch information
WaffleLapkin and danielhenrymantilla committed Jan 9, 2022
1 parent 268ae9a commit 96b2f8a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/trait_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]>>,
}
Expand Down
14 changes: 8 additions & 6 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,15 +1253,17 @@ 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)),
// Error is reported by `rustc_attr!`
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);
Expand All @@ -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();
Expand All @@ -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(),
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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() {}
}
Expand All @@ -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() {}
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 96b2f8a

Please sign in to comment.