Skip to content

Commit 3c857f4

Browse files
committed
Auto merge of #91677 - matthiaskrgr:rollup-yiczced, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #91245 (suggest casting between i/u32 and char) - #91337 (Add a suggestion if `macro_rules` is misspelled) - #91534 (Make rustdoc headings black, and markdown blue) - #91637 (Add test for packed drops in generators) - #91667 (Fix indent of itemTypes in search.js) Failed merges: - #91568 (Pretty print break and continue without redundant space) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e6b883c + 40c6606 commit 3c857f4

File tree

16 files changed

+215
-39
lines changed

16 files changed

+215
-39
lines changed

compiler/rustc_parse/src/parser/item.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_ast::{MacArgs, MacCall, MacDelimiter};
1515
use rustc_ast_pretty::pprust;
1616
use rustc_errors::{struct_span_err, Applicability, PResult, StashKey};
1717
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
18+
use rustc_span::lev_distance::lev_distance;
1819
use rustc_span::source_map::{self, Span};
1920
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2021

@@ -410,10 +411,30 @@ impl<'a> Parser<'a> {
410411
fn parse_item_macro(&mut self, vis: &Visibility) -> PResult<'a, MacCall> {
411412
let path = self.parse_path(PathStyle::Mod)?; // `foo::bar`
412413
self.expect(&token::Not)?; // `!`
413-
let args = self.parse_mac_args()?; // `( .. )` or `[ .. ]` (followed by `;`), or `{ .. }`.
414-
self.eat_semi_for_macro_if_needed(&args);
415-
self.complain_if_pub_macro(vis, false);
416-
Ok(MacCall { path, args, prior_type_ascription: self.last_type_ascription })
414+
match self.parse_mac_args() {
415+
// `( .. )` or `[ .. ]` (followed by `;`), or `{ .. }`.
416+
Ok(args) => {
417+
self.eat_semi_for_macro_if_needed(&args);
418+
self.complain_if_pub_macro(vis, false);
419+
Ok(MacCall { path, args, prior_type_ascription: self.last_type_ascription })
420+
}
421+
422+
Err(mut err) => {
423+
// Maybe the user misspelled `macro_rules` (issue #91227)
424+
if self.token.is_ident()
425+
&& path.segments.len() == 1
426+
&& lev_distance("macro_rules", &path.segments[0].ident.to_string()) <= 3
427+
{
428+
err.span_suggestion(
429+
path.span,
430+
"perhaps you meant to define a macro",
431+
"macro_rules".to_string(),
432+
Applicability::MachineApplicable,
433+
);
434+
}
435+
Err(err)
436+
}
437+
}
417438
}
418439

419440
/// Recover if we parsed attributes and expected an item but there was none.

compiler/rustc_typeck/src/check/demand.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12641264
}
12651265
true
12661266
}
1267+
(
1268+
&ty::Uint(ty::UintTy::U32 | ty::UintTy::U64 | ty::UintTy::U128)
1269+
| &ty::Int(ty::IntTy::I32 | ty::IntTy::I64 | ty::IntTy::I128),
1270+
&ty::Char,
1271+
) => {
1272+
err.multipart_suggestion_verbose(
1273+
&format!("{}, since a `char` always occupies 4 bytes", cast_msg,),
1274+
cast_suggestion,
1275+
Applicability::MachineApplicable,
1276+
);
1277+
true
1278+
}
12671279
_ => false,
12681280
}
12691281
}

