Skip to content

Commit e760daa

Browse files
committed
Auto merge of rust-lang#122735 - matthiaskrgr:rollup-pgb1s90, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#122435 (Don't trigger `unused_qualifications` on global paths) - rust-lang#122556 (Extend format arg help for simple tuple index access expression) - rust-lang#122634 (compiletest: Add support for `//@ aux-bin: foo.rs`) - rust-lang#122677 (Fix incorrect mutable suggestion information for binding in ref pattern.) - rust-lang#122691 (Fix ICE: `global_asm!()` Don't Panic When Unable to Evaluate Constant) - rust-lang#122695 (Change only_local to a enum type.) - rust-lang#122717 (Ensure stack before parsing dot-or-call) - rust-lang#122719 (Ensure nested statics have a HIR node to prevent various queries from ICEing) - rust-lang#122720 ([doc]:fix error code example) - rust-lang#122724 (add test for casting pointer to union with unsized tail) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a385e56 + 433449a commit e760daa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+5597
-367
lines changed

compiler/rustc_ast_lowering/src/index.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(super) fn index_hir<'hir>(
5555
OwnerNode::TraitItem(item) => collector.visit_trait_item(item),
5656
OwnerNode::ImplItem(item) => collector.visit_impl_item(item),
5757
OwnerNode::ForeignItem(item) => collector.visit_foreign_item(item),
58-
OwnerNode::AssocOpaqueTy(..) => unreachable!(),
58+
OwnerNode::Synthetic => unreachable!(),
5959
};
6060

6161
for (local_id, node) in collector.nodes.iter_enumerated() {

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+24-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(rustc::untranslatable_diagnostic)]
33

44
use core::ops::ControlFlow;
5-
use hir::ExprKind;
5+
use hir::{ExprKind, Param};
66
use rustc_errors::{Applicability, Diag};
77
use rustc_hir as hir;
88
use rustc_hir::intravisit::Visitor;
@@ -725,25 +725,26 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
725725
_ => local_decl.source_info.span,
726726
};
727727

728-
let def_id = self.body.source.def_id();
729-
let hir_id = if let Some(local_def_id) = def_id.as_local()
730-
&& let Some(body_id) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
731-
{
732-
let body = self.infcx.tcx.hir().body(body_id);
733-
BindingFinder { span: pat_span }.visit_body(body).break_value()
734-
} else {
735-
None
736-
};
737-
738728
// With ref-binding patterns, the mutability suggestion has to apply to
739729
// the binding, not the reference (which would be a type error):
740730
//
741731
// `let &b = a;` -> `let &(mut b) = a;`
742-
if let Some(hir_id) = hir_id
732+
// or
733+
// `fn foo(&x: &i32)` -> `fn foo(&(mut x): &i32)`
734+
let def_id = self.body.source.def_id();
735+
if let Some(local_def_id) = def_id.as_local()
736+
&& let Some(body_id) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
737+
&& let body = self.infcx.tcx.hir().body(body_id)
738+
&& let Some(hir_id) = (BindingFinder { span: pat_span }).visit_body(body).break_value()
739+
&& let node = self.infcx.tcx.hir_node(hir_id)
743740
&& let hir::Node::Local(hir::Local {
744741
pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. },
745742
..
746-
}) = self.infcx.tcx.hir_node(hir_id)
743+
})
744+
| hir::Node::Param(Param {
745+
pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. },
746+
..
747+
}) = node
747748
&& let Ok(name) =
748749
self.infcx.tcx.sess.source_map().span_to_snippet(local_decl.source_info.span)
749750
{
@@ -1310,6 +1311,16 @@ impl<'tcx> Visitor<'tcx> for BindingFinder {
13101311
hir::intravisit::walk_stmt(self, s)
13111312
}
13121313
}
1314+
1315+
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) -> Self::Result {
1316+
if let hir::Pat { kind: hir::PatKind::Ref(_, _), span, .. } = param.pat
1317+
&& *span == self.span
1318+
{
1319+
ControlFlow::Break(param.hir_id)
1320+
} else {
1321+
ControlFlow::Continue(())
1322+
}
1323+
}
13131324
}
13141325

13151326
pub fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<Symbol>) -> bool {

compiler/rustc_codegen_ssa/src/mono_item.rs

+29-17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::base;
22
use crate::common;
33
use crate::traits::*;
44
use rustc_hir as hir;
5+
use rustc_middle::mir::interpret::ErrorHandled;
56
use rustc_middle::mir::mono::MonoItem;
67
use rustc_middle::mir::mono::{Linkage, Visibility};
78
use rustc_middle::ty;
@@ -40,23 +41,34 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
4041
.iter()
4142
.map(|(op, op_sp)| match *op {
4243
hir::InlineAsmOperand::Const { ref anon_const } => {
43-
let const_value = cx
44-
.tcx()
45-
.const_eval_poly(anon_const.def_id.to_def_id())
46-
.unwrap_or_else(|_| {
47-
span_bug!(*op_sp, "asm const cannot be resolved")
48-
});
49-
let ty = cx
50-
.tcx()
51-
.typeck_body(anon_const.body)
52-
.node_type(anon_const.hir_id);
53-
let string = common::asm_const_to_str(
54-
cx.tcx(),
55-
*op_sp,
56-
const_value,
57-
cx.layout_of(ty),
58-
);
59-
GlobalAsmOperandRef::Const { string }
44+
match cx.tcx().const_eval_poly(anon_const.def_id.to_def_id()) {
45+
Ok(const_value) => {
46+
let ty = cx
47+
.tcx()
48+
.typeck_body(anon_const.body)
49+
.node_type(anon_const.hir_id);
50+
let string = common::asm_const_to_str(
51+
cx.tcx(),
52+
*op_sp,
53+
const_value,
54+
cx.layout_of(ty),
55+
);
56+
GlobalAsmOperandRef::Const { string }
57+
}
58+
Err(ErrorHandled::Reported { .. }) => {
59+
// An error has already been reported and
60+
// compilation is guaranteed to fail if execution
61+
// hits this path. So an empty string instead of
62+
// a stringified constant value will suffice.
63+
GlobalAsmOperandRef::Const { string: String::new() }
64+
}
65+
Err(ErrorHandled::TooGeneric(_)) => {
66+
span_bug!(
67+
*op_sp,
68+
"asm const cannot be resolved; too generic"
69+
)
70+
}
71+
}
6072
}
6173
hir::InlineAsmOperand::SymFn { ref anon_const } => {
6274
let ty = cx

compiler/rustc_const_eval/src/interpret/intern.rs

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ fn intern_as_new_static<'tcx>(
111111
feed.generics_of(tcx.generics_of(static_id).clone());
112112
feed.def_ident_span(tcx.def_ident_span(static_id));
113113
feed.explicit_predicates_of(tcx.explicit_predicates_of(static_id));
114+
115+
feed.feed_hir()
114116
}
115117

116118
/// How a constant value should be interned.

0 commit comments

Comments
 (0)