-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Partially fix explicit_outlives_requirements
lint in macros
#106064
Conversation
Show the suggestion if and only if the bounds are from the same source context.
r? @lcnr (rustbot has picked a reviewer for you, use r? to override) |
explicit_outlives_requirements
lint in macrosexplicit_outlives_requirements
lint in macros
r? compiler (on vacation) |
}) | ||
.unwrap_or(param_span.shrink_to_hi()); | ||
let span = | ||
bounds.iter().fold(param_span.shrink_to_hi(), |span, bound| span.to(bound.span())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, the issue is that we are trying to reconstruct a span during lowering, which will mix spans coming from macro different expansions.
Fortunately, we know what SyntaxContext
produces the :
, it's GenericParam::colon_span
.
So there are 2 cases here:
- if
colon_span
isNone
, we should useparam_span.shrink_to_hi()
; - if not, we should use it, and extend it with
bound.span().find_ancestor_in_same_ctxt(colon_span.ctxt())
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bound.span().find_ancestor_in_same_ctxt(colon_span.ctxt())
goes horribly wrong when the colon also comes from a macro parameter:
rust/src/test/ui/rust-2018/edition-lint-infer-outlives-macro.rs
Lines 89 to 96 in 1eba6c4
macro_rules! m { | |
($b:lifetime $colon:tt $a:lifetime) => { | |
struct Foo<$a, $b $colon $a>(&$a &$b ()); | |
struct Bar<$a, $b>(&$a &$b ()) where $b $colon $a; | |
struct Baz<$a, $b>(&$a &$b ()) where (): Sized, $b $colon $a; | |
} | |
} | |
m!('b: 'a); |
I changed this to search only in the "parent span", which is either the entire generics list for (normal) generic args or the impl Trait
span.
d379a25
to
1eba6c4
Compare
I've addressed the review comments and this PR also fixes #106063 now. There are, however, still some remaining inconsistencies. See the This happens, because the where clause span gets messed up in the parser here: rust/compiler/rustc_parse/src/parser/generics.rs Lines 248 to 315 in a1fc711
... due to incomplete handling of mixed macro expansions in rust/compiler/rustc_span/src/lib.rs Lines 810 to 818 in a1fc711
This is presumably a problem elsewhere too and should probably be addressed in general (in a different PR) instead of adding more special casing here. @rustbot review |
I'm not sure I understand what is the issue with your FIXME. |
…mpiler-errors Rollup of 9 pull requests Successful merges: - rust-lang#103718 (More inference-friendly API for lazy) - rust-lang#105765 (Detect likely `.` -> `..` typo in method calls) - rust-lang#105852 (Suggest rewriting a malformed hex literal if we expect a float) - rust-lang#105965 (Provide local extern function arg names) - rust-lang#106064 (Partially fix `explicit_outlives_requirements` lint in macros) - rust-lang#106179 (Fix a formatting error in Iterator::for_each docs) - rust-lang#106181 (Fix doc comment parsing description in book) - rust-lang#106187 (Update the documentation of `Vec` to use `extend(array)` instead of `extend(array.iter().copied())`) - rust-lang#106189 (Fix UnsafeCell Documentation Spelling Error) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Show the suggestion if and only if the bounds are from the same source context.
fixes #106044
fixes #106063