Skip to content

Commit d2b38d6

Browse files
committed
Auto merge of #82341 - GuillaumeGomez:rollup-t7y7tyg, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - #80595 (`impl PartialEq<Punct> for char`; symmetry for #78636) - #81991 (Fix panic in 'remove semicolon' when types are not local) - #82176 (fix MIR fn-ptr pretty-printing) - #82244 (Keep consistency in example for Stdin StdinLock) - #82260 (rustc: Show ``@path`` usage in stable) - #82316 (Fix minor mistake in LTO docs.) - #82332 (Don't generate src link on dummy spans) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 83b30a6 + fc0cb5d commit d2b38d6

File tree

14 files changed

+117
-25
lines changed

14 files changed

+117
-25
lines changed

compiler/rustc_driver/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ fn usage(verbose: bool, include_unstable_options: bool, nightly_build: bool) {
812812
} else {
813813
"\n --help -v Print the full set of options rustc accepts"
814814
};
815-
let at_path = if verbose && nightly_build {
815+
let at_path = if verbose {
816816
" @path Read newline separated options from `path`\n"
817817
} else {
818818
""

compiler/rustc_middle/src/ty/print/pretty.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ pub trait PrettyPrinter<'tcx>:
10181018
p!(write("{:?}", char::try_from(int).unwrap()))
10191019
}
10201020
// Raw pointers
1021-
(Scalar::Int(int), ty::RawPtr(_)) => {
1021+
(Scalar::Int(int), ty::RawPtr(_) | ty::FnPtr(_)) => {
10221022
let data = int.assert_bits(self.tcx().data_layout.pointer_size);
10231023
self = self.typed_value(
10241024
|mut this| {
@@ -1030,15 +1030,18 @@ pub trait PrettyPrinter<'tcx>:
10301030
)?;
10311031
}
10321032
(Scalar::Ptr(ptr), ty::FnPtr(_)) => {
1033-
// FIXME: this can ICE when the ptr is dangling or points to a non-function.
1034-
// We should probably have a helper method to share code with the "Byte strings"
1033+
// FIXME: We should probably have a helper method to share code with the "Byte strings"
10351034
// printing above (which also has to handle pointers to all sorts of things).
1036-
let instance = self.tcx().global_alloc(ptr.alloc_id).unwrap_fn();
1037-
self = self.typed_value(
1038-
|this| this.print_value_path(instance.def_id(), instance.substs),
1039-
|this| this.print_type(ty),
1040-
" as ",
1041-
)?;
1035+
match self.tcx().get_global_alloc(ptr.alloc_id) {
1036+
Some(GlobalAlloc::Function(instance)) => {
1037+
self = self.typed_value(
1038+
|this| this.print_value_path(instance.def_id(), instance.substs),
1039+
|this| this.print_type(ty),
1040+
" as ",
1041+
)?;
1042+
}
1043+
_ => self = self.pretty_print_const_pointer(ptr, ty, print_ty)?,
1044+
}
10421045
}
10431046
// For function type zsts just printing the path is enough
10441047
(Scalar::Int(int), ty::FnDef(d, s)) if int == ScalarInt::ZST => {

compiler/rustc_mir/src/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<Tag: Copy> std::fmt::Display for ImmTy<'tcx, Tag> {
112112
}
113113
ScalarMaybeUninit::Uninit => cx.typed_value(
114114
|mut this| {
115-
this.write_str("{uninit ")?;
115+
this.write_str("uninit ")?;
116116
Ok(this)
117117
},
118118
|this| this.print_type(ty),

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1074,13 +1074,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10741074
};
10751075
let last_expr_ty = self.node_ty(last_expr.hir_id);
10761076
let needs_box = match (last_expr_ty.kind(), expected_ty.kind()) {
1077+
(ty::Opaque(last_def_id, _), ty::Opaque(exp_def_id, _))
1078+
if last_def_id == exp_def_id =>
1079+
{
1080+
StatementAsExpression::CorrectType
1081+
}
10771082
(ty::Opaque(last_def_id, last_bounds), ty::Opaque(exp_def_id, exp_bounds)) => {
10781083
debug!(
10791084
"both opaque, likely future {:?} {:?} {:?} {:?}",
10801085
last_def_id, last_bounds, exp_def_id, exp_bounds
10811086
);
1082-
let last_hir_id = self.tcx.hir().local_def_id_to_hir_id(last_def_id.expect_local());
1083-
let exp_hir_id = self.tcx.hir().local_def_id_to_hir_id(exp_def_id.expect_local());
1087+
1088+
let (last_local_id, exp_local_id) =
1089+
match (last_def_id.as_local(), exp_def_id.as_local()) {
1090+
(Some(last_hir_id), Some(exp_hir_id)) => (last_hir_id, exp_hir_id),
1091+
(_, _) => return None,
1092+
};
1093+
1094+
let last_hir_id = self.tcx.hir().local_def_id_to_hir_id(last_local_id);
1095+
let exp_hir_id = self.tcx.hir().local_def_id_to_hir_id(exp_local_id);
1096+
10841097
match (
10851098
&self.tcx.hir().expect_item(last_hir_id).kind,
10861099
&self.tcx.hir().expect_item(exp_hir_id).kind,

library/proc_macro/src/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -842,13 +842,20 @@ impl fmt::Debug for Punct {
842842
}
843843
}
844844

845-
#[stable(feature = "proc_macro_punct_eq", since = "1.49.0")]
845+
#[stable(feature = "proc_macro_punct_eq", since = "1.50.0")]
846846
impl PartialEq<char> for Punct {
847847
fn eq(&self, rhs: &char) -> bool {
848848
self.as_char() == *rhs
849849
}
850850
}
851851

852+
#[stable(feature = "proc_macro_punct_eq_flipped", since = "1.52.0")]
853+
impl PartialEq<Punct> for char {
854+
fn eq(&self, rhs: &Punct) -> bool {
855+
*self == rhs.as_char()
856+
}
857+
}
858+
852859
/// An identifier (`ident`).
853860
#[derive(Clone)]
854861
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]

library/std/src/io/stdio.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ pub struct Stdin {
251251
/// let mut buffer = String::new();
252252
/// let stdin = io::stdin(); // We get `Stdin` here.
253253
/// {
254-
/// let mut stdin_lock = stdin.lock(); // We get `StdinLock` here.
255-
/// stdin_lock.read_to_string(&mut buffer)?;
254+
/// let mut handle = stdin.lock(); // We get `StdinLock` here.
255+
/// handle.read_to_string(&mut buffer)?;
256256
/// } // `StdinLock` is dropped here.
257257
/// Ok(())
258258
/// }

src/doc/rustc/src/codegen-options/index.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ opt-level=0`](#opt-level)). That is:
299299
* When `-C lto` is not specified:
300300
* `codegen-units=1`: disable LTO.
301301
* `opt-level=0`: disable LTO.
302-
* When `-C lto=true`:
303-
* `lto=true`: 16 codegen units, perform fat LTO across crates.
304-
* `codegen-units=1` + `lto=true`: 1 codegen unit, fat LTO across crates.
302+
* When `-C lto` is specified:
303+
* `lto`: 16 codegen units, perform fat LTO across crates.
304+
* `codegen-units=1` + `lto`: 1 codegen unit, fat LTO across crates.
305305

306306
See also [linker-plugin-lto](#linker-plugin-lto) for cross-language LTO.
307307

src/librustdoc/clean/types.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,10 @@ impl Span {
18521852
self.0
18531853
}
18541854

1855+
crate fn is_dummy(&self) -> bool {
1856+
self.0.is_dummy()
1857+
}
1858+
18551859
crate fn filename(&self, sess: &Session) -> FileName {
18561860
sess.source_map().span_to_filename(self.0)
18571861
}

src/librustdoc/html/render/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,9 @@ impl Context<'_> {
16381638
/// may happen, for example, with externally inlined items where the source
16391639
/// of their crate documentation isn't known.
16401640
fn src_href(&self, item: &clean::Item) -> Option<String> {
1641+
if item.source.is_dummy() {
1642+
return None;
1643+
}
16411644
let mut root = self.root_path();
16421645
let mut path = String::new();
16431646
let cnum = item.source.cnum(self.sess());
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![crate_name = "foo"]
2+
3+
// @has foo/struct.Unsized.html
4+
// @has - '//h3[@id="impl-Sized"]/code' 'impl !Sized for Unsized'
5+
// @!has - '//h3[@id="impl-Sized"]/a[@class="srclink"]' '[src]'
6+
// @has - '//h3[@id="impl-Sync"]/code' 'impl Sync for Unsized'
7+
// @!has - '//h3[@id="impl-Sync"]/a[@class="srclink"]' '[src]'
8+
// @has - '//h3[@id="impl-Any"]/code' 'impl<T> Any for T'
9+
// @has - '//h3[@id="impl-Any"]/a[@class="srclink"]' '[src]'
10+
pub struct Unsized {
11+
data: [u8],
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// edition:2018
2+
3+
pub struct Test {}
4+
5+
impl Test {
6+
pub async fn answer_str(&self, _s: &str) -> Test {
7+
Test {}
8+
}
9+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// aux-build:issue-81839.rs
2+
// edition:2018
3+
4+
extern crate issue_81839;
5+
6+
async fn test(ans: &str, num: i32, cx: &issue_81839::Test) -> u32 {
7+
match num {
8+
1 => {
9+
cx.answer_str("hi");
10+
}
11+
_ => cx.answer_str("hi"), //~ `match` arms have incompatible types
12+
}
13+
14+
1
15+
}
16+
17+
fn main() {}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0308]: `match` arms have incompatible types
2+
--> $DIR/issue-81839.rs:11:14
3+
|
4+
LL | / match num {
5+
LL | | 1 => {
6+
LL | | cx.answer_str("hi");
7+
| | --------------------
8+
| | | |
9+
| | | help: consider removing this semicolon
10+
| | this is found to be of type `()`
11+
LL | | }
12+
LL | | _ => cx.answer_str("hi"),
13+
| | ^^^^^^^^^^^^^^^^^^^ expected `()`, found opaque type
14+
LL | | }
15+
| |_____- `match` arms have incompatible types
16+
|
17+
::: $DIR/auxiliary/issue-81839.rs:6:49
18+
|
19+
LL | pub async fn answer_str(&self, _s: &str) -> Test {
20+
| ---- the `Output` of this `async fn`'s found opaque type
21+
|
22+
= note: expected type `()`
23+
found opaque type `impl Future`
24+
25+
error: aborting due to previous error
26+
27+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/suggestions/match-prev-arm-needing-semi.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@ help: consider `await`ing on the `Future`
2424
|
2525
LL | false => async_dummy().await,
2626
| ^^^^^^
27-
help: consider removing this semicolon and boxing the expressions
28-
|
29-
LL | Box::new(async_dummy())
30-
LL |
31-
LL | }
32-
LL | false => Box::new(async_dummy()),
27+
help: consider removing this semicolon
3328
|
29+
LL | async_dummy()
30+
| --
3431

3532
error[E0308]: `match` arms have incompatible types
3633
--> $DIR/match-prev-arm-needing-semi.rs:39:18

0 commit comments

Comments
 (0)