From 3dfbe359eb0417a766d93ead2822144ad761dc4d Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 14 Nov 2018 14:42:49 +0100 Subject: [PATCH 1/6] xLTO: Don't pass --plugin-opt=thin to LLD. That's not supported anymore. --- src/librustc_codegen_llvm/back/linker.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/librustc_codegen_llvm/back/linker.rs b/src/librustc_codegen_llvm/back/linker.rs index e18c8b9dec463..1998afa80e32b 100644 --- a/src/librustc_codegen_llvm/back/linker.rs +++ b/src/librustc_codegen_llvm/back/linker.rs @@ -205,17 +205,6 @@ impl<'a> GccLinker<'a> { self.linker_arg(&format!("-plugin-opt={}", opt_level)); self.linker_arg(&format!("-plugin-opt=mcpu={}", llvm_util::target_cpu(self.sess))); - - match self.sess.lto() { - config::Lto::Thin | - config::Lto::ThinLocal => { - self.linker_arg("-plugin-opt=thin"); - } - config::Lto::Fat | - config::Lto::No => { - // default to regular LTO - } - } } } From eab5ddb2ef8ac68f52fb72aaf44f30a98075c587 Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 10 Nov 2018 18:08:50 +0000 Subject: [PATCH 2/6] Rewrite `...` as `..=` as a MachineApplicable 2018 idiom lint --- src/librustc/lint/context.rs | 7 ++- src/librustc/lint/mod.rs | 2 +- src/librustc_lint/builtin.rs | 44 ++++++++++++++----- src/librustc_lint/unused.rs | 4 +- .../lint/inclusive-range-pattern-syntax.fixed | 6 +++ .../ui/lint/inclusive-range-pattern-syntax.rs | 6 +++ .../inclusive-range-pattern-syntax.stderr | 6 +++ .../range-inclusive-pattern-precedence.stderr | 4 +- 8 files changed, 62 insertions(+), 17 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 7e2532bb1c4e8..ebb495fdfcee6 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1020,9 +1020,12 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { } fn visit_pat(&mut self, p: &'a ast::Pat) { - run_lints!(self, check_pat, p); + let mut visit_subpats = true; + run_lints!(self, check_pat, p, &mut visit_subpats); self.check_id(p.id); - ast_visit::walk_pat(self, p); + if visit_subpats { + ast_visit::walk_pat(self, p); + } } fn visit_expr(&mut self, e: &'a ast::Expr) { diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 5ac0c0d32dcdc..c1e439ce607d4 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -341,7 +341,7 @@ pub trait EarlyLintPass: LintPass { fn check_block_post(&mut self, _: &EarlyContext<'_>, _: &ast::Block) { } fn check_stmt(&mut self, _: &EarlyContext<'_>, _: &ast::Stmt) { } fn check_arm(&mut self, _: &EarlyContext<'_>, _: &ast::Arm) { } - fn check_pat(&mut self, _: &EarlyContext<'_>, _: &ast::Pat) { } + fn check_pat(&mut self, _: &EarlyContext<'_>, _: &ast::Pat, _: &mut bool) { } fn check_expr(&mut self, _: &EarlyContext<'_>, _: &ast::Expr) { } fn check_expr_post(&mut self, _: &EarlyContext<'_>, _: &ast::Expr) { } fn check_ty(&mut self, _: &EarlyContext<'_>, _: &ast::Ty) { } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 19f9168cf0a0e..fec9542680fb0 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -40,6 +40,8 @@ use rustc::util::nodemap::FxHashSet; use syntax::tokenstream::{TokenTree, TokenStream}; use syntax::ast; +use syntax::ptr::P; +use syntax::ast::Expr; use syntax::attr; use syntax::source_map::Spanned; use syntax::edition::Edition; @@ -47,6 +49,7 @@ use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_a use syntax_pos::{BytePos, Span, SyntaxContext}; use syntax::symbol::keywords; use syntax::errors::{Applicability, DiagnosticBuilder}; +use syntax::print::pprust::expr_to_string; use rustc::hir::{self, GenericParamKind, PatKind}; use rustc::hir::intravisit::FnKind; @@ -1477,21 +1480,42 @@ impl LintPass for EllipsisInclusiveRangePatterns { } impl EarlyLintPass for EllipsisInclusiveRangePatterns { - fn check_pat(&mut self, cx: &EarlyContext, pat: &ast::Pat) { - use self::ast::{PatKind, RangeEnd, RangeSyntax}; + fn check_pat(&mut self, cx: &EarlyContext, pat: &ast::Pat, visit_subpats: &mut bool) { + use self::ast::{PatKind, RangeEnd, RangeSyntax::DotDotDot}; + + /// If `pat` is a `...` pattern, return the start and end of the range, as well as the span + /// corresponding to the ellipsis. + fn matches_ellipsis_pat(pat: &ast::Pat) -> Option<(&P, &P, Span)> { + match &pat.node { + PatKind::Range(a, b, Spanned { span, node: RangeEnd::Included(DotDotDot), .. }) => { + Some((a, b, *span)) + } + _ => None, + } + } + + let (parenthesise, endpoints) = match &pat.node { + PatKind::Ref(subpat, _) => (true, matches_ellipsis_pat(&subpat)), + _ => (false, matches_ellipsis_pat(pat)), + }; - if let PatKind::Range( - _, _, Spanned { span, node: RangeEnd::Included(RangeSyntax::DotDotDot) } - ) = pat.node { + if let Some((start, end, join)) = endpoints { let msg = "`...` range patterns are deprecated"; + let suggestion = "use `..=` for an inclusive range"; + let (span, replacement) = if parenthesise { + *visit_subpats = false; + (pat.span, format!("&({}..={})", expr_to_string(&start), expr_to_string(&end))) + } else { + (join, "..=".to_owned()) + }; let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, span, msg); err.span_suggestion_short_with_applicability( - span, "use `..=` for an inclusive range", "..=".to_owned(), - // FIXME: outstanding problem with precedence in ref patterns: - // https://github.com/rust-lang/rust/issues/51043#issuecomment-392252285 - Applicability::MaybeIncorrect + span, + suggestion, + replacement, + Applicability::MachineApplicable, ); - err.emit() + err.emit(); } } } diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 9ccfecd46fdb2..049bcc3010be1 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -397,12 +397,12 @@ impl EarlyLintPass for UnusedParens { self.check_unused_parens_expr(cx, &value, msg, followed_by_block); } - fn check_pat(&mut self, cx: &EarlyContext, p: &ast::Pat) { + fn check_pat(&mut self, cx: &EarlyContext, p: &ast::Pat, _: &mut bool) { use ast::PatKind::{Paren, Range}; // The lint visitor will visit each subpattern of `p`. We do not want to lint any range // pattern no matter where it occurs in the pattern. For something like `&(a..=b)`, there // is a recursive `check_pat` on `a` and `b`, but we will assume that if there are - // unnecessry parens they serve a purpose of readability. + // unnecessary parens they serve a purpose of readability. if let Paren(ref pat) = p.node { match pat.node { Range(..) => {} diff --git a/src/test/ui/lint/inclusive-range-pattern-syntax.fixed b/src/test/ui/lint/inclusive-range-pattern-syntax.fixed index d16859df79e25..f0aee8a51f18b 100644 --- a/src/test/ui/lint/inclusive-range-pattern-syntax.fixed +++ b/src/test/ui/lint/inclusive-range-pattern-syntax.fixed @@ -20,4 +20,10 @@ fn main() { //~^ WARN `...` range patterns are deprecated _ => {} } + + match &despondency { + &(1..=2) => {} + //~^ WARN `...` range patterns are deprecated + _ => {} + } } diff --git a/src/test/ui/lint/inclusive-range-pattern-syntax.rs b/src/test/ui/lint/inclusive-range-pattern-syntax.rs index 9d418aec0858f..97bc04faa774b 100644 --- a/src/test/ui/lint/inclusive-range-pattern-syntax.rs +++ b/src/test/ui/lint/inclusive-range-pattern-syntax.rs @@ -20,4 +20,10 @@ fn main() { //~^ WARN `...` range patterns are deprecated _ => {} } + + match &despondency { + &1...2 => {} + //~^ WARN `...` range patterns are deprecated + _ => {} + } } diff --git a/src/test/ui/lint/inclusive-range-pattern-syntax.stderr b/src/test/ui/lint/inclusive-range-pattern-syntax.stderr index de04fed589b23..9226137f1152f 100644 --- a/src/test/ui/lint/inclusive-range-pattern-syntax.stderr +++ b/src/test/ui/lint/inclusive-range-pattern-syntax.stderr @@ -10,3 +10,9 @@ note: lint level defined here LL | #![warn(ellipsis_inclusive_range_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +warning: `...` range patterns are deprecated + --> $DIR/inclusive-range-pattern-syntax.rs:25:9 + | +LL | &1...2 => {} + | ^^^^^^ help: use `..=` for an inclusive range + diff --git a/src/test/ui/range/range-inclusive-pattern-precedence.stderr b/src/test/ui/range/range-inclusive-pattern-precedence.stderr index cd5ce3035c683..3ac6be2b8ea6a 100644 --- a/src/test/ui/range/range-inclusive-pattern-precedence.stderr +++ b/src/test/ui/range/range-inclusive-pattern-precedence.stderr @@ -11,10 +11,10 @@ LL | box 10..=15 => {} | ^^^^^^^ help: add parentheses to clarify the precedence: `(10 ..=15)` warning: `...` range patterns are deprecated - --> $DIR/range-inclusive-pattern-precedence.rs:24:11 + --> $DIR/range-inclusive-pattern-precedence.rs:24:9 | LL | &0...9 => {} - | ^^^ help: use `..=` for an inclusive range + | ^^^^^^ help: use `..=` for an inclusive range | note: lint level defined here --> $DIR/range-inclusive-pattern-precedence.rs:19:9 From 7c23dcddffa0e54b3d0b71f4d1b0f36cecc44bd9 Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 10 Nov 2018 21:27:40 +0000 Subject: [PATCH 3/6] Use non-short suggestion for parenthesised ..= --- src/librustc_lint/builtin.rs | 28 +++++++++++-------- .../inclusive-range-pattern-syntax.stderr | 2 +- .../range-inclusive-pattern-precedence.stderr | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index fec9542680fb0..7291e27048280 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1502,20 +1502,26 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns { if let Some((start, end, join)) = endpoints { let msg = "`...` range patterns are deprecated"; let suggestion = "use `..=` for an inclusive range"; - let (span, replacement) = if parenthesise { + if parenthesise { *visit_subpats = false; - (pat.span, format!("&({}..={})", expr_to_string(&start), expr_to_string(&end))) + let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, pat.span, msg); + err.span_suggestion_with_applicability( + pat.span, + suggestion, + format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)), + Applicability::MachineApplicable, + ); + err.emit(); } else { - (join, "..=".to_owned()) + let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, join, msg); + err.span_suggestion_short_with_applicability( + join, + suggestion, + "..=".to_owned(), + Applicability::MachineApplicable, + ); + err.emit(); }; - let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, span, msg); - err.span_suggestion_short_with_applicability( - span, - suggestion, - replacement, - Applicability::MachineApplicable, - ); - err.emit(); } } } diff --git a/src/test/ui/lint/inclusive-range-pattern-syntax.stderr b/src/test/ui/lint/inclusive-range-pattern-syntax.stderr index 9226137f1152f..b13afdbc023d4 100644 --- a/src/test/ui/lint/inclusive-range-pattern-syntax.stderr +++ b/src/test/ui/lint/inclusive-range-pattern-syntax.stderr @@ -14,5 +14,5 @@ warning: `...` range patterns are deprecated --> $DIR/inclusive-range-pattern-syntax.rs:25:9 | LL | &1...2 => {} - | ^^^^^^ help: use `..=` for an inclusive range + | ^^^^^^ help: use `..=` for an inclusive range: `&(1..=2)` diff --git a/src/test/ui/range/range-inclusive-pattern-precedence.stderr b/src/test/ui/range/range-inclusive-pattern-precedence.stderr index 3ac6be2b8ea6a..6fa67a5d4fa30 100644 --- a/src/test/ui/range/range-inclusive-pattern-precedence.stderr +++ b/src/test/ui/range/range-inclusive-pattern-precedence.stderr @@ -14,7 +14,7 @@ warning: `...` range patterns are deprecated --> $DIR/range-inclusive-pattern-precedence.rs:24:9 | LL | &0...9 => {} - | ^^^^^^ help: use `..=` for an inclusive range + | ^^^^^^ help: use `..=` for an inclusive range: `&(0..=9)` | note: lint level defined here --> $DIR/range-inclusive-pattern-precedence.rs:19:9 From 52b540f194b02b48c53e50368086eba65410f430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 8 Nov 2018 15:18:55 -0800 Subject: [PATCH 4/6] Sidestep ICE in `type_of_def_id()` when called from `return_type_impl_trait` --- src/librustc/ty/context.rs | 22 +++++++++++- src/test/ui/issues/issue-55796.rs | 22 ++++++++++++ src/test/ui/issues/issue-55796.stderr | 50 +++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/issues/issue-55796.rs create mode 100644 src/test/ui/issues/issue-55796.stderr diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index d4b47db608163..1ff8c930b8e5a 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -17,7 +17,7 @@ use session::Session; use session::config::{BorrowckMode, OutputFilenames}; use session::config::CrateType; use middle; -use hir::{TraitCandidate, HirId, ItemLocalId, Node}; +use hir::{TraitCandidate, HirId, ItemKind, ItemLocalId, Node}; use hir::def::{Def, Export}; use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE}; use hir::map as hir_map; @@ -1604,6 +1604,26 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { &self, scope_def_id: DefId, ) -> Option> { + // HACK: `type_of_def_id()` will fail on these (#55796), so return None + let node_id = self.hir.as_local_node_id(scope_def_id).unwrap(); + match self.hir.get(node_id) { + Node::Item(item) => { + match item.node { + ItemKind::Trait(..) + | ItemKind::TraitAlias(..) + | ItemKind::Mod(..) + | ItemKind::ForeignMod(..) + | ItemKind::GlobalAsm(..) + | ItemKind::ExternCrate(..) + | ItemKind::Use(..) => { + return None; + } + _ => { /* type_of_def_id() will work */ } + } + } + _ => { /* type_of_def_id() will work or panic */ } + } + let ret_ty = self.type_of(scope_def_id); match ret_ty.sty { ty::FnDef(_, _) => { diff --git a/src/test/ui/issues/issue-55796.rs b/src/test/ui/issues/issue-55796.rs new file mode 100644 index 0000000000000..b48d4a9c022f4 --- /dev/null +++ b/src/test/ui/issues/issue-55796.rs @@ -0,0 +1,22 @@ +pub trait EdgeTrait { + fn target(&self) -> N; +} + +pub trait Graph<'a> { + type Node; + type Edge: EdgeTrait; + type NodesIter: Iterator + 'a; + type EdgesIter: Iterator + 'a; + + fn nodes(&'a self) -> Self::NodesIter; + fn out_edges(&'a self, u: &Self::Node) -> Self::EdgesIter; + fn in_edges(&'a self, u: &Self::Node) -> Self::EdgesIter; + + fn out_neighbors(&'a self, u: &Self::Node) -> Box> { + Box::new(self.out_edges(u).map(|e| e.target())) + } + + fn in_neighbors(&'a self, u: &Self::Node) -> Box> { + Box::new(self.in_edges(u).map(|e| e.target())) + } +} diff --git a/src/test/ui/issues/issue-55796.stderr b/src/test/ui/issues/issue-55796.stderr new file mode 100644 index 0000000000000..60ce8293a5ceb --- /dev/null +++ b/src/test/ui/issues/issue-55796.stderr @@ -0,0 +1,50 @@ +error[E0601]: `main` function not found in crate `issue_55796` + | + = note: consider adding a `main` function to `$DIR/issue-55796.rs` + +error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements + --> $DIR/issue-55796.rs:16:9 + | +LL | Box::new(self.out_edges(u).map(|e| e.target())) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first, the lifetime cannot outlive the lifetime 'a as defined on the trait at 5:17... + --> $DIR/issue-55796.rs:5:17 + | +LL | pub trait Graph<'a> { + | ^^ +note: ...so that the type `std::iter::Map<>::EdgesIter, [closure@$DIR/issue-55796.rs:16:40: 16:54]>` will meet its required lifetime bounds + --> $DIR/issue-55796.rs:16:9 + | +LL | Box::new(self.out_edges(u).map(|e| e.target())) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: but, the lifetime must be valid for the static lifetime... + = note: ...so that the expression is assignable: + expected std::boxed::Box<(dyn std::iter::Iterator>::Node> + 'static)> + found std::boxed::Box>::Node>> + +error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements + --> $DIR/issue-55796.rs:20:9 + | +LL | Box::new(self.in_edges(u).map(|e| e.target())) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first, the lifetime cannot outlive the lifetime 'a as defined on the trait at 5:17... + --> $DIR/issue-55796.rs:5:17 + | +LL | pub trait Graph<'a> { + | ^^ +note: ...so that the type `std::iter::Map<>::EdgesIter, [closure@$DIR/issue-55796.rs:20:39: 20:53]>` will meet its required lifetime bounds + --> $DIR/issue-55796.rs:20:9 + | +LL | Box::new(self.in_edges(u).map(|e| e.target())) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: but, the lifetime must be valid for the static lifetime... + = note: ...so that the expression is assignable: + expected std::boxed::Box<(dyn std::iter::Iterator>::Node> + 'static)> + found std::boxed::Box>::Node>> + +error: aborting due to 3 previous errors + +Some errors occurred: E0495, E0601. +For more information about an error, try `rustc --explain E0495`. From a0824fc78c27e5c2d9301b657b83c4eb6ea87fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 9 Nov 2018 10:16:07 -0800 Subject: [PATCH 5/6] Simplify logic --- src/librustc/ty/context.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 1ff8c930b8e5a..6485acf4ed2cc 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1609,16 +1609,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { match self.hir.get(node_id) { Node::Item(item) => { match item.node { - ItemKind::Trait(..) - | ItemKind::TraitAlias(..) - | ItemKind::Mod(..) - | ItemKind::ForeignMod(..) - | ItemKind::GlobalAsm(..) - | ItemKind::ExternCrate(..) - | ItemKind::Use(..) => { + ItemKind::Fn(..) => { /* type_of_def_id() will work */ } + _ => { return None; } - _ => { /* type_of_def_id() will work */ } } } _ => { /* type_of_def_id() will work or panic */ } From 4558914c229d3cc9742a6ec5733476f52205de7f Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 3 Nov 2018 00:07:56 +0300 Subject: [PATCH 6/6] resolve: Filter away macro prelude in modules with `#[no_implicit_prelude]` on 2018 edition --- src/librustc/session/mod.rs | 4 ++++ src/librustc_resolve/macros.rs | 12 ++++++++---- src/test/ui/hygiene/no_implicit_prelude-2018.rs | 11 +++++++++++ src/test/ui/hygiene/no_implicit_prelude-2018.stderr | 10 ++++++++++ src/test/ui/hygiene/no_implicit_prelude.rs | 5 ++++- 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/hygiene/no_implicit_prelude-2018.rs create mode 100644 src/test/ui/hygiene/no_implicit_prelude-2018.stderr diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index a17825a877d88..d5513080daf5f 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -963,6 +963,10 @@ impl Session { self.opts.debugging_opts.teach && self.diagnostic().must_teach(code) } + pub fn rust_2015(&self) -> bool { + self.opts.edition == Edition::Edition2015 + } + /// Are we allowed to use features from the Rust 2018 edition? pub fn rust_2018(&self) -> bool { self.opts.edition >= Edition::Edition2018 diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 7da483903bfbd..89d011d2bd45e 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -659,10 +659,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> { binding.map(|binding| (binding, Flags::MODULE, Flags::empty())) } WhereToResolve::MacroUsePrelude => { - match self.macro_use_prelude.get(&ident.name).cloned() { - Some(binding) => Ok((binding, Flags::PRELUDE, Flags::empty())), - None => Err(Determinacy::Determined), + let mut result = Err(Determinacy::Determined); + if use_prelude || self.session.rust_2015() { + if let Some(binding) = self.macro_use_prelude.get(&ident.name).cloned() { + result = Ok((binding, Flags::PRELUDE, Flags::empty())); + } } + result } WhereToResolve::BuiltinMacros => { match self.builtin_macros.get(&ident.name).cloned() { @@ -681,7 +684,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } } WhereToResolve::LegacyPluginHelpers => { - if self.session.plugin_attributes.borrow().iter() + if (use_prelude || self.session.rust_2015()) && + self.session.plugin_attributes.borrow().iter() .any(|(name, _)| ident.name == &**name) { let binding = (Def::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper), ty::Visibility::Public, ident.span, Mark::root()) diff --git a/src/test/ui/hygiene/no_implicit_prelude-2018.rs b/src/test/ui/hygiene/no_implicit_prelude-2018.rs new file mode 100644 index 0000000000000..3ad7435fecf29 --- /dev/null +++ b/src/test/ui/hygiene/no_implicit_prelude-2018.rs @@ -0,0 +1,11 @@ +// edition:2018 + +#[no_implicit_prelude] +mod bar { + fn f() { + ::std::print!(""); // OK + print!(); //~ ERROR cannot find macro `print!` in this scope + } +} + +fn main() {} diff --git a/src/test/ui/hygiene/no_implicit_prelude-2018.stderr b/src/test/ui/hygiene/no_implicit_prelude-2018.stderr new file mode 100644 index 0000000000000..370fc9784ad4d --- /dev/null +++ b/src/test/ui/hygiene/no_implicit_prelude-2018.stderr @@ -0,0 +1,10 @@ +error: cannot find macro `print!` in this scope + --> $DIR/no_implicit_prelude-2018.rs:7:9 + | +LL | print!(); //~ ERROR cannot find macro `print!` in this scope + | ^^^^^ + | + = help: have you added the `#[macro_use]` on the module/import? + +error: aborting due to previous error + diff --git a/src/test/ui/hygiene/no_implicit_prelude.rs b/src/test/ui/hygiene/no_implicit_prelude.rs index bf07bc05491cc..5b6041945abea 100644 --- a/src/test/ui/hygiene/no_implicit_prelude.rs +++ b/src/test/ui/hygiene/no_implicit_prelude.rs @@ -21,7 +21,10 @@ mod bar { Vec::new(); //~ ERROR failed to resolve ().clone() //~ ERROR no method named `clone` found } - fn f() { ::foo::m!(); } + fn f() { + ::foo::m!(); + println!(); // OK on 2015 edition (at least for now) + } } fn main() {}