Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3f5406f

Browse files
authored
Rollup merge of#140302 - compiler-errors:inline_asm-bug, r=lcnr
Move inline asm check to typeck, properly handle aliasesPull `InlineAsmCtxt` down to `rustc_hir_typeck`, and instead of using things like `Ty::is_copy`, use the `InferCtxt`-aware methods. Tofixrust-lang/trait-system-refactor-initiative#189, we also add a `try_structurally_resolve_*` call to `expr_ty`.r? lcnr
2 parents0bd531a +3ab6051 commit3f5406f

File tree

13 files changed

+86
-73
lines changed

13 files changed

+86
-73
lines changed

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3757,7 +3757,6 @@ dependencies = [
37573757
"rustc_middle",
37583758
"rustc_session",
37593759
"rustc_span",
3760-
"rustc_target",
37613760
"rustc_trait_selection",
37623761
"smallvec",
37633762
"tracing",
@@ -3796,6 +3795,7 @@ dependencies = [
37963795
"rustc_middle",
37973796
"rustc_session",
37983797
"rustc_span",
3798+
"rustc_target",
37993799
"rustc_trait_selection",
38003800
"smallvec",
38013801
"tracing",

‎compiler/rustc_hir_analysis/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ rustc_macros = { path = "../rustc_macros" }
2626
rustc_middle = {path ="../rustc_middle" }
2727
rustc_session = {path ="../rustc_session" }
2828
rustc_span = {path ="../rustc_span" }
29-
rustc_target = {path ="../rustc_target" }
3029
rustc_trait_selection = {path ="../rustc_trait_selection" }
3130
smallvec = {version ="1.8.1",features = ["union","may_dangle"] }
3231
tracing ="0.1"

‎compiler/rustc_hir_analysis/messages.ftl‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,6 @@ hir_analysis_recursive_generic_parameter = {$param_def_kind} `{$param_name}` is
450450
hir_analysis_redundant_lifetime_args =unnecessary lifetime parameter `{$victim}`
451451
.note =you can use the `{$candidate}` lifetime directly, in place of `{$victim}`
452452
453-
hir_analysis_register_type_unstable =
454-
type `{$ty}` cannot be used with this register class in stable
455-
456453
hir_analysis_requires_note =the `{$trait_name}` impl for `{$ty}` requires that `{$error_predicate}`
457454
458455
hir_analysis_return_type_notation_equality_bound =

‎compiler/rustc_hir_analysis/src/check/mod.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ mod check;
6767
mod compare_impl_item;
6868
mod entry;
6969
pubmod intrinsic;
70-
pubmod intrinsicck;
7170
mod region;
7271
pubmod wfcheck;
7372

‎compiler/rustc_hir_analysis/src/errors.rs‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,14 +1675,6 @@ pub(crate) struct CmseEntryGeneric {
16751675
pubspan:Span,
16761676
}
16771677

1678-
#[derive(Diagnostic)]
1679-
#[diag(hir_analysis_register_type_unstable)]
1680-
pub(crate)structRegisterTypeUnstable<'a>{
1681-
#[primary_span]
1682-
pubspan:Span,
1683-
pubty:Ty<'a>,
1684-
}
1685-
16861678
#[derive(LintDiagnostic)]
16871679
#[diag(hir_analysis_supertrait_item_shadowing)]
16881680
pub(crate)structSupertraitItemShadowing{

‎compiler/rustc_hir_typeck/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ rustc_macros = { path = "../rustc_macros" }
2222
rustc_middle = {path ="../rustc_middle" }
2323
rustc_session = {path ="../rustc_session" }
2424
rustc_span = {path ="../rustc_span" }
25+
rustc_target = {path ="../rustc_target" }
2526
rustc_trait_selection = {path ="../rustc_trait_selection" }
2627
smallvec = {version ="1.8.1",features = ["union","may_dangle"] }
2728
tracing ="0.1"

‎compiler/rustc_hir_typeck/messages.ftl‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ hir_typeck_ptr_cast_add_auto_to_object = cannot add {$traits_len ->
179179
.help =use `transmute` if you're sure this is sound
180180
.label =unsupported cast
181181
182+
hir_typeck_register_type_unstable =
183+
type `{$ty}` cannot be used with this register class in stable
184+
182185
hir_typeck_remove_semi_for_coerce =you might have meant to return the `match` expression
183186
hir_typeck_remove_semi_for_coerce_expr =this could be implicitly returned but it is a statement, not a tail expression
184187
hir_typeck_remove_semi_for_coerce_ret =the `match` arms can conform to this return type

‎compiler/rustc_hir_typeck/src/errors.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,3 +963,11 @@ pub(crate) enum SupertraitItemShadowee {
963963
traits:DiagSymbolList,
964964
},
965965
}
966+
967+
#[derive(Diagnostic)]
968+
#[diag(hir_typeck_register_type_unstable)]
969+
pub(crate)structRegisterTypeUnstable<'a>{
970+
#[primary_span]
971+
pubspan:Span,
972+
pubty:Ty<'a>,
973+
}

‎compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_hir::def::{CtorOf, DefKind, Res};
88
use rustc_hir::def_id::DefId;
99
use rustc_hir::intravisit::Visitor;
1010
use rustc_hir::{ExprKind,HirId,Node,QPath};
11-
use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt;
1211
use rustc_hir_analysis::check::potentially_plural_count;
1312
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
1413
use rustc_index::IndexVec;
@@ -33,6 +32,7 @@ use crate::errors::SuggestPtrNullMut;
3332
usecrate::fn_ctxt::arg_matrix::{ArgMatrix,Compatibility,Error,ExpectedIdx,ProvidedIdx};
3433
usecrate::fn_ctxt::infer::FnCall;
3534
usecrate::gather_locals::Declaration;
35+
usecrate::inline_asm::InlineAsmCtxt;
3636
usecrate::method::MethodCallee;
3737
usecrate::method::probe::IsSuggestion;
3838
usecrate::method::probe::Mode::MethodCall;
@@ -98,13 +98,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9898
debug!("FnCtxt::check_asm: {} deferred checks", deferred_asm_checks.len());
9999
for(asm, hir_id)in deferred_asm_checks.drain(..){
100100
let enclosing_id =self.tcx.hir_enclosing_body_owner(hir_id);
101-
InlineAsmCtxt::new(
102-
enclosing_id,
103-
&self.infcx,
104-
self.typing_env(self.param_env),
105-
&*self.typeck_results.borrow(),
106-
)
107-
.check_asm(asm);
101+
InlineAsmCtxt::new(self, enclosing_id).check_asm(asm);
108102
}
109103
}
110104

