diff options
21 files changed, 370 insertions, 228 deletions
diff --git a/Cargo.lock b/Cargo.lock index 12fa14ee817..cec227d2ed6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4110,6 +4110,7 @@ version = "0.0.0" dependencies = [ "bitflags", "rustc_data_structures", + "rustc_feature", "rustc_index", "rustc_macros", "rustc_serialize", diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 1ad5fa21d85..63ff64b00be 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -29,14 +29,28 @@ impl AddToDiagnostic for UseAngleBrackets { } #[derive(Diagnostic)] -#[help] #[diag(ast_lowering::invalid_abi, code = "E0703")] +#[note] pub struct InvalidAbi { #[primary_span] #[label] pub span: Span, pub abi: Symbol, - pub valid_abis: String, + pub command: String, + #[subdiagnostic] + pub suggestion: Option<InvalidAbiSuggestion>, +} + +#[derive(Subdiagnostic)] +#[suggestion( + ast_lowering::invalid_abi_suggestion, + code = "{suggestion}", + applicability = "maybe-incorrect" +)] +pub struct InvalidAbiSuggestion { + #[primary_span] + pub span: Span, + pub suggestion: String, } #[derive(Diagnostic, Clone, Copy)] diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 550833275e4..dfd04fe2974 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1,4 +1,4 @@ -use super::errors::{InvalidAbi, MisplacedRelaxTraitBound}; +use super::errors::{InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound}; use super::ResolverAstLoweringExt; use super::{Arena, AstOwner, ImplTraitContext, ImplTraitPosition}; use super::{FnDeclKind, LoweringContext, ParamMode}; @@ -14,9 +14,10 @@ use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_hir::PredicateOrigin; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::ty::{DefIdTree, ResolverAstLowering, TyCtxt}; +use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::source_map::DesugaringKind; use rustc_span::symbol::{kw, sym, Ident}; -use rustc_span::Span; +use rustc_span::{Span, Symbol}; use rustc_target::spec::abi; use smallvec::{smallvec, SmallVec}; @@ -1280,10 +1281,19 @@ impl<'hir> LoweringContext<'_, 'hir> { } fn error_on_invalid_abi(&self, abi: StrLit) { + let abi_names = abi::enabled_names(self.tcx.features(), abi.span) + .iter() + .map(|s| Symbol::intern(s)) + .collect::<Vec<_>>(); + let suggested_name = find_best_match_for_name(&abi_names, abi.symbol_unescaped, None); self.tcx.sess.emit_err(InvalidAbi { + abi: abi.symbol_unescaped, span: abi.span, - abi: abi.symbol, - valid_abis: abi::all_names().join(", "), + suggestion: suggested_name.map(|suggested_name| InvalidAbiSuggestion { + span: abi.span, + suggestion: format!("\"{suggested_name}\""), + }), + command: "rustc --print=calling-conventions".to_string(), }); } diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index aeff73c5bbb..0017a28cf1b 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -3,13 +3,13 @@ use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor}; use rustc_ast::{AssocConstraint, AssocConstraintKind, NodeId}; use rustc_ast::{PatKind, RangeEnd, VariantData}; use rustc_errors::{struct_span_err, Applicability, StashKey}; -use rustc_feature::Features; -use rustc_feature::{AttributeGate, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP}; -use rustc_session::parse::{feature_err, feature_warn}; +use rustc_feature::{AttributeGate, BuiltinAttribute, Features, GateIssue, BUILTIN_ATTRIBUTE_MAP}; +use rustc_session::parse::{feature_err, feature_err_issue, feature_warn}; use rustc_session::Session; use rustc_span::source_map::Spanned; use rustc_span::symbol::sym; use rustc_span::Span; +use rustc_target::spec::abi; macro_rules! gate_feature_fn { ($visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr, $help: expr) => {{ @@ -84,210 +84,26 @@ impl<'a> PostExpansionVisitor<'a> { } } - match symbol_unescaped.as_str() { - // Stable - "Rust" | "C" | "cdecl" | "stdcall" | "fastcall" | "aapcs" | "win64" | "sysv64" - | "system" => {} - "rust-intrinsic" => { - gate_feature_post!(&self, intrinsics, span, "intrinsics are subject to change"); - } - "platform-intrinsic" => { - gate_feature_post!( - &self, - platform_intrinsics, - span, - "platform intrinsics are experimental and possibly buggy" - ); - } - "vectorcall" => { - gate_feature_post!( - &self, - abi_vectorcall, - span, - "vectorcall is experimental and subject to change" - ); - } - "thiscall" => { - gate_feature_post!( - &self, - abi_thiscall, - span, - "thiscall is experimental and subject to change" - ); - } - "rust-call" => { - gate_feature_post!( - &self, - unboxed_closures, - span, - "rust-call ABI is subject to change" - ); - } - "rust-cold" => { - gate_feature_post!( - &self, - rust_cold_cc, - span, - "rust-cold is experimental and subject to change" - ); - } - "ptx-kernel" => { - gate_feature_post!( - &self, - abi_ptx, - span, - "PTX ABIs are experimental and subject to change" - ); - } - "unadjusted" => { - gate_feature_post!( - &self, - abi_unadjusted, - span, - "unadjusted ABI is an implementation detail and perma-unstable" - ); - } - "msp430-interrupt" => { - gate_feature_post!( - &self, - abi_msp430_interrupt, - span, - "msp430-interrupt ABI is experimental and subject to change" - ); - } - "x86-interrupt" => { - gate_feature_post!( - &self, - abi_x86_interrupt, - span, - "x86-interrupt ABI is experimental and subject to change" - ); - } - "amdgpu-kernel" => { - gate_feature_post!( - &self, - abi_amdgpu_kernel, - span, - "amdgpu-kernel ABI is experimental and subject to change" - ); - } - "avr-interrupt" | "avr-non-blocking-interrupt" => { - gate_feature_post!( - &self, - abi_avr_interrupt, - span, - "avr-interrupt and avr-non-blocking-interrupt ABIs are experimental and subject to change" - ); - } - "efiapi" => { - gate_feature_post!( - &self, - abi_efiapi, - span, - "efiapi ABI is experimental and subject to change" - ); - } - "C-cmse-nonsecure-call" => { - gate_feature_post!( - &self, - abi_c_cmse_nonsecure_call, - span, - "C-cmse-nonsecure-call ABI is experimental and subject to change" - ); - } - "C-unwind" => { - gate_feature_post!( - &self, - c_unwind, - span, - "C-unwind ABI is experimental and subject to change" - ); - } - "stdcall-unwind" => { - gate_feature_post!( - &self, - c_unwind, + match abi::is_enabled(&self.features, span, symbol_unescaped.as_str()) { + Ok(()) => (), + Err(abi::AbiDisabled::Unstable { feature, explain }) => { + feature_err_issue( + &self.sess.parse_sess, + feature, span, - "stdcall-unwind ABI is experimental and subject to change" - ); - } - "system-unwind" => { - gate_feature_post!( - &self, - c_unwind, - span, - "system-unwind ABI is experimental and subject to change" - ); - } - "thiscall-unwind" => { - gate_feature_post!( - &self, - c_unwind, - span, - "thiscall-unwind ABI is experimental and subject to change" - ); - } - "cdecl-unwind" => { - gate_feature_post!( - &self, - c_unwind, - span, - "cdecl-unwind ABI is experimental and subject to change" - ); - } - "fastcall-unwind" => { - gate_feature_post!( - &self, - c_unwind, - span, - "fastcall-unwind ABI is experimental and subject to change" - ); - } - "vectorcall-unwind" => { - gate_feature_post!( - &self, - c_unwind, - span, - "vectorcall-unwind ABI is experimental and subject to change" - ); - } - "aapcs-unwind" => { - gate_feature_post!( - &self, - c_unwind, - span, - "aapcs-unwind ABI is experimental and subject to change" - ); - } - "win64-unwind" => { - gate_feature_post!( - &self, - c_unwind, - span, - "win64-unwind ABI is experimental and subject to change" - ); - } - "sysv64-unwind" => { - gate_feature_post!( - &self, - c_unwind, - span, - "sysv64-unwind ABI is experimental and subject to change" - ); - } - "wasm" => { - gate_feature_post!( - &self, - wasm_abi, - span, - "wasm ABI is experimental and subject to change" - ); + GateIssue::Language, + explain, + ) + .emit(); } - abi => { + Err(abi::AbiDisabled::Unrecognized) => { if self.sess.opts.pretty.map_or(true, |ppm| ppm.needs_hir()) { self.sess.parse_sess.span_diagnostic.delay_span_bug( span, - &format!("unrecognized ABI not caught in lowering: {}", abi), + &format!( + "unrecognized ABI not caught in lowering: {}", + symbol_unescaped.as_str() + ), ); } } diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 8fb9508194b..c768935eb62 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -742,6 +742,11 @@ fn print_crate_info( println!("{}", cfg); } } + CallingConventions => { + let mut calling_conventions = rustc_target::spec::abi::all_names(); + calling_conventions.sort_unstable(); + println!("{}", calling_conventions.join("\n")); + } RelocationModels | CodeModels | TlsModels diff --git a/compiler/rustc_error_messages/locales/en-US/ast_lowering.ftl b/compiler/rustc_error_messages/locales/en-US/ast_lowering.ftl index c45e045b4db..03c88c6c0eb 100644 --- a/compiler/rustc_error_messages/locales/en-US/ast_lowering.ftl +++ b/compiler/rustc_error_messages/locales/en-US/ast_lowering.ftl @@ -7,7 +7,9 @@ ast_lowering_use_angle_brackets = use angle brackets instead ast_lowering_invalid_abi = invalid ABI: found `{$abi}` .label = invalid ABI - .help = valid ABIs: {$valid_abis} + .note = invoke `{$command}` for a full list of supported calling conventions. + +ast_lowering_invalid_abi_suggestion = did you mean ast_lowering_assoc_ty_parentheses = parenthesized generic arguments cannot be used in associated type constraints diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 57c9a3f4822..70b470f3811 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -538,6 +538,7 @@ pub enum PrintRequest { TargetLibdir, CrateName, Cfg, + CallingConventions, TargetList, TargetCPUs, TargetFeatures, @@ -1354,8 +1355,8 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> { "", "print", "Compiler information to print on stdout", - "[crate-name|file-names|sysroot|target-libdir|cfg|target-list|\ - target-cpus|target-features|relocation-models|code-models|\ + "[crate-name|file-names|sysroot|target-libdir|cfg|calling-conventions|\ + target-list|target-cpus|target-features|relocation-models|code-models|\ tls-models|target-spec-json|native-static-libs|stack-protector-strategies|\ link-args]", ), @@ -1794,6 +1795,7 @@ fn collect_print_requests( "sysroot" => PrintRequest::Sysroot, "target-libdir" => PrintRequest::TargetLibdir, "cfg" => PrintRequest::Cfg, + "calling-conventions" => PrintRequest::CallingConventions, "target-list" => PrintRequest::TargetList, "target-cpus" => PrintRequest::TargetCPUs, "target-features" => PrintRequest::TargetFeatures, diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 6ce75492caf..366fd9d2cd1 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -533,9 +533,6 @@ impl Span { self.data().with_hi(hi) } #[inline] - pub fn ctxt(self) -> SyntaxContext { - self.data_untracked().ctxt - } pub fn eq_ctxt(self, other: Span) -> bool { self.data_untracked().ctxt == other.data_untracked().ctxt } diff --git a/compiler/rustc_span/src/span_encoding.rs b/compiler/rustc_span/src/span_encoding.rs index 3ee329e9736..b3de6741594 100644 --- a/compiler/rustc_span/src/span_encoding.rs +++ b/compiler/rustc_span/src/span_encoding.rs @@ -28,12 +28,17 @@ use rustc_data_structures::fx::FxIndexSet; /// Inline (compressed) format: /// - `span.base_or_index == span_data.lo` /// - `span.len_or_tag == len == span_data.hi - span_data.lo` (must be `<= MAX_LEN`) -/// - `span.ctxt == span_data.ctxt` (must be `<= MAX_CTXT`) +/// - `span.ctxt_or_tag == span_data.ctxt` (must be `<= MAX_CTXT`) +/// +/// Interned format with inline `SyntaxContext`: +/// - `span.base_or_index == index` (indexes into the interner table) +/// - `span.len_or_tag == LEN_TAG` (high bit set, all other bits are zero) +/// - `span.ctxt_or_tag == span_data.ctxt` (must be `<= MAX_CTXT`) /// /// Interned format: /// - `span.base_or_index == index` (indexes into the interner table) /// - `span.len_or_tag == LEN_TAG` (high bit set, all other bits are zero) -/// - `span.ctxt == 0` +/// - `span.ctxt_or_tag == CTXT_TAG` /// /// The inline form uses 0 for the tag value (rather than 1) so that we don't /// need to mask out the tag bit when getting the length, and so that the @@ -50,10 +55,10 @@ use rustc_data_structures::fx::FxIndexSet; /// at 3 or 4, and then it drops off quickly from 8 onwards. 15 bits is enough /// for 99.99%+ of cases, but larger values (sometimes 20+ bits) might occur /// dozens of times in a typical crate. -/// - `ctxt` is 16 bits in `Span` and 32 bits in `SpanData`, which means that +/// - `ctxt_or_tag` is 16 bits in `Span` and 32 bits in `SpanData`, which means that /// large `ctxt` values will cause interning. The number of bits needed for /// `ctxt` values depend partly on the crate size and partly on the form of -/// the code. No crates in `rustc-perf` need more than 15 bits for `ctxt`, +/// the code. No crates in `rustc-perf` need more than 15 bits for `ctxt_or_tag`, /// but larger crates might need more than 16 bits. /// /// In order to reliably use parented spans in incremental compilation, @@ -65,15 +70,16 @@ use rustc_data_structures::fx::FxIndexSet; pub struct Span { base_or_index: u32, len_or_tag: u16, - ctxt_or_zero: u16, + ctxt_or_tag: u16, } const LEN_TAG: u16 = 0b1000_0000_0000_0000; const MAX_LEN: u32 = 0b0111_1111_1111_1111; -const MAX_CTXT: u32 = 0b1111_1111_1111_1111; +const CTXT_TAG: u32 = 0b1111_1111_1111_1111; +const MAX_CTXT: u32 = CTXT_TAG - 1; /// Dummy span, both position and length are zero, syntax context is zero as well. -pub const DUMMY_SP: Span = Span { base_or_index: 0, len_or_tag: 0, ctxt_or_zero: 0 }; +pub const DUMMY_SP: Span = Span { base_or_index: 0, len_or_tag: 0, ctxt_or_tag: 0 }; impl Span { #[inline] @@ -91,12 +97,13 @@ impl Span { if len <= MAX_LEN && ctxt2 <= MAX_CTXT && parent.is_none() { // Inline format. - Span { base_or_index: base, len_or_tag: len as u16, ctxt_or_zero: ctxt2 as u16 } + Span { base_or_index: base, len_or_tag: len as u16, ctxt_or_tag: ctxt2 as u16 } } else { // Interned format. let index = with_span_interner(|interner| interner.intern(&SpanData { lo, hi, ctxt, parent })); - Span { base_or_index: index, len_or_tag: LEN_TAG, ctxt_or_zero: 0 } + let ctxt_or_tag = if ctxt2 <= MAX_CTXT { ctxt2 } else { CTXT_TAG } as u16; + Span { base_or_index: index, len_or_tag: LEN_TAG, ctxt_or_tag } } } @@ -119,16 +126,29 @@ impl Span { SpanData { lo: BytePos(self.base_or_index), hi: BytePos(self.base_or_index + self.len_or_tag as u32), - ctxt: SyntaxContext::from_u32(self.ctxt_or_zero as u32), + ctxt: SyntaxContext::from_u32(self.ctxt_or_tag as u32), parent: None, } } else { // Interned format. - debug_assert!(self.ctxt_or_zero == 0); let index = self.base_or_index; with_span_interner(|interner| interner.spans[index as usize]) } } + + /// This function is used as a fast path when decoding the full `SpanData` is not necessary. + #[inline] + pub fn ctxt(self) -> SyntaxContext { + let ctxt_or_tag = self.ctxt_or_tag as u32; + if ctxt_or_tag <= MAX_CTXT { + // Inline format or interned format with inline ctxt. + SyntaxContext::from_u32(ctxt_or_tag) + } else { + // Interned format. + let index = self.base_or_index; + with_span_interner(|interner| interner.spans[index as usize].ctxt) + } + } } #[derive(Default)] diff --git a/compiler/rustc_target/Cargo.toml b/compiler/rustc_target/Cargo.toml index 162376af45f..fc37fdb1c43 100644 --- a/compiler/rustc_target/Cargo.toml +++ b/compiler/rustc_target/Cargo.toml @@ -8,7 +8,8 @@ bitflags = "1.2.1" tracing = "0.1" serde_json = "1.0.59" rustc_data_structures = { path = "../rustc_data_structures" } +rustc_feature = { path = "../rustc_feature" } +rustc_index = { path = "../rustc_index" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } -rustc_index = { path = "../rustc_index" } diff --git a/compiler/rustc_target/src/spec/abi.rs b/compiler/rustc_target/src/spec/abi.rs index 337554dc96e..c915124434b 100644 --- a/compiler/rustc_target/src/spec/abi.rs +++ b/compiler/rustc_target/src/spec/abi.rs @@ -1,6 +1,8 @@ use std::fmt; use rustc_macros::HashStable_Generic; +use rustc_span::symbol::sym; +use rustc_span::{Span, Symbol}; #[cfg(test)] mod tests; @@ -94,6 +96,192 @@ pub fn all_names() -> Vec<&'static str> { AbiDatas.iter().map(|d| d.name).collect() } +pub fn enabled_names(features: &rustc_feature::Features, span: Span) -> Vec<&'static str> { + AbiDatas + .iter() + .map(|d| d.name) + .filter(|name| is_enabled(features, span, name).is_ok()) + .collect() +} + +pub enum AbiDisabled { + Unstable { feature: Symbol, explain: &'static str }, + Unrecognized, +} + +fn gate_feature_post( + features: &rustc_feature::Features, + feature: Symbol, + span: Span, + explain: &'static str, +) -> Result<(), AbiDisabled> { + if !features.enabled(feature) && !span.allows_unstable(feature) { + Err(AbiDisabled::Unstable { feature, explain }) + } else { + Ok(()) + } +} + +pub fn is_enabled( + features: &rustc_feature::Features, + span: Span, + name: &str, +) -> Result<(), AbiDisabled> { + match name { + // Stable + "Rust" | "C" | "cdecl" | "stdcall" | "fastcall" | "aapcs" | "win64" | "sysv64" + | "system" => Ok(()), + "rust-intrinsic" => { + gate_feature_post(features, sym::intrinsics, span, "intrinsics are subject to change") + } + "platform-intrinsic" => gate_feature_post( + features, + sym::platform_intrinsics, + span, + "platform intrinsics are experimental and possibly buggy", + ), + "vectorcall" => gate_feature_post( + features, + sym::abi_vectorcall, + span, + "vectorcall is experimental and subject to change", + ), + "thiscall" => gate_feature_post( + features, + sym::abi_thiscall, + span, + "thiscall is experimental and subject to change", + ), + "rust-call" => gate_feature_post( + features, + sym::unboxed_closures, + span, + "rust-call ABI is subject to change", + ), + "rust-cold" => gate_feature_post( + features, + sym::rust_cold_cc, + span, + "rust-cold is experimental and subject to change", + ), + "ptx-kernel" => gate_feature_post( + features, + sym::abi_ptx, + span, + "PTX ABIs are experimental and subject to change", + ), + "unadjusted" => gate_feature_post( + features, + sym::abi_unadjusted, + span, + "unadjusted ABI is an implementation detail and perma-unstable", + ), + "msp430-interrupt" => gate_feature_post( + features, + sym::abi_msp430_interrupt, + span, + "msp430-interrupt ABI is experimental and subject to change", + ), + "x86-interrupt" => gate_feature_post( + features, + sym::abi_x86_interrupt, + span, + "x86-interrupt ABI is experimental and subject to change", + ), + "amdgpu-kernel" => gate_feature_post( + features, + sym::abi_amdgpu_kernel, + span, + "amdgpu-kernel ABI is experimental and subject to change", + ), + "avr-interrupt" | "avr-non-blocking-interrupt" => gate_feature_post( + features, + sym::abi_avr_interrupt, + span, + "avr-interrupt and avr-non-blocking-interrupt ABIs are experimental and subject to change", + ), + "efiapi" => gate_feature_post( + features, + sym::abi_efiapi, + span, + "efiapi ABI is experimental and subject to change", + ), + "C-cmse-nonsecure-call" => gate_feature_post( + features, + sym::abi_c_cmse_nonsecure_call, + span, + "C-cmse-nonsecure-call ABI is experimental and subject to change", + ), + "C-unwind" => gate_feature_post( + features, + sym::c_unwind, + span, + "C-unwind ABI is experimental and subject to change", + ), + "stdcall-unwind" => gate_feature_post( + features, + sym::c_unwind, + span, + "stdcall-unwind ABI is experimental and subject to change", + ), + "system-unwind" => gate_feature_post( + features, + sym::c_unwind, + span, + "system-unwind ABI is experimental and subject to change", + ), + "thiscall-unwind" => gate_feature_post( + features, + sym::c_unwind, + span, + "thiscall-unwind ABI is experimental and subject to change", + ), + "cdecl-unwind" => gate_feature_post( + features, + sym::c_unwind, + span, + "cdecl-unwind ABI is experimental and subject to change", + ), + "fastcall-unwind" => gate_feature_post( + features, + sym::c_unwind, + span, + "fastcall-unwind ABI is experimental and subject to change", + ), + "vectorcall-unwind" => gate_feature_post( + features, + sym::c_unwind, + span, + "vectorcall-unwind ABI is experimental and subject to change", + ), + "aapcs-unwind" => gate_feature_post( + features, + sym::c_unwind, + span, + "aapcs-unwind ABI is experimental and subject to change", + ), + "win64-unwind" => gate_feature_post( + features, + sym::c_unwind, + span, + "win64-unwind ABI is experimental and subject to change", + ), + "sysv64-unwind" => gate_feature_post( + features, + sym::c_unwind, + span, + "sysv64-unwind ABI is experimental and subject to change", + ), + "wasm" => gate_feature_post( + features, + sym::wasm_abi, + span, + "wasm ABI is experimental and subject to change", + ), + _ => Err(AbiDisabled::Unrecognized), + } +} + impl Abi { /// Default ABI chosen for `extern fn` declarations without an explicit ABI. pub const FALLBACK: Abi = Abi::C { unwind: false }; diff --git a/compiler/rustc_typeck/src/check/closure.rs b/compiler/rustc_typeck/src/check/closure.rs index a13d73c471b..84ea06a460b 100644 --- a/compiler/rustc_typeck/src/check/closure.rs +++ b/compiler/rustc_typeck/src/check/closure.rs @@ -641,6 +641,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ), bound_vars, ); + // Astconv can't normalize inputs or outputs with escaping bound vars, + // so normalize them here, after we've wrapped them in a binder. + let result = self.normalize_associated_types_in(self.tcx.hir().span(hir_id), result); let c_result = self.inh.infcx.canonicalize_response(result); self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id, c_result); diff --git a/src/test/run-make-fulldeps/print-calling-conventions/Makefile b/src/test/run-make-fulldeps/print-calling-conventions/Makefile new file mode 100644 index 00000000000..d3fd06392b0 --- /dev/null +++ b/src/test/run-make-fulldeps/print-calling-conventions/Makefile @@ -0,0 +1,4 @@ +-include ../tools.mk + +all: + $(RUSTC) --print calling-conventions diff --git a/src/test/ui/abi/abi-typo-unstable.rs b/src/test/ui/abi/abi-typo-unstable.rs new file mode 100644 index 00000000000..94991a5eb17 --- /dev/null +++ b/src/test/ui/abi/abi-typo-unstable.rs @@ -0,0 +1,6 @@ +// rust-intrinsic is unstable and not enabled, so it should not be suggested as a fix +extern "rust-intrinsec" fn rust_intrinsic() {} //~ ERROR invalid ABI + +fn main() { + rust_intrinsic(); +} diff --git a/src/test/ui/abi/abi-typo-unstable.stderr b/src/test/ui/abi/abi-typo-unstable.stderr new file mode 100644 index 00000000000..3b346e00227 --- /dev/null +++ b/src/test/ui/abi/abi-typo-unstable.stderr @@ -0,0 +1,11 @@ +error[E0703]: invalid ABI: found `rust-intrinsec` + --> $DIR/abi-typo-unstable.rs:2:8 + | +LL | extern "rust-intrinsec" fn rust_intrinsic() {} + | ^^^^^^^^^^^^^^^^ invalid ABI + | + = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions. + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0703`. diff --git a/src/test/ui/closures/issue-101696.rs b/src/test/ui/closures/issue-101696.rs new file mode 100644 index 00000000000..0a358bd1643 --- /dev/null +++ b/src/test/ui/closures/issue-101696.rs @@ -0,0 +1,36 @@ +// check-pass + +use std::marker::PhantomData; + +#[derive(Default)] +struct MyType<'a> { + field: usize, + _phantom: PhantomData<&'a ()>, +} + +#[derive(Default)] +struct MyTypeVariant<'a> { + field: usize, + _phantom: PhantomData<&'a ()>, +} + +trait AsVariantTrait { + type Type; +} + +impl<'a> AsVariantTrait for MyType<'a> { + type Type = MyTypeVariant<'a>; +} + +type Variant<G> = <G as AsVariantTrait>::Type; + +fn foo<T: Default, F: FnOnce(T)>(f: F) { + let input = T::default(); + f(input); +} + +fn main() { + foo(|a: <MyType as AsVariantTrait>::Type| { + a.field; + }); +} diff --git a/src/test/ui/codemap_tests/unicode.normal.stderr b/src/test/ui/codemap_tests/unicode.normal.stderr index 60f8cff84b3..05ceb6910da 100644 --- a/src/test/ui/codemap_tests/unicode.normal.stderr +++ b/src/test/ui/codemap_tests/unicode.normal.stderr @@ -4,7 +4,7 @@ error[E0703]: invalid ABI: found `路濫狼á́́` LL | extern "路濫狼á́́" fn foo() {} | ^^^^^^^^^ invalid ABI | - = help: valid ABIs: Rust, C, C-unwind, cdecl, cdecl-unwind, stdcall, stdcall-unwind, fastcall, fastcall-unwind, vectorcall, vectorcall-unwind, thiscall, thiscall-unwind, aapcs, aapcs-unwind, win64, win64-unwind, sysv64, sysv64-unwind, ptx-kernel, msp430-interrupt, x86-interrupt, amdgpu-kernel, efiapi, avr-interrupt, avr-non-blocking-interrupt, C-cmse-nonsecure-call, wasm, system, system-unwind, rust-intrinsic, rust-call, platform-intrinsic, unadjusted, rust-cold + = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions. error: aborting due to previous error diff --git a/src/test/ui/parser/issues/issue-8537.stderr b/src/test/ui/parser/issues/issue-8537.stderr index 505d830ef3e..523cc9dc588 100644 --- a/src/test/ui/parser/issues/issue-8537.stderr +++ b/src/test/ui/parser/issues/issue-8537.stderr @@ -4,7 +4,7 @@ error[E0703]: invalid ABI: found `invalid-ab_isize` LL | "invalid-ab_isize" | ^^^^^^^^^^^^^^^^^^ invalid ABI | - = help: valid ABIs: Rust, C, C-unwind, cdecl, cdecl-unwind, stdcall, stdcall-unwind, fastcall, fastcall-unwind, vectorcall, vectorcall-unwind, thiscall, thiscall-unwind, aapcs, aapcs-unwind, win64, win64-unwind, sysv64, sysv64-unwind, ptx-kernel, msp430-interrupt, x86-interrupt, amdgpu-kernel, efiapi, avr-interrupt, avr-non-blocking-interrupt, C-cmse-nonsecure-call, wasm, system, system-unwind, rust-intrinsic, rust-call, platform-intrinsic, unadjusted, rust-cold + = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions. error: aborting due to previous error diff --git a/src/test/ui/suggestions/abi-typo.fixed b/src/test/ui/suggestions/abi-typo.fixed new file mode 100644 index 00000000000..04d265865f0 --- /dev/null +++ b/src/test/ui/suggestions/abi-typo.fixed @@ -0,0 +1,6 @@ +// run-rustfix +extern "cdecl" fn cdedl() {} //~ ERROR invalid ABI + +fn main() { + cdedl(); +} diff --git a/src/test/ui/suggestions/abi-typo.rs b/src/test/ui/suggestions/abi-typo.rs new file mode 100644 index 00000000000..6d80db522eb --- /dev/null +++ b/src/test/ui/suggestions/abi-typo.rs @@ -0,0 +1,6 @@ +// run-rustfix +extern "cdedl" fn cdedl() {} //~ ERROR invalid ABI + +fn main() { + cdedl(); +} diff --git a/src/test/ui/suggestions/abi-typo.stderr b/src/test/ui/suggestions/abi-typo.stderr new file mode 100644 index 00000000000..67a84f119f6 --- /dev/null +++ b/src/test/ui/suggestions/abi-typo.stderr @@ -0,0 +1,14 @@ +error[E0703]: invalid ABI: found `cdedl` + --> $DIR/abi-typo.rs:2:8 + | +LL | extern "cdedl" fn cdedl() {} + | ^^^^^^^ + | | + | invalid ABI + | help: did you mean: `"cdecl"` + | + = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions. + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0703`. |
