Skip to content

Commit 77f2a2f

Browse files
committed
Turn the error for module-relative access to macro-expanded macro_export macros into a deprecation lint
1 parent 7a8b726 commit 77f2a2f

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

src/librustc/lint/builtin.rs

+12
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,13 @@ declare_lint! {
331331
via the module system"
332332
}
333333

334+
declare_lint! {
335+
pub MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
336+
Deny,
337+
"macro-expanded `macro_export` macros from the current crate \
338+
cannot be referred to by absolute paths"
339+
}
340+
334341
/// Some lints that are buffered from `libsyntax`. See `syntax::early_buffered_lints`.
335342
pub mod parser {
336343
declare_lint! {
@@ -398,6 +405,7 @@ impl LintPass for HardwiredLints {
398405
WHERE_CLAUSES_OBJECT_SAFETY,
399406
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
400407
MACRO_USE_EXTERN_CRATE,
408+
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
401409
parser::QUESTION_MARK_MACRO_SEP,
402410
)
403411
}
@@ -412,6 +420,7 @@ pub enum BuiltinLintDiagnostics {
412420
AbsPathWithModule(Span),
413421
DuplicatedMacroExports(ast::Ident, Span, Span),
414422
ProcMacroDeriveResolutionFallback(Span),
423+
MacroExpandedMacroExportsAccessedByAbsolutePaths(Span),
415424
ElidedLifetimesInPaths(usize, Span, bool, Span, String),
416425
}
417426

@@ -453,6 +462,9 @@ impl BuiltinLintDiagnostics {
453462
db.span_label(span, "names from parent modules are not \
454463
accessible without an explicit import");
455464
}
465+
BuiltinLintDiagnostics::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def) => {
466+
db.span_note(span_def, "the macro is defined here");
467+
}
456468
BuiltinLintDiagnostics::ElidedLifetimesInPaths(
457469
n, path_span, incl_angl_brckt, insertion_span, anon_lts
458470
) => {

src/librustc_lint/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,12 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
334334
id: LintId::of(QUESTION_MARK_MACRO_SEP),
335335
reference: "issue #48075 <https://github.com/rust-lang/rust/issues/48075>",
336336
edition: Some(Edition::Edition2018),
337-
}
337+
},
338+
FutureIncompatibleInfo {
339+
id: LintId::of(MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS),
340+
reference: "issue #52234 <https://github.com/rust-lang/rust/issues/52234>",
341+
edition: None,
342+
},
338343
]);
339344

340345
// Register renamed and removed lints

src/librustc_resolve/lib.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -4477,9 +4477,12 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
44774477
for &(span_use, span_def) in &self.macro_expanded_macro_export_errors {
44784478
let msg = "macro-expanded `macro_export` macros from the current crate \
44794479
cannot be referred to by absolute paths";
4480-
self.session.struct_span_err(span_use, msg)
4481-
.span_note(span_def, "the macro is defined here")
4482-
.emit();
4480+
self.session.buffer_lint_with_diagnostic(
4481+
lint::builtin::MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
4482+
CRATE_NODE_ID, span_use, msg,
4483+
lint::builtin::BuiltinLintDiagnostics::
4484+
MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def),
4485+
);
44834486
}
44844487

44854488
for &AmbiguityError { span, name, b1, b2, lexical } in &self.ambiguity_errors {

src/test/ui/imports/local-modularized-tricky-fail-3.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ define_exported!();
2222
mod m {
2323
use exported;
2424
//~^ ERROR macro-expanded `macro_export` macros from the current crate cannot
25+
//~| WARN this was previously accepted
2526
}
2627

2728
fn main() {
2829
::exported!();
2930
//~^ ERROR macro-expanded `macro_export` macros from the current crate cannot
31+
//~| WARN this was previously accepted
3032
}

src/test/ui/imports/local-modularized-tricky-fail-3.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ error: macro-expanded `macro_export` macros from the current crate cannot be ref
44
LL | use exported;
55
| ^^^^^^^^
66
|
7+
= note: #[deny(macro_expanded_macro_exports_accessed_by_absolute_paths)] on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #52234 <https://github.com/rust-lang/rust/issues/52234>
710
note: the macro is defined here
811
--> $DIR/local-modularized-tricky-fail-3.rs:15:5
912
|
@@ -16,11 +19,13 @@ LL | define_exported!();
1619
| ------------------- in this macro invocation
1720

1821
error: macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
19-
--> $DIR/local-modularized-tricky-fail-3.rs:28:5
22+
--> $DIR/local-modularized-tricky-fail-3.rs:29:5
2023
|
2124
LL | ::exported!();
2225
| ^^^^^^^^^^
2326
|
27+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
28+
= note: for more information, see issue #52234 <https://github.com/rust-lang/rust/issues/52234>
2429
note: the macro is defined here
2530
--> $DIR/local-modularized-tricky-fail-3.rs:15:5
2631
|

0 commit comments

Comments
 (0)