Skip to content

Commit 565235e

Browse files
committed
Auto merge of #50454 - Manishearth:edition-preview-fixes, r=alexcrichton
Various edition preview fixes Implement a bunch of things discussed in the meeting.
2 parents 6288970 + ae4b38e commit 565235e

File tree

14 files changed

+53
-24
lines changed

14 files changed

+53
-24
lines changed

src/librustc/lint/builtin.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! compiler code, rather than using their own custom pass. Those
1515
//! lints are all available in `rustc_lint::builtin`.
1616
17-
use errors::DiagnosticBuilder;
17+
use errors::{Applicability, DiagnosticBuilder};
1818
use lint::{LintPass, LateLintPass, LintArray};
1919
use session::Session;
2020
use syntax::codemap::Span;
@@ -341,15 +341,16 @@ impl BuiltinLintDiagnostics {
341341
match self {
342342
BuiltinLintDiagnostics::Normal => (),
343343
BuiltinLintDiagnostics::BareTraitObject(span, is_global) => {
344-
let sugg = match sess.codemap().span_to_snippet(span) {
345-
Ok(ref s) if is_global => format!("dyn ({})", s),
346-
Ok(s) => format!("dyn {}", s),
347-
Err(_) => format!("dyn <type>")
344+
let (sugg, app) = match sess.codemap().span_to_snippet(span) {
345+
Ok(ref s) if is_global => (format!("dyn ({})", s),
346+
Applicability::MachineApplicable),
347+
Ok(s) => (format!("dyn {}", s), Applicability::MachineApplicable),
348+
Err(_) => (format!("dyn <type>"), Applicability::HasPlaceholders)
348349
};
349-
db.span_suggestion(span, "use `dyn`", sugg);
350+
db.span_suggestion_with_applicability(span, "use `dyn`", sugg, app);
350351
}
351352
BuiltinLintDiagnostics::AbsPathWithModule(span) => {
352-
let sugg = match sess.codemap().span_to_snippet(span) {
353+
let (sugg, app) = match sess.codemap().span_to_snippet(span) {
353354
Ok(ref s) => {
354355
// FIXME(Manishearth) ideally the emitting code
355356
// can tell us whether or not this is global
@@ -359,11 +360,11 @@ impl BuiltinLintDiagnostics {
359360
"::"
360361
};
361362

362-
format!("crate{}{}", opt_colon, s)
363+
(format!("crate{}{}", opt_colon, s), Applicability::MachineApplicable)
363364
}
364-
Err(_) => format!("crate::<path>")
365+
Err(_) => (format!("crate::<path>"), Applicability::HasPlaceholders)
365366
};
366-
db.span_suggestion(span, "use `crate`", sugg);
367+
db.span_suggestion_with_applicability(span, "use `crate`", sugg, app);
367368
}
368369
}
369370
}

src/librustc_lint/builtin.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use syntax::attr;
4646
use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_attributes};
4747
use syntax_pos::{BytePos, Span, SyntaxContext};
4848
use syntax::symbol::keywords;
49-
use syntax::errors::DiagnosticBuilder;
49+
use syntax::errors::{Applicability, DiagnosticBuilder};
5050

5151
use rustc::hir::{self, PatKind};
5252
use rustc::hir::intravisit::FnKind;
@@ -1300,7 +1300,19 @@ impl UnreachablePub {
13001300
} else {
13011301
"pub(crate)"
13021302
}.to_owned();
1303-
err.span_suggestion(pub_span, "consider restricting its visibility", replacement);
1303+
let app = if span.ctxt().outer().expn_info().is_none() {
1304+
// even if macros aren't involved the suggestion
1305+
// may be incorrect -- the user may have mistakenly
1306+
// hidden it behind a private module and this lint is
1307+
// a helpful way to catch that. However, we're trying
1308+
// not to change the nature of the code with this lint
1309+
// so it's marked as machine applicable.
1310+
Applicability::MachineApplicable
1311+
} else {
1312+
Applicability::MaybeIncorrect
1313+
};
1314+
err.span_suggestion_with_applicability(pub_span, "consider restricting its visibility",
1315+
replacement, app);
13041316
if exportable {
13051317
err.help("or consider exporting it for use by other crates");
13061318
}

src/librustc_lint/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
178178
UNUSED_PARENS);
179179

180180
add_lint_group!(sess,
181-
"rust_2018_idioms",
181+
"rust_2018_migration",
182182
BARE_TRAIT_OBJECT,
183183
UNREACHABLE_PUB);
184184

