@@ -1745,3 +1745,50 @@ fn fix_with_run_cargo_in_proc_macros() {
1745
1745
. with_stderr_does_not_contain ( "error: could not find .rs file in rustc args" )
1746
1746
. run ( ) ;
1747
1747
}
1748
+
1749
+ #[ cargo_test]
1750
+ fn non_edition_lint_migration ( ) {
1751
+ // Migrating to a new edition where a non-edition lint causes problems.
1752
+ if !is_nightly ( ) {
1753
+ // Remove once force-warn hits stable.
1754
+ return ;
1755
+ }
1756
+ let p = project ( )
1757
+ . file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.1.0" ) )
1758
+ . file (
1759
+ "src/lib.rs" ,
1760
+ r#"
1761
+ // This is only used in a test.
1762
+ // To be correct, this should be gated on #[cfg(test)], but
1763
+ // sometimes people don't do that. If the unused_imports
1764
+ // lint removes this, then the unittest will fail to compile.
1765
+ use std::str::from_utf8;
1766
+
1767
+ pub mod foo {
1768
+ pub const FOO: &[u8] = &[102, 111, 111];
1769
+ }
1770
+
1771
+ #[test]
1772
+ fn example() {
1773
+ assert_eq!(
1774
+ from_utf8(::foo::FOO), Ok("foo")
1775
+ );
1776
+ }
1777
+ "# ,
1778
+ )
1779
+ . build ( ) ;
1780
+ // Check that it complains about an unused import.
1781
+ p. cargo ( "check --lib" )
1782
+ . with_stderr_contains ( "[..]unused_imports[..]" )
1783
+ . with_stderr_contains ( "[..]std::str::from_utf8[..]" )
1784
+ . run ( ) ;
1785
+ p. cargo ( "fix --edition --allow-no-vcs" )
1786
+ // Remove once --force-warn is stabilized
1787
+ . masquerade_as_nightly_cargo ( )
1788
+ . run ( ) ;
1789
+ let contents = p. read_file ( "src/lib.rs" ) ;
1790
+ // Check it does not remove the "unused" import.
1791
+ assert ! ( contents. contains( "use std::str::from_utf8;" ) ) ;
1792
+ // Check that it made the edition migration.
1793
+ assert ! ( contents. contains( "from_utf8(crate::foo::FOO)" ) ) ;
1794
+ }
0 commit comments