rustc: Disallow machine applicability in foreign macros
Recent changes to lints disallowed lints from being emitted against code located in foreign macros, except for future-incompatible lints. For a future incompatible lint, however, the automatic suggestions may not be applicable! This commit updates this code path to force all applicability suggestions made to foreign macros to never be `MachineApplicable`. This should avoid rustfix actually attempting fixing these suggestions, causing non-compiling code to be produced. Closes rust-lang/cargo#5799
This commit is contained in:
parent
54628c8ea8
commit
ca762ba954
8 changed files with 217 additions and 35 deletions
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![crate_type = "proc-macro"]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
use proc_macro::*;
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn foo(_attr: TokenStream, _f: TokenStream) -> TokenStream {
|
||||
"pub fn foo() -> ::Foo { ::Foo }".parse().unwrap()
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// aux-build:suggestions-not-always-applicable.rs
|
||||
// compile-flags: --edition 2015
|
||||
// run-rustfix
|
||||
// rustfix-only-machine-applicable
|
||||
// compile-pass
|
||||
|
||||
#![feature(rust_2018_preview)]
|
||||
#![warn(rust_2018_compatibility)]
|
||||
|
||||
extern crate suggestions_not_always_applicable as foo;
|
||||
|
||||
pub struct Foo;
|
||||
|
||||
mod test {
|
||||
use crate::foo::foo;
|
||||
|
||||
#[foo] //~ WARN: absolute paths must start with
|
||||
//~| WARN: previously accepted
|
||||
//~| WARN: absolute paths
|
||||
//~| WARN: previously accepted
|
||||
fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test::foo();
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// aux-build:suggestions-not-always-applicable.rs
|
||||
// compile-flags: --edition 2015
|
||||
// run-rustfix
|
||||
// rustfix-only-machine-applicable
|
||||
// compile-pass
|
||||
|
||||
#![feature(rust_2018_preview)]
|
||||
#![warn(rust_2018_compatibility)]
|
||||
|
||||
extern crate suggestions_not_always_applicable as foo;
|
||||
|
||||
pub struct Foo;
|
||||
|
||||
mod test {
|
||||
use crate::foo::foo;
|
||||
|
||||
#[foo] //~ WARN: absolute paths must start with
|
||||
//~| WARN: previously accepted
|
||||
//~| WARN: absolute paths
|
||||
//~| WARN: previously accepted
|
||||
fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test::foo();
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
warning: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/suggestions-not-always-applicable.rs:27:5
|
||||
|
|
||||
LL | #[foo] //~ WARN: absolute paths must start with
|
||||
| ^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/suggestions-not-always-applicable.rs:18:9
|
||||
|
|
||||
LL | #![warn(rust_2018_compatibility)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: #[warn(absolute_paths_not_starting_with_crate)] implied by #[warn(rust_2018_compatibility)]
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
|
||||
= note: for more information, see issue TBD
|
||||
|
||||
warning: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/suggestions-not-always-applicable.rs:27:5
|
||||
|
|
||||
LL | #[foo] //~ WARN: absolute paths must start with
|
||||
| ^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
|
||||
= note: for more information, see issue TBD
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue