Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #91676

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2135,22 +2135,20 @@ impl<'a> State<'a> {
ast::ExprKind::Path(Some(ref qself), ref path) => self.print_qpath(path, qself, true),
ast::ExprKind::Break(opt_label, ref opt_expr) => {
self.s.word("break");
self.s.space();
if let Some(label) = opt_label {
self.print_ident(label.ident);
self.s.space();
self.print_ident(label.ident);
}
if let Some(ref expr) = *opt_expr {
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
self.s.space();
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
}
}
ast::ExprKind::Continue(opt_label) => {
self.s.word("continue");
self.s.space();
if let Some(label) = opt_label {
self.s.space();
self.print_ident(label.ident);
self.s.space()
}
}
ast::ExprKind::Ret(ref result) => {
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,22 +1543,20 @@ impl<'a> State<'a> {
hir::ExprKind::Path(ref qpath) => self.print_qpath(qpath, true),
hir::ExprKind::Break(destination, ref opt_expr) => {
self.s.word("break");
self.s.space();
if let Some(label) = destination.label {
self.print_ident(label.ident);
self.s.space();
self.print_ident(label.ident);
}
if let Some(ref expr) = *opt_expr {
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
self.s.space();
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
}
}
hir::ExprKind::Continue(destination) => {
self.s.word("continue");
self.s.space();
if let Some(label) = destination.label {
self.s.space();
self.print_ident(label.ident);
self.s.space()
}
}
hir::ExprKind::Ret(ref result) => {
Expand Down
29 changes: 25 additions & 4 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_typeck/src/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/css/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/css/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/css/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
54 changes: 28 additions & 26 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/test/pretty/ast-stmt-expr-attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ fn syntax() {
let _ = #[attr] &mut 0;
let _ = #[attr] &#[attr] 0;
let _ = #[attr] &mut #[attr] 0;
let _ = #[attr] break ;
let _ = #[attr] continue ;
let _ = #[attr] break;
let _ = #[attr] continue;
let _ = #[attr] return;
let _ = #[attr] foo!();
let _ = #[attr] foo!(#! [attr]);
Expand Down
2 changes: 1 addition & 1 deletion src/test/pretty/hir-pretty-loop.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
// pretty-mode:hir
// pp-exact:hir-pretty-loop.pp

pub fn foo() { loop { break ; } }
pub fn foo() { loop { break; } }
5 changes: 2 additions & 3 deletions src/test/pretty/stmt_expr_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,8 @@ fn _11() {
let _ = #[rustc_dummy] &mut 0;
let _ = #[rustc_dummy] &#[rustc_dummy] 0;
let _ = #[rustc_dummy] &mut #[rustc_dummy] 0;
// FIXME: pp bug, extra space after keyword?
while false { let _ = #[rustc_dummy] continue ; }
while true { let _ = #[rustc_dummy] break ; }
while false { let _ = #[rustc_dummy] continue; }
while true { let _ = #[rustc_dummy] break; }
|| #[rustc_dummy] return;
let _ = #[rustc_dummy] expr_mac!();
let _ = #[rustc_dummy] expr_mac![];
Expand Down
15 changes: 12 additions & 3 deletions src/test/rustdoc-gui/headers-color.goml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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"}
Expand All @@ -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 changes: 9 additions & 0 deletions src/test/ui/cast/cast-int-to-char.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 53 additions & 0 deletions src/test/ui/cast/cast-int-to-char.stderr
Original file line number Diff line number Diff line change
@@ -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`.
5 changes: 5 additions & 0 deletions src/test/ui/match/match-type-err-first-arm.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 26 additions & 2 deletions src/test/ui/packed/packed-struct-drop-aligned.rs
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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);
}
Loading