Skip to content

Commit e9cdccc

Browse files
committed
Auto merge of #83964 - Dylan-DPC:rollup-9kinaiv, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - #83476 (Add strong_count mutation methods to Rc) - #83634 (Do not emit the advanced diagnostics on macros) - #83816 (Trigger `unused_doc_comments` on macros at once) - #83916 (Use AnonConst for asm! constants) - #83935 (forbid `impl Trait` in generic param defaults) - #83936 (Disable using non-ascii identifiers in extern blocks.) - #83945 (Add suggestion to reborrow mutable references when they're moved in a for loop) - #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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 7 deletions
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

Lines changed: 23 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 30 additions & 34 deletions
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

Lines changed: 12 additions & 2 deletions
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),

0 commit comments

Comments
 (0)