diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index fc9a2970e00ae..aa0f18846d154 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -281,7 +281,13 @@ impl<'tcx> TyCtxt<'tcx> { /// If `id` is `Some(_)`, this function will also check if the item at `def_id` has been /// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to /// `id`. - pub fn eval_stability(self, def_id: DefId, id: Option, span: Span) -> EvalResult { + pub fn eval_stability( + self, + def_id: DefId, + id: Option, + span: Span, + method_span: Option, + ) -> EvalResult { // Deprecated attributes apply in-crate and cross-crate. if let Some(id) = id { if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) { @@ -300,6 +306,7 @@ impl<'tcx> TyCtxt<'tcx> { let path = &with_no_trimmed_paths(|| self.def_path_str(def_id)); let kind = self.def_kind(def_id).descr(def_id); let (message, lint) = deprecation_message(&depr_entry.attr, kind, path); + let span = method_span.unwrap_or(span); late_report_deprecation( self, &message, @@ -382,8 +389,14 @@ impl<'tcx> TyCtxt<'tcx> { /// /// This function will also check if the item is deprecated. /// If so, and `id` is not `None`, a deprecated lint attached to `id` will be emitted. - pub fn check_stability(self, def_id: DefId, id: Option, span: Span) { - self.check_optional_stability(def_id, id, span, |span, def_id| { + pub fn check_stability( + self, + def_id: DefId, + id: Option, + span: Span, + method_span: Option, + ) { + self.check_optional_stability(def_id, id, span, method_span, |span, def_id| { // The API could be uncallable for other reasons, for example when a private module // was referenced. self.sess.delay_span_bug(span, &format!("encountered unmarked API: {:?}", def_id)); @@ -399,6 +412,7 @@ impl<'tcx> TyCtxt<'tcx> { def_id: DefId, id: Option, span: Span, + method_span: Option, unmarked: impl FnOnce(Span, DefId), ) { let soft_handler = |lint, span, msg: &_| { @@ -406,7 +420,7 @@ impl<'tcx> TyCtxt<'tcx> { lint.build(msg).emit() }) }; - match self.eval_stability(def_id, id, span) { + match self.eval_stability(def_id, id, span, method_span) { EvalResult::Allow => {} EvalResult::Deny { feature, reason, issue, is_soft } => { report_unstable(self.sess, feature, reason, issue, is_soft, span, soft_handler) diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 008e6d015e879..96aae3bd70cd2 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -159,10 +159,23 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { ) }), IntMismatch(ref values) => { - write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found) + let expected = match values.expected { + ty::IntVarValue::IntType(ty) => ty.name_str(), + ty::IntVarValue::UintType(ty) => ty.name_str(), + }; + let found = match values.found { + ty::IntVarValue::IntType(ty) => ty.name_str(), + ty::IntVarValue::UintType(ty) => ty.name_str(), + }; + write!(f, "expected `{}`, found `{}`", expected, found) } FloatMismatch(ref values) => { - write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found) + write!( + f, + "expected `{}`, found `{}`", + values.expected.name_str(), + values.found.name_str() + ) } VariadicMismatch(ref values) => write!( f, diff --git a/compiler/rustc_mir/src/transform/const_goto.rs b/compiler/rustc_mir/src/transform/const_goto.rs index ba10b54c5ae2e..b5c8b4bebc360 100644 --- a/compiler/rustc_mir/src/transform/const_goto.rs +++ b/compiler/rustc_mir/src/transform/const_goto.rs @@ -47,7 +47,7 @@ impl<'tcx> MirPass<'tcx> for ConstGoto { // if we applied optimizations, we potentially have some cfg to cleanup to // make it easier for further passes if should_simplify { - simplify_cfg(tcx, body); + simplify_cfg(body); simplify_locals(body, tcx); } } diff --git a/compiler/rustc_mir/src/transform/deduplicate_blocks.rs b/compiler/rustc_mir/src/transform/deduplicate_blocks.rs index 912505c65983e..c41e71e09a4ef 100644 --- a/compiler/rustc_mir/src/transform/deduplicate_blocks.rs +++ b/compiler/rustc_mir/src/transform/deduplicate_blocks.rs @@ -26,7 +26,7 @@ impl<'tcx> MirPass<'tcx> for DeduplicateBlocks { if has_opts_to_apply { let mut opt_applier = OptApplier { tcx, duplicates }; opt_applier.visit_body(body); - simplify_cfg(tcx, body); + simplify_cfg(body); } } } diff --git a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs index ac39206623308..f7ea9faec4728 100644 --- a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs +++ b/compiler/rustc_mir/src/transform/early_otherwise_branch.rs @@ -164,7 +164,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch { // Since this optimization adds new basic blocks and invalidates others, // clean up the cfg to make it nicer for other passes if should_cleanup { - simplify_cfg(tcx, body); + simplify_cfg(body); } } } diff --git a/compiler/rustc_mir/src/transform/generator.rs b/compiler/rustc_mir/src/transform/generator.rs index 3560b4b1e8645..003003a8abbea 100644 --- a/compiler/rustc_mir/src/transform/generator.rs +++ b/compiler/rustc_mir/src/transform/generator.rs @@ -964,7 +964,7 @@ fn create_generator_drop_shim<'tcx>( // Make sure we remove dead blocks to remove // unrelated code from the resume part of the function - simplify::remove_dead_blocks(tcx, &mut body); + simplify::remove_dead_blocks(&mut body); dump_mir(tcx, None, "generator_drop", &0, &body, |_, _| Ok(())); @@ -1137,7 +1137,7 @@ fn create_generator_resume_function<'tcx>( // Make sure we remove dead blocks to remove // unrelated code from the drop part of the function - simplify::remove_dead_blocks(tcx, body); + simplify::remove_dead_blocks(body); dump_mir(tcx, None, "generator_resume", &0, body, |_, _| Ok(())); } diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index f1c95a84ade85..b6f80763bc8c4 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -57,7 +57,7 @@ impl<'tcx> MirPass<'tcx> for Inline { if inline(tcx, body) { debug!("running simplify cfg on {:?}", body.source); CfgSimplifier::new(body).simplify(); - remove_dead_blocks(tcx, body); + remove_dead_blocks(body); } } } diff --git a/compiler/rustc_mir/src/transform/match_branches.rs b/compiler/rustc_mir/src/transform/match_branches.rs index 21b208a08c2dc..f7a9835353e5c 100644 --- a/compiler/rustc_mir/src/transform/match_branches.rs +++ b/compiler/rustc_mir/src/transform/match_branches.rs @@ -167,7 +167,7 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification { } if should_cleanup { - simplify_cfg(tcx, body); + simplify_cfg(body); } } } diff --git a/compiler/rustc_mir/src/transform/multiple_return_terminators.rs b/compiler/rustc_mir/src/transform/multiple_return_terminators.rs index cd2db18055286..4aaa0baa9f46a 100644 --- a/compiler/rustc_mir/src/transform/multiple_return_terminators.rs +++ b/compiler/rustc_mir/src/transform/multiple_return_terminators.rs @@ -38,6 +38,6 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators { } } - simplify::remove_dead_blocks(tcx, body) + simplify::remove_dead_blocks(body) } } diff --git a/compiler/rustc_mir/src/transform/remove_unneeded_drops.rs b/compiler/rustc_mir/src/transform/remove_unneeded_drops.rs index 02e45021a0aaf..5144d48750de7 100644 --- a/compiler/rustc_mir/src/transform/remove_unneeded_drops.rs +++ b/compiler/rustc_mir/src/transform/remove_unneeded_drops.rs @@ -36,7 +36,7 @@ impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops { // if we applied optimizations, we potentially have some cfg to cleanup to // make it easier for further passes if should_simplify { - simplify_cfg(tcx, body); + simplify_cfg(body); } } } diff --git a/compiler/rustc_mir/src/transform/simplify.rs b/compiler/rustc_mir/src/transform/simplify.rs index 63373b0cffbb0..65e2d096b2094 100644 --- a/compiler/rustc_mir/src/transform/simplify.rs +++ b/compiler/rustc_mir/src/transform/simplify.rs @@ -29,7 +29,6 @@ use crate::transform::MirPass; use rustc_index::vec::{Idx, IndexVec}; -use rustc_middle::mir::coverage::*; use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; @@ -47,9 +46,9 @@ impl SimplifyCfg { } } -pub fn simplify_cfg(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) { +pub fn simplify_cfg(body: &mut Body<'_>) { CfgSimplifier::new(body).simplify(); - remove_dead_blocks(tcx, body); + remove_dead_blocks(body); // FIXME: Should probably be moved into some kind of pass manager body.basic_blocks_mut().raw.shrink_to_fit(); @@ -60,9 +59,9 @@ impl<'tcx> MirPass<'tcx> for SimplifyCfg { Cow::Borrowed(&self.label) } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body.source); - simplify_cfg(tcx, body); + simplify_cfg(body); } } @@ -287,7 +286,7 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> { } } -pub fn remove_dead_blocks(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) { +pub fn remove_dead_blocks(body: &mut Body<'_>) { let reachable = traversal::reachable_as_bitset(body); let num_blocks = body.basic_blocks().len(); if num_blocks == reachable.count() { @@ -307,11 +306,6 @@ pub fn remove_dead_blocks(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) { } used_blocks += 1; } - - if tcx.sess.instrument_coverage() { - save_unreachable_coverage(basic_blocks, used_blocks); - } - basic_blocks.raw.truncate(used_blocks); for block in basic_blocks { @@ -321,32 +315,6 @@ pub fn remove_dead_blocks(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) { } } -fn save_unreachable_coverage( - basic_blocks: &mut IndexVec>, - first_dead_block: usize, -) { - // retain coverage info for dead blocks, so coverage reports will still - // report `0` executions for the uncovered code regions. - let mut dropped_coverage = Vec::new(); - for dead_block in first_dead_block..basic_blocks.len() { - for statement in basic_blocks[BasicBlock::new(dead_block)].statements.iter() { - if let StatementKind::Coverage(coverage) = &statement.kind { - if let Some(code_region) = &coverage.code_region { - dropped_coverage.push((statement.source_info, code_region.clone())); - } - } - } - } - for (source_info, code_region) in dropped_coverage { - basic_blocks[START_BLOCK].statements.push(Statement { - source_info, - kind: StatementKind::Coverage(box Coverage { - kind: CoverageKind::Unreachable, - code_region: Some(code_region), - }), - }) - } -} pub struct SimplifyLocals; impl<'tcx> MirPass<'tcx> for SimplifyLocals { diff --git a/compiler/rustc_mir/src/transform/simplify_try.rs b/compiler/rustc_mir/src/transform/simplify_try.rs index c9c4492062720..b42543c04eb3d 100644 --- a/compiler/rustc_mir/src/transform/simplify_try.rs +++ b/compiler/rustc_mir/src/transform/simplify_try.rs @@ -558,7 +558,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyBranchSame { if did_remove_blocks { // We have dead blocks now, so remove those. - simplify::remove_dead_blocks(tcx, body); + simplify::remove_dead_blocks(body); } } } diff --git a/compiler/rustc_mir/src/transform/unreachable_prop.rs b/compiler/rustc_mir/src/transform/unreachable_prop.rs index e7fb6b4f6b4ad..658c6b6e9db20 100644 --- a/compiler/rustc_mir/src/transform/unreachable_prop.rs +++ b/compiler/rustc_mir/src/transform/unreachable_prop.rs @@ -60,7 +60,7 @@ impl MirPass<'_> for UnreachablePropagation { } if replaced { - simplify::remove_dead_blocks(tcx, body); + simplify::remove_dead_blocks(body); } } } diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 9c4f9b1198cf2..6b1813fba7600 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -739,7 +739,7 @@ impl Visitor<'tcx> for Checker<'tcx> { None => return, }; let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX }; - self.tcx.check_stability(def_id, Some(item.hir_id()), item.span); + self.tcx.check_stability(def_id, Some(item.hir_id()), item.span, None); } // For implementations of traits, check the stability of each item @@ -783,7 +783,7 @@ impl Visitor<'tcx> for Checker<'tcx> { .map(|item| item.def_id); if let Some(def_id) = trait_item_def_id { // Pass `None` to skip deprecation warnings. - self.tcx.check_stability(def_id, None, impl_item.span); + self.tcx.check_stability(def_id, None, impl_item.span, None); } } } @@ -832,7 +832,7 @@ impl Visitor<'tcx> for Checker<'tcx> { fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, id: hir::HirId) { if let Some(def_id) = path.res.opt_def_id() { - self.tcx.check_stability(def_id, Some(id), path.span) + self.tcx.check_stability(def_id, Some(id), path.span, None) } intravisit::walk_path(self, path) } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 10e195f4f2548..ca8bb3af2ba69 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -621,9 +621,9 @@ mod parse { true } - crate fn parse_linker_flavor(slote: &mut Option, v: Option<&str>) -> bool { + crate fn parse_linker_flavor(slot: &mut Option, v: Option<&str>) -> bool { match v.and_then(LinkerFlavor::from_str) { - Some(lf) => *slote = Some(lf), + Some(lf) => *slot = Some(lf), _ => return false, } true diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 7696a0c69cac9..5285c1c859870 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -432,6 +432,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { param.def_id, Some(arg.id()), arg.span(), + None, |_, _| { // Default generic parameters may not be marked // with stability attributes, i.e. when the @@ -1059,7 +1060,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .span_label(binding.span, "private associated type") .emit(); } - tcx.check_stability(assoc_ty.def_id, Some(hir_ref_id), binding.span); + tcx.check_stability(assoc_ty.def_id, Some(hir_ref_id), binding.span, None); if !speculative { dup_bindings @@ -1666,7 +1667,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .find(|vd| tcx.hygienic_eq(assoc_ident, vd.ident, adt_def.did)); if let Some(variant_def) = variant_def { if permit_variants { - tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span); + tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span, None); self.prohibit_generics(slice::from_ref(assoc_segment)); return Ok((qself_ty, DefKind::Variant, variant_def.def_id)); } else { @@ -1786,7 +1787,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .span_label(span, &format!("private {}", kind)) .emit(); } - tcx.check_stability(item.def_id, Some(hir_ref_id), span); + tcx.check_stability(item.def_id, Some(hir_ref_id), span, None); if let Some(variant_def_id) = variant_resolution { tcx.struct_span_lint_hir(AMBIGUOUS_ASSOCIATED_ITEMS, hir_ref_id, span, |lint| { diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 991c2ba693d69..d0cbb58fb10eb 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -1230,7 +1230,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // struct-like enums (yet...), but it's definitely not // a bug to have constructed one. if adt_kind != AdtKind::Enum { - tcx.check_stability(v_field.did, Some(expr_id), field.span); + tcx.check_stability(v_field.did, Some(expr_id), field.span, None); } self.field_ty(field.span, v_field, substs) @@ -1571,7 +1571,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.apply_adjustments(base, adjustments); self.register_predicates(autoderef.into_obligations()); - self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span); + self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None); return field_ty; } private_candidate = Some((base_def.did, field_ty)); diff --git a/compiler/rustc_typeck/src/check/method/mod.rs b/compiler/rustc_typeck/src/check/method/mod.rs index bd7ffd057b466..0b1129a631249 100644 --- a/compiler/rustc_typeck/src/check/method/mod.rs +++ b/compiler/rustc_typeck/src/check/method/mod.rs @@ -205,7 +205,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .insert(*import_id); } - self.tcx.check_stability(pick.item.def_id, Some(call_expr.hir_id), span); + self.tcx.check_stability(pick.item.def_id, Some(call_expr.hir_id), span, None); let result = self.confirm_method(span, self_expr, call_expr, self_ty, pick.clone(), segment); @@ -445,7 +445,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // them as well. It's ok to use the variant's id as a ctor id since an // error will be reported on any use of such resolution anyway. let ctor_def_id = variant_def.ctor_def_id.unwrap_or(variant_def.def_id); - tcx.check_stability(ctor_def_id, Some(expr_id), span); + tcx.check_stability(ctor_def_id, Some(expr_id), span, Some(method_name.span)); return Ok(( DefKind::Ctor(CtorOf::Variant, variant_def.ctor_kind), ctor_def_id, @@ -475,7 +475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let def_kind = pick.item.kind.as_def_kind(); debug!("resolve_ufcs: def_kind={:?}, def_id={:?}", def_kind, pick.item.def_id); - tcx.check_stability(pick.item.def_id, Some(expr_id), span); + tcx.check_stability(pick.item.def_id, Some(expr_id), span, Some(method_name.span)); Ok((def_kind, pick.item.def_id)) } diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index c79743f2d7363..440e0f4e1a2ac 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -1286,7 +1286,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { if let Some(uc) = unstable_candidates { applicable_candidates.retain(|&(p, _)| { if let stability::EvalResult::Deny { feature, .. } = - self.tcx.eval_stability(p.item.def_id, None, self.span) + self.tcx.eval_stability(p.item.def_id, None, self.span, None) { uc.push((p, feature)); return false; diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 53593b9bab4b8..3ac760e23634e 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -958,7 +958,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let field_ty = self.field_ty(subpat.span, &variant.fields[i], substs); self.check_pat(&subpat, field_ty, def_bm, TopInfo { parent_pat: Some(&pat), ..ti }); - self.tcx.check_stability(variant.fields[i].did, Some(pat.hir_id), subpat.span); + self.tcx.check_stability( + variant.fields[i].did, + Some(pat.hir_id), + subpat.span, + None, + ); } } else { // Pattern has wrong number of fields. @@ -1192,7 +1197,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .get(&ident) .map(|(i, f)| { self.write_field_index(field.hir_id, *i); - self.tcx.check_stability(f.did, Some(pat.hir_id), span); + self.tcx.check_stability(f.did, Some(pat.hir_id), span, None); self.field_ty(span, f, substs) }) .unwrap_or_else(|| { diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 11d052dae9e90..4403280efc11b 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -324,13 +324,13 @@ impl Error for VarError { /// assert_eq!(env::var(key), Ok("VALUE".to_string())); /// ``` #[stable(feature = "env", since = "1.0.0")] -pub fn set_var, V: AsRef>(k: K, v: V) { - _set_var(k.as_ref(), v.as_ref()) +pub fn set_var, V: AsRef>(key: K, value: V) { + _set_var(key.as_ref(), value.as_ref()) } -fn _set_var(k: &OsStr, v: &OsStr) { - os_imp::setenv(k, v).unwrap_or_else(|e| { - panic!("failed to set environment variable `{:?}` to `{:?}`: {}", k, v, e) +fn _set_var(key: &OsStr, value: &OsStr) { + os_imp::setenv(key, value).unwrap_or_else(|e| { + panic!("failed to set environment variable `{:?}` to `{:?}`: {}", key, value, e) }) } @@ -366,13 +366,13 @@ fn _set_var(k: &OsStr, v: &OsStr) { /// assert!(env::var(key).is_err()); /// ``` #[stable(feature = "env", since = "1.0.0")] -pub fn remove_var>(k: K) { - _remove_var(k.as_ref()) +pub fn remove_var>(key: K) { + _remove_var(key.as_ref()) } -fn _remove_var(k: &OsStr) { - os_imp::unsetenv(k) - .unwrap_or_else(|e| panic!("failed to remove environment variable `{:?}`: {}", k, e)) +fn _remove_var(key: &OsStr) { + os_imp::unsetenv(key) + .unwrap_or_else(|e| panic!("failed to remove environment variable `{:?}`: {}", key, e)) } /// An iterator that splits an environment variable into paths according to diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index a32b92ef1af83..326a6fdaa80ff 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -549,6 +549,7 @@ impl Step for Rustc { cargo.rustdocflag("--enable-index-page"); cargo.rustdocflag("-Zunstable-options"); cargo.rustdocflag("-Znormalize-docs"); + cargo.rustdocflag("--show-type-layout"); compile::rustc_cargo(builder, &mut cargo, target); // Only include compiler crates, no dependencies of those, such as `libc`. @@ -648,6 +649,7 @@ impl Step for Rustdoc { cargo.rustdocflag("--document-private-items"); cargo.rustdocflag("--enable-index-page"); + cargo.rustdocflag("--show-type-layout"); cargo.rustdocflag("-Zunstable-options"); builder.run(&mut cargo.into()); } diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 78163651158ed..0e9c561c68994 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -827,17 +827,30 @@ impl Step for RustdocGUI { } let out_dir = builder.test_out(self.target).join("rustdoc-gui"); - let mut command = builder.rustdoc_cmd(self.compiler); - command.arg("src/test/rustdoc-gui/lib.rs").arg("-o").arg(&out_dir); - builder.run(&mut command); + // We remove existing folder to be sure there won't be artifacts remaining. + let _ = fs::remove_dir_all(&out_dir); + + // We generate docs for the libraries present in the rustdoc-gui's src folder. + let libs_dir = builder.build.src.join("src/test/rustdoc-gui/src"); + for entry in libs_dir.read_dir().expect("read_dir call failed") { + let entry = entry.expect("invalid entry"); + let path = entry.path(); + if path.extension().map(|e| e == "rs").unwrap_or(false) { + let mut command = builder.rustdoc_cmd(self.compiler); + command.arg(path).arg("-o").arg(&out_dir); + builder.run(&mut command); + } + } + + // We now run GUI tests. let mut command = Command::new(&nodejs); command - .arg("src/tools/rustdoc-gui/tester.js") + .arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js")) .arg("--doc-folder") - .arg(out_dir.join("test_docs")) + .arg(out_dir) .arg("--tests-folder") - .arg("src/test/rustdoc-gui"); + .arg(builder.build.src.join("src/test/rustdoc-gui")); builder.run(&mut command); } else { builder.info("No nodejs found, skipping \"src/test/rustdoc-gui\" tests"); diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 045b42d0dcaf7..b75e98ae16c16 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -267,6 +267,8 @@ crate struct RenderOptions { crate document_hidden: bool, /// If `true`, generate a JSON file in the crate folder instead of HTML redirection files. crate generate_redirect_map: bool, + /// Show the memory layout of types in the docs. + crate show_type_layout: bool, crate unstable_features: rustc_feature::UnstableFeatures, crate emit: Vec, } @@ -636,6 +638,7 @@ impl Options { let document_hidden = matches.opt_present("document-hidden-items"); let run_check = matches.opt_present("check"); let generate_redirect_map = matches.opt_present("generate-redirect-map"); + let show_type_layout = matches.opt_present("show-type-layout"); let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format); @@ -695,6 +698,7 @@ impl Options { document_private, document_hidden, generate_redirect_map, + show_type_layout, unstable_features: rustc_feature::UnstableFeatures::from_environment( crate_name.as_deref(), ), diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 4e17dc8d3a7d0..666d9dfc3e9e4 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -91,6 +91,8 @@ crate struct SharedContext<'tcx> { crate include_sources: bool, /// The local file sources we've emitted and their respective url-paths. crate local_sources: FxHashMap, + /// Show the memory layout of types in the docs. + pub(super) show_type_layout: bool, /// Whether the collapsed pass ran collapsed: bool, /// The base-URL of the issue tracker for when an item has been tagged with @@ -373,6 +375,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { generate_search_filter, unstable_features, generate_redirect_map, + show_type_layout, .. } = options; @@ -446,6 +449,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { all: RefCell::new(AllTypes::new()), errors: receiver, redirections: if generate_redirect_map { Some(Default::default()) } else { None }, + show_type_layout, }; // Add the default themes to the `Vec` of stylepaths diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 7ccc313cc5905..f0ca24b8f0221 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -7,6 +7,7 @@ use rustc_hir as hir; use rustc_hir::def::CtorKind; use rustc_hir::def_id::DefId; use rustc_middle::middle::stability; +use rustc_middle::ty::layout::LayoutError; use rustc_middle::ty::TyCtxt; use rustc_span::hygiene::MacroKind; use rustc_span::symbol::{kw, sym, Symbol}; @@ -830,11 +831,12 @@ fn item_typedef(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::T document(w, cx, it, None); + let def_id = it.def_id.expect_real(); // Render any items associated directly to this alias, as otherwise they // won't be visible anywhere in the docs. It would be nice to also show // associated items from the aliased type (see discussion in #32077), but // we need #14072 to make sense of the generics. - render_assoc_items(w, cx, it, it.def_id.expect_real(), AssocItemRender::All) + render_assoc_items(w, cx, it, def_id, AssocItemRender::All); } fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Union) { @@ -846,6 +848,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni }); document(w, cx, it, None); + let mut fields = s .fields .iter() @@ -880,7 +883,9 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni document(w, cx, field, Some(it)); } } - render_assoc_items(w, cx, it, it.def_id.expect_real(), AssocItemRender::All) + let def_id = it.def_id.expect_real(); + render_assoc_items(w, cx, it, def_id, AssocItemRender::All); + document_type_layout(w, cx, def_id); } fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum) { @@ -940,6 +945,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum }); document(w, cx, it, None); + if !e.variants.is_empty() { write!( w, @@ -1014,7 +1020,9 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum render_stability_since(w, variant, it, cx.tcx()); } } - render_assoc_items(w, cx, it, it.def_id.expect_real(), AssocItemRender::All) + let def_id = it.def_id.expect_real(); + render_assoc_items(w, cx, it, def_id, AssocItemRender::All); + document_type_layout(w, cx, def_id); } fn item_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Macro) { @@ -1114,6 +1122,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St }); document(w, cx, it, None); + let mut fields = s .fields .iter() @@ -1152,7 +1161,9 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St } } } - render_assoc_items(w, cx, it, it.def_id.expect_real(), AssocItemRender::All) + let def_id = it.def_id.expect_real(); + render_assoc_items(w, cx, it, def_id, AssocItemRender::All); + document_type_layout(w, cx, def_id); } fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Static) { @@ -1522,3 +1533,62 @@ fn document_non_exhaustive(w: &mut Buffer, item: &clean::Item) { w.write_str(""); } } + +fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) { + if !cx.shared.show_type_layout { + return; + } + + writeln!(w, "

Layout

"); + writeln!(w, "
"); + + let tcx = cx.tcx(); + let param_env = tcx.param_env(ty_def_id); + let ty = tcx.type_of(ty_def_id); + match tcx.layout_of(param_env.and(ty)) { + Ok(ty_layout) => { + writeln!( + w, + "

Note: Most layout information is \ + completely unstable and may be different between compiler versions and platforms. \ + The only exception is types with certain repr(...) attributes. \ + Please see the Rust Reference’s \ + “Type Layout” \ + chapter for details on type layout guarantees.

" + ); + if ty_layout.layout.abi.is_unsized() { + writeln!(w, "

Size: (unsized)

"); + } else { + let bytes = ty_layout.layout.size.bytes(); + writeln!( + w, + "

Size: {size} byte{pl}

", + size = bytes, + pl = if bytes == 1 { "" } else { "s" }, + ); + } + } + // This kind of layout error can occur with valid code, e.g. if you try to + // get the layout of a generic type such as `Vec`. + Err(LayoutError::Unknown(_)) => { + writeln!( + w, + "

Note: Unable to compute type layout, \ + possibly due to this type having generic parameters. \ + Layout can only be computed for concrete, fully-instantiated types.

" + ); + } + // This kind of error probably can't happen with valid code, but we don't + // want to panic and prevent the docs from building, so we just let the + // user know that we couldn't compute the layout. + Err(LayoutError::SizeOverflow(_)) => { + writeln!( + w, + "

Note: Encountered an error during type layout; \ + the type was too big.

" + ); + } + } + + writeln!(w, "
"); +} diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index dc65e14ab37b8..04dc25341f4d3 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -448,14 +448,14 @@ function hideThemeButtonState() { } function getHelpElement(build) { - if (build !== false) { + if (build) { buildHelperPopup(); } return document.getElementById("help"); } function displayHelp(display, ev, help) { - if (display === true) { + if (display) { help = help ? help : getHelpElement(true); if (hasClass(help, "hidden")) { ev.preventDefault(); @@ -466,7 +466,7 @@ function hideThemeButtonState() { // No need to build the help popup if we want to hide it in case it hasn't been // built yet... help = help ? help : getHelpElement(false); - if (help && hasClass(help, "hidden") === false) { + if (help && !hasClass(help, "hidden")) { ev.preventDefault(); addClass(help, "hidden"); removeClass(document.body, "blur"); @@ -477,9 +477,9 @@ function hideThemeButtonState() { function handleEscape(ev) { var help = getHelpElement(false); var search = searchState.outputElement(); - if (hasClass(help, "hidden") === false) { + if (!hasClass(help, "hidden")) { displayHelp(false, ev, help); - } else if (hasClass(search, "hidden") === false) { + } else if (!hasClass(search, "hidden")) { searchState.clearInputTimeout(); ev.preventDefault(); searchState.hideResults(search); @@ -491,7 +491,7 @@ function hideThemeButtonState() { var disableShortcuts = getSettingValue("disable-shortcuts") === "true"; function handleShortcut(ev) { // Don't interfere with browser shortcuts - if (ev.ctrlKey || ev.altKey || ev.metaKey || disableShortcuts === true) { + if (ev.ctrlKey || ev.altKey || ev.metaKey || disableShortcuts) { return; } @@ -908,11 +908,11 @@ function hideThemeButtonState() { function implHider(addOrRemove, fullHide) { return function(n) { var shouldHide = - fullHide === true || - hasClass(n, "method") === true || - hasClass(n, "associatedconstant") === true; - if (shouldHide === true || hasClass(n, "type") === true) { - if (shouldHide === true) { + fullHide || + hasClass(n, "method") || + hasClass(n, "associatedconstant"); + if (shouldHide || hasClass(n, "type")) { + if (shouldHide) { if (addOrRemove) { addClass(n, "hidden-by-impl-hider"); } else { @@ -934,7 +934,7 @@ function hideThemeButtonState() { var relatedDoc; var action = mode; - if (hasClass(toggle.parentNode, "impl") === false) { + if (!hasClass(toggle.parentNode, "impl")) { relatedDoc = toggle.parentNode.nextElementSibling; if (hasClass(relatedDoc, "item-info")) { relatedDoc = relatedDoc.nextElementSibling; @@ -964,11 +964,11 @@ function hideThemeButtonState() { relatedDoc = parentElem; var docblock = relatedDoc.nextElementSibling; - while (hasClass(relatedDoc, "impl-items") === false) { + while (!hasClass(relatedDoc, "impl-items")) { relatedDoc = relatedDoc.nextElementSibling; } - if (!relatedDoc && hasClass(docblock, "docblock") === false) { + if (!relatedDoc && !hasClass(docblock, "docblock")) { return; } @@ -987,7 +987,7 @@ function hideThemeButtonState() { if (action === "show") { removeClass(relatedDoc, "fns-now-collapsed"); // Stability/deprecation/portability information is never hidden. - if (hasClass(docblock, "item-info") === false) { + if (!hasClass(docblock, "item-info")) { removeClass(docblock, "hidden-by-usual-hider"); } onEachLazy(toggle.childNodes, adjustToggle(false, dontApplyBlockRule)); @@ -996,7 +996,7 @@ function hideThemeButtonState() { addClass(relatedDoc, "fns-now-collapsed"); // Stability/deprecation/portability information should be shown even when detailed // info is hidden. - if (hasClass(docblock, "item-info") === false) { + if (!hasClass(docblock, "item-info")) { addClass(docblock, "hidden-by-usual-hider"); } onEachLazy(toggle.childNodes, adjustToggle(true, dontApplyBlockRule)); @@ -1045,7 +1045,7 @@ function hideThemeButtonState() { }); } - if (hideMethodDocs === true) { + if (hideMethodDocs) { onEachLazy(document.getElementsByClassName("method"), function(e) { var toggle = e.parentNode; if (toggle) { @@ -1132,7 +1132,7 @@ function hideThemeButtonState() { if (sidebar_menu) { sidebar_menu.onclick = function() { var sidebar = document.getElementsByClassName("sidebar")[0]; - if (hasClass(sidebar, "mobile") === true) { + if (hasClass(sidebar, "mobile")) { hideSidebar(); } else { showSidebar(); diff --git a/src/librustdoc/html/static/search.js b/src/librustdoc/html/static/search.js index 9fab435de49c8..b4f9d7b374052 100644 --- a/src/librustdoc/html/static/search.js +++ b/src/librustdoc/html/static/search.js @@ -146,23 +146,21 @@ window.initSearch = function(rawSearchIndex) { removeEmptyStringsFromArray(split); - function transformResults(results, isType) { + function transformResults(results) { var out = []; for (var i = 0, len = results.length; i < len; ++i) { if (results[i].id > -1) { var obj = searchIndex[results[i].id]; obj.lev = results[i].lev; - if (isType !== true || obj.type) { - var res = buildHrefAndPath(obj); - obj.displayPath = pathSplitter(res[0]); - obj.fullPath = obj.displayPath + obj.name; - // To be sure than it some items aren't considered as duplicate. - obj.fullPath += "|" + obj.ty; - obj.href = res[1]; - out.push(obj); - if (out.length >= MAX_RESULTS) { - break; - } + var res = buildHrefAndPath(obj); + obj.displayPath = pathSplitter(res[0]); + obj.fullPath = obj.displayPath + obj.name; + // To be sure than it some items aren't considered as duplicate. + obj.fullPath += "|" + obj.ty; + obj.href = res[1]; + out.push(obj); + if (out.length >= MAX_RESULTS) { + break; } } } @@ -266,9 +264,7 @@ window.initSearch = function(rawSearchIndex) { path = result.item.path.toLowerCase(), parent = result.item.parent; - if (isType !== true && - validateResult(name, path, split, parent) === false) - { + if (!isType && !validateResult(name, path, split, parent)) { result.id = -1; } } @@ -352,7 +348,7 @@ window.initSearch = function(rawSearchIndex) { var lev_distance = MAX_LEV_DISTANCE + 1; var len, x, firstGeneric; if (obj[NAME] === val.name) { - if (literalSearch === true) { + if (literalSearch) { if (val.generics && val.generics.length !== 0) { if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length >= val.generics.length) { @@ -373,7 +369,7 @@ window.initSearch = function(rawSearchIndex) { break; } } - if (allFound === true) { + if (allFound) { return true; } } else { @@ -394,7 +390,7 @@ window.initSearch = function(rawSearchIndex) { } } // Names didn't match so let's check if one of the generic types could. - if (literalSearch === true) { + if (literalSearch) { if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) { return obj[GENERICS_DATA].some( function(name) { @@ -429,12 +425,12 @@ window.initSearch = function(rawSearchIndex) { var length = obj.type[INPUTS_DATA].length; for (var i = 0; i < length; i++) { var tmp = obj.type[INPUTS_DATA][i]; - if (typePassesFilter(typeFilter, tmp[1]) === false) { + if (!typePassesFilter(typeFilter, tmp[1])) { continue; } tmp = checkType(tmp, val, literalSearch); - if (literalSearch === true) { - if (tmp === true) { + if (literalSearch) { + if (tmp) { return true; } continue; @@ -445,7 +441,7 @@ window.initSearch = function(rawSearchIndex) { } } } - return literalSearch === true ? false : lev_distance; + return literalSearch ? false : lev_distance; } function checkReturned(obj, val, literalSearch, typeFilter) { @@ -458,12 +454,12 @@ window.initSearch = function(rawSearchIndex) { } for (var x = 0, len = ret.length; x < len; ++x) { var tmp = ret[x]; - if (typePassesFilter(typeFilter, tmp[1]) === false) { + if (!typePassesFilter(typeFilter, tmp[1])) { continue; } tmp = checkType(tmp, val, literalSearch); - if (literalSearch === true) { - if (tmp === true) { + if (literalSearch) { + if (tmp) { return true; } continue; @@ -474,7 +470,7 @@ window.initSearch = function(rawSearchIndex) { } } } - return literalSearch === true ? false : lev_distance; + return literalSearch ? false : lev_distance; } function checkPath(contains, lastElem, ty) { @@ -507,7 +503,7 @@ window.initSearch = function(rawSearchIndex) { } lev_total += lev; } - if (aborted === false) { + if (!aborted) { ret_lev = Math.min(ret_lev, Math.round(lev_total / clength)); } } @@ -634,14 +630,14 @@ window.initSearch = function(rawSearchIndex) { dontValidate: true, }; } - if (in_args === true && results_in_args[fullId] === undefined) { + if (in_args && results_in_args[fullId] === undefined) { results_in_args[fullId] = { id: i, index: -1, dontValidate: true, }; } - if (returned === true && results_returned[fullId] === undefined) { + if (returned && results_returned[fullId] === undefined) { results_returned[fullId] = { id: i, index: -1, @@ -676,7 +672,7 @@ window.initSearch = function(rawSearchIndex) { fullId = ty.id; returned = checkReturned(ty, output, true, NO_TYPE_FILTER); - if (output.name === "*" || returned === true) { + if (output.name === "*" || returned) { in_args = false; var is_module = false; @@ -684,26 +680,26 @@ window.initSearch = function(rawSearchIndex) { is_module = true; } else { var allFound = true; - for (it = 0, len = inputs.length; allFound === true && it < len; it++) { + for (it = 0, len = inputs.length; allFound && it < len; it++) { allFound = checkType(type, inputs[it], true); } in_args = allFound; } - if (in_args === true) { + if (in_args) { results_in_args[fullId] = { id: i, index: -1, dontValidate: true, }; } - if (returned === true) { + if (returned) { results_returned[fullId] = { id: i, index: -1, dontValidate: true, }; } - if (is_module === true) { + if (is_module) { results[fullId] = { id: i, index: -1, @@ -763,10 +759,10 @@ window.initSearch = function(rawSearchIndex) { } } if ((lev = levenshtein(searchWords[j], val)) <= MAX_LEV_DISTANCE) { - if (typePassesFilter(typeFilter, ty.ty) === false) { - lev = MAX_LEV_DISTANCE + 1; - } else { + if (typePassesFilter(typeFilter, ty.ty)) { lev += 1; + } else { + lev = MAX_LEV_DISTANCE + 1; } } in_args = findArg(ty, valGenerics, false, typeFilter); @@ -821,7 +817,7 @@ window.initSearch = function(rawSearchIndex) { var ret = { "in_args": sortResults(results_in_args, true), "returned": sortResults(results_returned, true), - "others": sortResults(results), + "others": sortResults(results, false), }; handleAliases(ret, query, filterCrates); return ret; @@ -1263,7 +1259,7 @@ window.initSearch = function(rawSearchIndex) { if (query.query.length === 0) { return; } - if (forced !== true && query.id === currentResults) { + if (!forced && query.id === currentResults) { if (query.query.length > 0) { searchState.putBackSearch(searchState.input); } diff --git a/src/librustdoc/html/static/source-script.js b/src/librustdoc/html/static/source-script.js index 42b54e4cc1e46..81df541189681 100644 --- a/src/librustdoc/html/static/source-script.js +++ b/src/librustdoc/html/static/source-script.js @@ -44,7 +44,7 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) { if (elem.dirs) { for (i = 0, len = elem.dirs.length; i < len; ++i) { if (createDirEntry(elem.dirs[i], folders, fullPath, currentFile, - hasFoundFile) === true) { + hasFoundFile)) { addClass(name, "expand"); hasFoundFile = true; } @@ -59,8 +59,7 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) { var file = document.createElement("a"); file.innerText = elem.files[i]; file.href = window.rootPath + "src/" + fullPath + elem.files[i] + ".html"; - if (hasFoundFile === false && - currentFile === fullPath + elem.files[i]) { + if (!hasFoundFile && currentFile === fullPath + elem.files[i]) { file.className = "selected"; addClass(name, "expand"); hasFoundFile = true; @@ -72,7 +71,7 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) { children.appendChild(files); parent.appendChild(name); parent.appendChild(children); - return hasFoundFile === true && currentFile.startsWith(fullPath); + return hasFoundFile && currentFile.startsWith(fullPath); } function toggleSidebar() { @@ -116,7 +115,7 @@ function createSidebarToggle() { // This function is called from "source-files.js", generated in `html/render/mod.rs`. // eslint-disable-next-line no-unused-vars function createSourceSidebar() { - if (window.rootPath.endsWith("/") === false) { + if (!window.rootPath.endsWith("/")) { window.rootPath += "/"; } var main = document.getElementById("main"); diff --git a/src/librustdoc/html/static/storage.js b/src/librustdoc/html/static/storage.js index 2ed87fdedaec6..208afd2e732dd 100644 --- a/src/librustdoc/html/static/storage.js +++ b/src/librustdoc/html/static/storage.js @@ -59,15 +59,15 @@ function onEach(arr, func, reversed) { if (arr && arr.length > 0 && func) { var length = arr.length; var i; - if (reversed !== true) { - for (i = 0; i < length; ++i) { - if (func(arr[i]) === true) { + if (reversed) { + for (i = length - 1; i >= 0; --i) { + if (func(arr[i])) { return true; } } } else { - for (i = length - 1; i >= 0; --i) { - if (func(arr[i]) === true) { + for (i = 0; i < length; ++i) { + if (func(arr[i])) { return true; } } @@ -111,7 +111,7 @@ function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) { // If this new value comes from a system setting or from the previously // saved theme, no need to save it. - if (saveTheme === true) { + if (saveTheme) { updateLocalStorage("rustdoc-theme", newTheme); } @@ -131,7 +131,7 @@ function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) { return true; } }); - if (found === true) { + if (found) { styleElem.href = newHref; } } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 169ef015fa88c..5ede3780e87ae 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -594,6 +594,9 @@ fn opts() -> Vec { ) }), unstable("no-run", |o| o.optflag("", "no-run", "Compile doctests without running them")), + unstable("show-type-layout", |o| { + o.optflag("", "show-type-layout", "Include the memory layout of types in the docs") + }), ] } diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.async2.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.async2.txt index dc06a485a8fc1..322f5681b3fd9 100644 --- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.async2.txt +++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.async2.txt @@ -12,7 +12,6 @@ 12| 1| if b { 13| 1| println!("non_async_func println in block"); 14| 1| } - ^0 15| 1|} 16| | 17| | diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.conditions.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.conditions.txt index 2d8a98a5d0c92..656a26597759d 100644 --- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.conditions.txt +++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.conditions.txt @@ -5,7 +5,6 @@ 5| 1| if true { 6| 1| countdown = 10; 7| 1| } - ^0 8| | 9| | const B: u32 = 100; 10| 1| let x = if countdown > 7 { @@ -25,7 +24,6 @@ 24| 1| if true { 25| 1| countdown = 10; 26| 1| } - ^0 27| | 28| 1| if countdown > 7 { 29| 1| countdown -= 4; @@ -44,7 +42,6 @@ 41| 1| if true { 42| 1| countdown = 10; 43| 1| } - ^0 44| | 45| 1| if countdown > 7 { 46| 1| countdown -= 4; @@ -57,14 +54,13 @@ 53| | } else { 54| 0| return; 55| | } - 56| 0| } - 57| | + 56| | } // Note: closing brace shows uncovered (vs. `0` for implicit else) because condition literal + 57| | // `true` was const-evaluated. The compiler knows the `if` block will be executed. 58| | 59| 1| let mut countdown = 0; 60| 1| if true { 61| 1| countdown = 1; 62| 1| } - ^0 63| | 64| 1| let z = if countdown > 7 { ^0 diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.doctest.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.doctest.txt index 7ae0e978808e7..1b6bb9ff8891d 100644 --- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.doctest.txt +++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.doctest.txt @@ -9,7 +9,7 @@ 8| 1|//! assert_eq!(1, 1); 9| |//! } else { 10| |//! // this is not! - 11| 0|//! assert_eq!(1, 2); + 11| |//! assert_eq!(1, 2); 12| |//! } 13| 1|//! ``` 14| |//! @@ -84,7 +84,7 @@ 74| 1| if true { 75| 1| assert_eq!(1, 1); 76| | } else { - 77| 0| assert_eq!(1, 2); + 77| | assert_eq!(1, 2); 78| | } 79| 1|} 80| | diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.drop_trait.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.drop_trait.txt index fe6a9e93cbf71..fab5be41901c9 100644 --- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.drop_trait.txt +++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.drop_trait.txt @@ -19,11 +19,11 @@ 19| 1| if true { 20| 1| println!("Exiting with error..."); 21| 1| return Err(1); - 22| 0| } - 23| 0| - 24| 0| let _ = Firework { strength: 1000 }; - 25| 0| - 26| 0| Ok(()) + 22| | } + 23| | + 24| | let _ = Firework { strength: 1000 }; + 25| | + 26| | Ok(()) 27| 1|} 28| | 29| |// Expected program output: diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.generics.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.generics.txt index 8e8bc0fd18943..7b38ffb87cba8 100644 --- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.generics.txt +++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.generics.txt @@ -52,15 +52,15 @@ 30| 1| if true { 31| 1| println!("Exiting with error..."); 32| 1| return Err(1); - 33| 0| } - 34| 0| - 35| 0| - 36| 0| - 37| 0| - 38| 0| - 39| 0| let _ = Firework { strength: 1000 }; - 40| 0| - 41| 0| Ok(()) + 33| | } // The remaining lines below have no coverage because `if true` (with the constant literal + 34| | // `true`) is guaranteed to execute the `then` block, which is also guaranteed to `return`. + 35| | // Thankfully, in the normal case, conditions are not guaranteed ahead of time, and as shown + 36| | // in other tests, the lines below would have coverage (which would show they had `0` + 37| | // executions, assuming the condition still evaluated to `true`). + 38| | + 39| | let _ = Firework { strength: 1000 }; + 40| | + 41| | Ok(()) 42| 1|} 43| | 44| |// Expected program output: diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.loops_branches.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.loops_branches.txt index 5d572db7cc60d..81d5c7d90346d 100644 --- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.loops_branches.txt +++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.loops_branches.txt @@ -9,23 +9,23 @@ 9| 1| fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 10| 1| if true { 11| 1| if false { - 12| 0| while true { - 13| 0| } + 12| | while true { + 13| | } 14| 1| } - 15| 1| write!(f, "cool")?; - ^0 - 16| 0| } else { - 17| 0| } + 15| 1| write!(f, "error")?; + ^0 + 16| | } else { + 17| | } 18| | 19| 10| for i in 0..10 { 20| 10| if true { 21| 10| if false { - 22| 0| while true {} + 22| | while true {} 23| 10| } - 24| 10| write!(f, "cool")?; - ^0 - 25| 0| } else { - 26| 0| } + 24| 10| write!(f, "error")?; + ^0 + 25| | } else { + 26| | } 27| | } 28| 1| Ok(()) 29| 1| } @@ -36,21 +36,21 @@ 34| |impl std::fmt::Display for DisplayTest { 35| 1| fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 36| 1| if false { - 37| 0| } else { + 37| | } else { 38| 1| if false { - 39| 0| while true {} + 39| | while true {} 40| 1| } - 41| 1| write!(f, "cool")?; - ^0 + 41| 1| write!(f, "error")?; + ^0 42| | } 43| 10| for i in 0..10 { 44| 10| if false { - 45| 0| } else { + 45| | } else { 46| 10| if false { - 47| 0| while true {} + 47| | while true {} 48| 10| } - 49| 10| write!(f, "cool")?; - ^0 + 49| 10| write!(f, "error")?; + ^0 50| | } 51| | } 52| 1| Ok(()) diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.tight_inf_loop.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.tight_inf_loop.txt index 2d4c57f451a2d..5adeef7d0850b 100644 --- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.tight_inf_loop.txt +++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.tight_inf_loop.txt @@ -1,6 +1,6 @@ 1| 1|fn main() { 2| 1| if false { - 3| 0| loop {} + 3| | loop {} 4| 1| } 5| 1|} diff --git a/src/test/run-make-fulldeps/coverage/conditions.rs b/src/test/run-make-fulldeps/coverage/conditions.rs index 057599d1b471a..8a2a0b53e5862 100644 --- a/src/test/run-make-fulldeps/coverage/conditions.rs +++ b/src/test/run-make-fulldeps/coverage/conditions.rs @@ -53,8 +53,8 @@ fn main() { } else { return; } - } - + } // Note: closing brace shows uncovered (vs. `0` for implicit else) because condition literal + // `true` was const-evaluated. The compiler knows the `if` block will be executed. let mut countdown = 0; if true { diff --git a/src/test/run-make-fulldeps/coverage/generics.rs b/src/test/run-make-fulldeps/coverage/generics.rs index 18b38868496d4..cbeda35d3b8cf 100644 --- a/src/test/run-make-fulldeps/coverage/generics.rs +++ b/src/test/run-make-fulldeps/coverage/generics.rs @@ -30,11 +30,11 @@ fn main() -> Result<(),u8> { if true { println!("Exiting with error..."); return Err(1); - } - - - - + } // The remaining lines below have no coverage because `if true` (with the constant literal + // `true`) is guaranteed to execute the `then` block, which is also guaranteed to `return`. + // Thankfully, in the normal case, conditions are not guaranteed ahead of time, and as shown + // in other tests, the lines below would have coverage (which would show they had `0` + // executions, assuming the condition still evaluated to `true`). let _ = Firework { strength: 1000 }; diff --git a/src/test/run-make-fulldeps/coverage/loops_branches.rs b/src/test/run-make-fulldeps/coverage/loops_branches.rs index 7116ce47f4b9d..4d9bbad3367f6 100644 --- a/src/test/run-make-fulldeps/coverage/loops_branches.rs +++ b/src/test/run-make-fulldeps/coverage/loops_branches.rs @@ -12,7 +12,7 @@ impl std::fmt::Debug for DebugTest { while true { } } - write!(f, "cool")?; + write!(f, "error")?; } else { } @@ -21,7 +21,7 @@ impl std::fmt::Debug for DebugTest { if false { while true {} } - write!(f, "cool")?; + write!(f, "error")?; } else { } } @@ -38,7 +38,7 @@ impl std::fmt::Display for DisplayTest { if false { while true {} } - write!(f, "cool")?; + write!(f, "error")?; } for i in 0..10 { if false { @@ -46,7 +46,7 @@ impl std::fmt::Display for DisplayTest { if false { while true {} } - write!(f, "cool")?; + write!(f, "error")?; } } Ok(()) diff --git a/src/test/rustdoc-gui/basic-code.goml b/src/test/rustdoc-gui/basic-code.goml index 8da465662547a..d014ed60eb039 100644 --- a/src/test/rustdoc-gui/basic-code.goml +++ b/src/test/rustdoc-gui/basic-code.goml @@ -1,3 +1,3 @@ -goto: file://|DOC_PATH|/index.html +goto: file://|DOC_PATH|/test_docs/index.html click: ".srclink" assert: (".line-numbers", 1) diff --git a/src/test/rustdoc-gui/basic.goml b/src/test/rustdoc-gui/basic.goml index ed23300860b70..44fcec3393744 100644 --- a/src/test/rustdoc-gui/basic.goml +++ b/src/test/rustdoc-gui/basic.goml @@ -1,4 +1,4 @@ -goto: file://|DOC_PATH|/index.html +goto: file://|DOC_PATH|/test_docs/index.html assert: ("#functions") goto: ./struct.Foo.html assert: ("div.type-decl") diff --git a/src/test/rustdoc-gui/check_info_sign_position.goml b/src/test/rustdoc-gui/check_info_sign_position.goml index 9aa72a3ad53e7..d64ee0261370c 100644 --- a/src/test/rustdoc-gui/check_info_sign_position.goml +++ b/src/test/rustdoc-gui/check_info_sign_position.goml @@ -1,4 +1,4 @@ -goto: file://|DOC_PATH|/index.html +goto: file://|DOC_PATH|/test_docs/index.html goto: ./fn.check_list_code_block.html // If the codeblock is the first element of the docblock, the information tooltip must have // have some top margin to avoid going over the toggle (the "[+]"). diff --git a/src/test/rustdoc-gui/code-sidebar-toggle.goml b/src/test/rustdoc-gui/code-sidebar-toggle.goml index 69fc860244b7b..7e7003d4340a3 100644 --- a/src/test/rustdoc-gui/code-sidebar-toggle.goml +++ b/src/test/rustdoc-gui/code-sidebar-toggle.goml @@ -1,4 +1,4 @@ -goto: file://|DOC_PATH|/index.html +goto: file://|DOC_PATH|/test_docs/index.html click: ".srclink" click: "#sidebar-toggle" wait-for: 500 diff --git a/src/test/rustdoc-gui/hash-item-expansion.goml b/src/test/rustdoc-gui/hash-item-expansion.goml index d736d15d184a3..1248d11200e6c 100644 --- a/src/test/rustdoc-gui/hash-item-expansion.goml +++ b/src/test/rustdoc-gui/hash-item-expansion.goml @@ -1,5 +1,5 @@ // This test ensures that the element corresponding to the hash is displayed. -goto: file://|DOC_PATH|/struct.Foo.html#method.borrow +goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.borrow // In the blanket implementations list, "Borrow" is the second one, hence the ":nth(2)". assert: ("#blanket-implementations-list > details:nth-child(2)", "open", "") // Please note the "\" below is needed because otherwise ".borrow" would be interpreted as diff --git a/src/test/rustdoc-gui/impl-default-expansion.goml b/src/test/rustdoc-gui/impl-default-expansion.goml index 686d98f9736e4..3f1e7ec4a789c 100644 --- a/src/test/rustdoc-gui/impl-default-expansion.goml +++ b/src/test/rustdoc-gui/impl-default-expansion.goml @@ -1,3 +1,3 @@ // This test ensures that the impl blocks are open by default. -goto: file://|DOC_PATH|/struct.Foo.html +goto: file://|DOC_PATH|/test_docs/struct.Foo.html assert: ("#main > details.implementors-toggle", "open", "") diff --git a/src/test/rustdoc-gui/list_code_block.goml b/src/test/rustdoc-gui/list_code_block.goml index 6f2465a5587f2..7d3490e9d9410 100644 --- a/src/test/rustdoc-gui/list_code_block.goml +++ b/src/test/rustdoc-gui/list_code_block.goml @@ -1,3 +1,3 @@ -goto: file://|DOC_PATH|/index.html +goto: file://|DOC_PATH|/test_docs/index.html goto: ./fn.check_list_code_block.html assert: ("pre.rust.fn") diff --git a/src/test/rustdoc-gui/search-input-mobile.goml b/src/test/rustdoc-gui/search-input-mobile.goml index 3eec3459a6393..5c95db70aecdd 100644 --- a/src/test/rustdoc-gui/search-input-mobile.goml +++ b/src/test/rustdoc-gui/search-input-mobile.goml @@ -1,6 +1,6 @@ // Test to ensure that you can click on the search input, whatever the width. // The PR which fixed it is: https://github.com/rust-lang/rust/pull/81592 -goto: file://|DOC_PATH|/index.html +goto: file://|DOC_PATH|/test_docs/index.html size: (463, 700) // We first check that the search input isn't already focused. assert-false: ("input.search-input:focus") diff --git a/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml b/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml index a4df102d245be..c828c72e910d5 100644 --- a/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml +++ b/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml @@ -1,11 +1,11 @@ -goto: file://|DOC_PATH|/index.html +goto: file://|DOC_PATH|/test_docs/index.html write: (".search-input", "Foo") // Waiting for the search results to appear... wait-for: "#titles" assert: ("#titles > button:nth-of-type(1)", "class", "selected") // To go back to the original "state" -goto: file://|DOC_PATH|/index.html +goto: file://|DOC_PATH|/test_docs/index.html write: (".search-input", "-> String") // Waiting for the search results to appear... wait-for: "#titles" @@ -13,7 +13,7 @@ wait-for: "#titles" assert: ("#titles > button:nth-of-type(3)", "class", "selected") // To go back to the original "state" -goto: file://|DOC_PATH|/index.html +goto: file://|DOC_PATH|/test_docs/index.html write: (".search-input", "-> Something") // Waiting for the search results to appear... wait-for: "#titles" diff --git a/src/test/rustdoc-gui/shortcuts.goml b/src/test/rustdoc-gui/shortcuts.goml index c35b48f57f4d2..884c38d85fbdb 100644 --- a/src/test/rustdoc-gui/shortcuts.goml +++ b/src/test/rustdoc-gui/shortcuts.goml @@ -1,5 +1,5 @@ // Check that the various shortcuts are working. -goto: file://|DOC_PATH|/index.html +goto: file://|DOC_PATH|/test_docs/index.html // We first check that the search input isn't already focused. assert-false: "input.search-input:focus" press-key: "s" diff --git a/src/test/rustdoc-gui/source-code-page.goml b/src/test/rustdoc-gui/source-code-page.goml index f11c41e8bd552..ff33a541a1801 100644 --- a/src/test/rustdoc-gui/source-code-page.goml +++ b/src/test/rustdoc-gui/source-code-page.goml @@ -1,11 +1,11 @@ -goto: file://|DOC_PATH|/../src/test_docs/lib.rs.html +goto: file://|DOC_PATH|/src/test_docs/lib.rs.html // Check that we can click on the line number. click: (40, 224) // This is the position of the span for line 4. // Unfortunately, "#4" isn't a valid query selector, so we have to go around that limitation // by instead getting the nth span. assert: (".line-numbers > span:nth-child(4)", "class", "line-highlighted") // We now check that the good spans are highlighted -goto: file://|DOC_PATH|/../src/test_docs/lib.rs.html#4-6 +goto: file://|DOC_PATH|/src/test_docs/lib.rs.html#4-6 assert-false: (".line-numbers > span:nth-child(3)", "class", "line-highlighted") assert: (".line-numbers > span:nth-child(4)", "class", "line-highlighted") assert: (".line-numbers > span:nth-child(5)", "class", "line-highlighted") diff --git a/src/test/rustdoc-gui/lib.rs b/src/test/rustdoc-gui/src/lib.rs similarity index 100% rename from src/test/rustdoc-gui/lib.rs rename to src/test/rustdoc-gui/src/lib.rs diff --git a/src/test/rustdoc-gui/theme-change.goml b/src/test/rustdoc-gui/theme-change.goml index 5bd65f61f4905..bc9063edd1e7a 100644 --- a/src/test/rustdoc-gui/theme-change.goml +++ b/src/test/rustdoc-gui/theme-change.goml @@ -1,4 +1,4 @@ -goto: file://|DOC_PATH|/index.html +goto: file://|DOC_PATH|/test_docs/index.html click: "#theme-picker" click: "#theme-choices > button:first-child" wait-for: 500 diff --git a/src/test/rustdoc-gui/toggle-docs.goml b/src/test/rustdoc-gui/toggle-docs.goml index 1ded33f659d3c..062bc7d51e542 100644 --- a/src/test/rustdoc-gui/toggle-docs.goml +++ b/src/test/rustdoc-gui/toggle-docs.goml @@ -1,7 +1,10 @@ -goto: file://|DOC_PATH|/index.html +goto: file://|DOC_PATH|/test_docs/index.html +assert: ("#main > details.top-doc", "open", "") click: "#toggle-all-docs" -wait-for: 5000 -assert: ("#main > div.docblock.hidden-by-usual-hider") +wait-for: 1000 +// This is now collapsed so there shouldn't be the "open" attribute on details. +assert-false: ("#main > details.top-doc", "open", "") click: "#toggle-all-docs" -wait-for: 5000 -assert: ("#main > div.docblock.hidden-by-usual-hider", 0) +wait-for: 1000 +// Not collapsed anymore so the "open" attribute should be back. +assert: ("#main > details.top-doc", "open", "") diff --git a/src/test/rustdoc-gui/trait-sidebar-item-order.goml b/src/test/rustdoc-gui/trait-sidebar-item-order.goml index 914486e1c281d..2e9f85336ecd8 100644 --- a/src/test/rustdoc-gui/trait-sidebar-item-order.goml +++ b/src/test/rustdoc-gui/trait-sidebar-item-order.goml @@ -1,4 +1,4 @@ -goto: file://|DOC_PATH|/trait.AnotherOne.html +goto: file://|DOC_PATH|/test_docs/trait.AnotherOne.html assert: (".sidebar-links a:nth-of-type(1)", "another") assert: (".sidebar-links a:nth-of-type(2)", "func1") assert: (".sidebar-links a:nth-of-type(3)", "func2") diff --git a/src/test/rustdoc/type-layout-flag-required.rs b/src/test/rustdoc/type-layout-flag-required.rs new file mode 100644 index 0000000000000..a01fbd229508b --- /dev/null +++ b/src/test/rustdoc/type-layout-flag-required.rs @@ -0,0 +1,4 @@ +// Tests that `--show-type-layout` is required in order to show layout info. + +// @!has type_layout_flag_required/struct.Foo.html 'Size: ' +pub struct Foo(usize); diff --git a/src/test/rustdoc/type-layout.rs b/src/test/rustdoc/type-layout.rs new file mode 100644 index 0000000000000..272911de6815b --- /dev/null +++ b/src/test/rustdoc/type-layout.rs @@ -0,0 +1,54 @@ +// compile-flags: --show-type-layout -Z unstable-options + +// @has type_layout/struct.Foo.html 'Size: ' +// @has - ' bytes' +pub struct Foo { + pub a: usize, + b: Vec, +} + +// @has type_layout/enum.Bar.html 'Size: ' +// @has - ' bytes' +pub enum Bar<'a> { + A(String), + B(&'a str, (std::collections::HashMap, Foo)), +} + +// @has type_layout/union.Baz.html 'Size: ' +// @has - ' bytes' +pub union Baz { + a: &'static str, + b: usize, + c: &'static [u8], +} + +// @has type_layout/struct.X.html 'Size: ' +// @has - ' bytes' +pub struct X(usize); + +// @has type_layout/struct.Y.html 'Size: ' +// @has - '1 byte' +// @!has - ' bytes' +pub struct Y(u8); + +// @has type_layout/struct.Z.html 'Size: ' +// @has - '0 bytes' +pub struct Z; + +// We can't compute layout for generic types. +// @has type_layout/struct.Generic.html 'Unable to compute type layout, possibly due to this type having generic parameters' +// @!has - 'Size: ' +pub struct Generic(T); + +// We *can*, however, compute layout for types that are only generic over lifetimes, +// because lifetimes are a type-system construct. +// @has type_layout/struct.GenericLifetimes.html 'Size: ' +// @has - ' bytes' +pub struct GenericLifetimes<'a>(&'a str); + +// @has type_layout/struct.Unsized.html 'Size: ' +// @has - '(unsized)' +pub struct Unsized([u8]); + +// @!has type_layout/trait.MyTrait.html 'Size: ' +pub trait MyTrait {} diff --git a/src/test/ui/deprecation/deprecation-lint.stderr b/src/test/ui/deprecation/deprecation-lint.stderr index 959cf93bac053..3699a939e2788 100644 --- a/src/test/ui/deprecation/deprecation-lint.stderr +++ b/src/test/ui/deprecation/deprecation-lint.stderr @@ -359,16 +359,16 @@ LL | foo.method_deprecated(); | ^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated`: text - --> $DIR/deprecation-lint.rs:18:9 + --> $DIR/deprecation-lint.rs:18:14 | LL | Foo::method_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated`: text - --> $DIR/deprecation-lint.rs:19:9 + --> $DIR/deprecation-lint.rs:19:16 | LL | ::method_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text --> $DIR/deprecation-lint.rs:20:13 @@ -377,10 +377,10 @@ LL | foo.trait_deprecated(); | ^^^^^^^^^^^^^^^^ error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text - --> $DIR/deprecation-lint.rs:22:9 + --> $DIR/deprecation-lint.rs:22:16 | LL | ::trait_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ error: use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated_text`: text --> $DIR/deprecation-lint.rs:26:13 @@ -389,16 +389,16 @@ LL | ... foo.method_deprecated_text(); | ^^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated_text`: text - --> $DIR/deprecation-lint.rs:27:9 + --> $DIR/deprecation-lint.rs:27:14 | LL | ... Foo::method_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated_text`: text - --> $DIR/deprecation-lint.rs:28:9 + --> $DIR/deprecation-lint.rs:28:16 | LL | ... ::method_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text --> $DIR/deprecation-lint.rs:29:13 @@ -407,10 +407,10 @@ LL | foo.trait_deprecated_text(); | ^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text - --> $DIR/deprecation-lint.rs:31:9 + --> $DIR/deprecation-lint.rs:31:16 | LL | ... ::trait_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated field `deprecation_lint::DeprecatedStruct::i`: text --> $DIR/deprecation-lint.rs:35:13 @@ -431,10 +431,10 @@ LL | foo.trait_deprecated(); | ^^^^^^^^^^^^^^^^ error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text - --> $DIR/deprecation-lint.rs:66:9 + --> $DIR/deprecation-lint.rs:66:16 | LL | ::trait_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text --> $DIR/deprecation-lint.rs:68:13 @@ -443,10 +443,10 @@ LL | foo.trait_deprecated_text(); | ^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text - --> $DIR/deprecation-lint.rs:70:9 + --> $DIR/deprecation-lint.rs:70:16 | LL | ... ::trait_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text --> $DIR/deprecation-lint.rs:75:13 @@ -551,16 +551,16 @@ LL | foo.method_deprecated(); | ^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `this_crate::MethodTester::method_deprecated`: text - --> $DIR/deprecation-lint.rs:247:9 + --> $DIR/deprecation-lint.rs:247:14 | LL | Foo::method_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `this_crate::MethodTester::method_deprecated`: text - --> $DIR/deprecation-lint.rs:248:9 + --> $DIR/deprecation-lint.rs:248:16 | LL | ::method_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text --> $DIR/deprecation-lint.rs:249:13 @@ -569,10 +569,10 @@ LL | foo.trait_deprecated(); | ^^^^^^^^^^^^^^^^ error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text - --> $DIR/deprecation-lint.rs:251:9 + --> $DIR/deprecation-lint.rs:251:16 | LL | ::trait_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ error: use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text --> $DIR/deprecation-lint.rs:255:13 @@ -581,16 +581,16 @@ LL | ... foo.method_deprecated_text(); | ^^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text - --> $DIR/deprecation-lint.rs:256:9 + --> $DIR/deprecation-lint.rs:256:14 | LL | ... Foo::method_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text - --> $DIR/deprecation-lint.rs:257:9 + --> $DIR/deprecation-lint.rs:257:16 | LL | ... ::method_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text --> $DIR/deprecation-lint.rs:258:13 @@ -599,10 +599,10 @@ LL | foo.trait_deprecated_text(); | ^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text - --> $DIR/deprecation-lint.rs:260:9 + --> $DIR/deprecation-lint.rs:260:16 | LL | ::trait_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated field `this_crate::DeprecatedStruct::i`: text --> $DIR/deprecation-lint.rs:269:13 @@ -623,10 +623,10 @@ LL | foo.trait_deprecated(); | ^^^^^^^^^^^^^^^^ error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text - --> $DIR/deprecation-lint.rs:293:9 + --> $DIR/deprecation-lint.rs:293:16 | LL | ::trait_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text --> $DIR/deprecation-lint.rs:295:13 @@ -635,10 +635,10 @@ LL | foo.trait_deprecated_text(); | ^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text - --> $DIR/deprecation-lint.rs:297:9 + --> $DIR/deprecation-lint.rs:297:16 | LL | ::trait_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text --> $DIR/deprecation-lint.rs:302:13 diff --git a/src/test/ui/deprecation/issue-84637-deprecated-associated-function.fixed b/src/test/ui/deprecation/issue-84637-deprecated-associated-function.fixed new file mode 100644 index 0000000000000..99a2b09614fd9 --- /dev/null +++ b/src/test/ui/deprecation/issue-84637-deprecated-associated-function.fixed @@ -0,0 +1,9 @@ +// run-rustfix + +#![deny(deprecated)] + +fn main() { + let _foo = str::trim_start(" aoeu"); //~ ERROR use of deprecated associated function `core::str::::trim_left`: superseded by `trim_start` [deprecated] + + let _bar = " aoeu".trim_start(); //~ ERROR use of deprecated associated function `core::str::::trim_left`: superseded by `trim_start` [deprecated] +} diff --git a/src/test/ui/deprecation/issue-84637-deprecated-associated-function.rs b/src/test/ui/deprecation/issue-84637-deprecated-associated-function.rs new file mode 100644 index 0000000000000..62bf84aa3ea28 --- /dev/null +++ b/src/test/ui/deprecation/issue-84637-deprecated-associated-function.rs @@ -0,0 +1,9 @@ +// run-rustfix + +#![deny(deprecated)] + +fn main() { + let _foo = str::trim_left(" aoeu"); //~ ERROR use of deprecated associated function `core::str::::trim_left`: superseded by `trim_start` [deprecated] + + let _bar = " aoeu".trim_left(); //~ ERROR use of deprecated associated function `core::str::::trim_left`: superseded by `trim_start` [deprecated] +} diff --git a/src/test/ui/deprecation/issue-84637-deprecated-associated-function.stderr b/src/test/ui/deprecation/issue-84637-deprecated-associated-function.stderr new file mode 100644 index 0000000000000..e65d21bb09bbe --- /dev/null +++ b/src/test/ui/deprecation/issue-84637-deprecated-associated-function.stderr @@ -0,0 +1,20 @@ +error: use of deprecated associated function `core::str::::trim_left`: superseded by `trim_start` + --> $DIR/issue-84637-deprecated-associated-function.rs:6:21 + | +LL | let _foo = str::trim_left(" aoeu"); + | ^^^^^^^^^ help: replace the use of the deprecated associated function: `trim_start` + | +note: the lint level is defined here + --> $DIR/issue-84637-deprecated-associated-function.rs:3:9 + | +LL | #![deny(deprecated)] + | ^^^^^^^^^^ + +error: use of deprecated associated function `core::str::::trim_left`: superseded by `trim_start` + --> $DIR/issue-84637-deprecated-associated-function.rs:8:26 + | +LL | let _bar = " aoeu".trim_left(); + | ^^^^^^^^^ help: replace the use of the deprecated associated function: `trim_start` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/lint/lint-stability-deprecated.stderr b/src/test/ui/lint/lint-stability-deprecated.stderr index 47dc8e4a63c07..94fc1a7b46dba 100644 --- a/src/test/ui/lint/lint-stability-deprecated.stderr +++ b/src/test/ui/lint/lint-stability-deprecated.stderr @@ -335,16 +335,16 @@ LL | foo.method_deprecated(); | ^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::MethodTester::method_deprecated`: text - --> $DIR/lint-stability-deprecated.rs:26:9 + --> $DIR/lint-stability-deprecated.rs:26:14 | LL | Foo::method_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::MethodTester::method_deprecated`: text - --> $DIR/lint-stability-deprecated.rs:27:9 + --> $DIR/lint-stability-deprecated.rs:27:16 | LL | ::method_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated`: text --> $DIR/lint-stability-deprecated.rs:28:13 @@ -353,10 +353,10 @@ LL | foo.trait_deprecated(); | ^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated`: text - --> $DIR/lint-stability-deprecated.rs:30:9 + --> $DIR/lint-stability-deprecated.rs:30:16 | LL | ::trait_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::MethodTester::method_deprecated_text`: text --> $DIR/lint-stability-deprecated.rs:34:13 @@ -365,16 +365,16 @@ LL | ... foo.method_deprecated_text(); | ^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::MethodTester::method_deprecated_text`: text - --> $DIR/lint-stability-deprecated.rs:35:9 + --> $DIR/lint-stability-deprecated.rs:35:14 | LL | ... Foo::method_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::MethodTester::method_deprecated_text`: text - --> $DIR/lint-stability-deprecated.rs:36:9 + --> $DIR/lint-stability-deprecated.rs:36:16 | LL | ... ::method_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated_text`: text --> $DIR/lint-stability-deprecated.rs:37:13 @@ -383,10 +383,10 @@ LL | foo.trait_deprecated_text(); | ^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated_text`: text - --> $DIR/lint-stability-deprecated.rs:39:9 + --> $DIR/lint-stability-deprecated.rs:39:16 | LL | ... ::trait_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::MethodTester::method_deprecated_unstable`: text --> $DIR/lint-stability-deprecated.rs:43:13 @@ -395,16 +395,16 @@ LL | ... foo.method_deprecated_unstable(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::MethodTester::method_deprecated_unstable`: text - --> $DIR/lint-stability-deprecated.rs:44:9 + --> $DIR/lint-stability-deprecated.rs:44:14 | LL | ... Foo::method_deprecated_unstable(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::MethodTester::method_deprecated_unstable`: text - --> $DIR/lint-stability-deprecated.rs:45:9 + --> $DIR/lint-stability-deprecated.rs:45:16 | LL | ... ::method_deprecated_unstable(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated_unstable`: text --> $DIR/lint-stability-deprecated.rs:46:13 @@ -413,10 +413,10 @@ LL | foo.trait_deprecated_unstable(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated_unstable`: text - --> $DIR/lint-stability-deprecated.rs:48:9 + --> $DIR/lint-stability-deprecated.rs:48:16 | LL | ... ::trait_deprecated_unstable(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::MethodTester::method_deprecated_unstable_text`: text --> $DIR/lint-stability-deprecated.rs:52:13 @@ -425,16 +425,16 @@ LL | ... foo.method_deprecated_unstable_text(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::MethodTester::method_deprecated_unstable_text`: text - --> $DIR/lint-stability-deprecated.rs:53:9 + --> $DIR/lint-stability-deprecated.rs:53:14 | LL | ... Foo::method_deprecated_unstable_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::MethodTester::method_deprecated_unstable_text`: text - --> $DIR/lint-stability-deprecated.rs:54:9 + --> $DIR/lint-stability-deprecated.rs:54:16 | LL | ... ::method_deprecated_unstable_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated_unstable_text`: text --> $DIR/lint-stability-deprecated.rs:55:13 @@ -443,10 +443,10 @@ LL | ... foo.trait_deprecated_unstable_text(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated_unstable_text`: text - --> $DIR/lint-stability-deprecated.rs:57:9 + --> $DIR/lint-stability-deprecated.rs:57:16 | LL | ... ::trait_deprecated_unstable_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated field `lint_stability::DeprecatedStruct::i`: text --> $DIR/lint-stability-deprecated.rs:109:13 @@ -467,10 +467,10 @@ LL | foo.trait_deprecated(); | ^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated`: text - --> $DIR/lint-stability-deprecated.rs:146:9 + --> $DIR/lint-stability-deprecated.rs:146:16 | LL | ::trait_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated_text`: text --> $DIR/lint-stability-deprecated.rs:148:13 @@ -479,10 +479,10 @@ LL | foo.trait_deprecated_text(); | ^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated_text`: text - --> $DIR/lint-stability-deprecated.rs:150:9 + --> $DIR/lint-stability-deprecated.rs:150:16 | LL | ... ::trait_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated_unstable`: text --> $DIR/lint-stability-deprecated.rs:152:13 @@ -491,10 +491,10 @@ LL | foo.trait_deprecated_unstable(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated_unstable`: text - --> $DIR/lint-stability-deprecated.rs:154:9 + --> $DIR/lint-stability-deprecated.rs:154:16 | LL | ... ::trait_deprecated_unstable(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated_unstable_text`: text --> $DIR/lint-stability-deprecated.rs:156:13 @@ -503,10 +503,10 @@ LL | ... foo.trait_deprecated_unstable_text(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated_unstable_text`: text - --> $DIR/lint-stability-deprecated.rs:158:9 + --> $DIR/lint-stability-deprecated.rs:158:16 | LL | ... ::trait_deprecated_unstable_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `lint_stability::Trait::trait_deprecated`: text --> $DIR/lint-stability-deprecated.rs:175:13 @@ -539,16 +539,16 @@ LL | foo.method_deprecated(); | ^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `this_crate::MethodTester::method_deprecated`: text - --> $DIR/lint-stability-deprecated.rs:332:9 + --> $DIR/lint-stability-deprecated.rs:332:14 | LL | Foo::method_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `this_crate::MethodTester::method_deprecated`: text - --> $DIR/lint-stability-deprecated.rs:333:9 + --> $DIR/lint-stability-deprecated.rs:333:16 | LL | ::method_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text --> $DIR/lint-stability-deprecated.rs:334:13 @@ -557,10 +557,10 @@ LL | foo.trait_deprecated(); | ^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text - --> $DIR/lint-stability-deprecated.rs:336:9 + --> $DIR/lint-stability-deprecated.rs:336:16 | LL | ::trait_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text --> $DIR/lint-stability-deprecated.rs:340:13 @@ -569,16 +569,16 @@ LL | ... foo.method_deprecated_text(); | ^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text - --> $DIR/lint-stability-deprecated.rs:341:9 + --> $DIR/lint-stability-deprecated.rs:341:14 | LL | ... Foo::method_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text - --> $DIR/lint-stability-deprecated.rs:342:9 + --> $DIR/lint-stability-deprecated.rs:342:16 | LL | ... ::method_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text --> $DIR/lint-stability-deprecated.rs:343:13 @@ -587,10 +587,10 @@ LL | foo.trait_deprecated_text(); | ^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text - --> $DIR/lint-stability-deprecated.rs:345:9 + --> $DIR/lint-stability-deprecated.rs:345:16 | LL | ::trait_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated field `this_crate::DeprecatedStruct::i`: text --> $DIR/lint-stability-deprecated.rs:386:13 @@ -605,10 +605,10 @@ LL | foo.trait_deprecated(); | ^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text - --> $DIR/lint-stability-deprecated.rs:407:9 + --> $DIR/lint-stability-deprecated.rs:407:16 | LL | ::trait_deprecated(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text --> $DIR/lint-stability-deprecated.rs:409:13 @@ -617,10 +617,10 @@ LL | foo.trait_deprecated_text(); | ^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text - --> $DIR/lint-stability-deprecated.rs:411:9 + --> $DIR/lint-stability-deprecated.rs:411:16 | LL | ::trait_deprecated_text(&foo); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text --> $DIR/lint-stability-deprecated.rs:428:13 diff --git a/src/test/ui/mismatched_types/issue-84976.rs b/src/test/ui/mismatched_types/issue-84976.rs new file mode 100644 index 0000000000000..db6fe0b45dcd3 --- /dev/null +++ b/src/test/ui/mismatched_types/issue-84976.rs @@ -0,0 +1,25 @@ +/* Checks whether primitive type names are formatted correctly in the + * error messages about mismatched types (#84976). + */ + +fn foo(length: &u32) -> i32 { + 0 +} + +fn bar(length: &f32) -> f64 { + 0.0 +} + +fn main() { + let mut length = 0; + length = { foo(&length) }; + //~^ ERROR mismatched types [E0308] + length = foo(&length); + //~^ ERROR mismatched types [E0308] + + let mut float_length = 0.0; + float_length = { bar(&float_length) }; + //~^ ERROR mismatched types [E0308] + float_length = bar(&float_length); + //~^ ERROR mismatched types [E0308] +} diff --git a/src/test/ui/mismatched_types/issue-84976.stderr b/src/test/ui/mismatched_types/issue-84976.stderr new file mode 100644 index 0000000000000..0c27e17294131 --- /dev/null +++ b/src/test/ui/mismatched_types/issue-84976.stderr @@ -0,0 +1,27 @@ +error[E0308]: mismatched types + --> $DIR/issue-84976.rs:15:16 + | +LL | length = { foo(&length) }; + | ^^^^^^^^^^^^ expected `u32`, found `i32` + +error[E0308]: mismatched types + --> $DIR/issue-84976.rs:17:14 + | +LL | length = foo(&length); + | ^^^^^^^^^^^^ expected `u32`, found `i32` + +error[E0308]: mismatched types + --> $DIR/issue-84976.rs:21:22 + | +LL | float_length = { bar(&float_length) }; + | ^^^^^^^^^^^^^^^^^^ expected `f32`, found `f64` + +error[E0308]: mismatched types + --> $DIR/issue-84976.rs:23:20 + | +LL | float_length = bar(&float_length); + | ^^^^^^^^^^^^^^^^^^ expected `f32`, found `f64` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0308`.