Skip to content

Commit e9cdccc

Browse files
committed
Auto merge of rust-lang#83964 - Dylan-DPC:rollup-9kinaiv, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - rust-lang#83476 (Add strong_count mutation methods to Rc) - rust-lang#83634 (Do not emit the advanced diagnostics on macros) - rust-lang#83816 (Trigger `unused_doc_comments` on macros at once) - rust-lang#83916 (Use AnonConst for asm! constants) - rust-lang#83935 (forbid `impl Trait` in generic param defaults) - rust-lang#83936 (Disable using non-ascii identifiers in extern blocks.) - rust-lang#83945 (Add suggestion to reborrow mutable references when they're moved in a for loop) - rust-lang#83954 (Do not ICE when closure is involved in Trait Alias Impl Trait) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b01026d + d82419b commit e9cdccc

File tree

127 files changed

+902
-400
lines changed

Some content is hidden

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

127 files changed

+902
-400
lines changed

compiler/rustc_ast/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,7 @@ pub enum InlineAsmOperand {
19981998
out_expr: Option<P<Expr>>,
19991999
},
20002000
Const {
2001-
expr: P<Expr>,
2001+
anon_const: AnonConst,
20022002
},
20032003
Sym {
20042004
expr: P<Expr>,

compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,6 @@ pub fn noop_visit_expr<T: MutVisitor>(
12521252
match op {
12531253
InlineAsmOperand::In { expr, .. }
12541254
| InlineAsmOperand::InOut { expr, .. }
1255-
| InlineAsmOperand::Const { expr, .. }
12561255
| InlineAsmOperand::Sym { expr, .. } => vis.visit_expr(expr),
12571256
InlineAsmOperand::Out { expr, .. } => {
12581257
if let Some(expr) = expr {
@@ -1265,6 +1264,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
12651264
vis.visit_expr(out_expr);
12661265
}
12671266
}
1267+
InlineAsmOperand::Const { anon_const, .. } => vis.visit_anon_const(anon_const),
12681268
}
12691269
}
12701270
}

compiler/rustc_ast/src/visit.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,6 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
835835
match op {
836836
InlineAsmOperand::In { expr, .. }
837837
| InlineAsmOperand::InOut { expr, .. }
838-
| InlineAsmOperand::Const { expr, .. }
839838
| InlineAsmOperand::Sym { expr, .. } => visitor.visit_expr(expr),
840839
InlineAsmOperand::Out { expr, .. } => {
841840
if let Some(expr) = expr {
@@ -848,6 +847,9 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
848847
visitor.visit_expr(out_expr);
849848
}
850849
}
850+
InlineAsmOperand::Const { anon_const, .. } => {
851+
visitor.visit_anon_const(anon_const)
852+
}
851853
}
852854
}
853855
}

compiler/rustc_ast_lowering/src/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1411,9 +1411,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
14111411
out_expr: out_expr.as_ref().map(|expr| self.lower_expr_mut(expr)),
14121412
}
14131413
}
1414-
InlineAsmOperand::Const { ref expr } => {
1415-
hir::InlineAsmOperand::Const { expr: self.lower_expr_mut(expr) }
1416-
}
1414+
InlineAsmOperand::Const { ref anon_const } => hir::InlineAsmOperand::Const {
1415+
anon_const: self.lower_anon_const(anon_const),
1416+
},
14171417
InlineAsmOperand::Sym { ref expr } => {
14181418
hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) }
14191419
}

compiler/rustc_ast_lowering/src/lib.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -2259,13 +2259,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22592259

22602260
let kind = hir::GenericParamKind::Type {
22612261
default: default.as_ref().map(|x| {
2262-
self.lower_ty(
2263-
x,
2264-
ImplTraitContext::OtherOpaqueTy {
2265-
capturable_lifetimes: &mut FxHashSet::default(),
2266-
origin: hir::OpaqueTyOrigin::Misc,
2267-
},
2268-
)
2262+
self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Other))
22692263
}),
22702264
synthetic: param
22712265
.attrs

compiler/rustc_ast_passes/src/ast_validation.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,25 @@ impl<'a> AstValidator<'a> {
532532
}
533533
}
534534

