Select proper span for delegation, update span of child path segment if needed#154002
Select proper span for delegation, update span of child path segment if needed#154002aerooneqq wants to merge 1 commit intorust-lang:mainfrom
Conversation
| // thus those spans can point either to local or external | ||
| // trait functions. This `span` is also used for diagnostics purposes, so we want it to point | ||
| // to delegation, not to the random trait function, so we perform this check here. | ||
| // We could have added similar check in `rustc_resolve::macros::glob_delegation_suffixes` |
There was a problem hiding this comment.
This was my first reaction - we should generate a good span (not referring to a completely different entity) during expansion, when we are building the expanded delegation item AST. Patching these spans during AST lowering doesn't seem right.
What exactly breaks if impl-reuse-pass if the span is changed during expansion?
There was a problem hiding this comment.
There's also a question of which spans to use exactly.
- For single delegations expanded from glob delegations I'd set the last segment's span to the star symbol's span.
- For
reuse implthere's no better choice than the whole item span, I guess.
There was a problem hiding this comment.
Errors are in macros test. I've tried to change span only for path segment (as in code below) and span of the ident, in both cases there were errors.
Changes
suffixes.iter().map(move |&(ident, rename)| {
let mut path = deleg.prefix.clone();
let mut seg_ident = ident;
if !item_span.contains(seg_ident.span) {
seg_ident.span = item_span;
}
path.segments.push(ast::PathSegment {
ident: seg_ident,
id: ast::DUMMY_NODE_ID,
args: None,
});
ast::Item {
attrs: item.attrs.clone(),
id: ast::DUMMY_NODE_ID,
span: if from_glob { item_span } else { ident.span },
vis: item.vis.clone(),
kind: Node::delegation_item_kind(Box::new(ast::Delegation {
id: ast::DUMMY_NODE_ID,
qself: deleg.qself.clone(),
path,
ident: rename.unwrap_or(ident),
rename,
body: deleg.body.clone(),
from_glob,
})),
tokens: None,
}
})Errors
error[E0424]: expected value, found module `self`
--> C:\work\rust\tests\ui\delegation\impl-reuse-pass.rs:177:80
|
LL | macro_rules! one_line_reuse { ($self:ident) => { reuse impl Trait for S1 { $self.0 } } }
| --------------------------^^^^^----
| | |
| | `self` value is a keyword only available in methods with a `self` parameter
| `self` not allowed in an implementation
LL | one_line_reuse!(self);
| --------------------- in this macro invocation
|
= note: this error originates in the macro `one_line_reuse` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0424]: expected value, found module `self`
--> C:\work\rust\tests\ui\delegation\impl-reuse-pass.rs:177:80
|
LL | macro_rules! one_line_reuse { ($self:ident) => { reuse impl Trait for S1 { $self.0 } } }
| --------------------------^^^^^----
| | |
| | `self` value is a keyword only available in methods with a `self` parameter
| `self` not allowed in an implementation
LL | one_line_reuse!(self);
| --------------------- in this macro invocation
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= note: this error originates in the macro `one_line_reuse` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0424]: expected value, found module `self`
--> C:\work\rust\tests\ui\delegation\impl-reuse-pass.rs:182:26
|
LL | macro_rules! one_line_reuse_expr { ($x:expr) => { reuse impl Trait for S2 { $x } } }
| ------------------------------ `self` not allowed in an implementation
LL | one_line_reuse_expr!(self.0);
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter
error[E0424]: expected value, found module `self`
--> C:\work\rust\tests\ui\delegation\impl-reuse-pass.rs:182:26
|
LL | macro_rules! one_line_reuse_expr { ($x:expr) => { reuse impl Trait for S2 { $x } } }
| ------------------------------ `self` not allowed in an implementation
LL | one_line_reuse_expr!(self.0);
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0424]: expected value, found module `self`
--> C:\work\rust\tests\ui\delegation\impl-reuse-pass.rs:187:27
|
LL | macro_rules! one_line_reuse_expr2 { ($x:expr) => { reuse impl Trait for s3!() { $x } } }
| --------------------------------- `self` not allowed in an implementation
LL | one_line_reuse_expr2!(self.0);
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter
error[E0424]: expected value, found module `self`
--> C:\work\rust\tests\ui\delegation\impl-reuse-pass.rs:187:27
|
LL | macro_rules! one_line_reuse_expr2 { ($x:expr) => { reuse impl Trait for s3!() { $x } } }
| --------------------------------- `self` not allowed in an implementation
LL | one_line_reuse_expr2!(self.0);
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: aborting due to 6 previous errors
There was a problem hiding this comment.
I'll debug the test failure, I'm sure that we should do it during macro expansion.
|
@rustbot ready |
|
Closing in favor of #154049. |
This PR selects more appropriate span for delegation, as span related to child segment of delegation path can point to delegee trait function. Moreover, we update span of child segment during AST -> HIR lowering for proper diagnostics.
Created from discussion. Part of #118212.
r? @petrochenkov