src/librustdoc/html/render/print_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
296296
let (short, name) = item_ty_to_strs(myty.unwrap());
297297
write!(
298298
w,
299-
"<h2 id=\"{id}\" class=\"section-header\">\
299+
"<h2 id=\"{id}\" class=\"small-section-header\">\
300300
<a href=\"#{id}\">{name}</a>\
301301
</h2>\n{}",
302302
ITEM_TABLE_OPEN,

src/librustdoc/html/static/css/themes/ayu.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ a {
219219
a.srclink,
220220
a#toggle-all-docs,
221221
a.anchor,
222-
.section-header a,
222+
.small-section-header a,
223223
#source-sidebar a,
224224
pre.rust a,
225225
.sidebar a,

src/librustdoc/html/static/css/themes/dark.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ a {
181181
a.srclink,
182182
a#toggle-all-docs,
183183
a.anchor,
184-
.section-header a,
184+
.small-section-header a,
185185
#source-sidebar a,
186186
pre.rust a,
187187
.sidebar a,

src/librustdoc/html/static/css/themes/light.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ a {
176176
a.srclink,
177177
a#toggle-all-docs,
178178
a.anchor,
179-
.section-header a,
179+
.small-section-header a,
180180
#source-sidebar a,
181181
pre.rust a,
182182
.sidebar a,

src/librustdoc/html/static/js/search.js

+28-26
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,34 @@
44
(function() {
55
// This mapping table should match the discriminants of
66
// `rustdoc::html::item_type::ItemType` type in Rust.
7-
var itemTypes = ["mod",
8-
"externcrate",
9-
"import",
10-
"struct",
11-
"enum",
12-
"fn",
13-
"type",
14-
"static",
15-
"trait",
16-
"impl",
17-
"tymethod",
18-
"method",
19-
"structfield",
20-
"variant",
21-
"macro",
22-
"primitive",
23-
"associatedtype",
24-
"constant",
25-
"associatedconstant",
26-
"union",
27-
"foreigntype",
28-
"keyword",
29-
"existential",
30-
"attr",
31-
"derive",
32-
"traitalias"];
7+
var itemTypes = [
8+
"mod",
9+
"externcrate",
10+
"import",
11+
"struct",
12+
"enum",
13+
"fn",
14+
"type",
15+
"static",
16+
"trait",
17+
"impl",
18+
"tymethod",
19+
"method",
20+
"structfield",
21+
"variant",
22+
"macro",
23+
"primitive",
24+
"associatedtype",
25+
"constant",
26+
"associatedconstant",
27+
"union",
28+
"foreigntype",
29+
"keyword",
30+
"existential",
31+
"attr",
32+
"derive",
33+
"traitalias",
34+
];
3335

3436
// used for special search precedence
3537
var TY_PRIMITIVE = itemTypes.indexOf("primitive");

src/test/rustdoc-gui/headers-color.goml

+12-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.must_use
1818
assert-css: ("#method\.must_use", {"color": "rgb(197, 197, 197)", "background-color": "rgba(255, 236, 164, 0.06)"}, ALL)
1919

2020
goto: file://|DOC_PATH|/test_docs/index.html
21-
assert-css: (".section-header a", {"color": "rgb(197, 197, 197)"}, ALL)
21+
assert-css: (".small-section-header a", {"color": "rgb(197, 197, 197)"}, ALL)
22+
23+
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
24+
assert-css: (".section-header a", {"color": "rgb(57, 175, 215)"}, ALL)
2225

2326
// Dark theme
2427
local-storage: {"rustdoc-theme": "dark", "rustdoc-preferred-dark-theme": "dark", "rustdoc-use-system-theme": "false"}
@@ -34,7 +37,10 @@ goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.must_use
3437
assert-css: ("#method\.must_use", {"color": "rgb(221, 221, 221)", "background-color": "rgb(73, 74, 61)"}, ALL)
3538

3639
goto: file://|DOC_PATH|/test_docs/index.html
37-
assert-css: (".section-header a", {"color": "rgb(221, 221, 221)"}, ALL)
40+
assert-css: (".small-section-header a", {"color": "rgb(221, 221, 221)"}, ALL)
41+
42+
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
43+
assert-css: (".section-header a", {"color": "rgb(210, 153, 29)"}, ALL)
3844

3945
// Light theme
4046
local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
@@ -52,4 +58,7 @@ goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.must_use
5258
assert-css: ("#method\.must_use", {"color": "rgb(0, 0, 0)", "background-color": "rgb(253, 255, 211)"}, ALL)
5359

5460
goto: file://|DOC_PATH|/test_docs/index.html
55-
assert-css: (".section-header a", {"color": "rgb(0, 0, 0)"}, ALL)
61+
assert-css: (".small-section-header a", {"color": "rgb(0, 0, 0)"}, ALL)
62+
63+
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
64+
assert-css: (".section-header a", {"color": "rgb(56, 115, 173)"}, ALL)

src/test/ui/cast/cast-int-to-char.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn foo<T>(_t: T) {}
2+
3+
fn main() {
4+
foo::<u32>('0'); //~ ERROR
5+
foo::<i32>('0'); //~ ERROR
6+
foo::<u64>('0'); //~ ERROR
7+
foo::<i64>('0'); //~ ERROR
8+
foo::<char>(0u32); //~ ERROR
9+
}
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/cast-int-to-char.rs:4:16
3+
|
4+
LL | foo::<u32>('0');
5+
| ^^^ expected `u32`, found `char`
6+
|
7+
help: you can cast a `char` to a `u32`, since a `char` always occupies 4 bytes
8+
|
9+
LL | foo::<u32>('0' as u32);
10+
| ++++++
11+
12+
error[E0308]: mismatched types
13+
--> $DIR/cast-int-to-char.rs:5:16
14+
|
15+
LL | foo::<i32>('0');
16+
| ^^^ expected `i32`, found `char`
17+
|
18+
help: you can cast a `char` to an `i32`, since a `char` always occupies 4 bytes
19+
|
20+
LL | foo::<i32>('0' as i32);
21+
| ++++++
22+
23+
error[E0308]: mismatched types
24+
--> $DIR/cast-int-to-char.rs:6:16
25+
|
26+
LL | foo::<u64>('0');
27+
| ^^^ expected `u64`, found `char`
28+
|
29+
help: you can cast a `char` to a `u64`, since a `char` always occupies 4 bytes
30+
|
31+
LL | foo::<u64>('0' as u64);
32+
| ++++++
33+
34+
error[E0308]: mismatched types
35+
--> $DIR/cast-int-to-char.rs:7:16
36+
|
37+
LL | foo::<i64>('0');
38+
| ^^^ expected `i64`, found `char`
39+
|
40+
help: you can cast a `char` to an `i64`, since a `char` always occupies 4 bytes
41+
|
42+
LL | foo::<i64>('0' as i64);
43+
| ++++++
44+
45+
error[E0308]: mismatched types
46+
--> $DIR/cast-int-to-char.rs:8:17
47+
|
48+
LL | foo::<char>(0u32);
49+
| ^^^^ expected `char`, found `u32`
50+
51+
error: aborting due to 5 previous errors
52+
53+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/match/match-type-err-first-arm.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ LL | fn test_func1(n: i32) -> i32 {
66
LL | match n {
77
LL | 12 => 'b',
88
| ^^^ expected `i32`, found `char`
9+
|
10+
help: you can cast a `char` to an `i32`, since a `char` always occupies 4 bytes
11+
|
12+
LL | 12 => 'b' as i32,
13+
| ++++++
914

1015
error[E0308]: `match` arms have incompatible types
1116
--> $DIR/match-type-err-first-arm.rs:18:14

src/test/ui/packed/packed-struct-drop-aligned.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// run-pass
2+
#![feature(generators)]
3+
#![feature(generator_trait)]
24
use std::cell::Cell;
35
use std::mem;
6+
use std::ops::Generator;
7+
use std::pin::Pin;
48

59
struct Aligned<'a> {
610
drop_count: &'a Cell<usize>
@@ -19,15 +23,35 @@ impl<'a> Drop for Aligned<'a> {
1923
}
2024
}
2125

26+
#[repr(transparent)]
27+
struct NotCopy(u8);
28+
2229
#[repr(packed)]
23-
struct Packed<'a>(u8, Aligned<'a>);
30+
struct Packed<'a>(NotCopy, Aligned<'a>);
2431

2532
fn main() {
2633
let drop_count = &Cell::new(0);
2734
{
28-
let mut p = Packed(0, Aligned { drop_count });
35+
let mut p = Packed(NotCopy(0), Aligned { drop_count });
2936
p.1 = Aligned { drop_count };
3037
assert_eq!(drop_count.get(), 1);
3138
}
3239
assert_eq!(drop_count.get(), 2);
40+
41+
let drop_count = &Cell::new(0);
42+
let mut g = || {
43+
let mut p = Packed(NotCopy(0), Aligned { drop_count });
44+
let _ = &p;
45+
p.1 = Aligned { drop_count };
46+
assert_eq!(drop_count.get(), 1);
47+
// Test that a generator drop function moves a value from a packed
48+
// struct to a separate local before dropping it. We move out the
49+
// first field to generate and open drop for the second field.
50+
drop(p.0);
51+
yield;
52+
};
53+
Pin::new(&mut g).resume(());
54+
assert_eq!(drop_count.get(), 1);
55+
drop(g);
56+
assert_eq!(drop_count.get(), 2);
3357
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Regression test for issue #91227.
2+
3+
// run-rustfix
4+
5+
#![allow(unused_macros)]
6+
7+
macro_rules! thing {
8+
//~^ ERROR: expected one of
9+
//~| HELP: perhaps you meant to define a macro
10+
() => {}
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Regression test for issue #91227.
2+
3+
// run-rustfix
4+
5+
#![allow(unused_macros)]
6+
7+
marco_rules! thing {
8+
//~^ ERROR: expected one of
9+
//~| HELP: perhaps you meant to define a macro
10+
() => {}
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: expected one of `(`, `[`, or `{`, found `thing`
2+
--> $DIR/misspelled-macro-rules.rs:7:14
3+
|
4+
LL | marco_rules! thing {
5+
| ----------- ^^^^^ expected one of `(`, `[`, or `{`
6+
| |
7+
| help: perhaps you meant to define a macro: `macro_rules`
8+
9+
error: aborting due to previous error
10+

src/test/ui/proc-macro/macro-brackets.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error[E0308]: mismatched types
33
|
44
LL | id![static X: u32 = 'a';];
55
| ^^^ expected `u32`, found `char`
6+
|
7+
help: you can cast a `char` to a `u32`, since a `char` always occupies 4 bytes
8+
|
9+
LL | id![static X: u32 = 'a' as u32;];
10+
| ++++++
611

712
error: aborting due to previous error
813

0 commit comments

Comments
 (0)