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

+5-2
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

+1-1
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

+4
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

+15-1
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

-11
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

+43-13
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

+2-2
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

+8-4
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())
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() {}
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+

src/test/ui/hygiene/no_implicit_prelude.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ mod bar {
2121
Vec::new(); //~ ERROR failed to resolve
2222
().clone() //~ ERROR no method named `clone` found
2323
}
24-
fn f() { ::foo::m!(); }
24+
fn f() {
25+
::foo::m!();
26+
println!(); // OK on 2015 edition (at least for now)
27+
}
2528
}
2629

2730
fn main() {}

src/test/ui/issues/issue-55796.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
pub trait EdgeTrait<N> {
2+
fn target(&self) -> N;
3+
}
4+
5+
pub trait Graph<'a> {
6+
type Node;
7+
type Edge: EdgeTrait<Self::Node>;
8+
type NodesIter: Iterator<Item = Self::Node> + 'a;
9+
type EdgesIter: Iterator<Item = Self::Edge> + 'a;
10+
11+
fn nodes(&'a self) -> Self::NodesIter;
12+
fn out_edges(&'a self, u: &Self::Node) -> Self::EdgesIter;
13+
fn in_edges(&'a self, u: &Self::Node) -> Self::EdgesIter;
14+
15+
fn out_neighbors(&'a self, u: &Self::Node) -> Box<Iterator<Item = Self::Node>> {
16+
Box::new(self.out_edges(u).map(|e| e.target()))
17+
}
18+
19+
fn in_neighbors(&'a self, u: &Self::Node) -> Box<Iterator<Item = Self::Node>> {
20+
Box::new(self.in_edges(u).map(|e| e.target()))
21+
}
22+
}

src/test/ui/issues/issue-55796.stderr

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
error[E0601]: `main` function not found in crate `issue_55796`
2+
|
3+
= note: consider adding a `main` function to `$DIR/issue-55796.rs`
4+
5+
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
6+
--> $DIR/issue-55796.rs:16:9
7+
|
8+
LL | Box::new(self.out_edges(u).map(|e| e.target()))
9+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
|
11+
note: first, the lifetime cannot outlive the lifetime 'a as defined on the trait at 5:17...
12+
--> $DIR/issue-55796.rs:5:17
13+
|
14+
LL | pub trait Graph<'a> {
15+
| ^^
16+
note: ...so that the type `std::iter::Map<<Self as Graph<'a>>::EdgesIter, [closure@$DIR/issue-55796.rs:16:40: 16:54]>` will meet its required lifetime bounds
17+
--> $DIR/issue-55796.rs:16:9
18+
|
19+
LL | Box::new(self.out_edges(u).map(|e| e.target()))
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
= note: but, the lifetime must be valid for the static lifetime...
22+
= note: ...so that the expression is assignable:
23+
expected std::boxed::Box<(dyn std::iter::Iterator<Item=<Self as Graph<'a>>::Node> + 'static)>
24+
found std::boxed::Box<dyn std::iter::Iterator<Item=<Self as Graph<'a>>::Node>>
25+
26+
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
27+
--> $DIR/issue-55796.rs:20:9
28+
|
29+
LL | Box::new(self.in_edges(u).map(|e| e.target()))
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
note: first, the lifetime cannot outlive the lifetime 'a as defined on the trait at 5:17...
33+
--> $DIR/issue-55796.rs:5:17
34+
|
35+
LL | pub trait Graph<'a> {
36+
| ^^
37+
note: ...so that the type `std::iter::Map<<Self as Graph<'a>>::EdgesIter, [closure@$DIR/issue-55796.rs:20:39: 20:53]>` will meet its required lifetime bounds
38+
--> $DIR/issue-55796.rs:20:9
39+
|
40+
LL | Box::new(self.in_edges(u).map(|e| e.target()))
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
= note: but, the lifetime must be valid for the static lifetime...
43+
= note: ...so that the expression is assignable:
44+
expected std::boxed::Box<(dyn std::iter::Iterator<Item=<Self as Graph<'a>>::Node> + 'static)>
45+
found std::boxed::Box<dyn std::iter::Iterator<Item=<Self as Graph<'a>>::Node>>
46+
47+
error: aborting due to 3 previous errors
48+
49+
Some errors occurred: E0495, E0601.
50+
For more information about an error, try `rustc --explain E0495`.

src/test/ui/lint/inclusive-range-pattern-syntax.fixed

+6
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ fn main() {
2020
//~^ WARN `...` range patterns are deprecated
2121
_ => {}
2222
}
23+
24+
match &despondency {
25+
&(1..=2) => {}
26+
//~^ WARN `...` range patterns are deprecated
27+
_ => {}
28+
}
2329
}

src/test/ui/lint/inclusive-range-pattern-syntax.rs

+6
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ fn main() {
2020
//~^ WARN `...` range patterns are deprecated
2121
_ => {}
2222
}
23+
24+
match &despondency {
25+
&1...2 => {}
26+
//~^ WARN `...` range patterns are deprecated
27+
_ => {}
28+
}
2329
}

src/test/ui/lint/inclusive-range-pattern-syntax.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ note: lint level defined here
1010
LL | #![warn(ellipsis_inclusive_range_patterns)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13+
warning: `...` range patterns are deprecated
14+
--> $DIR/inclusive-range-pattern-syntax.rs:25:9
15+
|
16+
LL | &1...2 => {}
17+
| ^^^^^^ help: use `..=` for an inclusive range: `&(1..=2)`
18+

src/test/ui/range/range-inclusive-pattern-precedence.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ LL | box 10..=15 => {}
1111
| ^^^^^^^ help: add parentheses to clarify the precedence: `(10 ..=15)`
1212

1313
warning: `...` range patterns are deprecated
14-
--> $DIR/range-inclusive-pattern-precedence.rs:24:11
14+
--> $DIR/range-inclusive-pattern-precedence.rs:24:9
1515
|
1616
LL | &0...9 => {}
17-
| ^^^ help: use `..=` for an inclusive range
17+
| ^^^^^^ help: use `..=` for an inclusive range: `&(0..=9)`
1818
|
1919
note: lint level defined here
2020
--> $DIR/range-inclusive-pattern-precedence.rs:19:9

0 commit comments

Comments
 (0)