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
This commit is contained in:
commit
3c857f48ce
16 changed files with 215 additions and 39 deletions
|
@ -15,6 +15,7 @@ use rustc_ast::{MacArgs, MacCall, MacDelimiter};
|
|||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::{struct_span_err, Applicability, PResult, StashKey};
|
||||
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
|
||||
use rustc_span::lev_distance::lev_distance;
|
||||
use rustc_span::source_map::{self, Span};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
|
||||
|
@ -410,10 +411,30 @@ impl<'a> Parser<'a> {
|
|||
fn parse_item_macro(&mut self, vis: &Visibility) -> PResult<'a, MacCall> {
|
||||
let path = self.parse_path(PathStyle::Mod)?; // `foo::bar`
|
||||
self.expect(&token::Not)?; // `!`
|
||||
let args = self.parse_mac_args()?; // `( .. )` or `[ .. ]` (followed by `;`), or `{ .. }`.
|
||||
self.eat_semi_for_macro_if_needed(&args);
|
||||
self.complain_if_pub_macro(vis, false);
|
||||
Ok(MacCall { path, args, prior_type_ascription: self.last_type_ascription })
|
||||
match self.parse_mac_args() {
|
||||
// `( .. )` or `[ .. ]` (followed by `;`), or `{ .. }`.
|
||||
Ok(args) => {
|
||||
self.eat_semi_for_macro_if_needed(&args);
|
||||
self.complain_if_pub_macro(vis, false);
|
||||
Ok(MacCall { path, args, prior_type_ascription: self.last_type_ascription })
|
||||
}
|
||||
|
||||
Err(mut err) => {
|
||||
// Maybe the user misspelled `macro_rules` (issue #91227)
|
||||
if self.token.is_ident()
|
||||
&& path.segments.len() == 1
|
||||
&& lev_distance("macro_rules", &path.segments[0].ident.to_string()) <= 3
|
||||
{
|
||||
err.span_suggestion(
|
||||
path.span,
|
||||
"perhaps you meant to define a macro",
|
||||
"macro_rules".to_string(),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Recover if we parsed attributes and expected an item but there was none.
|
||||
|
|
|
@ -1264,6 +1264,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
true
|
||||
}
|
||||
(
|
||||
&ty::Uint(ty::UintTy::U32 | ty::UintTy::U64 | ty::UintTy::U128)
|
||||
| &ty::Int(ty::IntTy::I32 | ty::IntTy::I64 | ty::IntTy::I128),
|
||||
&ty::Char,
|
||||
) => {
|
||||
err.multipart_suggestion_verbose(
|
||||
&format!("{}, since a `char` always occupies 4 bytes", cast_msg,),
|
||||
cast_suggestion,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -296,7 +296,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
|
|||
let (short, name) = item_ty_to_strs(myty.unwrap());
|
||||
write!(
|
||||
w,
|
||||
"<h2 id=\"{id}\" class=\"section-header\">\
|
||||
"<h2 id=\"{id}\" class=\"small-section-header\">\
|
||||
<a href=\"#{id}\">{name}</a>\
|
||||
</h2>\n{}",
|
||||
ITEM_TABLE_OPEN,
|
||||
|
|
|
@ -219,7 +219,7 @@ a {
|
|||
a.srclink,
|
||||
a#toggle-all-docs,
|
||||
a.anchor,
|
||||
.section-header a,
|
||||
.small-section-header a,
|
||||
#source-sidebar a,
|
||||
pre.rust a,
|
||||
.sidebar a,
|
||||
|
|
|
@ -181,7 +181,7 @@ a {
|
|||
a.srclink,
|
||||
a#toggle-all-docs,
|
||||
a.anchor,
|
||||
.section-header a,
|
||||
.small-section-header a,
|
||||
#source-sidebar a,
|
||||
pre.rust a,
|
||||
.sidebar a,
|
||||
|
|
|
@ -176,7 +176,7 @@ a {
|
|||
a.srclink,
|
||||
a#toggle-all-docs,
|
||||
a.anchor,
|
||||
.section-header a,
|
||||
.small-section-header a,
|
||||
#source-sidebar a,
|
||||
pre.rust a,
|
||||
.sidebar a,
|
||||
|
|
|
@ -4,32 +4,34 @@
|
|||
(function() {
|
||||
// This mapping table should match the discriminants of
|
||||
// `rustdoc::html::item_type::ItemType` type in Rust.
|
||||
var itemTypes = ["mod",
|
||||
"externcrate",
|
||||
"import",
|
||||
"struct",
|
||||
"enum",
|
||||
"fn",
|
||||
"type",
|
||||
"static",
|
||||
"trait",
|
||||
"impl",
|
||||
"tymethod",
|
||||
"method",
|
||||
"structfield",
|
||||
"variant",
|
||||
"macro",
|
||||
"primitive",
|
||||
"associatedtype",
|
||||
"constant",
|
||||
"associatedconstant",
|
||||
"union",
|
||||
"foreigntype",
|
||||
"keyword",
|
||||
"existential",
|
||||
"attr",
|
||||
"derive",
|
||||
"traitalias"];
|
||||
var itemTypes = [
|
||||
"mod",
|
||||
"externcrate",
|
||||
"import",
|
||||
"struct",
|
||||
"enum",
|
||||
"fn",
|
||||
"type",
|
||||
"static",
|
||||
"trait",
|
||||
"impl",
|
||||
"tymethod",
|
||||
"method",
|
||||
"structfield",
|
||||
"variant",
|
||||
"macro",
|
||||
"primitive",
|
||||
"associatedtype",
|
||||
"constant",
|
||||
"associatedconstant",
|
||||
"union",
|
||||
"foreigntype",
|
||||
"keyword",
|
||||
"existential",
|
||||
"attr",
|
||||
"derive",
|
||||
"traitalias",
|
||||
];
|
||||
|
||||
// used for special search precedence
|
||||
var TY_PRIMITIVE = itemTypes.indexOf("primitive");
|
||||
|
|
|
@ -18,7 +18,10 @@ goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.must_use
|
|||
assert-css: ("#method\.must_use", {"color": "rgb(197, 197, 197)", "background-color": "rgba(255, 236, 164, 0.06)"}, ALL)
|
||||
|
||||
goto: file://|DOC_PATH|/test_docs/index.html
|
||||
assert-css: (".section-header a", {"color": "rgb(197, 197, 197)"}, ALL)
|
||||
assert-css: (".small-section-header a", {"color": "rgb(197, 197, 197)"}, ALL)
|
||||
|
||||
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
|
||||
assert-css: (".section-header a", {"color": "rgb(57, 175, 215)"}, ALL)
|
||||
|
||||
// Dark theme
|
||||
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
|
|||
assert-css: ("#method\.must_use", {"color": "rgb(221, 221, 221)", "background-color": "rgb(73, 74, 61)"}, ALL)
|
||||
|
||||
goto: file://|DOC_PATH|/test_docs/index.html
|
||||
assert-css: (".section-header a", {"color": "rgb(221, 221, 221)"}, ALL)
|
||||
assert-css: (".small-section-header a", {"color": "rgb(221, 221, 221)"}, ALL)
|
||||
|
||||
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
|
||||
assert-css: (".section-header a", {"color": "rgb(210, 153, 29)"}, ALL)
|
||||
|
||||
// Light theme
|
||||
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
|
|||
assert-css: ("#method\.must_use", {"color": "rgb(0, 0, 0)", "background-color": "rgb(253, 255, 211)"}, ALL)
|
||||
|
||||
goto: file://|DOC_PATH|/test_docs/index.html
|
||||
assert-css: (".section-header a", {"color": "rgb(0, 0, 0)"}, ALL)
|
||||
assert-css: (".small-section-header a", {"color": "rgb(0, 0, 0)"}, ALL)
|
||||
|
||||
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
|
||||
assert-css: (".section-header a", {"color": "rgb(56, 115, 173)"}, ALL)
|
||||
|
|
9
src/test/ui/cast/cast-int-to-char.rs
Normal file
9
src/test/ui/cast/cast-int-to-char.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
fn foo<T>(_t: T) {}
|
||||
|
||||
fn main() {
|
||||
foo::<u32>('0'); //~ ERROR
|
||||
foo::<i32>('0'); //~ ERROR
|
||||
foo::<u64>('0'); //~ ERROR
|
||||
foo::<i64>('0'); //~ ERROR
|
||||
foo::<char>(0u32); //~ ERROR
|
||||
}
|
53
src/test/ui/cast/cast-int-to-char.stderr
Normal file
53
src/test/ui/cast/cast-int-to-char.stderr
Normal file
|
@ -0,0 +1,53 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/cast-int-to-char.rs:4:16
|
||||
|
|
||||
LL | foo::<u32>('0');
|
||||
| ^^^ expected `u32`, found `char`
|
||||
|
|
||||
help: you can cast a `char` to a `u32`, since a `char` always occupies 4 bytes
|
||||
|
|
||||
LL | foo::<u32>('0' as u32);
|
||||
| ++++++
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/cast-int-to-char.rs:5:16
|
||||
|
|
||||
LL | foo::<i32>('0');
|
||||
| ^^^ expected `i32`, found `char`
|
||||
|
|
||||
help: you can cast a `char` to an `i32`, since a `char` always occupies 4 bytes
|
||||
|
|
||||
LL | foo::<i32>('0' as i32);
|
||||
| ++++++
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/cast-int-to-char.rs:6:16
|
||||
|
|
||||
LL | foo::<u64>('0');
|
||||
| ^^^ expected `u64`, found `char`
|
||||
|
|
||||
help: you can cast a `char` to a `u64`, since a `char` always occupies 4 bytes
|
||||
|
|
||||
LL | foo::<u64>('0' as u64);
|
||||
| ++++++
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/cast-int-to-char.rs:7:16
|
||||
|
|
||||
LL | foo::<i64>('0');
|
||||
| ^^^ expected `i64`, found `char`
|
||||
|
|
||||
help: you can cast a `char` to an `i64`, since a `char` always occupies 4 bytes
|
||||
|
|
||||
LL | foo::<i64>('0' as i64);
|
||||
| ++++++
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/cast-int-to-char.rs:8:17
|
||||
|
|
||||
LL | foo::<char>(0u32);
|
||||
| ^^^^ expected `char`, found `u32`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
|
@ -6,6 +6,11 @@ LL | fn test_func1(n: i32) -> i32 {
|
|||
LL | match n {
|
||||
LL | 12 => 'b',
|
||||
| ^^^ expected `i32`, found `char`
|
||||
|
|
||||
help: you can cast a `char` to an `i32`, since a `char` always occupies 4 bytes
|
||||
|
|
||||
LL | 12 => 'b' as i32,
|
||||
| ++++++
|
||||
|
||||
error[E0308]: `match` arms have incompatible types
|
||||
--> $DIR/match-type-err-first-arm.rs:18:14
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
// run-pass
|
||||
#![feature(generators)]
|
||||
#![feature(generator_trait)]
|
||||
use std::cell::Cell;
|
||||
use std::mem;
|
||||
use std::ops::Generator;
|
||||
use std::pin::Pin;
|
||||
|
||||
struct Aligned<'a> {
|
||||
drop_count: &'a Cell<usize>
|
||||
|
@ -19,15 +23,35 @@ impl<'a> Drop for Aligned<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
struct NotCopy(u8);
|
||||
|
||||
#[repr(packed)]
|
||||
struct Packed<'a>(u8, Aligned<'a>);
|
||||
struct Packed<'a>(NotCopy, Aligned<'a>);
|
||||
|
||||
fn main() {
|
||||
let drop_count = &Cell::new(0);
|
||||
{
|
||||
let mut p = Packed(0, Aligned { drop_count });
|
||||
let mut p = Packed(NotCopy(0), Aligned { drop_count });
|
||||
p.1 = Aligned { drop_count };
|
||||
assert_eq!(drop_count.get(), 1);
|
||||
}
|
||||
assert_eq!(drop_count.get(), 2);
|
||||
|
||||
let drop_count = &Cell::new(0);
|
||||
let mut g = || {
|
||||
let mut p = Packed(NotCopy(0), Aligned { drop_count });
|
||||
let _ = &p;
|
||||
p.1 = Aligned { drop_count };
|
||||
assert_eq!(drop_count.get(), 1);
|
||||
// Test that a generator drop function moves a value from a packed
|
||||
// struct to a separate local before dropping it. We move out the
|
||||
// first field to generate and open drop for the second field.
|
||||
drop(p.0);
|
||||
yield;
|
||||
};
|
||||
Pin::new(&mut g).resume(());
|
||||
assert_eq!(drop_count.get(), 1);
|
||||
drop(g);
|
||||
assert_eq!(drop_count.get(), 2);
|
||||
}
|
||||
|
|
13
src/test/ui/parser/misspelled-macro-rules.fixed
Normal file
13
src/test/ui/parser/misspelled-macro-rules.fixed
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Regression test for issue #91227.
|
||||
|
||||
// run-rustfix
|
||||
|
||||
#![allow(unused_macros)]
|
||||
|
||||
macro_rules! thing {
|
||||
//~^ ERROR: expected one of
|
||||
//~| HELP: perhaps you meant to define a macro
|
||||
() => {}
|
||||
}
|
||||
|
||||
fn main() {}
|
13
src/test/ui/parser/misspelled-macro-rules.rs
Normal file
13
src/test/ui/parser/misspelled-macro-rules.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Regression test for issue #91227.
|
||||
|
||||
// run-rustfix
|
||||
|
||||
#![allow(unused_macros)]
|
||||
|
||||
marco_rules! thing {
|
||||
//~^ ERROR: expected one of
|
||||
//~| HELP: perhaps you meant to define a macro
|
||||
() => {}
|
||||
}
|
||||
|
||||
fn main() {}
|
10
src/test/ui/parser/misspelled-macro-rules.stderr
Normal file
10
src/test/ui/parser/misspelled-macro-rules.stderr
Normal file
|
@ -0,0 +1,10 @@
|
|||
error: expected one of `(`, `[`, or `{`, found `thing`
|
||||
--> $DIR/misspelled-macro-rules.rs:7:14
|
||||
|
|
||||
LL | marco_rules! thing {
|
||||
| ----------- ^^^^^ expected one of `(`, `[`, or `{`
|
||||
| |
|
||||
| help: perhaps you meant to define a macro: `macro_rules`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
|
@ -3,6 +3,11 @@ error[E0308]: mismatched types
|
|||
|
|
||||
LL | id![static X: u32 = 'a';];
|
||||
| ^^^ expected `u32`, found `char`
|
||||
|
|
||||
help: you can cast a `char` to a `u32`, since a `char` always occupies 4 bytes
|
||||
|
|
||||
LL | id![static X: u32 = 'a' as u32;];
|
||||
| ++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue