Skip to content

Commit

Permalink
Auto merge of rust-lang#122735 - matthiaskrgr:rollup-pgb1s90, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

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
  • Loading branch information
bors committed Mar 19, 2024
2 parents a385e56 + 433449a commit e760daa
Show file tree
Hide file tree
Showing 45 changed files with 5,597 additions and 367 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(super) fn index_hir<'hir>(
OwnerNode::TraitItem(item) => collector.visit_trait_item(item),
OwnerNode::ImplItem(item) => collector.visit_impl_item(item),
OwnerNode::ForeignItem(item) => collector.visit_foreign_item(item),
OwnerNode::AssocOpaqueTy(..) => unreachable!(),
OwnerNode::Synthetic => unreachable!(),
};

for (local_id, node) in collector.nodes.iter_enumerated() {
Expand Down
37 changes: 24 additions & 13 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(rustc::untranslatable_diagnostic)]

use core::ops::ControlFlow;
use hir::ExprKind;
use hir::{ExprKind, Param};
use rustc_errors::{Applicability, Diag};
use rustc_hir as hir;
use rustc_hir::intravisit::Visitor;
Expand Down Expand Up @@ -725,25 +725,26 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
_ => local_decl.source_info.span,
};

let def_id = self.body.source.def_id();
let hir_id = if let Some(local_def_id) = def_id.as_local()
&& let Some(body_id) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
{
let body = self.infcx.tcx.hir().body(body_id);
BindingFinder { span: pat_span }.visit_body(body).break_value()
} else {
None
};

// With ref-binding patterns, the mutability suggestion has to apply to
// the binding, not the reference (which would be a type error):
//
// `let &b = a;` -> `let &(mut b) = a;`
if let Some(hir_id) = hir_id
// or
// `fn foo(&x: &i32)` -> `fn foo(&(mut x): &i32)`
let def_id = self.body.source.def_id();
if let Some(local_def_id) = def_id.as_local()
&& let Some(body_id) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
&& let body = self.infcx.tcx.hir().body(body_id)
&& let Some(hir_id) = (BindingFinder { span: pat_span }).visit_body(body).break_value()
&& let node = self.infcx.tcx.hir_node(hir_id)
&& let hir::Node::Local(hir::Local {
pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. },
..
}) = self.infcx.tcx.hir_node(hir_id)
})
| hir::Node::Param(Param {
pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. },
..
}) = node
&& let Ok(name) =
self.infcx.tcx.sess.source_map().span_to_snippet(local_decl.source_info.span)
{
Expand Down Expand Up @@ -1310,6 +1311,16 @@ impl<'tcx> Visitor<'tcx> for BindingFinder {
hir::intravisit::walk_stmt(self, s)
}
}

fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) -> Self::Result {
if let hir::Pat { kind: hir::PatKind::Ref(_, _), span, .. } = param.pat
&& *span == self.span
{
ControlFlow::Break(param.hir_id)
} else {
ControlFlow::Continue(())
}
}
}

pub fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<Symbol>) -> bool {
Expand Down
46 changes: 29 additions & 17 deletions compiler/rustc_codegen_ssa/src/mono_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::base;
use crate::common;
use crate::traits::*;
use rustc_hir as hir;
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::mir::mono::{Linkage, Visibility};
use rustc_middle::ty;
Expand Down Expand Up @@ -40,23 +41,34 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
.iter()
.map(|(op, op_sp)| match *op {
hir::InlineAsmOperand::Const { ref anon_const } => {
let const_value = cx
.tcx()
.const_eval_poly(anon_const.def_id.to_def_id())
.unwrap_or_else(|_| {
span_bug!(*op_sp, "asm const cannot be resolved")
});
let ty = cx
.tcx()
.typeck_body(anon_const.body)
.node_type(anon_const.hir_id);
let string = common::asm_const_to_str(
cx.tcx(),
*op_sp,
const_value,
cx.layout_of(ty),
);
GlobalAsmOperandRef::Const { string }
match cx.tcx().const_eval_poly(anon_const.def_id.to_def_id()) {
Ok(const_value) => {
let ty = cx
.tcx()
.typeck_body(anon_const.body)
.node_type(anon_const.hir_id);
let string = common::asm_const_to_str(
cx.tcx(),
*op_sp,
const_value,
cx.layout_of(ty),
);
GlobalAsmOperandRef::Const { string }
}
Err(ErrorHandled::Reported { .. }) => {
// An error has already been reported and
// compilation is guaranteed to fail if execution
// hits this path. So an empty string instead of
// a stringified constant value will suffice.
GlobalAsmOperandRef::Const { string: String::new() }
}
Err(ErrorHandled::TooGeneric(_)) => {
span_bug!(
*op_sp,
"asm const cannot be resolved; too generic"
)
}
}
}
hir::InlineAsmOperand::SymFn { ref anon_const } => {
let ty = cx
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_const_eval/src/interpret/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ fn intern_as_new_static<'tcx>(
feed.generics_of(tcx.generics_of(static_id).clone());
feed.def_ident_span(tcx.def_ident_span(static_id));
feed.explicit_predicates_of(tcx.explicit_predicates_of(static_id));

feed.feed_hir()
}

/// How a constant value should be interned.
Expand Down
Loading

0 comments on commit e760daa

Please sign in to comment.