Skip to content

Commit e44fdf9

Browse files
committed
Auto merge of #63790 - Centril:rollup-m4ax3r9, r=Centril
Rollup of 6 pull requests Successful merges: - #61236 (take into account the system theme) - #63717 (Fix nested eager expansions in arguments of `format_args`) - #63747 (update Miri) - #63772 (ci: move libc mirrors to the rust-lang-ci-mirrors bucket) - #63780 (Improve diagnostics: break/continue in wrong context) - #63781 (Run Clippy without json-rendered flag) Failed merges: r? @ghost
2 parents 7b0085a + 1294774 commit e44fdf9

29 files changed

+194
-102
lines changed

src/bootstrap/builder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,7 @@ impl<'a> Builder<'a> {
875875
}
876876

877877
if cmd == "clippy" {
878-
extra_args.push_str("-Zforce-unstable-if-unmarked -Zunstable-options \
879-
--json-rendered=termcolor");
878+
extra_args.push_str("-Zforce-unstable-if-unmarked");
880879
}
881880

882881
if !extra_args.is_empty() {

src/ci/docker/dist-various-1/install-mipsel-musl.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mkdir /usr/local/mipsel-linux-musl
55
# Note that this originally came from:
66
# https://downloads.openwrt.org/snapshots/trunk/malta/generic/
77
# OpenWrt-Toolchain-malta-le_gcc-5.3.0_musl-1.1.15.Linux-x86_64.tar.bz2
8-
URL="https://rust-lang-ci2.s3.amazonaws.com/libc"
8+
URL="https://rust-lang-ci-mirrors.s3-us-west-1.amazonaws.com/rustc"
99
FILE="OpenWrt-Toolchain-malta-le_gcc-5.3.0_musl-1.1.15.Linux-x86_64.tar.bz2"
1010
curl -L "$URL/$FILE" | tar xjf - -C /usr/local/mipsel-linux-musl --strip-components=2
1111

src/librustc_passes/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ be taken. Erroneous code example:
131131
132132
```compile_fail,E0268
133133
fn some_func() {
134-
break; // error: `break` outside of loop
134+
break; // error: `break` outside of a loop
135135
}
136136
```
137137

src/librustc_passes/loops.rs

+18-19
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use errors::Applicability;
1616
enum Context {
1717
Normal,
1818
Loop(hir::LoopSource),
19-
Closure,
20-
AsyncClosure,
19+
Closure(Span),
20+
AsyncClosure(Span),
2121
LabeledBlock,
2222
AnonConst,
2323
}
@@ -58,11 +58,11 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
5858
hir::ExprKind::Loop(ref b, _, source) => {
5959
self.with_context(Loop(source), |v| v.visit_block(&b));
6060
}
61-
hir::ExprKind::Closure(_, ref function_decl, b, _, movability) => {
61+
hir::ExprKind::Closure(_, ref function_decl, b, span, movability) => {
6262
let cx = if let Some(GeneratorMovability::Static) = movability {
63-
AsyncClosure
63+
AsyncClosure(span)
6464
} else {
65-
Closure
65+
Closure(span)
6666
};
6767
self.visit_fn_decl(&function_decl);
6868
self.with_context(cx, |v| v.visit_nested_body(b));
@@ -170,23 +170,22 @@ impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> {
170170
}
171171

172172
fn require_break_cx(&self, name: &str, span: Span) {
173-
match self.cx {
174-
LabeledBlock | Loop(_) => {}
175-
Closure => {
176-
struct_span_err!(self.sess, span, E0267, "`{}` inside of a closure", name)
177-
.span_label(span, "cannot break inside of a closure")
173+
let err_inside_of = |article, ty, closure_span| {
174+
struct_span_err!(self.sess, span, E0267, "`{}` inside of {} {}", name, article, ty)
175+
.span_label(span, format!("cannot `{}` inside of {} {}", name, article, ty))
176+
.span_label(closure_span, &format!("enclosing {}", ty))
178177
.emit();
179-
}
180-
AsyncClosure => {
181-
struct_span_err!(self.sess, span, E0267, "`{}` inside of an async block", name)
182-
.span_label(span, "cannot break inside of an async block")
183-
.emit();
184-
}
178+
};
179+
180+
match self.cx {
181+
LabeledBlock | Loop(_) => {},
182+
Closure(closure_span) => err_inside_of("a", "closure", closure_span),
183+
AsyncClosure(closure_span) => err_inside_of("an", "`async` block", closure_span),
185184
Normal | AnonConst => {
186-
struct_span_err!(self.sess, span, E0268, "`{}` outside of loop", name)
187-
.span_label(span, "cannot break outside of a loop")
185+
struct_span_err!(self.sess, span, E0268, "`{}` outside of a loop", name)
186+
.span_label(span, format!("cannot `{}` outside of a loop", name))
188187
.emit();
189-
}
188+
},
190189
}
191190
}
192191

src/librustc_resolve/macros.rs

+22-12
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,23 @@ impl<'a> base::Resolver for Resolver<'a> {
140140
ImportResolver { r: self }.resolve_imports()
141141
}
142142

143-
fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: ExpnId, force: bool)
144-
-> Result<Option<Lrc<SyntaxExtension>>, Indeterminate> {
145-
let parent_scope = self.invocation_parent_scopes[&invoc_id];
143+
fn resolve_macro_invocation(
144+
&mut self, invoc: &Invocation, eager_expansion_root: ExpnId, force: bool
145+
) -> Result<Option<Lrc<SyntaxExtension>>, Indeterminate> {
146+
let invoc_id = invoc.expansion_data.id;
147+
let parent_scope = match self.invocation_parent_scopes.get(&invoc_id) {
148+
Some(parent_scope) => *parent_scope,
149+
None => {
150+
// If there's no entry in the table, then we are resolving an eagerly expanded
151+
// macro, which should inherit its parent scope from its eager expansion root -
152+
// the macro that requested this eager expansion.
153+
let parent_scope = *self.invocation_parent_scopes.get(&eager_expansion_root)
154+
.expect("non-eager expansion without a parent scope");
155+
self.invocation_parent_scopes.insert(invoc_id, parent_scope);
156+
parent_scope
157+
}
158+
};
159+
146160
let (path, kind, derives, after_derive) = match invoc.kind {
147161
InvocationKind::Attr { ref attr, ref derives, after_derive, .. } =>
148162
(&attr.path, MacroKind::Attr, self.arenas.alloc_ast_paths(derives), after_derive),
@@ -161,7 +175,7 @@ impl<'a> base::Resolver for Resolver<'a> {
161175
match self.resolve_macro_path(path, Some(MacroKind::Derive),
162176
&parent_scope, true, force) {
163177
Ok((Some(ref ext), _)) if ext.is_derive_copy => {
164-
self.add_derives(invoc.expansion_data.id, SpecialDerives::COPY);
178+
self.add_derives(invoc_id, SpecialDerives::COPY);
165179
return Ok(None);
166180
}
167181
Err(Determinacy::Undetermined) => result = Err(Indeterminate),
@@ -178,19 +192,15 @@ impl<'a> base::Resolver for Resolver<'a> {
178192
let (ext, res) = self.smart_resolve_macro_path(path, kind, parent_scope, force)?;
179193

180194
let span = invoc.span();
181-
invoc.expansion_data.id.set_expn_data(
182-
ext.expn_data(parent_scope.expansion, span, fast_print_path(path))
183-
);
195+
invoc_id.set_expn_data(ext.expn_data(parent_scope.expansion, span, fast_print_path(path)));
184196

185197
if let Res::Def(_, def_id) = res {
186198
if after_derive {
187199
self.session.span_err(span, "macro attributes must be placed before `#[derive]`");
188200
}
189-
self.macro_defs.insert(invoc.expansion_data.id, def_id);
190-
let normal_module_def_id =
191-
self.macro_def_scope(invoc.expansion_data.id).normal_ancestor_id;
192-
self.definitions.add_parent_module_of_macro_def(invoc.expansion_data.id,
193-
normal_module_def_id);
201+
self.macro_defs.insert(invoc_id, def_id);
202+
let normal_module_def_id = self.macro_def_scope(invoc_id).normal_ancestor_id;
203+
self.definitions.add_parent_module_of_macro_def(invoc_id, normal_module_def_id);
194204
}
195205

196206
Ok(Some(ext))

src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ themePicker.onblur = handleThemeButtonsBlur;
914914
var but = document.createElement('button');
915915
but.innerHTML = item;
916916
but.onclick = function(el) {{
917-
switchTheme(currentTheme, mainTheme, item);
917+
switchTheme(currentTheme, mainTheme, item, true);
918918
}};
919919
but.onblur = handleThemeButtonsBlur;
920920
themes.appendChild(but);

src/librustdoc/html/static/rustdoc.css

+15
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@
5454
box-sizing: border-box;
5555
}
5656

57+
/* This part handles the "default" theme being used depending on the system one. */
58+
html {
59+
content: "";
60+
}
61+
@media (prefers-color-scheme: light) {
62+
html {
63+
content: "light";
64+
}
65+
}
66+
@media (prefers-color-scheme: dark) {
67+
html {
68+
content: "dark";
69+
}
70+
}
71+
5772
/* General structure and fonts */
5873

5974
body {

src/librustdoc/html/static/storage.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function getCurrentValue(name) {
8686
return null;
8787
}
8888

89-
function switchTheme(styleElem, mainStyleElem, newTheme) {
89+
function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) {
9090
var fullBasicCss = "rustdoc" + resourcesSuffix + ".css";
9191
var fullNewTheme = newTheme + resourcesSuffix + ".css";
9292
var newHref = mainStyleElem.href.replace(fullBasicCss, fullNewTheme);
@@ -109,8 +109,18 @@ function switchTheme(styleElem, mainStyleElem, newTheme) {
109109
});
110110
if (found === true) {
111111
styleElem.href = newHref;
112-
updateLocalStorage("rustdoc-theme", newTheme);
112+
// If this new value comes from a system setting or from the previously saved theme, no
113+
// need to save it.
114+
if (saveTheme === true) {
115+
updateLocalStorage("rustdoc-theme", newTheme);
116+
}
113117
}
114118
}
115119

116-
switchTheme(currentTheme, mainTheme, getCurrentValue("rustdoc-theme") || "light");
120+
function getSystemValue() {
121+
return getComputedStyle(document.documentElement).getPropertyValue('content');
122+
}
123+
124+
switchTheme(currentTheme, mainTheme,
125+
getCurrentValue("rustdoc-theme") || getSystemValue() || "light",
126+
false);

src/libsyntax/ext/base.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,9 @@ pub trait Resolver {
682682

683683
fn resolve_imports(&mut self);
684684

685-
fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: ExpnId, force: bool)
686-
-> Result<Option<Lrc<SyntaxExtension>>, Indeterminate>;
685+
fn resolve_macro_invocation(
686+
&mut self, invoc: &Invocation, eager_expansion_root: ExpnId, force: bool
687+
) -> Result<Option<Lrc<SyntaxExtension>>, Indeterminate>;
687688

688689
fn check_unused_macros(&self);
689690

@@ -908,12 +909,9 @@ impl<'a> ExtCtxt<'a> {
908909
/// compilation on error, merely emits a non-fatal error and returns `None`.
909910
pub fn expr_to_spanned_string<'a>(
910911
cx: &'a mut ExtCtxt<'_>,
911-
mut expr: P<ast::Expr>,
912+
expr: P<ast::Expr>,
912913
err_msg: &str,
913914
) -> Result<(Symbol, ast::StrStyle, Span), Option<DiagnosticBuilder<'a>>> {
914-
// Update `expr.span`'s ctxt now in case expr is an `include!` macro invocation.
915-
expr.span = expr.span.apply_mark(cx.current_expansion.id);
916-
917915
// Perform eager expansion on the expression.
918916
// We want to be able to handle e.g., `concat!("foo", "bar")`.
919917
let expr = cx.expander().fully_expand_fragment(AstFragment::Expr(expr)).make_expr();

src/libsyntax/ext/expand.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
305305
continue
306306
};
307307

308-
let scope =
308+
let eager_expansion_root =
309309
if self.monotonic { invoc.expansion_data.id } else { orig_expansion_data.id };
310-
let ext = match self.cx.resolver.resolve_macro_invocation(&invoc, scope, force) {
310+
let ext = match self.cx.resolver.resolve_macro_invocation(
311+
&invoc, eager_expansion_root, force
312+
) {
311313
Ok(ext) => ext,
312314
Err(Indeterminate) => {
313315
undetermined_invocations.push(invoc);
@@ -318,7 +320,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
318320
progress = true;
319321
let ExpansionData { depth, id: expn_id, .. } = invoc.expansion_data;
320322
self.cx.current_expansion = invoc.expansion_data.clone();
321-
self.cx.current_expansion.id = scope;
322323

323324
// FIXME(jseyfried): Refactor out the following logic
324325
let (expanded_fragment, new_invocations) = if let Some(ext) = ext {

src/test/ui/array-break-length.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
fn main() {
22
loop {
3-
|_: [_; break]| {} //~ ERROR: `break` outside of loop
3+
|_: [_; break]| {} //~ ERROR: `break` outside of a loop
44
//~^ ERROR mismatched types
55
}
66

77
loop {
8-
|_: [_; continue]| {} //~ ERROR: `continue` outside of loop
8+
|_: [_; continue]| {} //~ ERROR: `continue` outside of a loop
99
//~^ ERROR mismatched types
1010
}
1111
}

src/test/ui/array-break-length.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0268]: `break` outside of loop
1+
error[E0268]: `break` outside of a loop
22
--> $DIR/array-break-length.rs:3:17
33
|
44
LL | |_: [_; break]| {}
5-
| ^^^^^ cannot break outside of a loop
5+
| ^^^^^ cannot `break` outside of a loop
66

7-
error[E0268]: `continue` outside of loop
7+
error[E0268]: `continue` outside of a loop
88
--> $DIR/array-break-length.rs:8:17
99
|
1010
LL | |_: [_; continue]| {}
11-
| ^^^^^^^^ cannot break outside of a loop
11+
| ^^^^^^^^ cannot `continue` outside of a loop
1212

1313
error[E0308]: mismatched types
1414
--> $DIR/array-break-length.rs:3:9

src/test/ui/async-await/async-block-control-flow-static-semantics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ async fn return_targets_async_block_not_async_fn() -> u8 {
3030

3131
fn no_break_in_async_block() {
3232
async {
33-
break 0u8; //~ ERROR `break` inside of an async block
33+
break 0u8; //~ ERROR `break` inside of an `async` block
3434
};
3535
}
3636

3737
fn no_break_in_async_block_even_with_outer_loop() {
3838
loop {
3939
async {
40-
break 0u8; //~ ERROR `break` inside of an async block
40+
break 0u8; //~ ERROR `break` inside of an `async` block
4141
};
4242
}
4343
}

src/test/ui/async-await/async-block-control-flow-static-semantics.stderr

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
error[E0267]: `break` inside of an async block
1+
error[E0267]: `break` inside of an `async` block
22
--> $DIR/async-block-control-flow-static-semantics.rs:33:9
33
|
4-
LL | break 0u8;
5-
| ^^^^^^^^^ cannot break inside of an async block
4+
LL | async {
5+
| ___________-
6+
LL | | break 0u8;
7+
| | ^^^^^^^^^ cannot `break` inside of an `async` block
8+
LL | | };
9+
| |_____- enclosing `async` block
610

7-
error[E0267]: `break` inside of an async block
11+
error[E0267]: `break` inside of an `async` block
812
--> $DIR/async-block-control-flow-static-semantics.rs:40:13
913
|
10-
LL | break 0u8;
11-
| ^^^^^^^^^ cannot break inside of an async block
14+
LL | async {
15+
| _______________-
16+
LL | | break 0u8;
17+
| | ^^^^^^^^^ cannot `break` inside of an `async` block
18+
LL | | };
19+
| |_________- enclosing `async` block
1220

1321
error[E0308]: mismatched types
1422
--> $DIR/async-block-control-flow-static-semantics.rs:13:43

src/test/ui/break-outside-loop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ fn cond() -> bool { true }
77
fn foo<F>(_: F) where F: FnOnce() {}
88

99
fn main() {
10-
let pth = break; //~ ERROR: `break` outside of loop
11-
if cond() { continue } //~ ERROR: `continue` outside of loop
10+
let pth = break; //~ ERROR: `break` outside of a loop
11+
if cond() { continue } //~ ERROR: `continue` outside of a loop
1212

1313
while cond() {
1414
if cond() { break }
@@ -21,5 +21,5 @@ fn main() {
2121

2222
let rs: Foo = Foo{t: pth};
2323

24-
let unconstrained = break; //~ ERROR: `break` outside of loop
24+
let unconstrained = break; //~ ERROR: `break` outside of a loop
2525
}

0 commit comments

Comments
 (0)