Skip to content

Commit 19b7065

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. * #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 + dfdebc4 commit 19b7065

File tree

9 files changed

+124
-17
lines changed

9 files changed

+124
-17
lines changed

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_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`.

0 commit comments

Comments
 (0)