‎compiler/rustc_hir_analysis/src/check/intrinsicck.rs‎renamed to ‎compiler/rustc_hir_typeck/src/inline_asm.rs‎

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,22 @@ use rustc_ast::InlineAsmTemplatePiece;
33
use rustc_data_structures::fx::FxIndexSet;
44
use rustc_hir::def_id::DefId;
55
use rustc_hir::{selfas hir,LangItem};
6-
use rustc_infer::infer::InferCtxt;
76
use rustc_middle::bug;
8-
use rustc_middle::ty::{
9-
self,Article,FloatTy,IntTy,Ty,TyCtxt,TypeVisitableExt,TypeckResults,UintTy,
10-
};
7+
use rustc_middle::ty::{self,Article,FloatTy,IntTy,Ty,TyCtxt,TypeVisitableExt,UintTy};
118
use rustc_session::lint;
129
use rustc_span::def_id::LocalDefId;
13-
use rustc_span::{Symbol, sym};
10+
use rustc_span::{Span,Symbol, sym};
1411
use rustc_target::asm::{
1512
InlineAsmReg,InlineAsmRegClass,InlineAsmRegOrRegClass,InlineAsmType,ModifierInfo,
1613
};
14+
use rustc_trait_selection::infer::InferCtxtExt;
1715

