Add diagnostics for unsafe_op_in_unsafe_fn

Turns out it's pretty easy, but I did have to add support for allowed-by-default lints.
This commit is contained in:
Chayim Refael Friedman 2024-09-18 03:02:12 +03:00
parent 94b526fc86
commit f6eb5be591
5 changed files with 55 additions and 10 deletions

View file

@ -258,6 +258,8 @@ pub struct PrivateField {
#[derive(Debug)]
pub struct MissingUnsafe {
pub expr: InFile<AstPtr<ast::Expr>>,
/// If true, the diagnostics is an `unsafe_op_in_unsafe_fn` lint instead of a hard error.
pub only_lint: bool,
}
#[derive(Debug)]

View file

@ -1884,9 +1884,10 @@ impl DefWithBody {
);
}
for expr in hir_ty::diagnostics::missing_unsafe(db, self.into()) {
let (unafe_exprs, only_lint) = hir_ty::diagnostics::missing_unsafe(db, self.into());
for expr in unafe_exprs {
match source_map.expr_syntax(expr) {
Ok(expr) => acc.push(MissingUnsafe { expr }.into()),
Ok(expr) => acc.push(MissingUnsafe { expr, only_lint }.into()),
Err(SyntheticSyntax) => {
// FIXME: Here and elsewhere in this file, the `expr` was
// desugared, report or assert that this doesn't happen.