Skip to content
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
19 changes: 19 additions & 0 deletions gcc/rust/checks/lints/unused/rust-unused-checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,5 +347,24 @@ UnusedChecker::visit (HIR::LetStmt &stmt)
walk (stmt);
}

void
UnusedChecker::visit (HIR::TypeAlias &type_alias)
{
bool has_bounds = type_alias.has_where_clause ();
for (auto &param : type_alias.get_generic_params ())
if (param->get_kind () == HIR::GenericParam::GenericKind::TYPE)
{
auto &type_param = static_cast<HIR::TypeParam &> (*param);
if (type_param.has_type_param_bounds ())
has_bounds = true;
}

if (has_bounds)
rust_warning_at (type_alias.get_locus (), OPT_Wunused,
"bounds on generic parameters in type aliases are not "
"enforced");
walk (type_alias);
}

} // namespace Analysis
} // namespace Rust
1 change: 1 addition & 0 deletions gcc/rust/checks/lints/unused/rust-unused-checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class UnusedChecker : public HIR::DefaultHIRVisitor
virtual void visit (HIR::MatchExpr &expr) override;
virtual void visit (HIR::ExternBlock &block) override;
virtual void visit (HIR::LetStmt &stmt) override;
virtual void visit (HIR::TypeAlias &type_alias) override;
virtual void visit_loop_label (HIR::LoopLabel &label) override;
};
} // namespace Analysis
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/rust-lang.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ grs_langhook_init_options_struct (struct gcc_options *opts)

/* We need to warn on unused variables by default */
opts->x_warn_unused_variable = 1;
/* Experimental lints under -frust-unused-check-2.0 warn by default */
opts->x_warn_unused = 1;
/* For const variables too */
opts->x_warn_unused_const_variable = 1;
/* And finally unused result for #[must_use] */
Expand Down
11 changes: 11 additions & 0 deletions gcc/testsuite/rust/compile/type-alias-bounds_0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// { dg-additional-options "-frust-unused-check-2.0" }
#![feature(no_core, lang_items)]
#![no_core]

#[lang = "sized"]
pub trait Sized {}

pub trait Foo {}

pub type Alias<T: Foo> = T;
// { dg-warning "bounds on generic parameters in type aliases are not enforced" "" { target *-*-* } .-1 }
Loading