535+
/// An item in `extern { ... }` cannot use non-ascii identifier.
536+
fn check_foreign_item_ascii_only(&self, ident: Ident) {
537+
let symbol_str = ident.as_str();
538+
if !symbol_str.is_ascii() {
539+
let n = 83942;
540+
self.err_handler()
541+
.struct_span_err(
542+
ident.span,
543+
"items in `extern` blocks cannot use non-ascii identifiers",
544+
)
545+
.span_label(self.current_extern_span(), "in this `extern` block")
546+
.note(&format!(
547+
"This limitation may be lifted in the future; see issue #{} <https://github.com/rust-lang/rust/issues/{}> for more information",
548+
n, n,
549+
))
550+
.emit();
551+
}
552+
}
553+
535554
/// Reject C-varadic type unless the function is foreign,
536555
/// or free and `unsafe extern "C"` semantically.
537556
fn check_c_varadic_type(&self, fk: FnKind<'a>) {
@@ -592,7 +611,7 @@ impl<'a> AstValidator<'a> {
592611
self.session,
593612
ident.span,
594613
E0754,
595-
"trying to load file for module `{}` with non ascii identifer name",
614+
"trying to load file for module `{}` with non-ascii identifier name",
596615
ident.name
597616
)
598617
.help("consider using `#[path]` attribute to specify filesystem path")
@@ -1103,15 +1122,18 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11031122
self.check_defaultness(fi.span, *def);
11041123
self.check_foreign_fn_bodyless(fi.ident, body.as_deref());
11051124
self.check_foreign_fn_headerless(fi.ident, fi.span, sig.header);
1125+
self.check_foreign_item_ascii_only(fi.ident);
11061126
}
11071127
ForeignItemKind::TyAlias(box TyAliasKind(def, generics, bounds, body)) => {
11081128
self.check_defaultness(fi.span, *def);
11091129
self.check_foreign_kind_bodyless(fi.ident, "type", body.as_ref().map(|b| b.span));
11101130
self.check_type_no_bounds(bounds, "`extern` blocks");
11111131
self.check_foreign_ty_genericless(generics);
1132+
self.check_foreign_item_ascii_only(fi.ident);
11121133
}
11131134
ForeignItemKind::Static(_, _, body) => {
11141135
self.check_foreign_kind_bodyless(fi.ident, "static", body.as_ref().map(|b| b.span));
1136+
self.check_foreign_item_ascii_only(fi.ident);
11151137
}
11161138
ForeignItemKind::MacCall(..) => {}
11171139
}

