Skip to content

Commit dc503c6

Browse files
committed
Auto merge of #65399 - Centril:rollup-6lzj0w5, r=Centril
Rollup of 7 pull requests Successful merges: - #65215 (Add long error explanation for E0697) - #65292 (Print lifetimes with backticks) - #65362 (syntax: consolidate function parsing in item.rs) - #65363 (Remove implicit dependencies on syntax::pprust) - #65379 (refactor session::config::build_session_options_and_crate_config) - #65392 (Move `Nonterminal::to_tokenstream` to parser & don't rely directly on parser in lowering) - #65395 (Add some tests for fixed ICEs) Failed merges: r? @ghost
2 parents d28a9c3 + a73e073 commit dc503c6

File tree

152 files changed

+1452
-1173
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+1452
-1173
lines changed

Diff for: src/librustc/error_codes.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -2005,6 +2005,24 @@ a (non-transparent) struct containing a single float, while `Grams` is a
20052005
transparent wrapper around a float. This can make a difference for the ABI.
20062006
"##,
20072007

2008+
E0697: r##"
2009+
A closure has been used as `static`.
2010+
2011+
Erroneous code example:
2012+
2013+
```compile_fail,E0697
2014+
fn main() {
2015+
static || {}; // used as `static`
2016+
}
2017+
```
2018+
2019+
Closures cannot be used as `static`. They "save" the environment,
2020+
and as such a static closure would save only a static environment
2021+
which would consist only of variables with a static lifetime. Given
2022+
this it would be better to use a proper function. The easiest fix
2023+
is to remove the `static` keyword.
2024+
"##,
2025+
20082026
E0698: r##"
20092027
When using generators (or async) all type variables must be bound so a
20102028
generator can be constructed.
@@ -2191,7 +2209,6 @@ See [RFC 2091] for details on this and other limitations.
21912209
E0657, // `impl Trait` can only capture lifetimes bound at the fn level
21922210
E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax
21932211
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
2194-
E0697, // closures cannot be static
21952212
// E0707, // multiple elided lifetimes used in arguments of `async fn`
21962213
E0708, // `async` non-`move` closures with parameters are not currently
21972214
// supported

Diff for: src/librustc/hir/lowering.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ use syntax::print::pprust;
7070
use syntax::source_map::{respan, ExpnData, ExpnKind, DesugaringKind, Spanned};
7171
use syntax::symbol::{kw, sym, Symbol};
7272
use syntax::tokenstream::{TokenStream, TokenTree};
73-
use syntax::parse::token::{self, Token};
73+
use syntax::parse::token::{self, Nonterminal, Token};
74+
use syntax::parse::ParseSess;
7475
use syntax::visit::{self, Visitor};
7576
use syntax_pos::Span;
7677

@@ -86,6 +87,11 @@ pub struct LoweringContext<'a> {
8687

8788
resolver: &'a mut dyn Resolver,
8889

90+
/// HACK(Centril): there is a cyclic dependency between the parser and lowering
91+
/// if we don't have this function pointer. To avoid that dependency so that
92+
/// librustc is independent of the parser, we use dynamic dispatch here.
93+
nt_to_tokenstream: NtToTokenstream,
94+
8995
/// The items being lowered are collected here.
9096
items: BTreeMap<hir::HirId, hir::Item>,
9197

@@ -180,6 +186,8 @@ pub trait Resolver {
180186
fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool;
181187
}
182188

189+
type NtToTokenstream = fn(&Nonterminal, &ParseSess, Span) -> TokenStream;
190+
183191
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
184192
/// and if so, what meaning it has.
185193
#[derive(Debug)]
@@ -236,6 +244,7 @@ pub fn lower_crate(
236244
dep_graph: &DepGraph,
237245
krate: &Crate,
238246
resolver: &mut dyn Resolver,
247+
nt_to_tokenstream: NtToTokenstream,
239248
) -> hir::Crate {
240249
// We're constructing the HIR here; we don't care what we will
241250
// read, since we haven't even constructed the *input* to
@@ -249,6 +258,7 @@ pub fn lower_crate(
249258
sess,
250259
cstore,
251260
resolver,
261+
nt_to_tokenstream,
252262
items: BTreeMap::new(),
253263
trait_items: BTreeMap::new(),
254264
impl_items: BTreeMap::new(),
@@ -1022,7 +1032,7 @@ impl<'a> LoweringContext<'a> {
10221032
fn lower_token(&mut self, token: Token) -> TokenStream {
10231033
match token.kind {
10241034
token::Interpolated(nt) => {
1025-
let tts = nt.to_tokenstream(&self.sess.parse_sess, token.span);
1035+
let tts = (self.nt_to_tokenstream)(&nt, &self.sess.parse_sess, token.span);
10261036
self.lower_token_stream(tts)
10271037
}
10281038
_ => TokenTree::Token(token).into(),

Diff for: src/librustc/infer/error_reporting/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<'tcx> TyCtxt<'tcx> {
200200
{
201201
sp = param.span;
202202
}
203-
(format!("the lifetime {} as defined on", br.name), sp)
203+
(format!("the lifetime `{}` as defined on", br.name), sp)
204204
}
205205
ty::ReFree(ty::FreeRegion {
206206
bound_region: ty::BoundRegion::BrNamed(_, name),
@@ -213,15 +213,15 @@ impl<'tcx> TyCtxt<'tcx> {
213213
{
214214
sp = param.span;
215215
}
216-
(format!("the lifetime {} as defined on", name), sp)
216+
(format!("the lifetime `{}` as defined on", name), sp)
217217
}
218218
ty::ReFree(ref fr) => match fr.bound_region {
219219
ty::BrAnon(idx) => (
220220
format!("the anonymous lifetime #{} defined on", idx + 1),
221221
self.hir().span(node),
222222
),
223223
_ => (
224-
format!("the lifetime {} as defined on", region),
224+
format!("the lifetime `{}` as defined on", region),
225225
cm.def_span(self.hir().span(node)),
226226
),
227227
},

Diff for: src/librustc/lint/levels.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHa
1212
use syntax::ast;
1313
use syntax::attr;
1414
use syntax::feature_gate;
15+
use syntax::print::pprust;
1516
use syntax::source_map::MultiSpan;
1617
use syntax::symbol::{Symbol, sym};
1718

@@ -285,7 +286,7 @@ impl<'a> LintLevelsBuilder<'a> {
285286
tool_ident.span,
286287
E0710,
287288
"an unknown tool name found in scoped lint: `{}`",
288-
meta_item.path
289+
pprust::path_to_string(&meta_item.path),
289290
);
290291
continue;
291292
}

0 commit comments

Comments
 (0)