Auto merge of #111680 - Dylan-DPC:rollup-1p45gxt, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #110930 (Don't expect normalization to succeed in elaborate_drops) - #111557 (Revert "Validate resolution for SelfCtor too.") - #111565 (rustdoc-json: Add tests for visibility of impls) - #111588 (Emits E0599 when meeting `MyTrait::missing_method`) - #111625 (Move rustc_middle/src/ty/query.rs to rustc_middle/src/query/plumbing.rs) - #111674 (Add missing backslash in HTML string) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
ad23942ad4
@ -3,7 +3,8 @@
|
||||
|
||||
use rustc_errors::Diagnostic;
|
||||
use rustc_middle::mir::AssertKind;
|
||||
use rustc_middle::ty::{layout::LayoutError, query::TyCtxtAt, ConstInt};
|
||||
use rustc_middle::query::TyCtxtAt;
|
||||
use rustc_middle::ty::{layout::LayoutError, ConstInt};
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
use super::InterpCx;
|
||||
|
@ -8,13 +8,12 @@
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::mir::interpret::{ErrorHandled, InterpError, ReportedErrorInfo};
|
||||
use rustc_middle::query::TyCtxtAt;
|
||||
use rustc_middle::ty::layout::{
|
||||
self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOf, LayoutOfHelpers,
|
||||
TyAndLayout,
|
||||
};
|
||||
use rustc_middle::ty::{
|
||||
self, query::TyCtxtAt, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable,
|
||||
};
|
||||
use rustc_middle::ty::{self, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_mir_dataflow::storage::always_storage_live_locals;
|
||||
use rustc_session::Limit;
|
||||
use rustc_span::Span;
|
||||
|
@ -478,6 +478,7 @@ pub enum StashKey {
|
||||
/// FRU syntax
|
||||
MaybeFruTypo,
|
||||
CallAssocMethod,
|
||||
TraitMissingMethod,
|
||||
}
|
||||
|
||||
fn default_track_diagnostic(d: &mut Diagnostic, f: &mut dyn FnMut(&mut Diagnostic)) {
|
||||
|
@ -19,7 +19,7 @@
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_errors::{
|
||||
struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, FatalError,
|
||||
MultiSpan,
|
||||
MultiSpan, StashKey,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
|
||||
@ -38,7 +38,6 @@
|
||||
use rustc_middle::ty::{DynKind, ToPredicate};
|
||||
use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, BARE_TRAIT_OBJECTS};
|
||||
use rustc_span::edit_distance::find_best_match_for_name;
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::symbol::{kw, Ident, Symbol};
|
||||
use rustc_span::{sym, Span, DUMMY_SP};
|
||||
use rustc_target::spec::abi;
|
||||
@ -3718,7 +3717,7 @@ fn maybe_lint_bare_trait(&self, self_ty: &hir::Ty<'_>, in_path: bool) {
|
||||
));
|
||||
}
|
||||
|
||||
if self_ty.span.edition() >= Edition::Edition2021 {
|
||||
if self_ty.span.edition().rust_2021() {
|
||||
let msg = "trait objects must include the `dyn` keyword";
|
||||
let label = "add `dyn` keyword before this trait";
|
||||
let mut diag =
|
||||
@ -3732,7 +3731,7 @@ fn maybe_lint_bare_trait(&self, self_ty: &hir::Ty<'_>, in_path: bool) {
|
||||
}
|
||||
// check if the impl trait that we are considering is a impl of a local trait
|
||||
self.maybe_lint_blanket_trait_impl(&self_ty, &mut diag);
|
||||
diag.emit();
|
||||
diag.stash(self_ty.span, StashKey::TraitMissingMethod);
|
||||
} else {
|
||||
let msg = "trait objects without an explicit `dyn` are deprecated";
|
||||
tcx.struct_span_lint_hir(
|
||||
|
@ -79,3 +79,14 @@ hir_typeck_arg_mismatch_indeterminate = argument type mismatch was detected, but
|
||||
hir_typeck_suggest_boxing_note = for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
|
||||
|
||||
hir_typeck_suggest_boxing_when_appropriate = store this in the heap by calling `Box::new`
|
||||
|
||||
hir_typeck_no_associated_item = no {$item_kind} named `{$item_name}` found for {$ty_prefix} `{$ty_str}`{$trait_missing_method ->
|
||||
[true] {""}
|
||||
*[other] {" "}in the current scope
|
||||
}
|
||||
|
||||
hir_typeck_candidate_trait_note = `{$trait_name}` defines an item `{$item_name}`{$action_or_ty ->
|
||||
[NONE] {""}
|
||||
[implement] , perhaps you need to implement it
|
||||
*[other] , perhaps you need to restrict type parameter `{$action_or_ty}` with it
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
//! Errors emitted by `rustc_hir_typeck`.
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::fluent_generated as fluent;
|
||||
use rustc_errors::{AddToDiagnostic, Applicability, Diagnostic, MultiSpan, SubdiagnosticMessage};
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
@ -295,3 +297,25 @@ pub enum SuggestBoxing {
|
||||
end: Span,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(hir_typeck_no_associated_item, code = "E0599")]
|
||||
pub struct NoAssociatedItem {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub item_kind: &'static str,
|
||||
pub item_name: Ident,
|
||||
pub ty_prefix: Cow<'static, str>,
|
||||
pub ty_str: String,
|
||||
pub trait_missing_method: bool,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[note(hir_typeck_candidate_trait_note)]
|
||||
pub struct CandidateTraitNote {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub trait_name: String,
|
||||
pub item_name: Ident,
|
||||
pub action_or_ty: String,
|
||||
}
|
||||
|
@ -1245,6 +1245,7 @@ fn check_method_call(
|
||||
error,
|
||||
Some((rcvr, args)),
|
||||
expected,
|
||||
false,
|
||||
) {
|
||||
err.emit();
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LocalTy, RawTy};
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::{Applicability, Diagnostic, ErrorGuaranteed, MultiSpan};
|
||||
use rustc_errors::{Applicability, Diagnostic, ErrorGuaranteed, MultiSpan, StashKey};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorOf, DefKind, Res};
|
||||
use rustc_hir::def_id::DefId;
|
||||
@ -853,6 +853,13 @@ pub fn resolve_ty_and_res_fully_qualified_call(
|
||||
let item_name = item_segment.ident;
|
||||
let result = self
|
||||
.resolve_fully_qualified_call(span, item_name, ty.normalized, qself.span, hir_id)
|
||||
.and_then(|r| {
|
||||
// lint bare trait if the method is found in the trait
|
||||
if span.edition().rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
|
||||
diag.emit();
|
||||
}
|
||||
Ok(r)
|
||||
})
|
||||
.or_else(|error| {
|
||||
let guar = self
|
||||
.tcx
|
||||
@ -863,17 +870,30 @@ pub fn resolve_ty_and_res_fully_qualified_call(
|
||||
_ => Err(guar),
|
||||
};
|
||||
|
||||
let trait_missing_method =
|
||||
matches!(error, method::MethodError::NoMatch(_)) && ty.normalized.is_trait();
|
||||
// If we have a path like `MyTrait::missing_method`, then don't register
|
||||
// a WF obligation for `dyn MyTrait` when method lookup fails. Otherwise,
|
||||
// register a WF obligation so that we can detect any additional
|
||||
// errors in the self type.
|
||||
if !(matches!(error, method::MethodError::NoMatch(_)) && ty.normalized.is_trait()) {
|
||||
if !trait_missing_method {
|
||||
self.register_wf_obligation(
|
||||
ty.raw.into(),
|
||||
qself.span,
|
||||
traits::WellFormed(None),
|
||||
);
|
||||
}
|
||||
|
||||
// emit or cancel the diagnostic for bare traits
|
||||
if span.edition().rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
|
||||
if trait_missing_method {
|
||||
// cancel the diag for bare traits when meeting `MyTrait::missing_method`
|
||||
diag.cancel();
|
||||
} else {
|
||||
diag.emit();
|
||||
}
|
||||
}
|
||||
|
||||
if item_name.name != kw::Empty {
|
||||
if let Some(mut e) = self.report_method_error(
|
||||
span,
|
||||
@ -883,10 +903,12 @@ pub fn resolve_ty_and_res_fully_qualified_call(
|
||||
error,
|
||||
None,
|
||||
Expectation::NoExpectation,
|
||||
trait_missing_method && span.edition().rust_2021(), // emits missing method for trait only after edition 2021
|
||||
) {
|
||||
e.emit();
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
});
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
//! found or is otherwise invalid.
|
||||
|
||||
use crate::errors;
|
||||
use crate::errors::CandidateTraitNote;
|
||||
use crate::errors::NoAssociatedItem;
|
||||
use crate::Expectation;
|
||||
use crate::FnCtxt;
|
||||
use rustc_ast::ast::Mutability;
|
||||
@ -38,6 +40,7 @@
|
||||
use rustc_trait_selection::traits::{
|
||||
FulfillmentError, Obligation, ObligationCause, ObligationCauseCode,
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::probe::{AutorefOrPtrAdjustment, IsSuggestion, Mode, ProbeScope};
|
||||
use super::{CandidateSource, MethodError, NoMatchData};
|
||||
@ -112,6 +115,7 @@ pub fn report_method_error(
|
||||
error: MethodError<'tcx>,
|
||||
args: Option<(&'tcx hir::Expr<'tcx>, &'tcx [hir::Expr<'tcx>])>,
|
||||
expected: Expectation<'tcx>,
|
||||
trait_missing_method: bool,
|
||||
) -> Option<DiagnosticBuilder<'_, ErrorGuaranteed>> {
|
||||
// Avoid suggestions when we don't know what's going on.
|
||||
if rcvr_ty.references_error() {
|
||||
@ -136,6 +140,7 @@ pub fn report_method_error(
|
||||
sugg_span,
|
||||
&mut no_match_data,
|
||||
expected,
|
||||
trait_missing_method,
|
||||
);
|
||||
}
|
||||
|
||||
@ -278,6 +283,7 @@ pub fn report_no_match_method_error(
|
||||
sugg_span: Span,
|
||||
no_match_data: &mut NoMatchData<'tcx>,
|
||||
expected: Expectation<'tcx>,
|
||||
trait_missing_method: bool,
|
||||
) -> Option<DiagnosticBuilder<'_, ErrorGuaranteed>> {
|
||||
let mode = no_match_data.mode;
|
||||
let tcx = self.tcx;
|
||||
@ -323,7 +329,12 @@ pub fn report_no_match_method_error(
|
||||
span = item_name.span;
|
||||
|
||||
// Don't show generic arguments when the method can't be found in any implementation (#81576).
|
||||
let mut ty_str_reported = ty_str.clone();
|
||||
let mut ty_str_reported = if trait_missing_method {
|
||||
ty_str.strip_prefix("dyn ").expect("Failed to remove the prefix dyn").to_owned()
|
||||
} else {
|
||||
ty_str.clone()
|
||||
};
|
||||
|
||||
if let ty::Adt(_, generics) = rcvr_ty.kind() {
|
||||
if generics.len() > 0 {
|
||||
let mut autoderef = self.autoderef(span, rcvr_ty);
|
||||
@ -355,25 +366,33 @@ pub fn report_no_match_method_error(
|
||||
{
|
||||
self.suggest_missing_writer(rcvr_ty, args)
|
||||
} else {
|
||||
struct_span_err!(
|
||||
tcx.sess,
|
||||
tcx.sess.create_err(NoAssociatedItem {
|
||||
span,
|
||||
E0599,
|
||||
"no {} named `{}` found for {} `{}` in the current scope",
|
||||
item_kind,
|
||||
item_name,
|
||||
rcvr_ty.prefix_string(self.tcx),
|
||||
ty_str_reported,
|
||||
)
|
||||
ty_prefix: if trait_missing_method {
|
||||
// FIXME(mu001999) E0599 maybe not suitable here because it is for types
|
||||
Cow::from("trait")
|
||||
} else {
|
||||
rcvr_ty.prefix_string(self.tcx)
|
||||
},
|
||||
ty_str: ty_str_reported,
|
||||
trait_missing_method,
|
||||
})
|
||||
};
|
||||
if tcx.sess.source_map().is_multiline(sugg_span) {
|
||||
err.span_label(sugg_span.with_hi(span.lo()), "");
|
||||
}
|
||||
let ty_str = if short_ty_str.len() < ty_str.len() && ty_str.len() > 10 {
|
||||
let mut ty_str = if short_ty_str.len() < ty_str.len() && ty_str.len() > 10 {
|
||||
short_ty_str
|
||||
} else {
|
||||
ty_str
|
||||
};
|
||||
if trait_missing_method {
|
||||
ty_str =
|
||||
ty_str.strip_prefix("dyn ").expect("Failed to remove the prefix dyn").to_owned();
|
||||
}
|
||||
|
||||
if let Some(file) = ty_file {
|
||||
err.note(format!("the full type name has been written to '{}'", file.display(),));
|
||||
}
|
||||
@ -1067,6 +1086,7 @@ trait bound{s}",
|
||||
&static_candidates,
|
||||
unsatisfied_bounds,
|
||||
expected.only_has_type(self),
|
||||
trait_missing_method,
|
||||
);
|
||||
}
|
||||
|
||||
@ -2375,6 +2395,7 @@ fn suggest_traits_to_import(
|
||||
static_candidates: &[CandidateSource],
|
||||
unsatisfied_bounds: bool,
|
||||
return_type: Option<Ty<'tcx>>,
|
||||
trait_missing_method: bool,
|
||||
) {
|
||||
let mut alt_rcvr_sugg = false;
|
||||
if let (SelfSource::MethodCall(rcvr), false) = (source, unsatisfied_bounds) {
|
||||
@ -2598,11 +2619,14 @@ fn suggest_traits_to_import(
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
err.help(if param_type.is_some() {
|
||||
"items from traits can only be used if the type parameter is bounded by the trait"
|
||||
} else {
|
||||
"items from traits can only be used if the trait is implemented and in scope"
|
||||
});
|
||||
if !trait_missing_method {
|
||||
err.help(if param_type.is_some() {
|
||||
"items from traits can only be used if the type parameter is bounded by the trait"
|
||||
} else {
|
||||
"items from traits can only be used if the trait is implemented and in scope"
|
||||
});
|
||||
}
|
||||
|
||||
let candidates_len = candidates.len();
|
||||
let message = |action| {
|
||||
format!(
|
||||
@ -2751,27 +2775,28 @@ enum Introducer {
|
||||
(candidates, Vec::new())
|
||||
};
|
||||
|
||||
let action = if let Some(param) = param_type {
|
||||
format!("restrict type parameter `{}` with", param)
|
||||
} else {
|
||||
// FIXME: it might only need to be imported into scope, not implemented.
|
||||
"implement".to_string()
|
||||
};
|
||||
match &potential_candidates[..] {
|
||||
[] => {}
|
||||
[trait_info] if trait_info.def_id.is_local() => {
|
||||
err.span_note(
|
||||
self.tcx.def_span(trait_info.def_id),
|
||||
format!(
|
||||
"`{}` defines an item `{}`, perhaps you need to {} it",
|
||||
self.tcx.def_path_str(trait_info.def_id),
|
||||
item_name,
|
||||
action
|
||||
),
|
||||
);
|
||||
err.subdiagnostic(CandidateTraitNote {
|
||||
span: self.tcx.def_span(trait_info.def_id),
|
||||
trait_name: self.tcx.def_path_str(trait_info.def_id),
|
||||
item_name,
|
||||
action_or_ty: if trait_missing_method {
|
||||
"NONE".to_string()
|
||||
} else {
|
||||
param_type.map_or_else(
|
||||
|| "implement".to_string(), // FIXME: it might only need to be imported into scope, not implemented.
|
||||
ToString::to_string,
|
||||
)
|
||||
},
|
||||
});
|
||||
}
|
||||
trait_infos => {
|
||||
let mut msg = message(action);
|
||||
let mut msg = message(param_type.map_or_else(
|
||||
|| "implement".to_string(), // FIXME: it might only need to be imported into scope, not implemented.
|
||||
|param| format!("restrict type parameter `{}` with", param),
|
||||
));
|
||||
for (i, trait_info) in trait_infos.iter().enumerate() {
|
||||
msg.push_str(&format!(
|
||||
"\ncandidate #{}: `{}`",
|
||||
|
@ -95,7 +95,6 @@
|
||||
pub mod mir;
|
||||
pub mod thir;
|
||||
pub mod traits;
|
||||
#[macro_use]
|
||||
pub mod ty;
|
||||
pub mod util;
|
||||
mod values;
|
||||
|
@ -1,7 +1,8 @@
|
||||
use super::{AllocId, AllocRange, ConstAlloc, Pointer, Scalar};
|
||||
|
||||
use crate::mir::interpret::ConstValue;
|
||||
use crate::ty::{layout, query::TyCtxtAt, tls, Ty, ValTree};
|
||||
use crate::query::TyCtxtAt;
|
||||
use crate::ty::{layout, tls, Ty, ValTree};
|
||||
|
||||
use rustc_data_structures::sync::Lock;
|
||||
use rustc_errors::{pluralize, struct_span_err, DiagnosticBuilder, ErrorGuaranteed};
|
||||
|
@ -1,9 +1,10 @@
|
||||
use super::{ErrorHandled, EvalToConstValueResult, EvalToValTreeResult, GlobalId};
|
||||
|
||||
use crate::mir;
|
||||
use crate::query::{TyCtxtAt, TyCtxtEnsure};
|
||||
use crate::ty::subst::InternalSubsts;
|
||||
use crate::ty::visit::TypeVisitableExt;
|
||||
use crate::ty::{self, query::TyCtxtAt, query::TyCtxtEnsure, TyCtxt};
|
||||
use crate::ty::{self, TyCtxt};
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_session::lint;
|
||||
|
@ -25,6 +25,7 @@
|
||||
use crate::mir::interpret::{LitToConstError, LitToConstInput};
|
||||
use crate::mir::mono::CodegenUnit;
|
||||
use crate::query::erase::{erase, restore, Erase};
|
||||
use crate::query::plumbing::{query_ensure, query_get_at, DynamicQuery};
|
||||
use crate::thir;
|
||||
use crate::traits::query::{
|
||||
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
|
||||
@ -39,10 +40,6 @@
|
||||
use crate::traits::{self, ImplSource};
|
||||
use crate::ty::fast_reject::SimplifiedType;
|
||||
use crate::ty::layout::ValidityRequirement;
|
||||
use crate::ty::query::{
|
||||
query_ensure, query_get_at, DynamicQuery, IntoQueryParam, TyCtxtAt, TyCtxtEnsure,
|
||||
TyCtxtEnsureWithValue,
|
||||
};
|
||||
use crate::ty::subst::{GenericArg, SubstsRef};
|
||||
use crate::ty::util::AlwaysRequiresDrop;
|
||||
use crate::ty::GeneratorDiagnosticData;
|
||||
@ -90,8 +87,11 @@
|
||||
|
||||
pub mod erase;
|
||||
mod keys;
|
||||
pub mod on_disk_cache;
|
||||
pub use keys::{AsLocalKey, Key, LocalCrate};
|
||||
pub mod on_disk_cache;
|
||||
#[macro_use]
|
||||
pub mod plumbing;
|
||||
pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsure, TyCtxtEnsureWithValue};
|
||||
|
||||
// Each of these queries corresponds to a function pointer field in the
|
||||
// `Providers` struct for requesting a value of that type, and a method
|
||||
|
@ -14,14 +14,14 @@
|
||||
use crate::middle::stability;
|
||||
use crate::mir::interpret::{self, Allocation, ConstAllocation};
|
||||
use crate::mir::{Body, Local, Place, PlaceElem, ProjectionKind, Promoted};
|
||||
use crate::query::plumbing::QuerySystem;
|
||||
use crate::query::LocalCrate;
|
||||
use crate::query::Providers;
|
||||
use crate::query::{IntoQueryParam, TyCtxtAt};
|
||||
use crate::thir::Thir;
|
||||
use crate::traits;
|
||||
use crate::traits::solve;
|
||||
use crate::traits::solve::{ExternalConstraints, ExternalConstraintsData};
|
||||
use crate::ty::query::QuerySystem;
|
||||
use crate::ty::query::{self, TyCtxtAt};
|
||||
use crate::ty::{
|
||||
self, AdtDef, AdtDefData, AdtKind, Binder, Const, ConstData, FloatTy, FloatVar, FloatVid,
|
||||
GenericParamDefKind, ImplPolarity, InferTy, IntTy, IntVar, IntVid, List, ParamConst, ParamTy,
|
||||
@ -80,8 +80,6 @@
|
||||
use std::mem;
|
||||
use std::ops::{Bound, Deref};
|
||||
|
||||
use super::query::IntoQueryParam;
|
||||
|
||||
const TINY_CONST_EVAL_LIMIT: Limit = Limit(20);
|
||||
|
||||
#[allow(rustc::usage_of_ty_tykind)]
|
||||
@ -512,7 +510,7 @@ pub struct GlobalCtxt<'tcx> {
|
||||
|
||||
untracked: Untracked,
|
||||
|
||||
pub query_system: query::QuerySystem<'tcx>,
|
||||
pub query_system: QuerySystem<'tcx>,
|
||||
pub(crate) query_kinds: &'tcx [DepKindStruct<'tcx>],
|
||||
|
||||
// Internal caches for metadata decoding. No need to track deps on this.
|
||||
|
@ -1,7 +1,7 @@
|
||||
use super::{GlobalCtxt, TyCtxt};
|
||||
|
||||
use crate::dep_graph::TaskDepsRef;
|
||||
use crate::ty::query;
|
||||
use crate::query::plumbing::QueryJobId;
|
||||
use rustc_data_structures::sync::{self, Lock};
|
||||
use rustc_errors::Diagnostic;
|
||||
#[cfg(not(parallel_compiler))]
|
||||
@ -22,7 +22,7 @@ pub struct ImplicitCtxt<'a, 'tcx> {
|
||||
|
||||
/// The current query job, if any. This is updated by `JobOwner::start` in
|
||||
/// `ty::query::plumbing` when executing a query.
|
||||
pub query: Option<query::QueryJobId>,
|
||||
pub query: Option<QueryJobId>,
|
||||
|
||||
/// Where to store diagnostics for the current query job, if any.
|
||||
/// This is updated by `JobOwner::start` in `ty::query::plumbing` when executing a query.
|
||||
|
@ -1,5 +1,6 @@
|
||||
use crate::fluent_generated as fluent;
|
||||
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||
use crate::query::TyCtxtAt;
|
||||
use crate::ty::normalize_erasing_regions::NormalizationError;
|
||||
use crate::ty::{self, ReprOptions, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_errors::{DiagnosticBuilder, Handler, IntoDiagnostic};
|
||||
@ -543,20 +544,20 @@ fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> HasDataLayout for ty::query::TyCtxtAt<'tcx> {
|
||||
impl<'tcx> HasDataLayout for TyCtxtAt<'tcx> {
|
||||
#[inline]
|
||||
fn data_layout(&self) -> &TargetDataLayout {
|
||||
&self.data_layout
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> HasTargetSpec for ty::query::TyCtxtAt<'tcx> {
|
||||
impl<'tcx> HasTargetSpec for TyCtxtAt<'tcx> {
|
||||
fn target_spec(&self) -> &Target {
|
||||
&self.sess.target
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> HasTyCtxt<'tcx> for ty::query::TyCtxtAt<'tcx> {
|
||||
impl<'tcx> HasTyCtxt<'tcx> for TyCtxtAt<'tcx> {
|
||||
#[inline]
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
**self
|
||||
@ -683,7 +684,7 @@ fn handle_layout_err(&self, err: LayoutError<'tcx>, _: Span, _: Ty<'tcx>) -> Lay
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> LayoutOfHelpers<'tcx> for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
|
||||
impl<'tcx> LayoutOfHelpers<'tcx> for LayoutCx<'tcx, TyCtxtAt<'tcx>> {
|
||||
type LayoutOfResult = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;
|
||||
|
||||
#[inline]
|
||||
|
@ -122,8 +122,6 @@
|
||||
pub mod layout;
|
||||
pub mod normalize_erasing_regions;
|
||||
pub mod print;
|
||||
#[macro_use]
|
||||
pub mod query;
|
||||
pub mod relate;
|
||||
pub mod subst;
|
||||
pub mod trait_def;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::mir::interpret::{AllocRange, GlobalAlloc, Pointer, Provenance, Scalar};
|
||||
use crate::query::IntoQueryParam;
|
||||
use crate::query::Providers;
|
||||
use crate::ty::query::IntoQueryParam;
|
||||
use crate::ty::{
|
||||
self, ConstInt, ParamConst, ScalarInt, Term, TermKind, Ty, TyCtxt, TypeFoldable,
|
||||
TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
|
||||
|
@ -276,6 +276,7 @@ fn move_paths_for_fields(
|
||||
assert_eq!(self.elaborator.param_env().reveal(), Reveal::All);
|
||||
let field_ty =
|
||||
tcx.normalize_erasing_regions(self.elaborator.param_env(), f.ty(tcx, substs));
|
||||
|
||||
(tcx.mk_place_field(base_place, field, field_ty), subpath)
|
||||
})
|
||||
.collect()
|
||||
|
@ -7,6 +7,7 @@
|
||||
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
|
||||
use rustc_middle::mir::visit::*;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::TypeVisitableExt;
|
||||
use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
|
||||
use rustc_session::config::OptLevel;
|
||||
use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span};
|
||||
@ -168,7 +169,7 @@ fn try_inlining(
|
||||
let callee_attrs = self.tcx.codegen_fn_attrs(callsite.callee.def_id());
|
||||
self.check_codegen_attributes(callsite, callee_attrs)?;
|
||||
self.check_mir_is_available(caller_body, &callsite.callee)?;
|
||||
let callee_body = self.tcx.instance_mir(callsite.callee.def);
|
||||
let callee_body = try_instance_mir(self.tcx, callsite.callee.def)?;
|
||||
self.check_mir_body(callsite, callee_body, callee_attrs)?;
|
||||
|
||||
if !self.tcx.consider_optimizing(|| {
|
||||
@ -1128,3 +1129,27 @@ fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, loc: Location)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(tcx), level = "debug")]
|
||||
fn try_instance_mir<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
instance: InstanceDef<'tcx>,
|
||||
) -> Result<&'tcx Body<'tcx>, &'static str> {
|
||||
match instance {
|
||||
ty::InstanceDef::DropGlue(_, Some(ty)) => match ty.kind() {
|
||||
ty::Adt(def, substs) => {
|
||||
let fields = def.all_fields();
|
||||
for field in fields {
|
||||
let field_ty = field.ty(tcx, substs);
|
||||
if field_ty.has_param() && field_ty.has_projections() {
|
||||
return Err("cannot build drop shim for polymorphic type");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(tcx.instance_mir(instance))
|
||||
}
|
||||
_ => Ok(tcx.instance_mir(instance)),
|
||||
},
|
||||
_ => Ok(tcx.instance_mir(instance)),
|
||||
}
|
||||
}
|
||||
|
@ -185,9 +185,9 @@
|
||||
use rustc_middle::mir::mono::{InstantiationMode, MonoItem};
|
||||
use rustc_middle::mir::visit::Visitor as MirVisitor;
|
||||
use rustc_middle::mir::{self, Local, Location};
|
||||
use rustc_middle::query::TyCtxtAt;
|
||||
use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCast};
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::query::TyCtxtAt;
|
||||
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
|
||||
use rustc_middle::ty::{
|
||||
self, GenericParamDefKind, Instance, InstanceDef, Ty, TyCtxt, TypeFoldable, TypeVisitableExt,
|
||||
|
@ -12,10 +12,9 @@
|
||||
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
|
||||
use rustc_fluent_macro::fluent_messages;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::query::{Providers, TyCtxtAt};
|
||||
use rustc_middle::traits;
|
||||
use rustc_middle::ty::adjustment::CustomCoerceUnsized;
|
||||
use rustc_middle::ty::query::TyCtxtAt;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
|
||||
mod collector;
|
||||
|
@ -24,12 +24,12 @@
|
||||
use rustc_middle::dep_graph::{self, DepKind, DepKindStruct};
|
||||
use rustc_middle::query::erase::{erase, restore, Erase};
|
||||
use rustc_middle::query::on_disk_cache::OnDiskCache;
|
||||
use rustc_middle::query::plumbing::{DynamicQuery, QuerySystem, QuerySystemFns};
|
||||
use rustc_middle::query::AsLocalKey;
|
||||
use rustc_middle::query::{
|
||||
query_keys, query_provided, query_provided_to_value, query_storage, query_values,
|
||||
DynamicQueries, ExternProviders, Providers, QueryCaches, QueryEngine, QueryStates,
|
||||
};
|
||||
use rustc_middle::ty::query::{DynamicQuery, QuerySystem, QuerySystemFns};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
|
@ -716,8 +716,7 @@ pub fn CompileMonoItem<'tcx>() -> DepKindStruct<'tcx> {
|
||||
|
||||
mod query_structs {
|
||||
use super::*;
|
||||
use rustc_middle::ty::query::QueryStruct;
|
||||
use rustc_middle::ty::query::QueryKeyStringCache;
|
||||
use rustc_middle::query::plumbing::{QueryKeyStringCache, QueryStruct};
|
||||
use rustc_middle::dep_graph::DepKind;
|
||||
use crate::QueryConfigRestored;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
use rustc_data_structures::profiling::SelfProfiler;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::DefPathData;
|
||||
use rustc_middle::ty::query::QueryKeyStringCache;
|
||||
use rustc_middle::query::plumbing::QueryKeyStringCache;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_query_system::query::QueryCache;
|
||||
use std::fmt::Debug;
|
||||
|
@ -550,7 +550,7 @@ pub(crate) fn into_struct_error(
|
||||
|
||||
let sm = self.tcx.sess.source_map();
|
||||
let def_id = match outer_res {
|
||||
Res::SelfTyParam { .. } | Res::SelfCtor(_) => {
|
||||
Res::SelfTyParam { .. } => {
|
||||
err.span_label(span, "can't use `Self` here");
|
||||
return err;
|
||||
}
|
||||
|
@ -1174,10 +1174,7 @@ fn validate_res_from_ribs(
|
||||
return Res::Err;
|
||||
}
|
||||
}
|
||||
Res::Def(DefKind::TyParam, _)
|
||||
| Res::SelfTyParam { .. }
|
||||
| Res::SelfTyAlias { .. }
|
||||
| Res::SelfCtor(_) => {
|
||||
Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => {
|
||||
for rib in ribs {
|
||||
let has_generic_params: HasGenericParams = match rib.kind {
|
||||
RibKind::Normal
|
||||
|
@ -1751,7 +1751,7 @@ fn render_default_items(
|
||||
if trait_.is_none() && i.inner_impl().items.is_empty() {
|
||||
w.write_str(
|
||||
"<div class=\"item-info\">\
|
||||
<div class=\"stab empty-impl\">This impl block contains no items.</div>
|
||||
<div class=\"stab empty-impl\">This impl block contains no items.</div>\
|
||||
</div>",
|
||||
);
|
||||
}
|
||||
|
26
tests/rustdoc-json/impls/impl_item_visibility.rs
Normal file
26
tests/rustdoc-json/impls/impl_item_visibility.rs
Normal file
@ -0,0 +1,26 @@
|
||||
#![feature(no_core)]
|
||||
#![no_core]
|
||||
|
||||
pub struct Foo;
|
||||
|
||||
/// impl Foo priv
|
||||
impl Foo {
|
||||
fn baz() {}
|
||||
}
|
||||
// @!has '$.index[*][?(@.docs=="impl Foo priv")]'
|
||||
|
||||
|
||||
/// impl Foo pub
|
||||
impl Foo {
|
||||
pub fn qux() {}
|
||||
}
|
||||
// @is '$.index[*][?(@.docs=="impl Foo pub")].visibility' '"default"'
|
||||
|
||||
|
||||
/// impl Foo hidden
|
||||
impl Foo {
|
||||
#[doc(hidden)]
|
||||
pub fn __quazl(){}
|
||||
}
|
||||
// FIXME(#111564): Is this the right behaviour?
|
||||
// @is '$.index[*][?(@.docs=="impl Foo hidden")].visibility' '"default"'
|
28
tests/rustdoc-json/impls/impl_item_visibility_show_hidden.rs
Normal file
28
tests/rustdoc-json/impls/impl_item_visibility_show_hidden.rs
Normal file
@ -0,0 +1,28 @@
|
||||
// compile-flags: --document-hidden-items
|
||||
#![feature(no_core)]
|
||||
#![no_core]
|
||||
|
||||
pub struct Foo;
|
||||
|
||||
/// impl Foo priv
|
||||
impl Foo {
|
||||
fn baz() {}
|
||||
}
|
||||
// FIXME(#111564): Is this the right behaviour?
|
||||
// @is '$.index[*][?(@.docs=="impl Foo priv")].visibility' '"default"'
|
||||
|
||||
|
||||
/// impl Foo pub
|
||||
impl Foo {
|
||||
pub fn qux() {}
|
||||
}
|
||||
// @is '$.index[*][?(@.docs=="impl Foo pub")].visibility' '"default"'
|
||||
|
||||
|
||||
/// impl Foo hidden
|
||||
impl Foo {
|
||||
#[doc(hidden)]
|
||||
pub fn __quazl(){}
|
||||
}
|
||||
// FIXME(#111564): Is this the right behaviour?
|
||||
// @is '$.index[*][?(@.docs=="impl Foo hidden")].visibility' '"default"'
|
@ -0,0 +1,27 @@
|
||||
// compile-flags: --document-private-items
|
||||
#![feature(no_core)]
|
||||
#![no_core]
|
||||
|
||||
pub struct Foo;
|
||||
|
||||
/// impl Foo priv
|
||||
impl Foo {
|
||||
fn baz() {}
|
||||
}
|
||||
// @is '$.index[*][?(@.docs=="impl Foo priv")].visibility' '"default"'
|
||||
|
||||
|
||||
/// impl Foo pub
|
||||
impl Foo {
|
||||
pub fn qux() {}
|
||||
}
|
||||
// @is '$.index[*][?(@.docs=="impl Foo pub")].visibility' '"default"'
|
||||
|
||||
|
||||
/// impl Foo hidden
|
||||
impl Foo {
|
||||
#[doc(hidden)]
|
||||
pub fn __quazl(){}
|
||||
}
|
||||
// FIXME(#111564): Is this the right behaviour?
|
||||
// @is '$.index[*][?(@.docs=="impl Foo hidden")].visibility' '"default"'
|
92
tests/ui/drop/issue-110682.rs
Normal file
92
tests/ui/drop/issue-110682.rs
Normal file
@ -0,0 +1,92 @@
|
||||
// build-pass
|
||||
// compile-flags: -Zmir-opt-level=3
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::mem::ManuallyDrop;
|
||||
use std::ptr;
|
||||
|
||||
pub trait BitRegister {}
|
||||
|
||||
macro_rules! register {
|
||||
($($t:ty),+ $(,)?) => { $(
|
||||
impl BitRegister for $t {
|
||||
}
|
||||
)* };
|
||||
}
|
||||
|
||||
register!(u8, u16, u32);
|
||||
|
||||
pub trait BitStore: Sized + Debug {
|
||||
/// The register type that the implementor describes.
|
||||
type Mem: BitRegister + Into<Self>;
|
||||
}
|
||||
|
||||
macro_rules! store {
|
||||
($($t:ty),+ $(,)?) => { $(
|
||||
impl BitStore for $t {
|
||||
type Mem = Self;
|
||||
}
|
||||
)+ };
|
||||
}
|
||||
|
||||
store!(u8, u16, u32,);
|
||||
|
||||
#[repr(C)]
|
||||
pub struct BitVec<T>
|
||||
where
|
||||
T: BitStore,
|
||||
{
|
||||
/// Region pointer describing the live portion of the owned buffer.
|
||||
pointer: ptr::NonNull<T>,
|
||||
/// Allocated capacity, in elements `T`, of the owned buffer.
|
||||
capacity: usize,
|
||||
}
|
||||
|
||||
impl<T> BitVec<T>
|
||||
where
|
||||
T: BitStore,
|
||||
{
|
||||
pub fn new() -> Self {
|
||||
let pointer = ptr::NonNull::<T>::new(ptr::null_mut()).unwrap();
|
||||
|
||||
BitVec { pointer, capacity: 10 }
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
unsafe {
|
||||
self.set_len(0);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn set_len(&mut self, new_len: usize) {}
|
||||
|
||||
fn with_vec<F, R>(&mut self, func: F) -> R
|
||||
where
|
||||
F: FnOnce(&mut ManuallyDrop<Vec<T::Mem>>) -> R,
|
||||
{
|
||||
let cap = self.capacity;
|
||||
let elts = 10;
|
||||
let mut vec = ManuallyDrop::new(unsafe { Vec::from_raw_parts(ptr::null_mut(), elts, cap) });
|
||||
let out = func(&mut vec);
|
||||
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Drop for BitVec<T>
|
||||
where
|
||||
T: BitStore,
|
||||
{
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
// The buffer elements do not have destructors.
|
||||
self.clear();
|
||||
// Run the `Vec` destructor to deällocate the buffer.
|
||||
self.with_vec(|vec| unsafe { ManuallyDrop::drop(vec) });
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let bitvec = BitVec::<u32>::new();
|
||||
}
|
11
tests/ui/resolve/issue-111312.rs
Normal file
11
tests/ui/resolve/issue-111312.rs
Normal file
@ -0,0 +1,11 @@
|
||||
// edition: 2021
|
||||
|
||||
trait Has {
|
||||
fn has() {}
|
||||
}
|
||||
|
||||
trait HasNot {}
|
||||
|
||||
fn main() {
|
||||
HasNot::has(); //~ ERROR
|
||||
}
|
15
tests/ui/resolve/issue-111312.stderr
Normal file
15
tests/ui/resolve/issue-111312.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
error[E0599]: no function or associated item named `has` found for trait `HasNot`
|
||||
--> $DIR/issue-111312.rs:10:13
|
||||
|
|
||||
LL | HasNot::has();
|
||||
| ^^^ function or associated item not found in `HasNot`
|
||||
|
|
||||
note: `Has` defines an item `has`
|
||||
--> $DIR/issue-111312.rs:3:1
|
||||
|
|
||||
LL | trait Has {
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0599`.
|
@ -1,17 +0,0 @@
|
||||
// Verify that we ban usage of `Self` as constructor from inner items.
|
||||
|
||||
struct S0<T>(T);
|
||||
|
||||
impl<T> S0<T> {
|
||||
fn foo() {
|
||||
const C: S0<u8> = Self(0);
|
||||
//~^ ERROR can't use generic parameters from outer function
|
||||
fn bar() -> Self {
|
||||
//~^ ERROR can't use generic parameters from outer function
|
||||
Self(0)
|
||||
//~^ ERROR can't use generic parameters from outer function
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,33 +0,0 @@
|
||||
error[E0401]: can't use generic parameters from outer function
|
||||
--> $DIR/self-ctor-inner-const.rs:7:27
|
||||
|
|
||||
LL | const C: S0<u8> = Self(0);
|
||||
| ^^^^
|
||||
| |
|
||||
| use of generic parameter from outer function
|
||||
| can't use `Self` here
|
||||
|
||||
error[E0401]: can't use generic parameters from outer function
|
||||
--> $DIR/self-ctor-inner-const.rs:9:21
|
||||
|
|
||||
LL | impl<T> S0<T> {
|
||||
| ---- `Self` type implicitly declared here, by this `impl`
|
||||
...
|
||||
LL | fn bar() -> Self {
|
||||
| ^^^^
|
||||
| |
|
||||
| use of generic parameter from outer function
|
||||
| use a type here instead
|
||||
|
||||
error[E0401]: can't use generic parameters from outer function
|
||||
--> $DIR/self-ctor-inner-const.rs:11:13
|
||||
|
|
||||
LL | Self(0)
|
||||
| ^^^^
|
||||
| |
|
||||
| use of generic parameter from outer function
|
||||
| can't use `Self` here
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0401`.
|
15
tests/ui/self/self-ctor-nongeneric.rs
Normal file
15
tests/ui/self/self-ctor-nongeneric.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// `Self` as a constructor is currently allowed when the outer item is not generic.
|
||||
// check-pass
|
||||
|
||||
struct S0(usize);
|
||||
|
||||
impl S0 {
|
||||
fn foo() {
|
||||
const C: S0 = Self(0);
|
||||
fn bar() -> S0 {
|
||||
Self(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,5 +1,4 @@
|
||||
#[derive(Clone)] //~ trait objects must include the `dyn` keyword
|
||||
//~| trait objects must include the `dyn` keyword
|
||||
struct Foo;
|
||||
trait Foo {} //~ the name `Foo` is defined multiple times
|
||||
fn main() {}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0428]: the name `Foo` is defined multiple times
|
||||
--> $DIR/issue-106072.rs:4:1
|
||||
--> $DIR/issue-106072.rs:3:1
|
||||
|
|
||||
LL | struct Foo;
|
||||
| ----------- previous definition of the type `Foo` here
|
||||
@ -16,15 +16,7 @@ LL | #[derive(Clone)]
|
||||
|
|
||||
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0782]: trait objects must include the `dyn` keyword
|
||||
--> $DIR/issue-106072.rs:1:10
|
||||
|
|
||||
LL | #[derive(Clone)]
|
||||
| ^^^^^
|
||||
|
|
||||
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0428, E0782.
|
||||
For more information about an error, try `rustc --explain E0428`.
|
||||
|
Loading…
Reference in New Issue
Block a user