Skip to content

Commit 56be633

Browse files
committed
Auto merge of #63807 - Centril:rollup-b8lo8ct, r=Centril
Rollup of 7 pull requests Successful merges: - #63624 (When declaring a declarative macro in an item it's only accessible inside it) - #63737 (Fix naming misspelling) - #63767 (Use more optimal Ord implementation for integers) - #63782 (Fix confusion in theme picker functions) - #63788 (Add amanjeev to rustc-guide toolstate) - #63796 (Tweak E0308 on opaque types) - #63805 (Apply few Clippy suggestions) Failed merges: r? @ghost
2 parents 201e52e + 3068064 commit 56be633

File tree

17 files changed

+157
-61
lines changed

17 files changed

+157
-61
lines changed

src/build_helper/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ pub fn native_lib_boilerplate(
262262
if !up_to_date(Path::new("build.rs"), &timestamp) || !up_to_date(src_dir, &timestamp) {
263263
Ok(NativeLibBoilerplate {
264264
src_dir: src_dir.to_path_buf(),
265-
out_dir: out_dir,
265+
out_dir,
266266
})
267267
} else {
268268
Err(())

src/libcore/cmp.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1012,9 +1012,11 @@ mod impls {
10121012
impl Ord for $t {
10131013
#[inline]
10141014
fn cmp(&self, other: &$t) -> Ordering {
1015-
if *self == *other { Equal }
1016-
else if *self < *other { Less }
1017-
else { Greater }
1015+
// The order here is important to generate more optimal assembly.
1016+
// See <https://github.com/rust-lang/rust/issues/63758> for more info.
1017+
if *self < *other { Less }
1018+
else if *self > *other { Greater }
1019+
else { Equal }
10181020
}
10191021
}
10201022
)*)

src/libcore/iter/adapters/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ impl<I> DoubleEndedIterator for Peekable<I> where I: DoubleEndedIterator {
13091309
Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Ok=B>
13101310
{
13111311
match self.peeked.take() {
1312-
Some(None) => return Try::from_ok(init),
1312+
Some(None) => Try::from_ok(init),
13131313
Some(Some(v)) => match self.iter.try_rfold(init, &mut f).into_result() {
13141314
Ok(acc) => f(acc, v),
13151315
Err(e) => {
@@ -1326,7 +1326,7 @@ impl<I> DoubleEndedIterator for Peekable<I> where I: DoubleEndedIterator {
13261326
where Fold: FnMut(Acc, Self::Item) -> Acc,
13271327
{
13281328
match self.peeked {
1329-
Some(None) => return init,
1329+
Some(None) => init,
13301330
Some(Some(v)) => {
13311331
let acc = self.iter.rfold(init, &mut fold);
13321332
fold(acc, v)

src/libcore/slice/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3026,8 +3026,7 @@ macro_rules! len {
30263026
if size == 0 {
30273027
// This _cannot_ use `unchecked_sub` because we depend on wrapping
30283028
// to represent the length of long ZST slice iterators.
3029-
let diff = ($self.end as usize).wrapping_sub(start as usize);
3030-
diff
3029+
($self.end as usize).wrapping_sub(start as usize)
30313030
} else {
30323031
// We know that `start <= end`, so can do better than `offset_from`,
30333032
// which needs to deal in signed. By setting appropriate flags here

src/librustc/hir/map/mod.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,7 @@ impl<'hir> Map<'hir> {
514514
&self.forest.krate.attrs
515515
}
516516

517-
pub fn get_module(&self, module: DefId) -> (&'hir Mod, Span, HirId)
518-
{
517+
pub fn get_module(&self, module: DefId) -> (&'hir Mod, Span, HirId) {
519518
let hir_id = self.as_local_hir_id(module).unwrap();
520519
self.read(hir_id);
521520
match self.find_entry(hir_id).unwrap().node {
@@ -525,7 +524,7 @@ impl<'hir> Map<'hir> {
525524
..
526525
}) => (m, span, hir_id),
527526
Node::Crate => (&self.forest.krate.module, self.forest.krate.span, hir_id),
528-
_ => panic!("not a module")
527+
node => panic!("not a module: {:?}", node),
529528
}
530529
}
531530

@@ -679,6 +678,16 @@ impl<'hir> Map<'hir> {
679678
}
680679
}
681680

681+
/// Wether `hir_id` corresponds to a `mod` or a crate.
682+
pub fn is_hir_id_module(&self, hir_id: HirId) -> bool {
683+
match self.lookup(hir_id) {
684+
Some(Entry { node: Node::Item(Item { node: ItemKind::Mod(_), .. }), .. }) |
685+
Some(Entry { node: Node::Crate, .. }) => true,
686+
_ => false,
687+
}
688+
}
689+
690+
682691
/// If there is some error when walking the parents (e.g., a node does not
683692
/// have a parent in the map or a node can't be found), then we return the
684693
/// last good `HirId` we found. Note that reaching the crate root (`id == 0`),

src/librustc/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ impl<'tcx> ObligationCause<'tcx> {
16501650
hir::MatchSource::IfLetDesugar { .. } => "`if let` arms have compatible types",
16511651
_ => "match arms have compatible types",
16521652
},
1653-
IfExpression { .. } => "if and else have compatible types",
1653+
IfExpression { .. } => "if and else have incompatible types",
16541654
IfExpressionWithNoElse => "if missing an else returns ()",
16551655
MainFunctionType => "`main` function has the correct type",
16561656
StartFunctionType => "`start` function has the correct type",

src/librustc/ty/error.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,32 @@ impl<'tcx> ty::TyS<'tcx> {
247247
}
248248

249249
impl<'tcx> TyCtxt<'tcx> {
250-
pub fn note_and_explain_type_err(self,
251-
db: &mut DiagnosticBuilder<'_>,
252-
err: &TypeError<'tcx>,
253-
sp: Span) {
250+
pub fn note_and_explain_type_err(
251+
self,
252+
db: &mut DiagnosticBuilder<'_>,
253+
err: &TypeError<'tcx>,
254+
sp: Span,
255+
) {
254256
use self::TypeError::*;
255257

256-
match err.clone() {
258+
match err {
257259
Sorts(values) => {
258260
let expected_str = values.expected.sort_string(self);
259261
let found_str = values.found.sort_string(self);
260262
if expected_str == found_str && expected_str == "closure" {
261263
db.note("no two closures, even if identical, have the same type");
262264
db.help("consider boxing your closure and/or using it as a trait object");
263265
}
266+
if expected_str == found_str && expected_str == "opaque type" { // Issue #63167
267+
db.note("distinct uses of `impl Trait` result in different opaque types");
268+
let e_str = values.expected.to_string();
269+
let f_str = values.found.to_string();
270+
if &e_str == &f_str && &e_str == "impl std::future::Future" {
271+
// FIXME: use non-string based check.
272+
db.help("if both `Future`s have the same `Output` type, consider \
273+
`.await`ing on both of them");
274+
}
275+
}
264276
if let (ty::Infer(ty::IntVar(_)), ty::Float(_)) =
265277
(&values.found.sty, &values.expected.sty) // Issue #53280
266278
{

src/librustc_privacy/lib.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,7 @@ impl EmbargoVisitor<'tcx> {
508508
}
509509
}
510510

511-
fn update_macro_reachable_mod(
512-
&mut self,
513-
reachable_mod: hir::HirId,
514-
defining_mod: DefId,
515-
) {
511+
fn update_macro_reachable_mod(&mut self, reachable_mod: hir::HirId, defining_mod: DefId) {
516512
let module_def_id = self.tcx.hir().local_def_id(reachable_mod);
517513
let module = self.tcx.hir().get_module(module_def_id).0;
518514
for item_id in &module.item_ids {
@@ -524,19 +520,13 @@ impl EmbargoVisitor<'tcx> {
524520
self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod);
525521
}
526522
}
527-
528523
if let Some(exports) = self.tcx.module_exports(module_def_id) {
529524
for export in exports {
530525
if export.vis.is_accessible_from(defining_mod, self.tcx) {
531526
if let Res::Def(def_kind, def_id) = export.res {
532527
let vis = def_id_visibility(self.tcx, def_id).0;
533528
if let Some(hir_id) = self.tcx.hir().as_local_hir_id(def_id) {
534-
self.update_macro_reachable_def(
535-
hir_id,
536-
def_kind,
537-
vis,
538-
defining_mod,
539-
);
529+
self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod);
540530
}
541531
}
542532
}
@@ -892,10 +882,14 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
892882
self.tcx.hir().local_def_id(md.hir_id)
893883
).unwrap();
894884
let mut module_id = self.tcx.hir().as_local_hir_id(macro_module_def_id).unwrap();
885+
if !self.tcx.hir().is_hir_id_module(module_id) {
886+
// `module_id` doesn't correspond to a `mod`, return early (#63164).
887+
return;
888+
}
895889
let level = if md.vis.node.is_pub() { self.get(module_id) } else { None };
896890
let new_level = self.update(md.hir_id, level);
897891
if new_level.is_none() {
898-
return
892+
return;
899893
}
900894

901895
loop {

src/librustdoc/html/render.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -876,22 +876,22 @@ r#"var themes = document.getElementById("theme-choices");
876876
var themePicker = document.getElementById("theme-picker");
877877
878878
function showThemeButtonState() {{
879-
themes.style.display = "none";
880-
themePicker.style.borderBottomRightRadius = "3px";
881-
themePicker.style.borderBottomLeftRadius = "3px";
882-
}}
883-
884-
function hideThemeButtonState() {{
885879
themes.style.display = "block";
886880
themePicker.style.borderBottomRightRadius = "0";
887881
themePicker.style.borderBottomLeftRadius = "0";
888882
}}
889883
884+
function hideThemeButtonState() {{
885+
themes.style.display = "none";
886+
themePicker.style.borderBottomRightRadius = "3px";
887+
themePicker.style.borderBottomLeftRadius = "3px";
888+
}}
889+
890890
function switchThemeButtonState() {{
891891
if (themes.style.display === "block") {{
892-
showThemeButtonState();
893-
}} else {{
894892
hideThemeButtonState();
893+
}} else {{
894+
showThemeButtonState();
895895
}}
896896
}};
897897

src/librustdoc/html/static/main.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ if (!DOMTokenList.prototype.remove) {
105105
sidebar.appendChild(div);
106106
}
107107
}
108-
var themePicker = document.getElementsByClassName("theme-picker");
109-
if (themePicker && themePicker.length > 0) {
110-
themePicker[0].style.display = "none";
108+
var themePickers = document.getElementsByClassName("theme-picker");
109+
if (themePickers && themePickers.length > 0) {
110+
themePickers[0].style.display = "none";
111111
}
112112
}
113113

@@ -123,9 +123,9 @@ if (!DOMTokenList.prototype.remove) {
123123
filler.remove();
124124
}
125125
document.getElementsByTagName("body")[0].style.marginTop = "";
126-
var themePicker = document.getElementsByClassName("theme-picker");
127-
if (themePicker && themePicker.length > 0) {
128-
themePicker[0].style.display = null;
126+
var themePickers = document.getElementsByClassName("theme-picker");
127+
if (themePickers && themePickers.length > 0) {
128+
themePickers[0].style.display = null;
129129
}
130130
}
131131

src/test/codegen/integer-cmp.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This is test for more optimal Ord implementation for integers.
2+
// See <https://github.com/rust-lang/rust/issues/63758> for more info.
3+
4+
// compile-flags: -C opt-level=3
5+
6+
#![crate_type = "lib"]
7+
8+
use std::cmp::Ordering;
9+
10+
// CHECK-LABEL: @cmp_signed
11+
#[no_mangle]
12+
pub fn cmp_signed(a: i64, b: i64) -> Ordering {
13+
// CHECK: icmp slt
14+
// CHECK: icmp sgt
15+
// CHECK: zext i1
16+
// CHECK: select i1
17+
a.cmp(&b)
18+
}
19+
20+
// CHECK-LABEL: @cmp_unsigned
21+
#[no_mangle]
22+
pub fn cmp_unsigned(a: u32, b: u32) -> Ordering {
23+
// CHECK: icmp ult
24+
// CHECK: icmp ugt
25+
// CHECK: zext i1
26+
// CHECK: select i1
27+
a.cmp(&b)
28+
}

src/test/ui/macros/macro-in-fn.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-pass
2+
#![feature(decl_macro)]
3+
4+
pub fn moo() {
5+
pub macro ABC() {{}}
6+
}
7+
8+
fn main() {}

src/test/ui/non-interger-atomic.stderr renamed to src/test/ui/non-integer-atomic.stderr

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,95 @@
11
error[E0511]: invalid monomorphization of `atomic_load` intrinsic: expected basic integer type, found `bool`
2-
--> $DIR/non-interger-atomic.rs:13:5
2+
--> $DIR/non-integer-atomic.rs:13:5
33
|
44
LL | intrinsics::atomic_load(p);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
66

77
error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer type, found `bool`
8-
--> $DIR/non-interger-atomic.rs:18:5
8+
--> $DIR/non-integer-atomic.rs:18:5
99
|
1010
LL | intrinsics::atomic_store(p, v);
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer type, found `bool`
14-
--> $DIR/non-interger-atomic.rs:23:5
14+
--> $DIR/non-integer-atomic.rs:23:5
1515
|
1616
LL | intrinsics::atomic_xchg(p, v);
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

1919
error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer type, found `bool`
20-
--> $DIR/non-interger-atomic.rs:28:5
20+
--> $DIR/non-integer-atomic.rs:28:5
2121
|
2222
LL | intrinsics::atomic_cxchg(p, v, v);
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424

2525
error[E0511]: invalid monomorphization of `atomic_load` intrinsic: expected basic integer type, found `Foo`
26-
--> $DIR/non-interger-atomic.rs:33:5
26+
--> $DIR/non-integer-atomic.rs:33:5
2727
|
2828
LL | intrinsics::atomic_load(p);
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
3030

3131
error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer type, found `Foo`
32-
--> $DIR/non-interger-atomic.rs:38:5
32+
--> $DIR/non-integer-atomic.rs:38:5
3333
|
3434
LL | intrinsics::atomic_store(p, v);
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636

3737
error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer type, found `Foo`
38-
--> $DIR/non-interger-atomic.rs:43:5
38+
--> $DIR/non-integer-atomic.rs:43:5
3939
|
4040
LL | intrinsics::atomic_xchg(p, v);
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4242

4343
error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer type, found `Foo`
44-
--> $DIR/non-interger-atomic.rs:48:5
44+
--> $DIR/non-integer-atomic.rs:48:5
4545
|
4646
LL | intrinsics::atomic_cxchg(p, v, v);
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4848

4949
error[E0511]: invalid monomorphization of `atomic_load` intrinsic: expected basic integer type, found `&dyn std::ops::Fn()`
50-
--> $DIR/non-interger-atomic.rs:53:5
50+
--> $DIR/non-integer-atomic.rs:53:5
5151
|
5252
LL | intrinsics::atomic_load(p);
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
5454

5555
error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer type, found `&dyn std::ops::Fn()`
56-
--> $DIR/non-interger-atomic.rs:58:5
56+
--> $DIR/non-integer-atomic.rs:58:5
5757
|
5858
LL | intrinsics::atomic_store(p, v);
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6060

6161
error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer type, found `&dyn std::ops::Fn()`
62-
--> $DIR/non-interger-atomic.rs:63:5
62+
--> $DIR/non-integer-atomic.rs:63:5
6363
|
6464
LL | intrinsics::atomic_xchg(p, v);
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6666

6767
error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer type, found `&dyn std::ops::Fn()`
68-
--> $DIR/non-interger-atomic.rs:68:5
68+
--> $DIR/non-integer-atomic.rs:68:5
6969
|
7070
LL | intrinsics::atomic_cxchg(p, v, v);
7171
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7272

7373
error[E0511]: invalid monomorphization of `atomic_load` intrinsic: expected basic integer type, found `[u8; 100]`
74-
--> $DIR/non-interger-atomic.rs:73:5
74+
--> $DIR/non-integer-atomic.rs:73:5
7575
|
7676
LL | intrinsics::atomic_load(p);
7777
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
7878

7979
error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer type, found `[u8; 100]`
80-
--> $DIR/non-interger-atomic.rs:78:5
80+
--> $DIR/non-integer-atomic.rs:78:5
8181
|
8282
LL | intrinsics::atomic_store(p, v);
8383
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8484

8585
error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer type, found `[u8; 100]`
86-
--> $DIR/non-interger-atomic.rs:83:5
86+
--> $DIR/non-integer-atomic.rs:83:5
8787
|
8888
LL | intrinsics::atomic_xchg(p, v);
8989
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9090

9191
error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer type, found `[u8; 100]`
92-
--> $DIR/non-interger-atomic.rs:88:5
92+
--> $DIR/non-integer-atomic.rs:88:5
9393
|
9494
LL | intrinsics::atomic_cxchg(p, v, v);
9595
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)