You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
elided_lifetime_in_path triggers for the format! macro #48385
error: hidden lifetime parameters are deprecated, try `Foo<'_>`
--> src/main.rs:5:5
|
5 | format!("foo {}", 22)
| ^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> src/main.rs:2:9
|
2 | #![deny(elided_lifetime_in_path)]
| ^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
I suppose the easiest fix is to fix the format! expansion, but maybe better to suppress this warning for macros outside of the current crate? Feels like a more general problem.
I think the more general problem is that lints should be hygienic - we should only check them against ast nodes from this code, not those generated by a macro.
we should only check them against ast nodes from this code
I've seen someone bit by something similar. They had a deny(unsafe) but a crate's macro ended up expanding to an unsafe block. IIRC, they fixed the library to add an allow on the block inside the macro.
It does feel wrong to do this on a lint-by-lint basis, though, right? Maybe as part of struct_lint_level?
It's not that simple, though. The node being linted may be outside of a macro, but it may contain macroy things that affect the lint. The correct way to handle this is to identify all the "important" nodes and do a macro check.
(Also: All currently supported ways of doing a macro check will not lint stuff like some_macro!(some.code.that.hits.the.lint), which isn't an uncommon breed of macro.)
bug!("lint traversal reached the root of the crate");
}
id = next;
}
})
}
That is, this seems like an identical problem to deciding whether the lint is enabled. We're basically talking about adding some measure of hygiene to that check, right?
(Also, I'm totally willing to be believe we should just work around this for now, and defer any more general changes to be done as part of a hygiene-overhaul-sort-of-thing.)
However, bear in mind that we may not want this at all for future compat lints (we already catalog these so we can special case this).
Interesting point. Probably we don't, yes. =) (The story around future compatibility and dependencies is sort of complicated, I think, but see also #34596)
This issue is also related to this topic: #51903.
Is this prioritised in any way? Seems like this had been known for a while now, and it's a shame because i would like to use this lint in my code.
Activity
nikomatsakis commentedon Feb 20, 2018
cc @Dylan-DPC
withoutboats commentedon Feb 20, 2018
I think the more general problem is that lints should be hygienic - we should only check them against ast nodes from this code, not those generated by a macro.
shepmaster commentedon Feb 20, 2018
I've seen someone bit by something similar. They had a
deny(unsafe)but a crate's macro ended up expanding to anunsafeblock. IIRC, they fixed the library to add anallowon the block inside the macro.So +1 for this kind of fix.
durka commentedon Feb 20, 2018
That won't help with
forbid.Dylan-DPC-zz commentedon Feb 21, 2018
Any pointers on how to suppress this warning for macros outside of the current crate?
durka commentedon Feb 21, 2018
Clippy has a function.
nikomatsakis commentedon Feb 21, 2018
It does feel wrong to do this on a lint-by-lint basis, though, right? Maybe as part of
struct_lint_level?rust/src/librustc/lint/mod.rs
Lines 404 to 420 in 27a046e
We could e.g. return the "dummy" value for spans that are not in the current crate:
rust/src/librustc/lint/mod.rs
Line 413 in 27a046e
Manishearth commentedon Feb 23, 2018
It's not that simple, though. The node being linted may be outside of a macro, but it may contain macroy things that affect the lint. The correct way to handle this is to identify all the "important" nodes and do a macro check.
(Also: All currently supported ways of doing a macro check will not lint stuff like
some_macro!(some.code.that.hits.the.lint), which isn't an uncommon breed of macro.)nikomatsakis commentedon Feb 23, 2018
@Manishearth
So actually
struct_lint_levelis probably not the right place. Rather,lint_level_at_node:rust/src/librustc/ty/context.rs
Lines 2222 to 2247 in 27a046e
That is, this seems like an identical problem to deciding whether the lint is enabled. We're basically talking about adding some measure of hygiene to that check, right?
(Also, I'm totally willing to be believe we should just work around this for now, and defer any more general changes to be done as part of a hygiene-overhaul-sort-of-thing.)
nikomatsakis commentedon Feb 23, 2018
(One annoying problem: that fn does not presently have a span.)
Manishearth commentedon Feb 23, 2018
It's almost identical to that problem, and I think we can get away with that approximation for now.
I can think of counterexamples but it just makes the lints slightly overconservative so nbd.
However, bear in mind that we may not want this at all for future compat lints (we already catalog these so we can special case this).
nikomatsakis commentedon Feb 23, 2018
@Manishearth
Interesting point. Probably we don't, yes. =) (The story around future compatibility and dependencies is sort of complicated, I think, but see also #34596)
Manishearth commentedon Mar 8, 2018
Issue for adding macro checks to lints at #48855
reuvenpo commentedon Jul 3, 2018
This issue is also related to this topic: #51903.
Is this prioritised in any way? Seems like this had been known for a while now, and it's a shame because i would like to use this lint in my code.
zackmdavis commentedon Oct 20, 2018
This is now fixed (lint was rewritten in #52069).