Thread overview
Diagnostics for redundant qualifiers
Jul 28, 2021
Per Nordlöw
Jul 28, 2021
Paul Backus
Jul 28, 2021
Nicholas Wilson
Jul 29, 2021
Walter Bright
Jul 30, 2021
Per Nordlöw
July 28, 2021

What about making

@safe struct S  {
   void f() @safe {}
}

warn or deprecate as

Warning: redundant function attribute `@safe`

?

July 28, 2021

On Wednesday, 28 July 2021 at 18:54:12 UTC, Per Nordlöw wrote:

>

What about making

@safe struct S  {
   void f() @safe {}
}

warn or deprecate as

Warning: redundant function attribute `@safe`

?

What's the harm in allowing redundant attributes?

Generally, warnings are helpful when they point out code that is likely to do something different from what the programmer intended (e.g., if (a = b)). If the programmer wrote @safe in two places, I'd say there's very little chance they did it by mistake.

July 28, 2021

On Wednesday, 28 July 2021 at 18:54:12 UTC, Per Nordlöw wrote:

>

What about making

@safe struct S  {
   void f() @safe {}
}

warn or deprecate as

Warning: redundant function attribute `@safe`

?

No, think about if f is generated from a string or template mixin.

July 29, 2021
On 7/28/2021 11:54 AM, Per Nordlöw wrote:
> What about making
> 
> ```d
> @safe struct S  {
>     void f() @safe {}
> }
> ```
> 
> warn or deprecate as
> 
> ```
> Warning: redundant function attribute `@safe`
> ```
> 
> ?

The compiler will complain about:

    @safe @safe void test();

but not:

    @safe { @safe void test(); }
    @safe: @safe void bar();

This is quite deliberate. It's the same for all the attributes.

Nicholas has the right justification.
July 30, 2021

On Thursday, 29 July 2021 at 17:22:28 UTC, Walter Bright wrote:

>

This is quite deliberate. It's the same for all the attributes.

Nicholas has the right justification.

Seems reasonable. Thanks.