compiler/rustc_ast_pretty/src/pprust/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2149,10 +2149,10 @@ impl<'a> State<'a> {
21492149
None => s.word("_"),
21502150
}
21512151
}
2152-
InlineAsmOperand::Const { expr } => {
2152+
InlineAsmOperand::Const { anon_const } => {
21532153
s.word("const");
21542154
s.space();
2155-
s.print_expr(expr);
2155+
s.print_expr(&anon_const.value);
21562156
}
21572157
InlineAsmOperand::Sym { expr } => {
21582158
s.word("sym");

compiler/rustc_builtin_macros/src/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ fn parse_args<'a>(
136136
ast::InlineAsmOperand::InOut { reg, expr, late: true }
137137
}
138138
} else if p.eat_keyword(kw::Const) {
139-
let expr = p.parse_expr()?;
140-
ast::InlineAsmOperand::Const { expr }
139+
let anon_const = p.parse_anon_const_expr()?;
140+
ast::InlineAsmOperand::Const { anon_const }
141141
} else if p.eat_keyword(sym::sym) {
142142
let expr = p.parse_expr()?;
143143
match expr.kind {

compiler/rustc_codegen_ssa/src/mir/block.rs

+30-34
Original file line numberDiff line numberDiff line change
@@ -822,41 +822,37 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
822822
InlineAsmOperandRef::InOut { reg, late, in_value, out_place }
823823
}
824824
mir::InlineAsmOperand::Const { ref value } => {
825-
if let mir::Operand::Constant(constant) = value {
826-
let const_value = self
827-
.eval_mir_constant(constant)
828-
.unwrap_or_else(|_| span_bug!(span, "asm const cannot be resolved"));
829-
let ty = constant.ty();
830-
let size = bx.layout_of(ty).size;
831-
let scalar = match const_value {
832-
ConstValue::Scalar(s) => s,
833-
_ => span_bug!(
834-
span,
835-
"expected Scalar for promoted asm const, but got {:#?}",
836-
const_value
837-
),
838-
};
839-
let value = scalar.assert_bits(size);
840-
let string = match ty.kind() {
841-
ty::Uint(_) => value.to_string(),
842-
ty::Int(int_ty) => {
843-
match int_ty.normalize(bx.tcx().sess.target.pointer_width) {
844-
ty::IntTy::I8 => (value as i8).to_string(),
845-
ty::IntTy::I16 => (value as i16).to_string(),
846-
ty::IntTy::I32 => (value as i32).to_string(),
847-
ty::IntTy::I64 => (value as i64).to_string(),
848-
ty::IntTy::I128 => (value as i128).to_string(),
849-
ty::IntTy::Isize => unreachable!(),
850-
}
825+
let const_value = self
826+
.eval_mir_constant(value)
827+
.unwrap_or_else(|_| span_bug!(span, "asm const cannot be resolved"));
828+
let ty = value.ty();
829+
let size = bx.layout_of(ty).size;
830+
let scalar = match const_value {
831+
ConstValue::Scalar(s) => s,
832+
_ => span_bug!(
833+
span,
834+
"expected Scalar for promoted asm const, but got {:#?}",
835+
const_value
836+
),
837+
};
838+
let value = scalar.assert_bits(size);
839+
let string = match ty.kind() {
840+
ty::Uint(_) => value.to_string(),
841+
ty::Int(int_ty) => {
842+
match int_ty.normalize(bx.tcx().sess.target.pointer_width) {
843+
ty::IntTy::I8 => (value as i8).to_string(),
844+
ty::IntTy::I16 => (value as i16).to_string(),
845+
ty::IntTy::I32 => (value as i32).to_string(),
846+
ty::IntTy::I64 => (value as i64).to_string(),
847+
ty::IntTy::I128 => (value as i128).to_string(),
848+
ty::IntTy::Isize => unreachable!(),
851849
}
852-
ty::Float(ty::FloatTy::F32) => f32::from_bits(value as u32).to_string(),
853-
ty::Float(ty::FloatTy::F64) => f64::from_bits(value as u64).to_string(),
854-
_ => span_bug!(span, "asm const has bad type {}", ty),
855-
};
856-
InlineAsmOperandRef::Const { string }
857-
} else {
858-
span_bug!(span, "asm const is not a constant");
859-
}
850+
}
851+
ty::Float(ty::FloatTy::F32) => f32::from_bits(value as u32).to_string(),
852+
ty::Float(ty::FloatTy::F64) => f64::from_bits(value as u64).to_string(),
853+
_ => span_bug!(span, "asm const has bad type {}", ty),
854+
};
855+
InlineAsmOperandRef::Const { string }
860856
}
861857
mir::InlineAsmOperand::SymFn { ref value } => {
862858
let literal = self.monomorphize(value.literal);

compiler/rustc_expand/src/expand.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1067,13 +1067,23 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
10671067
// since they will not be detected after macro expansion.
10681068
fn check_attributes(&mut self, attrs: &[ast::Attribute]) {
10691069
let features = self.cx.ecfg.features.unwrap();
1070-
for attr in attrs.iter() {
1070+
let mut attrs = attrs.iter().peekable();
1071+
let mut span: Option<Span> = None;
1072+
while let Some(attr) = attrs.next() {
10711073
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
10721074
validate_attr::check_meta(&self.cx.sess.parse_sess, attr);
1075+
1076+
let current_span = if let Some(sp) = span { sp.to(attr.span) } else { attr.span };
1077+
span = Some(current_span);
1078+
1079+
if attrs.peek().map_or(false, |next_attr| next_attr.doc_str().is_some()) {
1080+
continue;
1081+
}
1082+
10731083
if attr.doc_str().is_some() {
10741084
self.cx.sess.parse_sess.buffer_lint_with_diagnostic(
10751085
&UNUSED_DOC_COMMENTS,
1076-
attr.span,
1086+
current_span,
10771087
ast::CRATE_NODE_ID,
10781088
"unused doc comment",
10791089
BuiltinLintDiagnostics::UnusedDocComment(attr.span),

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2347,7 +2347,7 @@ pub enum InlineAsmOperand<'hir> {
23472347
out_expr: Option<Expr<'hir>>,
23482348
},
23492349
Const {
2350-
expr: Expr<'hir>,
2350+
anon_const: AnonConst,
23512351
},
23522352
Sym {
23532353
expr: Expr<'hir>,

compiler/rustc_hir/src/intravisit.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,6 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
11891189
match op {
11901190
InlineAsmOperand::In { expr, .. }
11911191
| InlineAsmOperand::InOut { expr, .. }
1192-
| InlineAsmOperand::Const { expr, .. }
11931192
| InlineAsmOperand::Sym { expr, .. } => visitor.visit_expr(expr),
11941193
InlineAsmOperand::Out { expr, .. } => {
11951194
if let Some(expr) = expr {
@@ -1202,6 +1201,9 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
12021201
visitor.visit_expr(out_expr);
12031202
}
12041203
}
1204+
InlineAsmOperand::Const { anon_const, .. } => {
1205+
visitor.visit_anon_const(anon_const)
1206+
}
12051207
}
12061208
}
12071209
}

compiler/rustc_hir_pretty/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1570,10 +1570,10 @@ impl<'a> State<'a> {
15701570
None => s.word("_"),
15711571
}
15721572
}
1573-
hir::InlineAsmOperand::Const { expr } => {
1573+
hir::InlineAsmOperand::Const { anon_const } => {
15741574
s.word("const");
15751575
s.space();
1576-
s.print_expr(expr);
1576+
s.print_anon_const(anon_const);
15771577
}
15781578
hir::InlineAsmOperand::Sym { expr } => {
15791579
s.word("sym");

compiler/rustc_lint/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &
989989
Some(sugared_span.map_or(attr.span, |span| span.with_hi(attr.span.hi())));
990990
}
991991

992-
if attrs.peek().map(|next_attr| next_attr.is_doc_comment()).unwrap_or_default() {
992+
if attrs.peek().map_or(false, |next_attr| next_attr.is_doc_comment()) {
993993
continue;
994994
}
995995

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ pub enum InlineAsmOperand<'tcx> {
12131213
out_place: Option<Place<'tcx>>,
12141214
},
12151215
Const {
1216-
value: Operand<'tcx>,
1216+
value: Box<Constant<'tcx>>,
12171217
},
12181218
SymFn {
12191219
value: Box<Constant<'tcx>>,

compiler/rustc_middle/src/mir/visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,7 @@ macro_rules! make_mir_visitor {
584584
} => {
585585
for op in operands {
586586
match op {
587-
InlineAsmOperand::In { value, .. }
588-
| InlineAsmOperand::Const { value } => {
587+
InlineAsmOperand::In { value, .. } => {
589588
self.visit_operand(value, location);
590589
}
591590
InlineAsmOperand::Out { place, .. } => {
@@ -607,7 +606,8 @@ macro_rules! make_mir_visitor {
607606
);
608607
}
609608
}
610-
InlineAsmOperand::SymFn { value } => {
609+
InlineAsmOperand::Const { value }
610+
| InlineAsmOperand::SymFn { value } => {
611611
self.visit_constant(value, location);
612612
}
613613
InlineAsmOperand::SymStatic { def_id: _ } => {}

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,24 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
264264

265265
if let Some(DesugaringKind::ForLoop(_)) = move_span.desugaring_kind() {
266266
let sess = self.infcx.tcx.sess;
267-
if let Ok(snippet) = sess.source_map().span_to_snippet(move_span) {
267+
let ty = used_place.ty(self.body, self.infcx.tcx).ty;
268+
// If we have a `&mut` ref, we need to reborrow.
269+
if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind() {
270+
// If we are in a loop this will be suggested later.
271+
if !is_loop_move {
272+
err.span_suggestion_verbose(
273+
move_span.shrink_to_lo(),
274+
&format!(
275+
"consider creating a fresh reborrow of {} here",
276+
self.describe_place(moved_place.as_ref())
277+
.map(|n| format!("`{}`", n))
278+
.unwrap_or_else(|| "the mutable reference".to_string()),
279+
),
280+
format!("&mut *"),
281+
Applicability::MachineApplicable,
282+
);
283+
}
284+
} else if let Ok(snippet) = sess.source_map().span_to_snippet(move_span) {
268285
err.span_suggestion(
269286
move_span,
270287
"consider borrowing to avoid moving into the for loop",

compiler/rustc_mir/src/borrow_check/invalidation.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
204204
} => {
205205
for op in operands {
206206
match *op {
207-
InlineAsmOperand::In { reg: _, ref value }
208-
| InlineAsmOperand::Const { ref value } => {
207+
InlineAsmOperand::In { reg: _, ref value } => {
209208
self.consume_operand(location, value);
210209
}
211210
InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
@@ -219,7 +218,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
219218
self.mutate_place(location, out_place, Shallow(None), JustWrite);
220219
}
221220
}
222-
InlineAsmOperand::SymFn { value: _ }
221+
InlineAsmOperand::Const { value: _ }
222+
| InlineAsmOperand::SymFn { value: _ }
223223
| InlineAsmOperand::SymStatic { def_id: _ } => {}
224224
}
225225
}

compiler/rustc_mir/src/borrow_check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,7 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
734734
} => {
735735
for op in operands {
736736
match *op {
737-
InlineAsmOperand::In { reg: _, ref value }
738-
| InlineAsmOperand::Const { ref value } => {
737+
InlineAsmOperand::In { reg: _, ref value } => {
739738
self.consume_operand(loc, (value, span), flow_state);
740739
}
741740
InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
@@ -761,7 +760,8 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
761760
);
762761
}
763762
}
764-
InlineAsmOperand::SymFn { value: _ }
763+
InlineAsmOperand::Const { value: _ }
764+
| InlineAsmOperand::SymFn { value: _ }
765765
| InlineAsmOperand::SymStatic { def_id: _ } => {}
766766
}
767767
}

0 commit comments

Comments
 (0)