Skip to content

Commit ddc10ff

Browse files
committed
Auto merge of #55989 - pietroalbini:beta-rollup, r=pietroalbini
[beta] Rollup backports Merged and approved: * #55947: xLTO: Don't pass --plugin-opt=thin to LLD. That's not supported anymore. * #55852: Rewrite `...` as `..=` as a `MachineApplicable` 2018 idiom lint * #55800: Fix ICE in `return_type_impl_trait` * #55630: resolve: Filter away macro prelude in modules with `#[no_implicit_prelude]` on 2018 edition r? @ghost
2 parents 51be258 + 4558914 commit ddc10ff

17 files changed

+195
-37
lines changed

src/librustc/lint/context.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,9 +1020,12 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> {
10201020
}
10211021

10221022
fn visit_pat(&mut self, p: &'a ast::Pat) {
1023-
run_lints!(self, check_pat, p);
1023+
let mut visit_subpats = true;
1024+
run_lints!(self, check_pat, p, &mut visit_subpats);
10241025
self.check_id(p.id);
1025-
ast_visit::walk_pat(self, p);
1026+
if visit_subpats {
1027+
ast_visit::walk_pat(self, p);
1028+
}
10261029
}
10271030

10281031
fn visit_expr(&mut self, e: &'a ast::Expr) {

src/librustc/lint/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub trait EarlyLintPass: LintPass {
341341
fn check_block_post(&mut self, _: &EarlyContext<'_>, _: &ast::Block) { }
342342
fn check_stmt(&mut self, _: &EarlyContext<'_>, _: &ast::Stmt) { }
343343
fn check_arm(&mut self, _: &EarlyContext<'_>, _: &ast::Arm) { }
344-
fn check_pat(&mut self, _: &EarlyContext<'_>, _: &ast::Pat) { }
344+
fn check_pat(&mut self, _: &EarlyContext<'_>, _: &ast::Pat, _: &mut bool) { }
345345
fn check_expr(&mut self, _: &EarlyContext<'_>, _: &ast::Expr) { }
346346
fn check_expr_post(&mut self, _: &EarlyContext<'_>, _: &ast::Expr) { }
347347
fn check_ty(&mut self, _: &EarlyContext<'_>, _: &ast::Ty) { }

src/librustc/session/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,10 @@ impl Session {
963963
self.opts.debugging_opts.teach && self.diagnostic().must_teach(code)
964964
}
965965

966+
pub fn rust_2015(&self) -> bool {
967+
self.opts.edition == Edition::Edition2015
968+
}
969+
966970
/// Are we allowed to use features from the Rust 2018 edition?
967971
pub fn rust_2018(&self) -> bool {
968972
self.opts.edition >= Edition::Edition2018

src/librustc/ty/context.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use session::Session;
1717
use session::config::{BorrowckMode, OutputFilenames};
1818
use session::config::CrateType;
1919
use middle;
20-
use hir::{TraitCandidate, HirId, ItemLocalId, Node};
20+
use hir::{TraitCandidate, HirId, ItemKind, ItemLocalId, Node};
2121
use hir::def::{Def, Export};
2222
use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
2323
use hir::map as hir_map;
@@ -1604,6 +1604,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
16041604
&self,
16051605
scope_def_id: DefId,
16061606
) -> Option<Ty<'tcx>> {
1607+
// HACK: `type_of_def_id()` will fail on these (#55796), so return None
1608+
let node_id = self.hir.as_local_node_id(scope_def_id).unwrap();
1609+
match self.hir.get(node_id) {
1610+
Node::Item(item) => {
1611+
match item.node {
1612+
ItemKind::Fn(..) => { /* type_of_def_id() will work */ }
1613+
_ => {
1614+
return None;
1615+
}
1616+
}
1617+
}
1618+
_ => { /* type_of_def_id() will work or panic */ }
1619+
}
1620+
16071621
let ret_ty = self.type_of(scope_def_id);
16081622
match ret_ty.sty {
16091623
ty::FnDef(_, _) => {

src/librustc_codegen_llvm/back/linker.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,6 @@ impl<'a> GccLinker<'a> {
205205

206206
self.linker_arg(&format!("-plugin-opt={}", opt_level));
207207
self.linker_arg(&format!("-plugin-opt=mcpu={}", llvm_util::target_cpu(self.sess)));
208-
209-
match self.sess.lto() {
210-
config::Lto::Thin |
211-
config::Lto::ThinLocal => {
212-
self.linker_arg("-plugin-opt=thin");
213-
}
214-
config::Lto::Fat |
215-
config::Lto::No => {
216-
// default to regular LTO
217-
}
218-
}
219208
}
220209
}
221210

src/librustc_lint/builtin.rs

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ use rustc::util::nodemap::FxHashSet;
4040

4141
use syntax::tokenstream::{TokenTree, TokenStream};
4242
use syntax::ast;
43+
use syntax::ptr::P;
44+
use syntax::ast::Expr;
4345
use syntax::attr;
4446
use syntax::source_map::Spanned;
4547
use syntax::edition::Edition;
4648
use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_attributes};
4749
use syntax_pos::{BytePos, Span, SyntaxContext};
4850
use syntax::symbol::keywords;
4951
use syntax::errors::{Applicability, DiagnosticBuilder};
52+
use syntax::print::pprust::expr_to_string;
5053

5154
use rustc::hir::{self, GenericParamKind, PatKind};
5255
use rustc::hir::intravisit::FnKind;
@@ -1477,21 +1480,48 @@ impl LintPass for EllipsisInclusiveRangePatterns {
14771480
}
14781481

14791482
impl EarlyLintPass for EllipsisInclusiveRangePatterns {
1480-
fn check_pat(&mut self, cx: &EarlyContext, pat: &ast::Pat) {
1481-
use self::ast::{PatKind, RangeEnd, RangeSyntax};
1483+
fn check_pat(&mut self, cx: &EarlyContext, pat: &ast::Pat, visit_subpats: &mut bool) {
1484+
use self::ast::{PatKind, RangeEnd, RangeSyntax::DotDotDot};
1485+
1486+
/// If `pat` is a `...` pattern, return the start and end of the range, as well as the span
1487+
/// corresponding to the ellipsis.
1488+
fn matches_ellipsis_pat(pat: &ast::Pat) -> Option<(&P<Expr>, &P<Expr>, Span)> {
1489+
match &pat.node {
1490+
PatKind::Range(a, b, Spanned { span, node: RangeEnd::Included(DotDotDot), .. }) => {
1491+
Some((a, b, *span))
1492+
}
1493+
_ => None,
1494+
}
1495+
}
14821496

1483-
if let PatKind::Range(
1484-
_, _, Spanned { span, node: RangeEnd::Included(RangeSyntax::DotDotDot) }
1485-
) = pat.node {
1497+
let (parenthesise, endpoints) = match &pat.node {
1498+
PatKind::Ref(subpat, _) => (true, matches_ellipsis_pat(&subpat)),
1499+
_ => (false, matches_ellipsis_pat(pat)),
1500+
};
1501+
1502+
if let Some((start, end, join)) = endpoints {
14861503
let msg = "`...` range patterns are deprecated";
1487-
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, span, msg);
1488-
err.span_suggestion_short_with_applicability(
1489-
span, "use `..=` for an inclusive range", "..=".to_owned(),
1490-
// FIXME: outstanding problem with precedence in ref patterns:
1491-
// https://github.com/rust-lang/rust/issues/51043#issuecomment-392252285
1492-
Applicability::MaybeIncorrect
1493-
);
1494-
err.emit()
1504+
let suggestion = "use `..=` for an inclusive range";
1505+
if parenthesise {
1506+
*visit_subpats = false;
1507+
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, pat.span, msg);
1508+
err.span_suggestion_with_applicability(
1509+
pat.span,
1510+
suggestion,
1511+
format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)),
1512+
Applicability::MachineApplicable,
1513+
);
1514+
err.emit();
1515+
} else {
1516+
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, join, msg);
1517+
err.span_suggestion_short_with_applicability(
1518+
join,
1519+
suggestion,
1520+
"..=".to_owned(),
1521+
Applicability::MachineApplicable,
1522+
);
1523+
err.emit();
1524+
};
14951525
}
14961526
}
14971527
}

src/librustc_lint/unused.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,12 @@ impl EarlyLintPass for UnusedParens {
397397
self.check_unused_parens_expr(cx, &value, msg, followed_by_block);
398398
}
399399

400-
fn check_pat(&mut self, cx: &EarlyContext, p: &ast::Pat) {
400+
fn check_pat(&mut self, cx: &EarlyContext, p: &ast::Pat, _: &mut bool) {
401401
use ast::PatKind::{Paren, Range};
402402
// The lint visitor will visit each subpattern of `p`. We do not want to lint any range
403403
// pattern no matter where it occurs in the pattern. For something like `&(a..=b)`, there
404404
// is a recursive `check_pat` on `a` and `b`, but we will assume that if there are
405-
// unnecessry parens they serve a purpose of readability.
405+
// unnecessary parens they serve a purpose of readability.
406406
if let Paren(ref pat) = p.node {
407407
match pat.node {
408408
Range(..) => {}

src/librustc_resolve/macros.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,10 +659,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
659659
binding.map(|binding| (binding, Flags::MODULE, Flags::empty()))
660660
}
661661
WhereToResolve::MacroUsePrelude => {
662-
match self.macro_use_prelude.get(&ident.name).cloned() {
663-
Some(binding) => Ok((binding, Flags::PRELUDE, Flags::empty())),
664-
None => Err(Determinacy::Determined),
662+
let mut result = Err(Determinacy::Determined);
663+
if use_prelude || self.session.rust_2015() {
664+
if let Some(binding) = self.macro_use_prelude.get(&ident.name).cloned() {
665+
result = Ok((binding, Flags::PRELUDE, Flags::empty()));
666+
}
665667
}
668+
result
666669
}
667670
WhereToResolve::BuiltinMacros => {
668671
match self.builtin_macros.get(&ident.name).cloned() {
@@ -681,7 +684,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
681684
}
682685
}
683686
WhereToResolve::LegacyPluginHelpers => {
684-
if self.session.plugin_attributes.borrow().iter()
687+
if (use_prelude || self.session.rust_2015()) &&
688+
self.session.plugin_attributes.borrow().iter()
685689
.any(|(name, _)| ident.name == &**name) {
686690
let binding = (Def::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper),
687691
ty::Visibility::Public, ident.span, Mark::root())
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// edition:2018
2+
3+
#[no_implicit_prelude]
4+
mod bar {
5+
fn f() {
6+
::std::print!(""); // OK
7+
print!(); //~ ERROR cannot find macro `print!` in this scope
8+
}
9+
}
10+
11+
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: cannot find macro `print!` in this scope
2+
--> $DIR/no_implicit_prelude-2018.rs:7:9
3+
|
4+
LL | print!(); //~ ERROR cannot find macro `print!` in this scope
5+
| ^^^^^
6+
|
7+
= help: have you added the `#[macro_use]` on the module/import?
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)