16+
usecrate::FnCtxt;
1817
usecrate::errors::RegisterTypeUnstable;
1918

20-
pubstructInlineAsmCtxt<'a,'tcx>{
21-
typing_env: ty::TypingEnv<'tcx>,
19+
pub(crate)structInlineAsmCtxt<'a,'tcx>{
2220
target_features:&'tcxFxIndexSet<Symbol>,
23-
infcx:&'aInferCtxt<'tcx>,
24-
typeck_results:&'aTypeckResults<'tcx>,
21+
fcx:&'aFnCtxt<'a,'tcx>,
2522
}
2623

2724
enumNonAsmTypeReason<'tcx>{
@@ -33,27 +30,17 @@ enum NonAsmTypeReason<'tcx> {
3330
}
3431

3532
impl<'a,'tcx>InlineAsmCtxt<'a,'tcx>{
36-
pubfnnew(
37-
def_id:LocalDefId,
38-
infcx:&'aInferCtxt<'tcx>,
39-
typing_env: ty::TypingEnv<'tcx>,
40-
typeck_results:&'aTypeckResults<'tcx>,
41-
) ->Self{
42-
InlineAsmCtxt{
43-
typing_env,
44-
target_features: infcx.tcx.asm_target_features(def_id),
45-
infcx,
46-
typeck_results,
47-
}
33+
pub(crate)fnnew(fcx:&'aFnCtxt<'a,'tcx>,def_id:LocalDefId) ->Self{
34+
InlineAsmCtxt{target_features: fcx.tcx.asm_target_features(def_id), fcx}
4835
}
4936

5037
fntcx(&self) ->TyCtxt<'tcx>{
51-
self.infcx.tcx
38+
self.fcx.tcx
5239
}
5340

5441
fnexpr_ty(&self,expr:&hir::Expr<'tcx>) ->Ty<'tcx>{
55-
let ty =self.typeck_results.expr_ty_adjusted(expr);
56-
let ty =self.infcx.resolve_vars_if_possible(ty);
42+
let ty =self.fcx.typeck_results.borrow().expr_ty_adjusted(expr);
43+
let ty =self.fcx.try_structurally_resolve_type(expr.span,ty);
5744
if ty.has_non_region_infer(){
5845
Ty::new_misc_error(self.tcx())
5946
}else{
@@ -62,19 +49,23 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
6249
}
6350

6451
// FIXME(compiler-errors): This could use `<$ty as Pointee>::Metadata == ()`
65-
fnis_thin_ptr_ty(&self,ty:Ty<'tcx>) ->bool{
52+
fnis_thin_ptr_ty(&self,span:Span,ty:Ty<'tcx>) ->bool{
6653
// Type still may have region variables, but `Sized` does not depend
6754
// on those, so just erase them before querying.
68-
ifty.is_sized(self.tcx(),self.typing_env){
55+
ifself.fcx.type_is_sized_modulo_regions(self.fcx.param_env, ty){
6956
returntrue;
7057
}
71-
iflet ty::Foreign(..) =ty.kind(){
58+
iflet ty::Foreign(..) =self.fcx.try_structurally_resolve_type(span, ty).kind(){
7259
returntrue;
7360
}
7461
false
7562
}
7663

77-
fnget_asm_ty(&self,ty:Ty<'tcx>) ->Result<InlineAsmType,NonAsmTypeReason<'tcx>>{
64+
fnget_asm_ty(
65+
&self,
66+
span:Span,
67+
ty:Ty<'tcx>,
68+
) ->Result<InlineAsmType,NonAsmTypeReason<'tcx>>{
7869
let asm_ty_isize =matchself.tcx().sess.target.pointer_width{
7970
16 =>InlineAsmType::I16,
8071
32 =>InlineAsmType::I32,
@@ -95,7 +86,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
9586
ty::Float(FloatTy::F128) =>Ok(InlineAsmType::F128),
9687
ty::FnPtr(..) =>Ok(asm_ty_isize),
9788
ty::RawPtr(elem_ty, _) =>{
98-
ifself.is_thin_ptr_ty(elem_ty){
89+
ifself.is_thin_ptr_ty(span,elem_ty){
9990
Ok(asm_ty_isize)
10091
}else{
10192
Err(NonAsmTypeReason::NotSizedPtr(ty))
@@ -109,11 +100,20 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
109100
let field =&fields[FieldIdx::ZERO];
110101
let elem_ty = field.ty(self.tcx(), args);
111102

112-
let(size, ty) =match elem_ty.kind(){
103+
let(size, ty) =match*elem_ty.kind(){
113104
ty::Array(ty, len) =>{
114-
let len =self.tcx().normalize_erasing_regions(self.typing_env,*len);
105+
// FIXME: `try_structurally_resolve_const` doesn't eval consts
106+
// in the old solver.
107+
let len =ifself.fcx.next_trait_solver(){
108+
self.fcx.try_structurally_resolve_const(span, len)
109+
}else{
110+
self.fcx.tcx.normalize_erasing_regions(
111+
self.fcx.typing_env(self.fcx.param_env),
112+
len,
113+
)
114+
};
115115
ifletSome(len) = len.try_to_target_usize(self.tcx()){
116-
(len,*ty)
116+
(len, ty)
117117
}else{
118118
returnErr(NonAsmTypeReason::UnevaluatedSIMDArrayLength(
119119
field.did, len,
@@ -183,17 +183,17 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
183183
);
184184
let fields =&ty.non_enum_variant().fields;
185185
let ty = fields[FieldIdx::ZERO].ty(self.tcx(), args);
186-
self.get_asm_ty(ty)
186+
self.get_asm_ty(expr.span,ty)
187187
}
188-
_ =>self.get_asm_ty(ty),
188+
_ =>self.get_asm_ty(expr.span,ty),
189189
};
190190
let asm_ty =match asm_ty{
191191
Ok(asm_ty) => asm_ty,
192192
Err(reason) =>{
193193
match reason{
194194
NonAsmTypeReason::UnevaluatedSIMDArrayLength(did, len) =>{
195195
let msg =format!("cannot evaluate SIMD vector length `{len}`");
196-
self.infcx
196+
self.fcx
197197
.dcx()
198198
.struct_span_err(self.tcx().def_span(did), msg)
199199
.with_span_note(
@@ -204,7 +204,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
204204
}
205205
NonAsmTypeReason::Invalid(ty) =>{
206206
let msg =format!("cannot use value of type `{ty}` for inline assembly");
207-
self.infcx.dcx().struct_span_err(expr.span, msg).with_note(
207+
self.fcx.dcx().struct_span_err(expr.span, msg).with_note(
208208
"only integers, floats, SIMD vectors, pointers and function pointers\
209209
can be used as arguments for inline assembly",
210210
).emit();
@@ -213,7 +213,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
213213
let msg =format!(
214214
"cannot use value of unsized pointer type `{ty}` for inline assembly"
215215
);
216-
self.infcx
216+
self.fcx
217217
.dcx()
218218
.struct_span_err(expr.span, msg)
219219
.with_note("only sized pointers can be used in inline assembly")
@@ -223,7 +223,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
223223
let msg =format!(
224224
"cannot use SIMD vector with element type `{ty}` for inline assembly"
225225
);
226-
self.infcx.dcx()
226+
self.fcx.dcx()
227227
.struct_span_err(self.tcx().def_span(did), msg).with_span_note(
228228
expr.span,
229229
"only integers, floats, SIMD vectors, pointers and function pointers\
@@ -232,7 +232,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
232232
}
233233
NonAsmTypeReason::EmptySIMDArray(ty) =>{
234234
let msg =format!("use of empty SIMD vector `{ty}`");
235-
self.infcx.dcx().struct_span_err(expr.span, msg).emit();
235+
self.fcx.dcx().struct_span_err(expr.span, msg).emit();
236236
}
237237
}
238238
returnNone;
@@ -241,9 +241,9 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
241241

242242
// Check that the type implements Copy. The only case where this can
243243
// possibly fail is for SIMD types which don't #[derive(Copy)].
244-
if !self.tcx().type_is_copy_modulo_regions(self.typing_env, ty){
244+
if !self.fcx.type_is_copy_modulo_regions(self.fcx.param_env, ty){
245245
let msg ="arguments for inline assembly must be copyable";
246-
self.infcx
246+
self.fcx
247247
.dcx()
248248
.struct_span_err(expr.span, msg)
249249
.with_note(format!("`{ty}` does not implement the Copy trait"))
@@ -263,7 +263,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
263263
if in_asm_ty != asm_ty{
264264
let msg ="incompatible types for asm inout argument";
265265
let in_expr_ty =self.expr_ty(in_expr);
266-
self.infcx
266+
self.fcx
267267
.dcx()
268268
.struct_span_err(vec![in_expr.span, expr.span], msg)
269269
.with_span_label(in_expr.span,format!("type `{in_expr_ty}`"))
@@ -296,7 +296,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
296296
)
297297
}else{
298298
let msg =format!("type `{ty}` cannot be used with this register class");
299-
letmut err =self.infcx.dcx().struct_span_err(expr.span, msg);
299+
letmut err =self.fcx.dcx().struct_span_err(expr.span, msg);
300300
let supported_tys:Vec<_> =
301301
supported_tys.iter().map(|(t, _)| t.to_string()).collect();
302302
err.note(format!(
@@ -326,7 +326,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
326326
ifletSome(feature) = feature{
327327
if !self.target_features.contains(feature){
328328
let msg =format!("`{feature}` target feature is not enabled");
329-
self.infcx
329+
self.fcx
330330
.dcx()
331331
.struct_span_err(expr.span, msg)
332332
.with_note(format!(
@@ -384,9 +384,9 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
384384
Some(asm_ty)
385385
}
386386

387-
pubfncheck_asm(&self,asm:&hir::InlineAsm<'tcx>){
387+
pub(crate)fncheck_asm(&self,asm:&hir::InlineAsm<'tcx>){
388388
letSome(asm_arch) =self.tcx().sess.asm_archelse{
389-
self.infcx.dcx().delayed_bug("target architecture does not support asm");
389+
self.fcx.dcx().delayed_bug("target architecture does not support asm");
390390
return;
391391
};
392392
let allow_experimental_reg =self.tcx().features().asm_experimental_reg();
@@ -418,7 +418,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
418418
op.is_clobber(),
419419
){
420420
let msg =format!("cannot use register `{}`: {}", reg.name(), msg);
421-
self.infcx.dcx().span_err(op_sp, msg);
421+
self.fcx.dcx().span_err(op_sp, msg);
422422
continue;
423423
}
424424
}
@@ -458,7 +458,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
458458
reg_class.name(),
459459
feature
460460
);
461-
self.infcx.dcx().span_err(op_sp, msg);
461+
self.fcx.dcx().span_err(op_sp, msg);
462462
// register isn't enabled, don't do more checks
463463
continue;
464464
}
@@ -472,7 +472,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
472472
.intersperse(", ")
473473
.collect::<String>(),
474474
);
475-
self.infcx.dcx().span_err(op_sp, msg);
475+
self.fcx.dcx().span_err(op_sp, msg);
476476
// register isn't enabled, don't do more checks
477477
continue;
478478
}
@@ -512,7 +512,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
512512
ty::Error(_) =>{}
513513
_if ty.is_integral() =>{}
514514
_ =>{
515-
self.infcx
515+
self.fcx
516516
.dcx()
517517
.struct_span_err(op_sp,"invalid type for `const` operand")
518518
.with_span_label(
@@ -531,7 +531,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
531531
ty::FnDef(..) =>{}
532532
ty::Error(_) =>{}
533533
_ =>{
534-
self.infcx
534+
self.fcx
535535
.dcx()
536536
.struct_span_err(op_sp,"invalid `sym` operand")
537537
.with_span_label(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp