Skip to content

Allow #[must_use] on associated types to warn on unused values in generic contexts #142590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mod sealed {

/// This is for compatibility with the regular `Visitor`.
pub trait MutVisitorResult {
#[cfg_attr(not(bootstrap), must_use)]
type Result: VisitorResult;
}

Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub enum LifetimeCtxt {
pub trait Visitor<'ast>: Sized {
/// The result type of the `visit_*` methods. Can be either `()`,
/// or `ControlFlow<T>`.
#[cfg_attr(not(bootstrap), must_use)]
type Result: VisitorResult = ();

fn visit_ident(&mut self, _ident: &'ast Ident) -> Self::Result {
Expand Down Expand Up @@ -884,7 +885,7 @@ macro_rules! common_visitor_and_walkers {
TyKind::BareFn(function_declaration) => {
let BareFnTy { safety, ext: _, generic_params, decl, decl_span } =
&$($mut)? **function_declaration;
visit_safety(vis, safety);
try_visit!(visit_safety(vis, safety));
try_visit!(visit_generic_params(vis, generic_params));
try_visit!(vis.visit_fn_decl(decl));
try_visit!(visit_span(vis, decl_span));
Expand Down Expand Up @@ -1235,7 +1236,7 @@ macro_rules! common_visitor_and_walkers {
bounds,
bound_generic_params,
}) => {
visit_generic_params(vis, bound_generic_params);
try_visit!(visit_generic_params(vis, bound_generic_params));
try_visit!(vis.visit_ty(bounded_ty));
walk_list!(vis, visit_param_bound, bounds, BoundKind::Bound);
}
Expand Down Expand Up @@ -1420,7 +1421,7 @@ macro_rules! common_visitor_and_walkers {
let StructExpr { qself, path, fields, rest } = &$($mut)?**se;
try_visit!(vis.visit_qself(qself));
try_visit!(vis.visit_path(path));
visit_expr_fields(vis, fields);
try_visit!(visit_expr_fields(vis, fields));
match rest {
StructRest::Base(expr) => try_visit!(vis.visit_expr(expr)),
StructRest::Rest(_span) => {}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ pub trait Visitor<'v>: Sized {

/// The result type of the `visit_*` methods. Can be either `()`,
/// or `ControlFlow<T>`.
#[cfg_attr(not(bootstrap), must_use)]
type Result: VisitorResult = ();

/// If `type NestedFilter` is set to visit nested items, this method
Expand Down
Loading
Loading