src/librustc_resolve/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3277,9 +3277,8 @@ impl<'a> Resolver<'a> {
32773277
let prev_name = path[0].name;
32783278
if prev_name == keywords::Extern.name() ||
32793279
prev_name == keywords::CrateRoot.name() &&
3280-
// Note: When this feature stabilizes, this should
3281-
// be gated on sess.rust_2018()
3282-
self.session.features_untracked().extern_absolute_paths {
3280+
self.session.features_untracked().extern_absolute_paths &&
3281+
self.session.rust_2018() {
32833282
// `::extern_crate::a::b`
32843283
let crate_id = self.crate_loader.process_path_extern(name, ident.span);
32853284
let crate_root =

src/librustc_resolve/resolve_imports.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
646646
if module_path.len() == 1 && (module_path[0].name == keywords::CrateRoot.name() ||
647647
module_path[0].name == keywords::Extern.name()) {
648648
let is_extern = module_path[0].name == keywords::Extern.name() ||
649-
self.session.features_untracked().extern_absolute_paths;
649+
(self.session.features_untracked().extern_absolute_paths &&
650+
self.session.rust_2018());
650651
match directive.subclass {
651652
GlobImport { .. } if is_extern => {
652653
return Some((directive.span,

src/libsyntax/edition.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ impl fmt::Display for Edition {
5050
impl Edition {
5151
pub fn lint_name(&self) -> &'static str {
5252
match *self {
53-
Edition::Edition2015 => "edition_2015",
54-
Edition::Edition2018 => "edition_2018",
53+
Edition::Edition2015 => "rust_2015_breakage",
54+
Edition::Edition2018 => "rust_2018_breakage",
5555
}
5656
}
5757

src/libsyntax/feature_gate.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ declare_features! (
300300
(active, abi_unadjusted, "1.16.0", None, None),
301301

302302
// Procedural macros 2.0.
303-
(active, proc_macro, "1.16.0", Some(38356), None),
303+
(active, proc_macro, "1.16.0", Some(38356), Some(Edition::Edition2018)),
304304

305305
// Declarative macros 2.0 (`macro`).
306306
(active, decl_macro, "1.17.0", Some(39412), None),
@@ -324,7 +324,7 @@ declare_features! (
324324

325325

326326
// Allows the `catch {...}` expression
327-
(active, catch_expr, "1.17.0", Some(31436), None),
327+
(active, catch_expr, "1.17.0", Some(31436), Some(Edition::Edition2018)),
328328

329329
// Used to preserve symbols (see llvm.used)
330330
(active, used, "1.18.0", Some(40289), None),
@@ -1848,6 +1848,14 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
18481848

18491849
let mut feature_checker = FeatureChecker::default();
18501850

1851+
for &(.., f_edition, set) in ACTIVE_FEATURES.iter() {
1852+
if let Some(f_edition) = f_edition {
1853+
if f_edition <= crate_edition {
1854+
set(&mut features, DUMMY_SP);
1855+
}
1856+
}
1857+
}
1858+
18511859
for attr in krate_attrs {
18521860
if !attr.check_name("feature") {
18531861
continue

src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: --edition=2018 -Zunstable-options
12+
1113
#![feature(extern_absolute_paths)]
1214

1315
use xcrate::S; //~ ERROR can't find crate for `xcrate`

src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-2.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: --edition=2018 -Zunstable-options
12+
1113
#![feature(extern_absolute_paths)]
1214

1315
fn main() {

src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-3.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: --edition=2018 -Zunstable-options
12+
1113
#![feature(extern_absolute_paths)]
1214

1315
use ycrate; //~ ERROR can't find crate for `ycrate`

src/test/compile-fail/rfc-2126-extern-absolute-paths/single-segment.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
// aux-build:xcrate.rs
12+
// compile-flags: --edition=2018 -Zunstable-options
1213

1314
#![feature(crate_in_paths)]
1415
#![feature(extern_absolute_paths)]

src/test/run-make-fulldeps/save-analysis-rfc2126/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
-include ../tools.mk
22

33
all: extern_absolute_paths.rs extern_in_paths.rs krate2
4-
$(RUSTC) extern_absolute_paths.rs -Zsave-analysis
4+
$(RUSTC) extern_absolute_paths.rs -Zsave-analysis --edition=2018
55
cat $(TMPDIR)/save-analysis/extern_absolute_paths.json | "$(PYTHON)" validate_json.py
6-
$(RUSTC) extern_in_paths.rs -Zsave-analysis
6+
$(RUSTC) extern_in_paths.rs -Zsave-analysis --edition=2018
77
cat $(TMPDIR)/save-analysis/extern_in_paths.json | "$(PYTHON)" validate_json.py
88

99
krate2: krate2.rs

src/test/run-pass/rfc-2126-extern-absolute-paths/basic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
// aux-build:xcrate.rs
12+
// compile-flags: --edition=2018 -Zunstable-options
1213

1314
#![feature(extern_absolute_paths)]
1415

src/test/run-pass/rfc-2126-extern-absolute-paths/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
// Regression test for #47075.
1414

15-
// compile-flags: --test
15+
// compile-flags: --test --edition=2018 -Zunstable-options
1616

1717
#![feature(extern_absolute_paths)]
1818

0 commit comments

Comments
 (0)