diff --git a/compiler/rustc_const_eval/src/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/check_consts/qualifs.rs index e1cab9af046be..0410521034b6b 100644 --- a/compiler/rustc_const_eval/src/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/check_consts/qualifs.rs @@ -9,7 +9,7 @@ use rustc_errors::ErrorGuaranteed; use rustc_hir::LangItem; use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::mir::*; -use rustc_middle::ty::{self, AdtDef, Ty}; +use rustc_middle::ty::{self, AdtDef, Ty, TypingMode}; use rustc_middle::{bug, mir}; use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt}; use tracing::instrument; @@ -100,13 +100,14 @@ impl Qualif for HasMutInterior { // Instead we invoke an obligation context manually, and provide the opaque type inference settings // that allow the trait solver to just error out instead of cycling. let freeze_def_id = cx.tcx.require_lang_item(LangItem::Freeze, cx.body.span); - // FIXME(#132279): Once we've got a typing mode which reveals opaque types using the HIR - // typeck results without causing query cycles, we should use this here instead of defining - // opaque types. - let typing_env = ty::TypingEnv::new( - cx.typing_env.param_env, - ty::TypingMode::analysis_in_body(cx.tcx, cx.body.source.def_id().expect_local()), - ); + let did = cx.body.source.def_id().expect_local(); + + let typing_env = if cx.tcx.use_typing_mode_borrowck() { + cx.typing_env + } else { + ty::TypingEnv::new(cx.typing_env.param_env, TypingMode::analysis_in_body(cx.tcx, did)) + }; + let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(typing_env); let ocx = ObligationCtxt::new(&infcx); let obligation = Obligation::new( diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index b802c3b2e8d40..3c70d03aed0d6 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -320,6 +320,35 @@ pub struct InferCtxt<'tcx> { pub obligation_inspector: Cell>>, } +impl<'tcx> Drop for InferCtxt<'tcx> { + fn drop(&mut self) { + let mut inner = self.inner.borrow_mut(); + let opaque_type_storage = &mut inner.opaque_type_storage; + + // No need for the drop bomb when we're in TypingMode::Borrowck, and the InferCtxt doesn't consider regions. + // This is okay since in `Borrowck`, the only reason we care about opaques is in relation to regions. + // In some places *after* typeck, like in lints we use `TypingMode::Borrowck` + // to prevent defining opaque types and we simply don't care about regions. + match self.typing_mode_raw() { + TypingMode::Coherence + | TypingMode::Analysis { .. } + | TypingMode::PostBorrowckAnalysis { .. } + | TypingMode::PostAnalysis => {} + // In erased mode, the opaque type storage is always empty + TypingMode::ErasedNotCoherence(..) => {} + TypingMode::Borrowck { .. } => { + if !self.considering_regions { + return; + } + } + } + + if !opaque_type_storage.is_empty() { + ty::tls::with(|tcx| tcx.dcx().delayed_bug(format!("{opaque_type_storage:?}"))); + } + } +} + /// See the `error_reporting` module for more details. #[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable, TypeVisitable)] pub enum ValuePairs<'tcx> { diff --git a/compiler/rustc_infer/src/infer/opaque_types/table.rs b/compiler/rustc_infer/src/infer/opaque_types/table.rs index 55c00a8695fa5..066d12be320a2 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/table.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/table.rs @@ -3,7 +3,7 @@ use std::ops::Deref; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::undo_log::UndoLogs; use rustc_middle::bug; -use rustc_middle::ty::{self, OpaqueTypeKey, ProvisionalHiddenType, Ty}; +use rustc_middle::ty::{OpaqueTypeKey, ProvisionalHiddenType, Ty}; use tracing::instrument; use crate::infer::snapshot::undo_log::{InferCtxtUndoLogs, UndoLog}; @@ -121,14 +121,6 @@ impl<'tcx> OpaqueTypeStorage<'tcx> { } } -impl<'tcx> Drop for OpaqueTypeStorage<'tcx> { - fn drop(&mut self) { - if !self.is_empty() { - ty::tls::with(|tcx| tcx.dcx().delayed_bug(format!("{:?}", self.opaque_types))); - } - } -} - pub struct OpaqueTypeTable<'a, 'tcx> { storage: &'a mut OpaqueTypeStorage<'tcx>, diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 352652413751e..6b0205f9a78a3 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -633,9 +633,14 @@ impl<'tcx> LateContext<'tcx> { /// The typing mode of the currently visited node. Use this when /// building a new `InferCtxt`. pub fn typing_mode(&self) -> TypingMode<'tcx> { - // FIXME(#132279): In case we're in a body, we should use a typing - // mode which reveals the opaque types defined by that body. - TypingMode::non_body_analysis() + if let Some(body_id) = self.enclosing_body + && self.tcx.use_typing_mode_borrowck() + { + let def_id = self.tcx.hir_enclosing_body_owner(body_id.hir_id); + TypingMode::borrowck(self.tcx, def_id) + } else { + TypingMode::non_body_analysis() + } } pub fn typing_env(&self) -> TypingEnv<'tcx> { diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs index 97df4ebc8ae13..6b19aa17c6d6c 100644 --- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs +++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs @@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { } let def_id = opaque.def_id.to_def_id(); - let infcx = &cx.tcx.infer_ctxt().build(cx.typing_mode()); + let infcx = &cx.tcx.infer_ctxt().ignoring_regions().build(cx.typing_mode()); // For every projection predicate in the opaque type's explicit bounds, // check that the type that we're assigning actually satisfies the bounds // of the associated type. diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 6124b92da5c10..49077c3007f4a 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -413,13 +413,36 @@ impl<'tcx> Body<'tcx> { } pub fn typing_env(&self, tcx: TyCtxt<'tcx>) -> TypingEnv<'tcx> { - match self.phase { - // FIXME(#132279): we should reveal the opaques defined in the body during analysis. - MirPhase::Built | MirPhase::Analysis(_) => TypingEnv::new( - tcx.param_env(self.source.def_id()), - ty::TypingMode::non_body_analysis(), - ), - MirPhase::Runtime(_) => TypingEnv::post_analysis(tcx, self.source.def_id()), + if tcx.use_typing_mode_borrowck() { + match self.phase { + MirPhase::Built if let Some(def_id) = self.source.def_id().as_local() => { + TypingEnv::new( + tcx.param_env(self.source.def_id()), + ty::TypingMode::borrowck(tcx, def_id), + ) + } + MirPhase::Analysis(_) if let Some(def_id) = self.source.def_id().as_local() => { + TypingEnv::new( + tcx.param_env(self.source.def_id()), + ty::TypingMode::post_borrowck_analysis(tcx, def_id), + ) + } + MirPhase::Built | MirPhase::Analysis(_) => { + // This branch happens for drop glue and fn ptr shims. + // FIXME: why do we do any of this analysis on drop glue etc? + // This should ideally all be skipped. + TypingEnv::post_analysis(tcx, self.source.def_id()) + } + MirPhase::Runtime(_) => TypingEnv::post_analysis(tcx, self.source.def_id()), + } + } else { + match self.phase { + MirPhase::Built | MirPhase::Analysis(_) => TypingEnv::new( + tcx.param_env(self.source.def_id()), + ty::TypingMode::non_body_analysis(), + ), + MirPhase::Runtime(_) => TypingEnv::post_analysis(tcx, self.source.def_id()), + } } } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index e38e5393d967d..73392d9e6eeaf 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -528,12 +528,6 @@ pub trait HasTyCtxt<'tcx>: HasDataLayout { pub trait HasTypingEnv<'tcx> { fn typing_env(&self) -> ty::TypingEnv<'tcx>; - - /// FIXME(#132279): This method should not be used as in the future - /// everything should take a `TypingEnv` instead. Remove it as that point. - fn param_env(&self) -> ty::ParamEnv<'tcx> { - self.typing_env().param_env - } } impl<'tcx> HasDataLayout for TyCtxt<'tcx> { diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 4043b9bca61c5..12dc35d29ad9f 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -3238,7 +3238,7 @@ pub(crate) struct DotDotDotRestPattern { #[suggestion( "for a rest pattern, use `..` instead of `...`", style = "verbose", - code = "", + code = "..", applicability = "machine-applicable" )] pub suggestion: Option, diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 4e6d76fefd9c2..b8718b503df26 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -920,7 +920,7 @@ impl<'a> Parser<'a> { // The user probably mistook `...` for a rest pattern `..`. self.dcx().emit_err(DotDotDotRestPattern { span: lo, - suggestion: Some(lo.with_lo(lo.hi() - BytePos(1))), + suggestion: Some(lo), var_args: None, }); PatKind::Rest diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 9cdf79ca57d87..5e52ebcc3f194 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -2307,7 +2307,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { self.mention_default_field_values(source, ident, &mut err); - let mut not_publicly_reexported = false; if let Some((this_res, outer_ident)) = outermost_res { let mut import_suggestions = self.lookup_import_candidates( outer_ident, @@ -2332,7 +2331,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ); // If we suggest importing a public re-export, don't point at the definition. if point_to_def && ident.span != outer_ident.span { - not_publicly_reexported = true; let label = errors::OuterIdentIsNotPubliclyReexported { span: outer_ident.span, outer_ident_descr: this_res.descr(), @@ -2408,7 +2406,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let first_binding = decl; let mut next_binding = Some(decl); let mut next_ident = ident; - let mut path = vec![]; while let Some(binding) = next_binding { let name = next_ident; next_binding = match binding.kind { @@ -2428,18 +2425,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { }; match binding.kind { - DeclKind::Import { import, .. } => { - for segment in import.module_path.iter().skip(1) { - // Don't include `{{root}}` in suggestions - it's an internal symbol - // that should never be shown to users. - if segment.ident.name != kw::PathRoot { - path.push(segment.ident); - } - } - sugg_paths.push(( - path.iter().cloned().chain(std::iter::once(ident)).collect::>(), - true, // re-export - )); + DeclKind::Import { source_decl, import, .. } => { + // Don't include `{{root}}` in suggestions - it's an internal symbol + // that should never be shown to users. + let path = import + .module_path + .iter() + .filter(|seg| seg.ident.name != kw::PathRoot) + .map(|seg| seg.ident.clone()) + .chain(std::iter::once(ident)) + .collect::>(); + let through_reexport = !matches!(source_decl.kind, DeclKind::Def(_)); + sugg_paths.push((path, through_reexport)); } DeclKind::Def(_) => {} } @@ -2472,25 +2469,34 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { }; err.subdiagnostic(note); } - // We prioritize shorter paths, non-core imports and direct imports over the alternatives. - sugg_paths.sort_by_key(|(p, reexport)| (p.len(), p[0].name == sym::core, *reexport)); - for (sugg, reexport) in sugg_paths { - if not_publicly_reexported { + // The suggestion replaces `dedup_span` with a path reaching the failing ident. + // That's valid only when + // 1) the failing ident is the imported leaf, otherwise `as` renames and trailing segments + // get dropped, and + // 2) the use isn't nested, otherwise `dedup_span` is one ident in `{...}`. + // + // See issue #156060. + let can_replace_use = + !single_nested && !outermost_res.is_some_and(|(_, outer)| outer.span != ident.span); + if can_replace_use { + // We prioritize shorter paths, non-core imports and direct imports over the + // alternatives. + sugg_paths.sort_by_key(|(p, reexport)| (p.len(), p[0].name == sym::core, *reexport)); + for (sugg, reexport) in sugg_paths { + if sugg.len() <= 1 { + // A single path segment suggestion is wrong. This happens on circular + // imports. `tests/ui/imports/issue-55884-2.rs` + continue; + } + let path = join_path_idents(sugg); + let sugg = if reexport { + errors::ImportIdent::ThroughReExport { span: dedup_span, ident, path } + } else { + errors::ImportIdent::Directly { span: dedup_span, ident, path } + }; + err.subdiagnostic(sugg); break; } - if sugg.len() <= 1 { - // A single path segment suggestion is wrong. This happens on circular imports. - // `tests/ui/imports/issue-55884-2.rs` - continue; - } - let path = join_path_idents(sugg); - let sugg = if reexport { - errors::ImportIdent::ThroughReExport { span: dedup_span, ident, path } - } else { - errors::ImportIdent::Directly { span: dedup_span, ident, path } - }; - err.subdiagnostic(sugg); - break; } err.emit(); diff --git a/src/doc/rustc-dev-guide/ci/sembr/src/main.rs b/src/doc/rustc-dev-guide/ci/sembr/src/main.rs index 4038f112d59fd..b9d659d40d365 100644 --- a/src/doc/rustc-dev-guide/ci/sembr/src/main.rs +++ b/src/doc/rustc-dev-guide/ci/sembr/src/main.rs @@ -45,14 +45,16 @@ fn main() -> Result<()> { continue; } let old = fs::read_to_string(&path)?; - let new = lengthen_lines(&comply(&old), cli.line_length_limit); + let new = comply(&old); if new == old { compliant.push(path.clone()); - } else if cli.overwrite { - fs::write(&path, new)?; - made_compliant.push(path.clone()); } else { - not_compliant.push(path.clone()); + if cli.overwrite { + fs::write(&path, lengthen_lines(&new, cli.line_length_limit))?; + made_compliant.push(path.clone()); + } else { + not_compliant.push(path.clone()); + } } } } diff --git a/src/doc/rustc-dev-guide/rust-version b/src/doc/rustc-dev-guide/rust-version index ea416dc27b52d..d33dd7b83a6a7 100644 --- a/src/doc/rustc-dev-guide/rust-version +++ b/src/doc/rustc-dev-guide/rust-version @@ -1 +1 @@ -f53b654a8882fd5fc036c4ca7a4ff41ce32497a6 +f2b291d902bfde7d7f209fc3a64908134bcef201 diff --git a/src/doc/rustc-dev-guide/src/autodiff/installation.md b/src/doc/rustc-dev-guide/src/autodiff/installation.md index 648e6c0ccef6f..a1e802ffaea5e 100644 --- a/src/doc/rustc-dev-guide/src/autodiff/installation.md +++ b/src/doc/rustc-dev-guide/src/autodiff/installation.md @@ -6,7 +6,7 @@ For the meantime, you can download up-to-date builds to enable `std::autodiff` o **Linux**, with `x86_64-unknown-linux-gnu` or `aarch64-unknown-linux-gnu` **Windows**, with `x86_64-llvm-mingw` or `aarch64-llvm-mingw` -You can also download slightly outdated builds for **Apple** (aarch64-apple), which should generally work for now. +In the past you could also download builds for **Apple** (aarch64-apple), however they are not usable at the moment. If you need any other platform, you can build rustc including autodiff from source. Please open an issue if you want to help enabling automatic builds for your prefered target. @@ -24,7 +24,7 @@ For now, you'll have to manually download and copy it. 5) Copy the artifact (libEnzyme-22.so for linux, libEnzyme-22.dylib for apple, etc.), which should be in a folder named `enzyme-preview`, to your rust toolchain directory. E.g. for linux: `cp ~/Downloads/enzyme-nightly-x86_64-unknown-linux-gnu/enzyme-preview/lib/rustlib/x86_64-unknown-linux-gnu/lib/libEnzyme-22.so ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib` Apple support was temporarily reverted, due to downstream breakages. -If you want to download autodiff for apple, please look at the artifacts from this [`run`]. +Please (currently) build it from source. ## Installation guide for Nix user. @@ -111,8 +111,7 @@ docker cp :/rust/build/dist/rust-nightly-x86_64-unknown-linux-gnu.tar. Afterwards we can create a new (pre-release) tag on the EnzymeAD/rust repository and make a PR against the EnzymeAD/enzyme-explorer repository to update the tag. Remember to ping `tgymnich` on the PR to run his update script. Note: We should archive EnzymeAD/rust and update the instructions here. -The explorer should soon -be able to get the rustc toolchain from the official rust servers. +The explorer should soon be able to get the rustc toolchain from the official rust servers. ## Build instruction for Enzyme itself @@ -144,5 +143,4 @@ This will build Enzyme, and you can find it in `Enzyme/enzyme/build/lib/ $DIR/issue-44239.rs:8:26 + --> $DIR/local-var-in-associated-const.rs:10:26 | LL | const N: usize = n; | ^ non-constant value diff --git a/tests/ui/issues/issue-25757.rs b/tests/ui/consts/method-reference-in-const-dyn-fn.rs similarity index 77% rename from tests/ui/issues/issue-25757.rs rename to tests/ui/consts/method-reference-in-const-dyn-fn.rs index dc9c2ffaa6fad..edb6efc770096 100644 --- a/tests/ui/issues/issue-25757.rs +++ b/tests/ui/consts/method-reference-in-const-dyn-fn.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/25757 + //@ run-pass struct Foo { a: u32 diff --git a/tests/ui/issues/issue-27433.fixed b/tests/ui/consts/non-constant-value-in-nested-const.fixed similarity index 72% rename from tests/ui/issues/issue-27433.fixed rename to tests/ui/consts/non-constant-value-in-nested-const.fixed index f847b698976a0..9942537b48934 100644 --- a/tests/ui/issues/issue-27433.fixed +++ b/tests/ui/consts/non-constant-value-in-nested-const.fixed @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/27433 + //@ run-rustfix fn main() { let foo = 42u32; diff --git a/tests/ui/issues/issue-27433.rs b/tests/ui/consts/non-constant-value-in-nested-const.rs similarity index 72% rename from tests/ui/issues/issue-27433.rs rename to tests/ui/consts/non-constant-value-in-nested-const.rs index 9bbc5bcbb459d..fbaba2de615d6 100644 --- a/tests/ui/issues/issue-27433.rs +++ b/tests/ui/consts/non-constant-value-in-nested-const.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/27433 + //@ run-rustfix fn main() { let foo = 42u32; diff --git a/tests/ui/issues/issue-27433.stderr b/tests/ui/consts/non-constant-value-in-nested-const.stderr similarity index 87% rename from tests/ui/issues/issue-27433.stderr rename to tests/ui/consts/non-constant-value-in-nested-const.stderr index d8fd3d84ecbbc..c50bb8651716a 100644 --- a/tests/ui/issues/issue-27433.stderr +++ b/tests/ui/consts/non-constant-value-in-nested-const.stderr @@ -1,5 +1,5 @@ error[E0435]: attempt to use a non-constant value in a constant - --> $DIR/issue-27433.rs:5:23 + --> $DIR/non-constant-value-in-nested-const.rs:7:23 | LL | const FOO : u32 = foo; | ^^^ non-constant value diff --git a/tests/ui/issues/issue-17252.rs b/tests/ui/consts/recursive-const-stack-overflow.rs similarity index 81% rename from tests/ui/issues/issue-17252.rs rename to tests/ui/consts/recursive-const-stack-overflow.rs index dd002bfd187a0..aee95a685b20a 100644 --- a/tests/ui/issues/issue-17252.rs +++ b/tests/ui/consts/recursive-const-stack-overflow.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/17252 + const FOO: usize = FOO; //~ ERROR E0391 //@ ignore-parallel-frontend query cycle fn main() { diff --git a/tests/ui/issues/issue-17252.stderr b/tests/ui/consts/recursive-const-stack-overflow.stderr similarity index 82% rename from tests/ui/issues/issue-17252.stderr rename to tests/ui/consts/recursive-const-stack-overflow.stderr index b0d9d94e07ddf..054102f0978ab 100644 --- a/tests/ui/issues/issue-17252.stderr +++ b/tests/ui/consts/recursive-const-stack-overflow.stderr @@ -1,36 +1,36 @@ error[E0391]: cycle detected when checking if `FOO` is a trivial const - --> $DIR/issue-17252.rs:1:1 + --> $DIR/recursive-const-stack-overflow.rs:3:1 | LL | const FOO: usize = FOO; | ^^^^^^^^^^^^^^^^ | note: ...which requires building MIR for `FOO`... - --> $DIR/issue-17252.rs:1:1 + --> $DIR/recursive-const-stack-overflow.rs:3:1 | LL | const FOO: usize = FOO; | ^^^^^^^^^^^^^^^^ = note: ...which again requires checking if `FOO` is a trivial const, completing the cycle note: cycle used when simplifying constant for the type system `FOO` - --> $DIR/issue-17252.rs:1:1 + --> $DIR/recursive-const-stack-overflow.rs:3:1 | LL | const FOO: usize = FOO; | ^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error[E0391]: cycle detected when checking if `main::BAR` is a trivial const - --> $DIR/issue-17252.rs:6:9 + --> $DIR/recursive-const-stack-overflow.rs:8:9 | LL | const BAR: usize = BAR; | ^^^^^^^^^^^^^^^^ | note: ...which requires building MIR for `main::BAR`... - --> $DIR/issue-17252.rs:6:9 + --> $DIR/recursive-const-stack-overflow.rs:8:9 | LL | const BAR: usize = BAR; | ^^^^^^^^^^^^^^^^ = note: ...which again requires checking if `main::BAR` is a trivial const, completing the cycle note: cycle used when simplifying constant for the type system `main::BAR` - --> $DIR/issue-17252.rs:6:9 + --> $DIR/recursive-const-stack-overflow.rs:8:9 | LL | const BAR: usize = BAR; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/issues/issue-30891.rs b/tests/ui/consts/short-circuit-or-with-const-bool.rs similarity index 66% rename from tests/ui/issues/issue-30891.rs rename to tests/ui/consts/short-circuit-or-with-const-bool.rs index 25b7165d01167..aafe9cefa2220 100644 --- a/tests/ui/issues/issue-30891.rs +++ b/tests/ui/consts/short-circuit-or-with-const-bool.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/30891 + //@ run-pass const ERROR_CONST: bool = true; diff --git a/tests/ui/issues/issue-40951.rs b/tests/ui/consts/static-lifetime-inference-from-const-array.rs similarity index 73% rename from tests/ui/issues/issue-40951.rs rename to tests/ui/consts/static-lifetime-inference-from-const-array.rs index e99fe76c08527..05edbd66052af 100644 --- a/tests/ui/issues/issue-40951.rs +++ b/tests/ui/consts/static-lifetime-inference-from-const-array.rs @@ -1,6 +1,6 @@ //@ run-pass #![allow(unused_variables)] -// Regression test for #40951. +// Regression test for https://github.com/rust-lang/rust/issues/40951. const FOO: [&'static str; 1] = ["foo"]; diff --git a/tests/ui/issues/issue-49955.rs b/tests/ui/consts/static-ref-to-const-array-element.rs similarity index 81% rename from tests/ui/issues/issue-49955.rs rename to tests/ui/consts/static-ref-to-const-array-element.rs index c2f160bd6d4cc..b53ffc2685619 100644 --- a/tests/ui/issues/issue-49955.rs +++ b/tests/ui/consts/static-ref-to-const-array-element.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/49955 + //@ run-pass const ALL_THE_NUMS: [u32; 1] = [ diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob-priv.stderr b/tests/ui/imports/ambiguous-import-visibility-globglob-priv.stderr index 4485f5ac96481..a6119dba34d70 100644 --- a/tests/ui/imports/ambiguous-import-visibility-globglob-priv.stderr +++ b/tests/ui/imports/ambiguous-import-visibility-globglob-priv.stderr @@ -14,10 +14,10 @@ note: ...and refers to the struct `S` which is defined here | LL | pub struct S {} | ^^^^^^^^^^^^ you could import this directly -help: import `S` through the re-export +help: import `S` directly | LL - use crate::both::private::S; -LL + use m::S; +LL + use crate::m::S; | error[E0603]: struct import `S` is private @@ -36,10 +36,10 @@ note: ...and refers to the struct `S` which is defined here | LL | pub struct S {} | ^^^^^^^^^^^^ you could import this directly -help: import `S` through the re-export +help: import `S` directly | LL - use crate::both::private::S; -LL + use m::S; +LL + use crate::m::S; | error: aborting due to 2 previous errors diff --git a/tests/ui/imports/issue-55884-2.stderr b/tests/ui/imports/issue-55884-2.stderr index 7425b92a11e0f..55b5158ffca89 100644 --- a/tests/ui/imports/issue-55884-2.stderr +++ b/tests/ui/imports/issue-55884-2.stderr @@ -24,6 +24,11 @@ note: ...and refers to the struct `ParseOptions` which is defined here | LL | pub struct ParseOptions {} | ^^^^^^^^^^^^^^^^^^^^^^^ you could import this directly +help: import `ParseOptions` directly + | +LL - pub use parser::ParseOptions; +LL + pub use options::ParseOptions; + | error: aborting due to 1 previous error diff --git a/tests/ui/imports/private-import-nested-suggestion-156060.rs b/tests/ui/imports/private-import-nested-suggestion-156060.rs new file mode 100644 index 0000000000000..90a7b94aad555 --- /dev/null +++ b/tests/ui/imports/private-import-nested-suggestion-156060.rs @@ -0,0 +1,17 @@ +// Regression test for #156060. + +mod one { + pub struct One(); +} + +mod two { + use crate::one::One; + pub struct Two(); +} + +mod test { + use crate::two::{One, Two}; + //~^ ERROR struct import `One` is private [E0603] +} + +fn main() {} diff --git a/tests/ui/imports/private-import-nested-suggestion-156060.stderr b/tests/ui/imports/private-import-nested-suggestion-156060.stderr new file mode 100644 index 0000000000000..09d5391bd58df --- /dev/null +++ b/tests/ui/imports/private-import-nested-suggestion-156060.stderr @@ -0,0 +1,20 @@ +error[E0603]: struct import `One` is private + --> $DIR/private-import-nested-suggestion-156060.rs:13:22 + | +LL | use crate::two::{One, Two}; + | ^^^ private struct import + | +note: the struct import `One` is defined here... + --> $DIR/private-import-nested-suggestion-156060.rs:8:9 + | +LL | use crate::one::One; + | ^^^^^^^^^^^^^^^ +note: ...and refers to the struct `One` which is defined here + --> $DIR/private-import-nested-suggestion-156060.rs:4:5 + | +LL | pub struct One(); + | ^^^^^^^^^^^^^^^^^ you could import this directly + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/imports/private-import-suggestion-path-156244.edition_2015.stderr b/tests/ui/imports/private-import-suggestion-path-156244.edition_2015.stderr new file mode 100644 index 0000000000000..95b1760e6a239 --- /dev/null +++ b/tests/ui/imports/private-import-suggestion-path-156244.edition_2015.stderr @@ -0,0 +1,81 @@ +error[E0603]: struct import `One` is private + --> $DIR/private-import-suggestion-path-156244.rs:17:12 + | +LL | use b::One; + | ^^^ private struct import + | +note: the struct import `One` is defined here... + --> $DIR/private-import-suggestion-path-156244.rs:12:20 + | +LL | use crate::a::{One, Two}; + | ^^^ +note: ...and refers to the struct `One` which is defined here + --> $DIR/private-import-suggestion-path-156244.rs:7:5 + | +LL | pub struct One; + | ^^^^^^^^^^^^^^^ you could import this directly +help: import `One` directly + | +LL - use b::One; +LL + use crate::a::One; + | + +error[E0603]: struct import `One` is private + --> $DIR/private-import-suggestion-path-156244.rs:35:20 + | +LL | use crate::b::{One, Two}; + | ^^^ private struct import + | +note: the struct import `One` is defined here... + --> $DIR/private-import-suggestion-path-156244.rs:12:20 + | +LL | use crate::a::{One, Two}; + | ^^^ +note: ...and refers to the struct `One` which is defined here + --> $DIR/private-import-suggestion-path-156244.rs:7:5 + | +LL | pub struct One; + | ^^^^^^^^^^^^^^^ you could import this directly + +error[E0603]: struct import `Two` is private + --> $DIR/private-import-suggestion-path-156244.rs:35:25 + | +LL | use crate::b::{One, Two}; + | ^^^ private struct import + | +note: the struct import `Two` is defined here... + --> $DIR/private-import-suggestion-path-156244.rs:12:25 + | +LL | use crate::a::{One, Two}; + | ^^^ +note: ...and refers to the struct `Two` which is defined here + --> $DIR/private-import-suggestion-path-156244.rs:8:5 + | +LL | pub struct Two; + | ^^^^^^^^^^^^^^^ you could import this directly + +error[E0603]: module import `inner` is private + --> $DIR/private-import-suggestion-path-156244.rs:38:24 + | +LL | use crate::rename::inner::Item as Item1; + | ^^^^^ private module import + | +note: the module import `inner` is defined here... + --> $DIR/private-import-suggestion-path-156244.rs:31:9 + | +LL | use crate::outer::actual as inner; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...and refers to the module `actual` which is defined here + --> $DIR/private-import-suggestion-path-156244.rs:25:5 + | +LL | pub mod actual { + | ^^^^^^^^^^^^^^ you could import this directly +help: consider importing this struct instead + | +LL - use crate::rename::inner::Item as Item1; +LL + use outer::actual::Item as Item1; + | + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/imports/private-import-suggestion-path-156244.edition_2018.stderr b/tests/ui/imports/private-import-suggestion-path-156244.edition_2018.stderr new file mode 100644 index 0000000000000..e153b0cdc95aa --- /dev/null +++ b/tests/ui/imports/private-import-suggestion-path-156244.edition_2018.stderr @@ -0,0 +1,81 @@ +error[E0603]: struct import `One` is private + --> $DIR/private-import-suggestion-path-156244.rs:20:19 + | +LL | use crate::b::One; + | ^^^ private struct import + | +note: the struct import `One` is defined here... + --> $DIR/private-import-suggestion-path-156244.rs:12:20 + | +LL | use crate::a::{One, Two}; + | ^^^ +note: ...and refers to the struct `One` which is defined here + --> $DIR/private-import-suggestion-path-156244.rs:7:5 + | +LL | pub struct One; + | ^^^^^^^^^^^^^^^ you could import this directly +help: import `One` directly + | +LL - use crate::b::One; +LL + use crate::a::One; + | + +error[E0603]: struct import `One` is private + --> $DIR/private-import-suggestion-path-156244.rs:35:20 + | +LL | use crate::b::{One, Two}; + | ^^^ private struct import + | +note: the struct import `One` is defined here... + --> $DIR/private-import-suggestion-path-156244.rs:12:20 + | +LL | use crate::a::{One, Two}; + | ^^^ +note: ...and refers to the struct `One` which is defined here + --> $DIR/private-import-suggestion-path-156244.rs:7:5 + | +LL | pub struct One; + | ^^^^^^^^^^^^^^^ you could import this directly + +error[E0603]: struct import `Two` is private + --> $DIR/private-import-suggestion-path-156244.rs:35:25 + | +LL | use crate::b::{One, Two}; + | ^^^ private struct import + | +note: the struct import `Two` is defined here... + --> $DIR/private-import-suggestion-path-156244.rs:12:25 + | +LL | use crate::a::{One, Two}; + | ^^^ +note: ...and refers to the struct `Two` which is defined here + --> $DIR/private-import-suggestion-path-156244.rs:8:5 + | +LL | pub struct Two; + | ^^^^^^^^^^^^^^^ you could import this directly + +error[E0603]: module import `inner` is private + --> $DIR/private-import-suggestion-path-156244.rs:38:24 + | +LL | use crate::rename::inner::Item as Item1; + | ^^^^^ private module import + | +note: the module import `inner` is defined here... + --> $DIR/private-import-suggestion-path-156244.rs:31:9 + | +LL | use crate::outer::actual as inner; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...and refers to the module `actual` which is defined here + --> $DIR/private-import-suggestion-path-156244.rs:25:5 + | +LL | pub mod actual { + | ^^^^^^^^^^^^^^ you could import this directly +help: consider importing this struct instead + | +LL - use crate::rename::inner::Item as Item1; +LL + use crate::outer::actual::Item as Item1; + | + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/imports/private-import-suggestion-path-156244.rs b/tests/ui/imports/private-import-suggestion-path-156244.rs new file mode 100644 index 0000000000000..3f9d247097f7d --- /dev/null +++ b/tests/ui/imports/private-import-suggestion-path-156244.rs @@ -0,0 +1,42 @@ +// PR #156244 comment +//@ revisions: edition_2015 edition_2018 +//@[edition_2015] edition: 2015 +//@[edition_2018] edition: 2018 + +mod a { + pub struct One; + pub struct Two; +} + +mod b { + use crate::a::{One, Two}; +} + +mod test { + #[cfg(edition_2015)] + use b::One; + //[edition_2015]~^ ERROR struct import `One` is private [E0603] + #[cfg(edition_2018)] + use crate::b::One; + //[edition_2018]~^ ERROR struct import `One` is private [E0603] +} + +mod outer { + pub mod actual { + pub struct Item; + } +} + +mod rename { + use crate::outer::actual as inner; +} + +mod bad { + use crate::b::{One, Two}; + //~^ ERROR struct import `One` is private [E0603] + //~| ERROR struct import `Two` is private [E0603] + use crate::rename::inner::Item as Item1; + //~^ ERROR module import `inner` is private [E0603] +} + +fn main() {} diff --git a/tests/ui/imports/private-std-reexport-suggest-public.stderr b/tests/ui/imports/private-std-reexport-suggest-public.stderr index 49718da7fc939..cc4365d73ad9a 100644 --- a/tests/ui/imports/private-std-reexport-suggest-public.stderr +++ b/tests/ui/imports/private-std-reexport-suggest-public.stderr @@ -13,7 +13,7 @@ note: ...and refers to the module `mem` which is defined here --> $SRC_DIR/std/src/lib.rs:LL:COL | = note: you could import this directly -help: import `mem` through the re-export +help: import `mem` directly | LL - use foo::mem; LL + use std::mem; diff --git a/tests/ui/issues/issue-4387.rs b/tests/ui/issues/issue-4387.rs deleted file mode 100644 index 10f607aacbd2d..0000000000000 --- a/tests/ui/issues/issue-4387.rs +++ /dev/null @@ -1,5 +0,0 @@ -//@ run-pass - -pub fn main() { - let _foo = [0; 2*4]; -} diff --git a/tests/ui/parser/dotdotdot-rest-pattern-suggestion-span.rs b/tests/ui/parser/dotdotdot-rest-pattern-suggestion-span.rs new file mode 100644 index 0000000000000..0db10726c5dc4 --- /dev/null +++ b/tests/ui/parser/dotdotdot-rest-pattern-suggestion-span.rs @@ -0,0 +1,20 @@ +// Suggestions for `...` in patterns should not perform span manipulations that +// assume the token is ASCII, because it could have been recovered from +// similar-looking Unicode characters. +// +// Regression test for https://github.com/rust-lang/rust/issues/156316. + +// These dots are U+00B7 MIDDLE DOT, not ASCII periods. +impl S { fn f(···>) } +//~^ ERROR unknown start of token +//~| ERROR unknown start of token +//~| ERROR unknown start of token +//~| ERROR unexpected `...` +//~| ERROR expected `:`, found `>` +//~| ERROR expected one of +//~| ERROR associated function in `impl` without body +//~| ERROR cannot find type `S` in this scope +//~| ERROR missing pattern for `...` argument +//~| WARN this was previously accepted by the compiler + +fn main() {} diff --git a/tests/ui/parser/dotdotdot-rest-pattern-suggestion-span.stderr b/tests/ui/parser/dotdotdot-rest-pattern-suggestion-span.stderr new file mode 100644 index 0000000000000..d483c40ca5e0b --- /dev/null +++ b/tests/ui/parser/dotdotdot-rest-pattern-suggestion-span.stderr @@ -0,0 +1,110 @@ +error: unknown start of token: \u{b7} + --> $DIR/dotdotdot-rest-pattern-suggestion-span.rs:8:15 + | +LL | impl S { fn f(···>) } + | ^^^ + | + = note: character appears 2 more times +help: Unicode character '·' (Middle Dot) looks like '.' (Period), but it is not + | +LL - impl S { fn f(···>) } +LL + impl S { fn f(...>) } + | + +error: unknown start of token: \u{b7} + --> $DIR/dotdotdot-rest-pattern-suggestion-span.rs:8:16 + | +LL | impl S { fn f(···>) } + | ^^ + | + = note: character appears once more +help: Unicode character '·' (Middle Dot) looks like '.' (Period), but it is not + | +LL - impl S { fn f(···>) } +LL + impl S { fn f(·..>) } + | + +error: unknown start of token: \u{b7} + --> $DIR/dotdotdot-rest-pattern-suggestion-span.rs:8:17 + | +LL | impl S { fn f(···>) } + | ^ + | +help: Unicode character '·' (Middle Dot) looks like '.' (Period), but it is not + | +LL - impl S { fn f(···>) } +LL + impl S { fn f(··.>) } + | + +error: unexpected `...` + --> $DIR/dotdotdot-rest-pattern-suggestion-span.rs:8:15 + | +LL | impl S { fn f(···>) } + | ^^^ not a valid pattern + | +help: for a rest pattern, use `..` instead of `...` + | +LL - impl S { fn f(···>) } +LL + impl S { fn f(..>) } + | + +error: expected `:`, found `>` + --> $DIR/dotdotdot-rest-pattern-suggestion-span.rs:8:18 + | +LL | impl S { fn f(···>) } + | ^ expected `:` + +error: expected one of `->`, `where`, or `{`, found `}` + --> $DIR/dotdotdot-rest-pattern-suggestion-span.rs:8:21 + | +LL | impl S { fn f(···>) } + | - ^ expected one of `->`, `where`, or `{` + | | + | while parsing this `fn` + +error: associated function in `impl` without body + --> $DIR/dotdotdot-rest-pattern-suggestion-span.rs:8:10 + | +LL | impl S { fn f(···>) } + | ^^^^^^^^^^- help: provide a definition for the function: `{ }` + +error[E0425]: cannot find type `S` in this scope + --> $DIR/dotdotdot-rest-pattern-suggestion-span.rs:8:6 + | +LL | impl S { fn f(···>) } + | ^ not found in this scope + +error: missing pattern for `...` argument + --> $DIR/dotdotdot-rest-pattern-suggestion-span.rs:8:15 + | +LL | impl S { fn f(···>) } + | ^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #145544 + = note: `#[deny(varargs_without_pattern)]` (part of `#[deny(future_incompatible)]`) on by default +help: name the argument, or use `_` to continue ignoring it + | +LL - impl S { fn f(···>) } +LL + impl S { fn f(_: ...>) } + | + +error: aborting due to 9 previous errors + +For more information about this error, try `rustc --explain E0425`. +Future incompatibility report: Future breakage diagnostic: +error: missing pattern for `...` argument + --> $DIR/dotdotdot-rest-pattern-suggestion-span.rs:8:15 + | +LL | impl S { fn f(···>) } + | ^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #145544 + = note: `#[deny(varargs_without_pattern)]` (part of `#[deny(future_incompatible)]`) on by default +help: name the argument, or use `_` to continue ignoring it + | +LL - impl S { fn f(···>) } +LL + impl S { fn f(_: ...>) } + | + diff --git a/tests/ui/privacy/privacy2.stderr b/tests/ui/privacy/privacy2.stderr index 3d36f26f784ab..cef8fdb6c5154 100644 --- a/tests/ui/privacy/privacy2.stderr +++ b/tests/ui/privacy/privacy2.stderr @@ -20,6 +20,11 @@ note: ...and refers to the function `foo` which is defined here | LL | pub fn foo() {} | ^^^^^^^^^^^^ you could import this directly +help: import `foo` directly + | +LL - use bar::glob::foo; +LL + use crate::foo; + | error: requires `sized` lang_item --> $DIR/privacy2.rs:17:14