diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a992129773e29..b51105750c82c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,9 +60,8 @@ jobs: env: {} - name: x86_64-gnu-tools tidy: false - env: - CI_ONLY_WHEN_SUBMODULES_CHANGED: 1 os: ubuntu-20.04-xl + env: {} timeout-minutes: 600 runs-on: "${{ matrix.os }}" steps: diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index b0a8188e5e04d..7b07c2a463371 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -803,6 +803,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { predicates .iter() .map(|(param, constraint)| (param.name.as_str(), &**constraint, None)), + None, ); } } diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index 782a62accad9e..3e416b89ca6ea 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -136,6 +136,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> { ¶m_ty.name.as_str(), &constraint, None, + None, ); } } diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index 072b0f2fcceab..800f3c521778d 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -286,6 +286,7 @@ E0519: include_str!("./error_codes/E0519.md"), E0520: include_str!("./error_codes/E0520.md"), E0521: include_str!("./error_codes/E0521.md"), E0522: include_str!("./error_codes/E0522.md"), +E0523: include_str!("./error_codes/E0523.md"), E0524: include_str!("./error_codes/E0524.md"), E0525: include_str!("./error_codes/E0525.md"), E0527: include_str!("./error_codes/E0527.md"), @@ -622,7 +623,6 @@ E0793: include_str!("./error_codes/E0793.md"), // E0488, // lifetime of variable does not enclose its declaration // E0489, // type/lifetime parameter not in scope here // E0490, // removed: unreachable - E0523, // two dependencies have same (crate-name, disambiguator) but different SVH // E0526, // shuffle indices are not constant // E0540, // multiple rustc_deprecated attributes // E0548, // replaced with a generic attribute input check diff --git a/compiler/rustc_error_codes/src/error_codes/E0464.md b/compiler/rustc_error_codes/src/error_codes/E0464.md index 9108d856c9d77..209cbb00db562 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0464.md +++ b/compiler/rustc_error_codes/src/error_codes/E0464.md @@ -1,6 +1,21 @@ The compiler found multiple library files with the requested crate name. +```compile_fail +// aux-build:crateresolve-1.rs +// aux-build:crateresolve-2.rs +// aux-build:crateresolve-3.rs + +extern crate crateresolve; +//~^ ERROR multiple candidates for `rlib` dependency `crateresolve` found + +fn main() {} +``` + This error can occur in several different cases -- for example, when using `extern crate` or passing `--extern` options without crate paths. It can also be caused by caching issues with the build directory, in which case `cargo clean` may help. + +In the above example, there are three different library files, all of which +define the same crate name. Without providing a full path, there is no way for +the compiler to know which crate it should use. diff --git a/compiler/rustc_error_codes/src/error_codes/E0523.md b/compiler/rustc_error_codes/src/error_codes/E0523.md new file mode 100644 index 0000000000000..0ddf70386c28d --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0523.md @@ -0,0 +1,25 @@ +#### Note: this error code is no longer emitted by the compiler. + +The compiler found multiple library files with the requested crate name. + +```compile_fail +// aux-build:crateresolve-1.rs +// aux-build:crateresolve-2.rs +// aux-build:crateresolve-3.rs + +extern crate crateresolve; +//~^ ERROR multiple candidates for `rlib` dependency `crateresolve` found + +fn main() {} +``` + +This error can occur in several different cases -- for example, when using +`extern crate` or passing `--extern` options without crate paths. It can also be +caused by caching issues with the build directory, in which case `cargo clean` +may help. + +In the above example, there are three different library files, all of which +define the same crate name. Without providing a full path, there is no way for +the compiler to know which crate it should use. + +*Note that E0523 has been merged into E0464.* diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 6600e4216bd1f..8c2423e3ca0d1 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -176,6 +176,7 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) { bounds.iter().map(|(param, constraint, def_id)| { (param.as_str(), constraint.as_str(), *def_id) }), + None, ); err.emit(); } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 51e3e3ec73db9..05e976534126b 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -1457,6 +1457,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { generics, diag, vec![(param.name.as_str(), "Clone", Some(clone_trait_did))].into_iter(), + None, ); } else { self.suggest_derive(diag, &[(trait_ref.to_predicate(self.tcx), None, None)]); diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index b5c2d14e8d15b..86f3174b7b2bb 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1922,7 +1922,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { (ty::Uint(ty::UintTy::U8), ty::Char) => { if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span) && let Some(code) = code.strip_prefix('\'').and_then(|s| s.strip_suffix('\'')) - && code.chars().next().map_or(false, |c| c.is_ascii()) + && !code.starts_with("\\u") // forbid all Unicode escapes + && code.chars().next().map_or(false, |c| c.is_ascii()) // forbids literal Unicode characters beyond ASCII { err.span_suggestion( span, diff --git a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs index 39b3c98f0a5cc..984e8cf6a0eb9 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs @@ -77,49 +77,86 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { (ty::Param(p), ty::Alias(ty::Projection, proj)) | (ty::Alias(ty::Projection, proj), ty::Param(p)) if tcx.def_kind(proj.def_id) != DefKind::ImplTraitPlaceholder => { - let generics = tcx.generics_of(body_owner_def_id); - let p_span = tcx.def_span(generics.type_param(p, tcx).def_id); + let p_def_id = tcx + .generics_of(body_owner_def_id) + .type_param(p, tcx) + .def_id; + let p_span = tcx.def_span(p_def_id); if !sp.contains(p_span) { diag.span_label(p_span, "this type parameter"); } let hir = tcx.hir(); let mut note = true; - if let Some(generics) = generics - .type_param(p, tcx) - .def_id + let parent = p_def_id .as_local() - .map(|id| hir.local_def_id_to_hir_id(id)) - .and_then(|id| tcx.hir().find_parent(id)) - .as_ref() - .and_then(|node| node.generics()) + .and_then(|id| { + let local_id = hir.local_def_id_to_hir_id(id); + let generics = tcx.hir().find_parent(local_id)?.generics()?; + Some((id, generics)) + }); + if let Some((local_id, generics)) = parent { // Synthesize the associated type restriction `Add`. // FIXME: extract this logic for use in other diagnostics. let (trait_ref, assoc_substs) = proj.trait_ref_and_own_substs(tcx); - let path = - tcx.def_path_str_with_substs(trait_ref.def_id, trait_ref.substs); let item_name = tcx.item_name(proj.def_id); let item_args = self.format_generic_args(assoc_substs); - let path = if path.ends_with('>') { - format!( - "{}, {}{} = {}>", - &path[..path.len() - 1], - item_name, - item_args, - p - ) + // Here, we try to see if there's an existing + // trait implementation that matches the one that + // we're suggesting to restrict. If so, find the + // "end", whether it be at the end of the trait + // or the end of the generic arguments. + let mut matching_span = None; + let mut matched_end_of_args = false; + for bound in generics.bounds_for_param(local_id) { + let potential_spans = bound + .bounds + .iter() + .find_map(|bound| { + let bound_trait_path = bound.trait_ref()?.path; + let def_id = bound_trait_path.res.opt_def_id()?; + let generic_args = bound_trait_path.segments.iter().last().map(|path| path.args()); + (def_id == trait_ref.def_id).then_some((bound_trait_path.span, generic_args)) + }); + + if let Some((end_of_trait, end_of_args)) = potential_spans { + let args_span = end_of_args.and_then(|args| args.span()); + matched_end_of_args = args_span.is_some(); + matching_span = args_span + .or_else(|| Some(end_of_trait)) + .map(|span| span.shrink_to_hi()); + break; + } + } + + if matched_end_of_args { + // Append suggestion to the end of our args + let path = format!(", {}{} = {}",item_name, item_args, p); + note = !suggest_constraining_type_param( + tcx, + generics, + diag, + &format!("{}", proj.self_ty()), + &path, + None, + matching_span, + ); } else { - format!("{}<{}{} = {}>", path, item_name, item_args, p) - }; - note = !suggest_constraining_type_param( - tcx, - generics, - diag, - &format!("{}", proj.self_ty()), - &path, - None, - ); + // Suggest adding a bound to an existing trait + // or if the trait doesn't exist, add the trait + // and the suggested bounds. + let path = format!("<{}{} = {}>", item_name, item_args, p); + note = !suggest_constraining_type_param( + tcx, + generics, + diag, + &format!("{}", proj.self_ty()), + &path, + None, + matching_span, + ); + } } if note { diag.note("you might be missing a type parameter or trait bound"); diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 21652063b4716..bf8b8aa2ce497 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -356,7 +356,12 @@ impl<'a> CrateLoader<'a> { for (_, other) in self.cstore.iter_crate_data() { // Same stable crate id but different SVH if other.stable_crate_id() == root.stable_crate_id() && other.hash() != root.hash() { - return Err(CrateError::SymbolConflictsOthers(root.name())); + bug!( + "Previously returned E0523 here. \ + See https://github.com/rust-lang/rust/pull/100599 for additional discussion.\ + root.name() = {}.", + root.name() + ); } } diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 02c03114eb67f..c32686779facb 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -511,14 +511,6 @@ pub struct SymbolConflictsCurrent { pub crate_name: Symbol, } -#[derive(Diagnostic)] -#[diag(metadata_symbol_conflicts_others, code = "E0523")] -pub struct SymbolConflictsOthers { - #[primary_span] - pub span: Span, - pub crate_name: Symbol, -} - #[derive(Diagnostic)] #[diag(metadata_stable_crate_id_collision)] pub struct StableCrateIdCollision { diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 74f91a14ea9ae..755a24253504e 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -945,7 +945,6 @@ pub(crate) enum CrateError { ExternLocationNotFile(Symbol, PathBuf), MultipleCandidates(Symbol, CrateFlavor, Vec), SymbolConflictsCurrent(Symbol), - SymbolConflictsOthers(Symbol), StableCrateIdCollision(Symbol, Symbol), DlOpen(String), DlSym(String), @@ -989,9 +988,6 @@ impl CrateError { CrateError::SymbolConflictsCurrent(root_name) => { sess.emit_err(errors::SymbolConflictsCurrent { span, crate_name: root_name }); } - CrateError::SymbolConflictsOthers(root_name) => { - sess.emit_err(errors::SymbolConflictsOthers { span, crate_name: root_name }); - } CrateError::StableCrateIdCollision(crate_name0, crate_name1) => { sess.emit_err(errors::StableCrateIdCollision { span, crate_name0, crate_name1 }); } diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index cd9b927014077..0a30ae9d0aa78 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -193,6 +193,9 @@ fn suggest_removing_unsized_bound( } /// Suggest restricting a type param with a new bound. +/// +/// If `span_to_replace` is provided, then that span will be replaced with the +/// `constraint`. If one wasn't provided, then the full bound will be suggested. pub fn suggest_constraining_type_param( tcx: TyCtxt<'_>, generics: &hir::Generics<'_>, @@ -200,12 +203,14 @@ pub fn suggest_constraining_type_param( param_name: &str, constraint: &str, def_id: Option, + span_to_replace: Option, ) -> bool { suggest_constraining_type_params( tcx, generics, err, [(param_name, constraint, def_id)].into_iter(), + span_to_replace, ) } @@ -215,6 +220,7 @@ pub fn suggest_constraining_type_params<'a>( generics: &hir::Generics<'_>, err: &mut Diagnostic, param_names_and_constraints: impl Iterator)>, + span_to_replace: Option, ) -> bool { let mut grouped = FxHashMap::default(); param_names_and_constraints.for_each(|(param_name, constraint, def_id)| { @@ -253,7 +259,9 @@ pub fn suggest_constraining_type_params<'a>( let mut suggest_restrict = |span, bound_list_non_empty| { suggestions.push(( span, - if bound_list_non_empty { + if span_to_replace.is_some() { + constraint.clone() + } else if bound_list_non_empty { format!(" + {}", constraint) } else { format!(" {}", constraint) @@ -262,6 +270,11 @@ pub fn suggest_constraining_type_params<'a>( )) }; + if let Some(span) = span_to_replace { + suggest_restrict(span, true); + continue; + } + // When the type parameter has been provided bounds // // Message: diff --git a/compiler/rustc_mir_transform/src/copy_prop.rs b/compiler/rustc_mir_transform/src/copy_prop.rs index 4c7d45be0753e..6e279232bcb48 100644 --- a/compiler/rustc_mir_transform/src/copy_prop.rs +++ b/compiler/rustc_mir_transform/src/copy_prop.rs @@ -153,8 +153,9 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { fn visit_operand(&mut self, operand: &mut Operand<'tcx>, loc: Location) { if let Operand::Move(place) = *operand - && let Some(local) = place.as_local() - && !self.fully_moved.contains(local) + // A move out of a projection of a copy is equivalent to a copy of the original projection. + && !place.has_deref() + && !self.fully_moved.contains(place.local) { *operand = Operand::Copy(place); } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 87dbf7c3fd699..91da690a00056 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -679,6 +679,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ¶m_name, &constraint, Some(trait_pred.def_id()), + None, ) { return; } @@ -1087,6 +1088,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { param.name.as_str(), "Clone", Some(clone_trait), + None, ); } err.span_suggestion_verbose( diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 818721062d7f7..1d14efc7523b4 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -928,8 +928,8 @@ impl AtomicBool { /// ``` #[inline] #[unstable(feature = "atomic_mut_ptr", reason = "recently added", issue = "66893")] - pub fn as_mut_ptr(&self) -> *mut bool { - self.v.get() as *mut bool + pub const fn as_mut_ptr(&self) -> *mut bool { + self.v.get().cast() } /// Fetches the value, and applies a function to it that returns an optional @@ -1803,7 +1803,7 @@ impl AtomicPtr { /// /// ```ignore (extern-declaration) /// #![feature(atomic_mut_ptr)] - //// use std::sync::atomic::AtomicPtr; + /// use std::sync::atomic::AtomicPtr; /// /// extern "C" { /// fn my_atomic_op(arg: *mut *mut u32); @@ -1819,7 +1819,7 @@ impl AtomicPtr { /// ``` #[inline] #[unstable(feature = "atomic_mut_ptr", reason = "recently added", issue = "66893")] - pub fn as_mut_ptr(&self) -> *mut *mut T { + pub const fn as_mut_ptr(&self) -> *mut *mut T { self.p.get() } } @@ -2727,7 +2727,7 @@ macro_rules! atomic_int { #[unstable(feature = "atomic_mut_ptr", reason = "recently added", issue = "66893")] - pub fn as_mut_ptr(&self) -> *mut $int_type { + pub const fn as_mut_ptr(&self) -> *mut $int_type { self.v.get() } } diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index c0a1341ebca5c..3c128c0ca251b 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -307,8 +307,6 @@ jobs: - name: x86_64-gnu-tools <<: *job-linux-xl tidy: false - env: - CI_ONLY_WHEN_SUBMODULES_CHANGED: 1 auto: permissions: diff --git a/src/ci/scripts/should-skip-this.sh b/src/ci/scripts/should-skip-this.sh index 85d772253808a..48127166ad080 100755 --- a/src/ci/scripts/should-skip-this.sh +++ b/src/ci/scripts/should-skip-this.sh @@ -1,46 +1,11 @@ #!/bin/bash -# Set the SKIP_JOB environment variable if this job is supposed to only run -# when submodules are updated and they were not. The following time consuming -# tasks will be skipped when the environment variable is present. +# Set the SKIP_JOB environment variable if this job is not supposed to run on the current builder. set -euo pipefail IFS=$'\n\t' source "$(cd "$(dirname "$0")" && pwd)/../shared.sh" -if [[ -n "${CI_ONLY_WHEN_SUBMODULES_CHANGED-}" ]]; then - git fetch "https://github.com/$GITHUB_REPOSITORY" "$GITHUB_BASE_REF" - BASE_COMMIT="$(git merge-base FETCH_HEAD HEAD)" - - echo "Searching for toolstate changes between $BASE_COMMIT and $(git rev-parse HEAD)" - - if git diff "$BASE_COMMIT" | grep --quiet "^index .* 160000"; then - # Submodules pseudo-files inside git have the 160000 permissions, so when - # those files are present in the diff a submodule was updated. - echo "Submodules were updated" - elif ! (git diff --quiet "$BASE_COMMIT" -- \ - src/tools/clippy src/tools/rustfmt src/tools/miri \ - library/std/src/sys); then - # There is not an easy blanket search for subtrees. For now, manually list - # the subtrees. - # Also run this when the platform-specific parts of std change, in case - # that breaks Miri. - echo "Tool subtrees were updated" - elif ! (git diff --quiet "$BASE_COMMIT" -- \ - tests/rustdoc-gui \ - src/librustdoc \ - src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile \ - src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version \ - src/tools/rustdoc-gui); then - # There was a change in either rustdoc or in its GUI tests. - echo "Rustdoc was updated" - else - echo "Not executing this job since no submodules nor subtrees were updated" - ciCommandSetEnv SKIP_JOB 1 - exit 0 - fi -fi - if [[ -n "${CI_ONLY_WHEN_CHANNEL-}" ]]; then if [[ "${CI_ONLY_WHEN_CHANNEL}" = "$(cat src/ci/channel)" ]]; then echo "The channel is the expected one" diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index 8540ee6631934..7690d8f251f74 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -23,11 +23,13 @@ {%- for theme in themes -%} {#- -#} {%- endfor -%} + {%- if !layout.default_settings.is_empty() -%} {#- -#} + {%- endif -%} {#- -#} {%- if page.css_class.contains("crate") -%} {#- -#} diff --git a/src/tools/tidy/src/error_codes.rs b/src/tools/tidy/src/error_codes.rs index 6bb4d32f87d0a..dd2fd1911f227 100644 --- a/src/tools/tidy/src/error_codes.rs +++ b/src/tools/tidy/src/error_codes.rs @@ -31,7 +31,7 @@ const IGNORE_DOCTEST_CHECK: &[&str] = &["E0464", "E0570", "E0601", "E0602", "E06 // Error codes that don't yet have a UI test. This list will eventually be removed. const IGNORE_UI_TEST_CHECK: &[&str] = - &["E0461", "E0465", "E0476", "E0514", "E0523", "E0554", "E0640", "E0717", "E0729"]; + &["E0461", "E0465", "E0476", "E0514", "E0554", "E0640", "E0717", "E0729"]; macro_rules! verbose_print { ($verbose:expr, $($fmt:tt)*) => { diff --git a/tests/mir-opt/copy-prop/move_projection.f.CopyProp.diff b/tests/mir-opt/copy-prop/move_projection.f.CopyProp.diff new file mode 100644 index 0000000000000..02308beb88af2 --- /dev/null +++ b/tests/mir-opt/copy-prop/move_projection.f.CopyProp.diff @@ -0,0 +1,31 @@ +- // MIR for `f` before CopyProp ++ // MIR for `f` after CopyProp + + fn f(_1: Foo) -> bool { + let mut _0: bool; // return place in scope 0 at $DIR/move_projection.rs:+0:17: +0:21 + let mut _2: Foo; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL + let mut _3: u8; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL + + bb0: { +- _2 = _1; // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL +- _3 = move (_2.0: u8); // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL +- _0 = opaque::(move _1) -> bb1; // scope 0 at $DIR/move_projection.rs:+6:13: +6:44 ++ _3 = (_1.0: u8); // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL ++ _0 = opaque::(_1) -> bb1; // scope 0 at $DIR/move_projection.rs:+6:13: +6:44 + // mir::Constant + // + span: $DIR/move_projection.rs:19:28: 19:34 + // + literal: Const { ty: fn(Foo) -> bool {opaque::}, val: Value() } + } + + bb1: { + _0 = opaque::(move _3) -> bb2; // scope 0 at $DIR/move_projection.rs:+9:13: +9:44 + // mir::Constant + // + span: $DIR/move_projection.rs:22:28: 22:34 + // + literal: Const { ty: fn(u8) -> bool {opaque::}, val: Value() } + } + + bb2: { + return; // scope 0 at $DIR/move_projection.rs:+12:13: +12:21 + } + } + diff --git a/tests/mir-opt/copy-prop/move_projection.rs b/tests/mir-opt/copy-prop/move_projection.rs new file mode 100644 index 0000000000000..2a1bbae99a4c8 --- /dev/null +++ b/tests/mir-opt/copy-prop/move_projection.rs @@ -0,0 +1,34 @@ +// unit-test: CopyProp + +#![feature(custom_mir, core_intrinsics)] +#![allow(unused_assignments)] +extern crate core; +use core::intrinsics::mir::*; + +fn opaque(_: impl Sized) -> bool { true } + +struct Foo(u8); + +#[custom_mir(dialect = "analysis", phase = "post-cleanup")] +fn f(a: Foo) -> bool { + mir!( + { + let b = a; + // This is a move out of a copy, so must become a copy of `a.0`. + let c = Move(b.0); + Call(RET, bb1, opaque(Move(a))) + } + bb1 = { + Call(RET, ret, opaque(Move(c))) + } + ret = { + Return() + } + ) +} + +fn main() { + assert!(f(Foo(0))); +} + +// EMIT_MIR move_projection.f.CopyProp.diff diff --git a/tests/mir-opt/simple_option_map_e2e.ezmap.PreCodegen.after.mir b/tests/mir-opt/simple_option_map_e2e.ezmap.PreCodegen.after.mir index e338f15b48531..66ba4df767ccf 100644 --- a/tests/mir-opt/simple_option_map_e2e.ezmap.PreCodegen.after.mir +++ b/tests/mir-opt/simple_option_map_e2e.ezmap.PreCodegen.after.mir @@ -34,7 +34,7 @@ fn ezmap(_1: Option) -> Option { } bb3: { - _4 = move ((_1 as Some).0: i32); // scope 1 at $DIR/simple_option_map_e2e.rs:7:14: 7:15 + _4 = ((_1 as Some).0: i32); // scope 1 at $DIR/simple_option_map_e2e.rs:7:14: 7:15 StorageLive(_5); // scope 2 at $DIR/simple_option_map_e2e.rs:7:25: 7:29 _5 = Add(_4, const 1_i32); // scope 3 at $DIR/simple_option_map_e2e.rs:+1:16: +1:21 _0 = Option::::Some(move _5); // scope 2 at $DIR/simple_option_map_e2e.rs:7:20: 7:30 diff --git a/tests/ui/associated-types/hr-associated-type-projection-1.stderr b/tests/ui/associated-types/hr-associated-type-projection-1.stderr index a65f84ae58ead..2281d9419b461 100644 --- a/tests/ui/associated-types/hr-associated-type-projection-1.stderr +++ b/tests/ui/associated-types/hr-associated-type-projection-1.stderr @@ -16,8 +16,8 @@ LL | for<'b> >::Item: std::ops::Deref, | ^^^^^^^^^^ required by this bound in `UnsafeCopy` help: consider further restricting this bound | -LL | impl> UnsafeCopy<'_, T> for T { - | +++++++++++++++++++ +LL | impl> UnsafeCopy<'_, T> for T { + | ++++++++++++ error: aborting due to previous error diff --git a/tests/ui/async-await/future-sizes/async-awaiting-fut.rs b/tests/ui/async-await/future-sizes/async-awaiting-fut.rs new file mode 100644 index 0000000000000..1816d842d6c41 --- /dev/null +++ b/tests/ui/async-await/future-sizes/async-awaiting-fut.rs @@ -0,0 +1,24 @@ +// compile-flags: -Z print-type-sizes --crate-type lib +// edition:2021 +// build-pass +// ignore-pass + +async fn wait() {} + +async fn big_fut(arg: [u8; 1024]) {} + +async fn calls_fut(fut: impl std::future::Future) { + loop { + wait().await; + if true { + return fut.await; + } else { + wait().await; + } + } +} + +pub async fn test() { + let fut = big_fut([0u8; 1024]); + calls_fut(fut).await; +} diff --git a/tests/ui/async-await/future-sizes/async-awaiting-fut.stdout b/tests/ui/async-await/future-sizes/async-awaiting-fut.stdout new file mode 100644 index 0000000000000..eaf3e4b61e304 --- /dev/null +++ b/tests/ui/async-await/future-sizes/async-awaiting-fut.stdout @@ -0,0 +1,72 @@ +print-type-size type: `[async fn body@$DIR/async-awaiting-fut.rs:21:21: 24:2]`: 3078 bytes, alignment: 1 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Unresumed`: 0 bytes +print-type-size variant `Suspend0`: 3077 bytes +print-type-size local `.__awaitee`: 3077 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size variant `Returned`: 0 bytes +print-type-size variant `Panicked`: 0 bytes +print-type-size type: `[async fn body@$DIR/async-awaiting-fut.rs:10:64: 19:2]`: 3077 bytes, alignment: 1 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Unresumed`: 2051 bytes +print-type-size padding: 1026 bytes +print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes +print-type-size variant `Suspend0`: 2052 bytes +print-type-size local `.fut`: 1025 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size local `..generator_field4`: 1 bytes +print-type-size padding: 1 bytes +print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes +print-type-size local `.__awaitee`: 1 bytes +print-type-size variant `Suspend1`: 3076 bytes +print-type-size padding: 1024 bytes +print-type-size local `..generator_field4`: 1 bytes, alignment: 1 bytes +print-type-size padding: 1 bytes +print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes +print-type-size local `.__awaitee`: 1025 bytes +print-type-size variant `Suspend2`: 2052 bytes +print-type-size local `.fut`: 1025 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size local `..generator_field4`: 1 bytes +print-type-size padding: 1 bytes +print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes +print-type-size local `.__awaitee`: 1 bytes +print-type-size variant `Returned`: 2051 bytes +print-type-size padding: 1026 bytes +print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes +print-type-size variant `Panicked`: 2051 bytes +print-type-size padding: 1026 bytes +print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes +print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/async-awaiting-fut.rs:10:64: 19:2]>`: 3077 bytes, alignment: 1 bytes +print-type-size field `.value`: 3077 bytes +print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/async-awaiting-fut.rs:10:64: 19:2]>`: 3077 bytes, alignment: 1 bytes +print-type-size variant `MaybeUninit`: 3077 bytes +print-type-size field `.uninit`: 0 bytes +print-type-size field `.value`: 3077 bytes +print-type-size type: `[async fn body@$DIR/async-awaiting-fut.rs:8:35: 8:37]`: 1025 bytes, alignment: 1 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Unresumed`: 1024 bytes +print-type-size upvar `.arg`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size variant `Returned`: 1024 bytes +print-type-size upvar `.arg`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size variant `Panicked`: 1024 bytes +print-type-size upvar `.arg`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes +print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/async-awaiting-fut.rs:8:35: 8:37]>`: 1025 bytes, alignment: 1 bytes +print-type-size field `.value`: 1025 bytes +print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/async-awaiting-fut.rs:8:35: 8:37]>`: 1025 bytes, alignment: 1 bytes +print-type-size variant `MaybeUninit`: 1025 bytes +print-type-size field `.uninit`: 0 bytes +print-type-size field `.value`: 1025 bytes +print-type-size type: `[async fn body@$DIR/async-awaiting-fut.rs:6:17: 6:19]`: 1 bytes, alignment: 1 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Unresumed`: 0 bytes +print-type-size variant `Returned`: 0 bytes +print-type-size variant `Panicked`: 0 bytes +print-type-size type: `std::mem::ManuallyDrop`: 1 bytes, alignment: 1 bytes +print-type-size field `.value`: 1 bytes +print-type-size type: `std::mem::MaybeUninit`: 1 bytes, alignment: 1 bytes +print-type-size variant `MaybeUninit`: 1 bytes +print-type-size field `.uninit`: 0 bytes +print-type-size field `.value`: 1 bytes +print-type-size type: `std::task::Poll<()>`: 1 bytes, alignment: 1 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Ready`: 0 bytes +print-type-size field `.0`: 0 bytes +print-type-size variant `Pending`: 0 bytes diff --git a/tests/ui/error-codes/E0523.rs b/tests/ui/error-codes/E0523.rs new file mode 100644 index 0000000000000..47717fbd508a8 --- /dev/null +++ b/tests/ui/error-codes/E0523.rs @@ -0,0 +1,14 @@ +// aux-build:crateresolve1-1.rs +// aux-build:crateresolve1-2.rs +// aux-build:crateresolve1-3.rs + +// normalize-stderr-test: "\.nll/" -> "/" +// normalize-stderr-test: "\\\?\\" -> "" +// normalize-stderr-test: "(lib)?crateresolve1-([123])\.[a-z]+" -> "libcrateresolve1-$2.somelib" + +// NOTE: This test is duplicated from `tests/ui/crate-loading/crateresolve1.rs`. + +extern crate crateresolve1; +//~^ ERROR multiple candidates for `rlib` dependency `crateresolve1` found + +fn main() {} diff --git a/tests/ui/error-codes/E0523.stderr b/tests/ui/error-codes/E0523.stderr new file mode 100644 index 0000000000000..8e3eb2159c298 --- /dev/null +++ b/tests/ui/error-codes/E0523.stderr @@ -0,0 +1,13 @@ +error[E0464]: multiple candidates for `rlib` dependency `crateresolve1` found + --> $DIR/E0523.rs:11:1 + | +LL | extern crate crateresolve1; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: candidate #1: $TEST_BUILD_DIR/error-codes/E0523/auxiliary/libcrateresolve1-1.somelib + = note: candidate #2: $TEST_BUILD_DIR/error-codes/E0523/auxiliary/libcrateresolve1-2.somelib + = note: candidate #3: $TEST_BUILD_DIR/error-codes/E0523/auxiliary/libcrateresolve1-3.somelib + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0464`. diff --git a/tests/ui/generic-associated-types/issue-68656-unsized-values.stderr b/tests/ui/generic-associated-types/issue-68656-unsized-values.stderr index e8770aedfa1c7..f0212e985a92c 100644 --- a/tests/ui/generic-associated-types/issue-68656-unsized-values.stderr +++ b/tests/ui/generic-associated-types/issue-68656-unsized-values.stderr @@ -15,8 +15,8 @@ LL | type Item<'a>: std::ops::Deref; | ^^^^^^^^^^ required by this bound in `UnsafeCopy::Item` help: consider further restricting this bound | -LL | impl> UnsafeCopy for T { - | +++++++++++++++++++ +LL | impl> UnsafeCopy for T { + | ++++++++++++ error: aborting due to previous error diff --git a/tests/ui/generic-associated-types/missing-bounds.fixed b/tests/ui/generic-associated-types/missing-bounds.fixed index ee758f19ec105..054adbffbeafb 100644 --- a/tests/ui/generic-associated-types/missing-bounds.fixed +++ b/tests/ui/generic-associated-types/missing-bounds.fixed @@ -4,7 +4,7 @@ use std::ops::Add; struct A(B); -impl Add for A where B: Add + Add { +impl Add for A where B: Add { type Output = Self; fn add(self, rhs: Self) -> Self { @@ -14,7 +14,7 @@ impl Add for A where B: Add + Add { struct C(B); -impl> Add for C { +impl> Add for C { type Output = Self; fn add(self, rhs: Self) -> Self { @@ -34,7 +34,7 @@ impl> Add for D { struct E(B); -impl> Add for E where B: Add { +impl> Add for E where B: Add { //~^ ERROR equality constraints are not yet supported in `where` clauses type Output = Self; diff --git a/tests/ui/generic-associated-types/missing-bounds.stderr b/tests/ui/generic-associated-types/missing-bounds.stderr index 9f669b9a5214b..535edec575a7d 100644 --- a/tests/ui/generic-associated-types/missing-bounds.stderr +++ b/tests/ui/generic-associated-types/missing-bounds.stderr @@ -37,8 +37,8 @@ LL | struct A(B); | ^ help: consider further restricting this bound | -LL | impl Add for A where B: Add + Add { - | +++++++++++++++++ +LL | impl Add for A where B: Add { + | ++++++++++++ error[E0308]: mismatched types --> $DIR/missing-bounds.rs:21:14 @@ -60,8 +60,8 @@ LL | struct C(B); | ^ help: consider further restricting this bound | -LL | impl> Add for C { - | +++++++++++++++++ +LL | impl> Add for C { + | ++++++++++++ error[E0369]: cannot add `B` to `B` --> $DIR/missing-bounds.rs:31:21 @@ -96,8 +96,8 @@ LL | struct E(B); | ^ help: consider further restricting this bound | -LL | impl> Add for E where ::Output = B { - | +++++++++++++++++ +LL | impl> Add for E where ::Output = B { + | ++++++++++++ error: aborting due to 5 previous errors diff --git a/tests/ui/suggestions/restrict-existing-type-bounds.rs b/tests/ui/suggestions/restrict-existing-type-bounds.rs new file mode 100644 index 0000000000000..07712ce0de684 --- /dev/null +++ b/tests/ui/suggestions/restrict-existing-type-bounds.rs @@ -0,0 +1,30 @@ +pub trait TryAdd { + type Error; + type Output; + + fn try_add(self, rhs: Rhs) -> Result; +} + +impl TryAdd for Option { + type Error = ::Error; + type Output = Option<::Output>; + + fn try_add(self, rhs: Self) -> Result { + Ok(self) //~ ERROR mismatched types + } +} + +struct Other(A); + +struct X; + +impl> TryAdd for Other { + type Error = ::Error; + type Output = Other<::Output>; + + fn try_add(self, rhs: Self) -> Result { + Ok(self) //~ ERROR mismatched types + } +} + +fn main() {} diff --git a/tests/ui/suggestions/restrict-existing-type-bounds.stderr b/tests/ui/suggestions/restrict-existing-type-bounds.stderr new file mode 100644 index 0000000000000..14a244b790a63 --- /dev/null +++ b/tests/ui/suggestions/restrict-existing-type-bounds.stderr @@ -0,0 +1,57 @@ +error[E0308]: mismatched types + --> $DIR/restrict-existing-type-bounds.rs:13:12 + | +LL | impl TryAdd for Option { + | - this type parameter +... +LL | Ok(self) + | -- ^^^^ expected `Option<::Output>`, found `Option` + | | + | arguments to this enum variant are incorrect + | + = note: expected enum `Option<::Output>` + found enum `Option` +help: the type constructed contains `Option` due to the type of the argument passed + --> $DIR/restrict-existing-type-bounds.rs:13:9 + | +LL | Ok(self) + | ^^^----^ + | | + | this argument influences the type of `Ok` +note: tuple variant defined here + --> $SRC_DIR/core/src/result.rs:LL:COL +help: consider further restricting this bound + | +LL | impl> TryAdd for Option { + | ++++++++++++ + +error[E0308]: mismatched types + --> $DIR/restrict-existing-type-bounds.rs:26:12 + | +LL | impl> TryAdd for Other { + | - this type parameter +... +LL | Ok(self) + | -- ^^^^ expected `Other<::Output>`, found `Other` + | | + | arguments to this enum variant are incorrect + | + = note: expected struct `Other<::Output>` + found struct `Other` +help: the type constructed contains `Other` due to the type of the argument passed + --> $DIR/restrict-existing-type-bounds.rs:26:9 + | +LL | Ok(self) + | ^^^----^ + | | + | this argument influences the type of `Ok` +note: tuple variant defined here + --> $SRC_DIR/core/src/result.rs:LL:COL +help: consider further restricting this bound + | +LL | impl> TryAdd for Other { + | ++++++++++++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/suggestions/type-mismatch-byte-literal.rs b/tests/ui/suggestions/type-mismatch-byte-literal.rs index 34199f8c37c10..80cd2ca7dfc9a 100644 --- a/tests/ui/suggestions/type-mismatch-byte-literal.rs +++ b/tests/ui/suggestions/type-mismatch-byte-literal.rs @@ -12,7 +12,19 @@ fn main() { //~^ ERROR: mismatched types [E0308] //~| HELP: if you meant to write a byte literal, prefix with `b` + let _a: u8 = '\x20'; + //~^ ERROR: mismatched types [E0308] + //~| HELP: if you meant to write a byte literal, prefix with `b` + + // Do not issue the suggestion if the char literal is a Unicode escape + foo('\u{0080}'); + //~^ ERROR: mismatched types [E0308] + // Do not issue the suggestion if the char literal isn't ASCII let _t: u8 = '€'; //~^ ERROR: mismatched types [E0308] + + // Do not issue the suggestion if the char literal isn't ASCII + foo('\u{1f980}'); + //~^ ERROR: mismatched types [E0308] } diff --git a/tests/ui/suggestions/type-mismatch-byte-literal.stderr b/tests/ui/suggestions/type-mismatch-byte-literal.stderr index c9c2e7498d058..3d27149f0dcf1 100644 --- a/tests/ui/suggestions/type-mismatch-byte-literal.stderr +++ b/tests/ui/suggestions/type-mismatch-byte-literal.stderr @@ -30,13 +30,54 @@ LL | foo(b'#'); | ~~~~ error[E0308]: mismatched types - --> $DIR/type-mismatch-byte-literal.rs:16:18 + --> $DIR/type-mismatch-byte-literal.rs:15:18 + | +LL | let _a: u8 = '\x20'; + | -- ^^^^^^ expected `u8`, found `char` + | | + | expected due to this + | +help: if you meant to write a byte literal, prefix with `b` + | +LL | let _a: u8 = b'\x20'; + | ~~~~~~~ + +error[E0308]: mismatched types + --> $DIR/type-mismatch-byte-literal.rs:20:9 + | +LL | foo('\u{0080}'); + | --- ^^^^^^^^^^ expected `u8`, found `char` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/type-mismatch-byte-literal.rs:4:4 + | +LL | fn foo(_t: u8) {} + | ^^^ ------ + +error[E0308]: mismatched types + --> $DIR/type-mismatch-byte-literal.rs:24:18 | LL | let _t: u8 = '€'; | -- ^^^ expected `u8`, found `char` | | | expected due to this -error: aborting due to 3 previous errors +error[E0308]: mismatched types + --> $DIR/type-mismatch-byte-literal.rs:28:9 + | +LL | foo('\u{1f980}'); + | --- ^^^^^^^^^^^ expected `u8`, found `char` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/type-mismatch-byte-literal.rs:4:4 + | +LL | fn foo(_t: u8) {} + | ^^^ ------ + +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0308`.