Skip to content

The compiler sets bad krate span for plugins #23964

@huonw

Description

@huonw
// bad_plugin_span.rs
#![crate_type="dylib"]
#![feature(plugin_registrar, rustc_private)]

extern crate rustc;

#[plugin_registrar]
pub fn plugin_registrar(reg: &mut rustc::plugin::Registry) {
    println!("{:?}", reg.krate_span);
    reg.sess.span_err(reg.krate_span, "should point to `#[plugin(...)]`");
}
// bad_plugin_span_demo.rs
#![feature(plugin)]
#![plugin(bad_plugin_span)]

fn main() {}
$ rustc bad_plugin_span.rs && rustc -L . bad_plugin_span_demo.rs
Span { lo: BytePos(27), hi: BytePos(87), expn_id: ExpnId(4294967295) }
bad_plugin_span_demo.rs:2:1: 5:12 error: should point to `#[plugin(...)]`
bad_plugin_span_demo.rs:2 #![feature(plugin)]
bad_plugin_span_demo.rs:3 #![plugin(bad_plugin_span)]
bad_plugin_span_demo.rs:4 
bad_plugin_span_demo.rs:5 fn main() {}
error: aborting due to previous error

The krate_span field of the registry should be pointing to the place that introduces the plugin, i.e. the #[plugin(...)] but it is instead pointing to the whole file (at least, from the start of the first token to the end of the last).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-pluginsArea: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.htmlP-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions