From 063afa7684e9200268b8b142b695a54c92f3b1f6 Mon Sep 17 00:00:00 2001 From: Shunpoco Date: Sat, 7 Mar 2026 17:01:04 +0000 Subject: [PATCH 01/14] introduce granular tidy_ctx.start_check in extra_checks Currently extra_checks acts as a single check. It has some downsides: - It is completely sequential. If one sub-check fails, next sub-checks are not executed - sub-checks are not tracked on TidyCtx's failed checks This commit extract those sub-chekcs into separate functions, and call tidy_ctx.start_check() in each function. It also add start_check() for prepare functions (installing python/npm packages) because some sub-checks rely on them. --- src/tools/tidy/src/extra_checks/mod.rs | 512 +++++++++++++++---------- 1 file changed, 312 insertions(+), 200 deletions(-) diff --git a/src/tools/tidy/src/extra_checks/mod.rs b/src/tools/tidy/src/extra_checks/mod.rs index 124de884637ea..ccd53453bbf37 100644 --- a/src/tools/tidy/src/extra_checks/mod.rs +++ b/src/tools/tidy/src/extra_checks/mod.rs @@ -58,38 +58,6 @@ pub fn check( pos_args: Vec, tidy_ctx: TidyCtx, ) { - let mut check = tidy_ctx.start_check("extra_checks"); - - if let Err(e) = check_impl( - root_path, - outdir, - librustdoc_path, - tools_path, - npm, - cargo, - extra_checks, - pos_args, - &tidy_ctx, - ) { - check.error(e); - } -} - -fn check_impl( - root_path: &Path, - outdir: &Path, - librustdoc_path: &Path, - tools_path: &Path, - npm: &Path, - cargo: &Path, - extra_checks: Option>, - pos_args: Vec, - tidy_ctx: &TidyCtx, -) -> Result<(), Error> { - let show_diff = - std::env::var("TIDY_PRINT_DIFF").is_ok_and(|v| v.eq_ignore_ascii_case("true") || v == "1"); - let bless = tidy_ctx.is_bless_enabled(); - // Split comma-separated args up let mut lint_args = match extra_checks { Some(s) => s @@ -129,12 +97,6 @@ fn check_impl( }; } - let rerun_with_bless = |mode: &str, action: &str| { - if !bless { - eprintln!("rerun tidy with `--extra-checks={mode} --bless` to {action}"); - } - }; - let python_lint = extra_check!(Py, Lint); let python_fmt = extra_check!(Py, Fmt); let shell_lint = extra_check!(Shell, Lint); @@ -151,204 +113,354 @@ fn check_impl( .partition(|arg| arg.to_str().is_some_and(|s| s.starts_with('-'))); if python_lint || python_fmt || cpp_fmt { - let venv_path = outdir.join("venv"); - let mut reqs_path = root_path.to_owned(); - reqs_path.extend(PIP_REQ_PATH); - py_path = Some(get_or_create_venv(&venv_path, &reqs_path)?); + match py_prepare(root_path, outdir, &tidy_ctx) { + Ok(p) => py_path = Some(p), + Err(_) => return, + } } if python_lint { - let py_path = py_path.as_ref().unwrap(); - let args: &[&OsStr] = if bless { - eprintln!("linting python files and applying suggestions"); - &["check".as_ref(), "--fix".as_ref()] - } else { - eprintln!("linting python files"); - &["check".as_ref()] - }; + check_python_lint( + root_path, + outdir, + &cfg_args, + &file_args, + py_path.as_ref().unwrap(), + &tidy_ctx, + ); + } - let res = run_ruff(root_path, outdir, py_path, &cfg_args, &file_args, args); + if python_fmt { + check_python_fmt( + root_path, + outdir, + &cfg_args, + &file_args, + py_path.as_ref().unwrap(), + &tidy_ctx, + ); + } - if res.is_err() && show_diff && !bless { - eprintln!("\npython linting failed! Printing diff suggestions:"); + if cpp_fmt { + check_cpp_fmt(root_path, &cfg_args, &file_args, py_path.as_ref().unwrap(), &tidy_ctx); + } - let diff_res = run_ruff( - root_path, - outdir, - py_path, - &cfg_args, - &file_args, - &["check".as_ref(), "--diff".as_ref()], - ); - // `ruff check --diff` will return status 0 if there are no suggestions. - if diff_res.is_err() { - rerun_with_bless("py:lint", "apply ruff suggestions"); - } - } - // Rethrow error - res?; + if shell_lint { + check_shell_lint(root_path, &cfg_args, &file_args, &tidy_ctx); } - if python_fmt { - let mut args: Vec<&OsStr> = vec!["format".as_ref()]; - if bless { - eprintln!("formatting python files"); - } else { - eprintln!("checking python file formatting"); - args.push("--check".as_ref()); + if spellcheck { + check_spellcheck(root_path, outdir, cargo, &tidy_ctx); + } + + if js_lint || js_typecheck { + if js_prepare(root_path, outdir, npm, &tidy_ctx).is_err() { + return; } + } + + if js_lint { + check_js_lint(outdir, librustdoc_path, tools_path, &tidy_ctx); + } - let py_path = py_path.as_ref().unwrap(); - let res = run_ruff(root_path, outdir, py_path, &cfg_args, &file_args, &args); + if js_typecheck { + check_js_typecheck(outdir, librustdoc_path, &tidy_ctx); + } +} - if res.is_err() && !bless { - if show_diff { - eprintln!("\npython formatting does not match! Printing diff:"); +/// Since python lint, format and cpp format share python env, we need to ensure python env is installed before running those checks. +fn py_prepare(root_path: &Path, outdir: &Path, tidy_ctx: &TidyCtx) -> Result { + let mut check = tidy_ctx.start_check("extra_checks:py_prepare"); - let _ = run_ruff( - root_path, - outdir, - py_path, - &cfg_args, - &file_args, - &["format".as_ref(), "--diff".as_ref()], - ); - } - rerun_with_bless("py:fmt", "reformat Python code"); - } + let venv_path = outdir.join("venv"); + let mut reqs_path = root_path.to_owned(); + reqs_path.extend(PIP_REQ_PATH); - // Rethrow error - res?; + let res = get_or_create_venv(&venv_path, &reqs_path); + if let Err(e) = res { + check.error(e.to_string()); + return Err(e); } - if cpp_fmt { - let mut cfg_args_clang_format = cfg_args.clone(); - let mut file_args_clang_format = file_args.clone(); - let config_path = root_path.join(".clang-format"); - let config_file_arg = format!("file:{}", config_path.display()); - cfg_args_clang_format.extend(&["--style".as_ref(), config_file_arg.as_ref()]); - if bless { - eprintln!("formatting C++ files"); - cfg_args_clang_format.push("-i".as_ref()); - } else { - eprintln!("checking C++ file formatting"); - cfg_args_clang_format.extend(&["--dry-run".as_ref(), "--Werror".as_ref()]); - } - let files; - if file_args_clang_format.is_empty() { - let llvm_wrapper = root_path.join("compiler/rustc_llvm/llvm-wrapper"); - files = find_with_extension( - root_path, - Some(llvm_wrapper.as_path()), - &[OsStr::new("h"), OsStr::new("cpp")], - )?; - file_args_clang_format.extend(files.iter().map(|p| p.as_os_str())); - } - let args = merge_args(&cfg_args_clang_format, &file_args_clang_format); - let res = py_runner(py_path.as_ref().unwrap(), false, None, "clang-format", &args); - - if res.is_err() && show_diff && !bless { - eprintln!("\nclang-format linting failed! Printing diff suggestions:"); - - let mut cfg_args_clang_format_diff = cfg_args.clone(); - cfg_args_clang_format_diff.extend(&["--style".as_ref(), config_file_arg.as_ref()]); - for file in file_args_clang_format { - let mut formatted = String::new(); - let mut diff_args = cfg_args_clang_format_diff.clone(); - diff_args.push(file); - let _ = py_runner( - py_path.as_ref().unwrap(), - false, - Some(&mut formatted), - "clang-format", - &diff_args, - ); - if formatted.is_empty() { - eprintln!( - "failed to obtain the formatted content for '{}'", - file.to_string_lossy() - ); - continue; - } - let actual = std::fs::read_to_string(file).unwrap_or_else(|e| { - panic!( - "failed to read the C++ file at '{}' due to '{e}'", - file.to_string_lossy() - ) - }); - if formatted != actual { - let diff = similar::TextDiff::from_lines(&actual, &formatted); - eprintln!( - "{}", - diff.unified_diff().context_radius(4).header( - &format!("{} (actual)", file.to_string_lossy()), - &format!("{} (formatted)", file.to_string_lossy()) - ) - ); - } + res +} + +/// Since js lint and format share node env, we need to ensure node env is installed before running those checks. +fn js_prepare( + root_path: &Path, + outdir: &Path, + npm: &Path, + tidy_ctx: &TidyCtx, +) -> Result<(), Error> { + let mut check = tidy_ctx.start_check("extra_checks:js_prepare"); + + if let Err(e) = rustdoc_js::npm_install(root_path, outdir, npm) { + check.error(e.to_string()); + return Err(e); + } + + Ok(()) +} + +fn rerun_with_bless(mode: &str, action: &str, bless: bool) { + if !bless { + eprintln!("rerun tidy with `--extra-checks={mode} --bless` to {action}"); + } +} + +fn show_diff() -> bool { + std::env::var("TIDY_PRINT_DIFF").is_ok_and(|v| v.eq_ignore_ascii_case("true") || v == "1") +} + +fn check_spellcheck(root_path: &Path, outdir: &Path, cargo: &Path, tidy_ctx: &TidyCtx) { + let mut check = tidy_ctx.start_check("extra_checks:spellcheck"); + + let bless = tidy_ctx.is_bless_enabled(); + + let config_path = root_path.join("typos.toml"); + let mut args = vec!["-c", config_path.as_os_str().to_str().unwrap()]; + args.extend_from_slice(SPELLCHECK_DIRS); + + if bless { + eprintln!("spellchecking files and fixing typos"); + args.push("--write-changes"); + } else { + eprintln!("spellchecking files"); + } + + if let Err(e) = + spellcheck_runner(root_path, &outdir, &cargo, &args, tidy_ctx.is_running_on_ci()) + { + rerun_with_bless("spellcheck", "fix typos", bless); + check.error(e); + } +} + +fn check_js_lint(outdir: &Path, librustdoc_path: &Path, tools_path: &Path, tidy_ctx: &TidyCtx) { + let mut check = tidy_ctx.start_check("extra_checks:js_lint"); + + let bless = tidy_ctx.is_bless_enabled(); + + if bless { + eprintln!("linting javascript files and applying suggestions"); + } else { + eprintln!("linting javascript files"); + } + + if let Err(e) = rustdoc_js::lint(outdir, librustdoc_path, tools_path, bless) { + rerun_with_bless("js:lint", "apply esplint suggestion", bless); + check.error(e); + return; + } + + if let Err(e) = rustdoc_js::es_check(outdir, librustdoc_path) { + check.error(e); + } +} + +fn check_js_typecheck(outdir: &Path, librustdoc_path: &Path, tidy_ctx: &TidyCtx) { + let mut check = tidy_ctx.start_check("extra_checks:js_typecheck"); + + eprintln!("typechecking javascript files"); + if let Err(e) = rustdoc_js::typecheck(outdir, librustdoc_path) { + check.error(e); + } +} + +fn check_shell_lint( + root_path: &Path, + cfg_args: &Vec<&OsStr>, + file_args: &Vec<&OsStr>, + tidy_ctx: &TidyCtx, +) { + let mut check = tidy_ctx.start_check("extra_checks:shell_lint"); + + eprintln!("linting shell files"); + + let mut file_args_shc = file_args.clone(); + let files; + if file_args.is_empty() { + match find_with_extension(root_path, None, &[OsStr::new("sh")]) { + Ok(f) => files = f, + Err(e) => { + check.error(e); + return; } - rerun_with_bless("cpp:fmt", "reformat C++ code"); } - // Rethrow error - res?; + + file_args_shc.extend(files.iter().map(|p| p.as_os_str())); } - if shell_lint { - eprintln!("linting shell files"); + if let Err(e) = shellcheck_runner(&merge_args(&cfg_args, &file_args_shc)) { + check.error(e); + } +} + +fn check_python_lint( + root_path: &Path, + outdir: &Path, + cfg_args: &Vec<&OsStr>, + file_args: &Vec<&OsStr>, + py_path: &Path, + tidy_ctx: &TidyCtx, +) { + let mut check = tidy_ctx.start_check("extra_checks:python_lint"); - let mut file_args_shc = file_args.clone(); - let files; - if file_args_shc.is_empty() { - files = find_with_extension(root_path, None, &[OsStr::new("sh")])?; - file_args_shc.extend(files.iter().map(|p| p.as_os_str())); + let bless = tidy_ctx.is_bless_enabled(); + + let args: &[&OsStr] = if bless { + eprintln!("linting python files and applying suggestions"); + &["check".as_ref(), "--fix".as_ref()] + } else { + eprintln!("linting python files"); + &["check".as_ref()] + }; + + let res = run_ruff(root_path, outdir, py_path, &cfg_args, &file_args, args); + + if res.is_err() && show_diff() && !bless { + eprintln!("\npython linting failed! Printing diff suggestions:"); + + let diff_res = run_ruff( + root_path, + outdir, + py_path, + &cfg_args, + &file_args, + &["check".as_ref(), "--diff".as_ref()], + ); + // `ruff check --diff` will return status 0 if there are no suggestions. + if diff_res.is_err() { + rerun_with_bless("py:lint", "apply ruff suggestions", bless); } + } + if let Err(e) = res { + check.error(e); + } +} + +fn check_python_fmt( + root_path: &Path, + outdir: &Path, + cfg_args: &Vec<&OsStr>, + file_args: &Vec<&OsStr>, + py_path: &Path, + tidy_ctx: &TidyCtx, +) { + let mut check = tidy_ctx.start_check("extra_checks:python_fmt"); + + let bless = tidy_ctx.is_bless_enabled(); - shellcheck_runner(&merge_args(&cfg_args, &file_args_shc))?; + let mut args: Vec<&OsStr> = vec!["format".as_ref()]; + if bless { + eprintln!("formatting python files"); + } else { + eprintln!("checking python file formatting"); + args.push("--check".as_ref()); } - if spellcheck { - let config_path = root_path.join("typos.toml"); - let mut args = vec!["-c", config_path.as_os_str().to_str().unwrap()]; + let res = run_ruff(root_path, outdir, py_path, &cfg_args, &file_args, &args); - args.extend_from_slice(SPELLCHECK_DIRS); + if res.is_err() && !bless { + if show_diff() { + eprintln!("\npython formatting does not match! Printing diff:"); - if bless { - eprintln!("spellchecking files and fixing typos"); - args.push("--write-changes"); - } else { - eprintln!("spellchecking files"); - } - let res = spellcheck_runner(root_path, &outdir, &cargo, &args, tidy_ctx.is_running_on_ci()); - if res.is_err() { - rerun_with_bless("spellcheck", "fix typos"); + let _ = run_ruff( + root_path, + outdir, + py_path, + &cfg_args, + &file_args, + &["format".as_ref(), "--diff".as_ref()], + ); } - res?; + rerun_with_bless("py:fmt", "reformat Python code", bless); } - if js_lint || js_typecheck { - rustdoc_js::npm_install(root_path, outdir, npm)?; + if let Err(e) = res { + check.error(e); } +} - if js_lint { - if bless { - eprintln!("linting javascript files and applying suggestions"); - } else { - eprintln!("linting javascript files"); +fn check_cpp_fmt( + root_path: &Path, + cfg_args: &Vec<&OsStr>, + file_args: &Vec<&OsStr>, + py_path: &Path, + tidy_ctx: &TidyCtx, +) { + let mut check = tidy_ctx.start_check("extra_checks:cpp_fmt"); + + let bless = tidy_ctx.is_bless_enabled(); + + let mut cfg_args_clang_format = cfg_args.clone(); + let mut file_args_clang_format = file_args.clone(); + let config_path = root_path.join(".clang-format"); + let config_file_arg = format!("file:{}", config_path.display()); + cfg_args_clang_format.extend(&["--style".as_ref(), config_file_arg.as_ref()]); + if bless { + eprintln!("formatting C++ files"); + cfg_args_clang_format.push("-i".as_ref()); + } else { + eprintln!("checking C++ file formatting"); + cfg_args_clang_format.extend(&["--dry-run".as_ref(), "--Werror".as_ref()]); + } + let files; + if file_args_clang_format.is_empty() { + let llvm_wrapper = root_path.join("compiler/rustc_llvm/llvm-wrapper"); + match find_with_extension( + root_path, + Some(llvm_wrapper.as_path()), + &[OsStr::new("h"), OsStr::new("cpp")], + ) { + Ok(f) => files = f, + Err(e) => { + check.error(e); + return; + } } - let res = rustdoc_js::lint(outdir, librustdoc_path, tools_path, bless); - if res.is_err() { - rerun_with_bless("js:lint", "apply eslint suggestions"); + file_args_clang_format.extend(files.iter().map(|p| p.as_os_str())); + } + let args = merge_args(&cfg_args_clang_format, &file_args_clang_format); + let res = py_runner(py_path, false, None, "clang-format", &args); + + if res.is_err() && show_diff() && !bless { + eprintln!("\nclang-format linting failed! Printing diff suggestions:"); + + let mut cfg_args_diff = cfg_args.clone(); + cfg_args_diff.extend(&["--style".as_ref(), config_file_arg.as_ref()]); + for file in file_args { + let mut formatted = String::new(); + let mut diff_args = cfg_args_diff.clone(); + diff_args.push(file); + let _ = py_runner(py_path, false, Some(&mut formatted), "clang-format", &diff_args); + if formatted.is_empty() { + eprintln!( + "failed to obtain the formatted content for '{}'", + file.to_string_lossy() + ); + continue; + } + let actual = std::fs::read_to_string(file).unwrap_or_else(|e| { + panic!("failed to read the C++ file at '{}' due to '{e}'", file.to_string_lossy()) + }); + if formatted != actual { + let diff = similar::TextDiff::from_lines(&actual, &formatted); + eprintln!( + "{}", + diff.unified_diff().context_radius(4).header( + &format!("{} (actual)", file.to_string_lossy()), + &format!("{} (formatted)", file.to_string_lossy()) + ) + ); + } } - res?; - rustdoc_js::es_check(outdir, librustdoc_path)?; + rerun_with_bless("cpp:fmt", "reformat C++ code", bless); } - if js_typecheck { - eprintln!("typechecking javascript files"); - rustdoc_js::typecheck(outdir, librustdoc_path)?; + if let Err(e) = res { + check.error(e); } - - Ok(()) } fn run_ruff( From 514f833a6b75de6e66f559efa917fc085dd9604b Mon Sep 17 00:00:00 2001 From: Shunpoco Date: Sun, 8 Mar 2026 21:23:36 +0000 Subject: [PATCH 02/14] address review comments --- src/tools/tidy/src/extra_checks/mod.rs | 50 +++++++++++++++----------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/tools/tidy/src/extra_checks/mod.rs b/src/tools/tidy/src/extra_checks/mod.rs index ccd53453bbf37..a1fe9f3b77630 100644 --- a/src/tools/tidy/src/extra_checks/mod.rs +++ b/src/tools/tidy/src/extra_checks/mod.rs @@ -17,7 +17,7 @@ //! 3. Print the output of the given command. If it fails and `TIDY_PRINT_DIFF` //! is set, rerun the tool to print a suggestion diff (for e.g. CI) -use std::ffi::OsStr; +use std::ffi::{OsStr, OsString}; use std::path::{Path, PathBuf}; use std::process::Command; use std::str::FromStr; @@ -113,6 +113,7 @@ pub fn check( .partition(|arg| arg.to_str().is_some_and(|s| s.starts_with('-'))); if python_lint || python_fmt || cpp_fmt { + // Since python lint, format and cpp format share python env, we need to ensure python env is installed before running those checks. match py_prepare(root_path, outdir, &tidy_ctx) { Ok(p) => py_path = Some(p), Err(_) => return, @@ -154,6 +155,7 @@ pub fn check( } if js_lint || js_typecheck { + // Since js lint and format share node env, we need to ensure node env is installed before running those checks. if js_prepare(root_path, outdir, npm, &tidy_ctx).is_err() { return; } @@ -168,41 +170,46 @@ pub fn check( } } -/// Since python lint, format and cpp format share python env, we need to ensure python env is installed before running those checks. -fn py_prepare(root_path: &Path, outdir: &Path, tidy_ctx: &TidyCtx) -> Result { +// It is used by prepare functions because they handle errors themselves, so the caller doesn't need to handle errors. +struct ErrorGuaranteed(()); + +fn py_prepare( + root_path: &Path, + outdir: &Path, + tidy_ctx: &TidyCtx, +) -> Result { let mut check = tidy_ctx.start_check("extra_checks:py_prepare"); let venv_path = outdir.join("venv"); let mut reqs_path = root_path.to_owned(); reqs_path.extend(PIP_REQ_PATH); - let res = get_or_create_venv(&venv_path, &reqs_path); - if let Err(e) = res { - check.error(e.to_string()); - return Err(e); + match get_or_create_venv(&venv_path, &reqs_path) { + Ok(p) => Ok(p), + Err(e) => { + check.error(e); + Err(ErrorGuaranteed(())) + } } - - res } -/// Since js lint and format share node env, we need to ensure node env is installed before running those checks. fn js_prepare( root_path: &Path, outdir: &Path, npm: &Path, tidy_ctx: &TidyCtx, -) -> Result<(), Error> { +) -> Result<(), ErrorGuaranteed> { let mut check = tidy_ctx.start_check("extra_checks:js_prepare"); if let Err(e) = rustdoc_js::npm_install(root_path, outdir, npm) { check.error(e.to_string()); - return Err(e); + return Err(ErrorGuaranteed(())); } Ok(()) } -fn rerun_with_bless(mode: &str, action: &str, bless: bool) { +fn show_bless_help(mode: &str, action: &str, bless: bool) { if !bless { eprintln!("rerun tidy with `--extra-checks={mode} --bless` to {action}"); } @@ -231,7 +238,7 @@ fn check_spellcheck(root_path: &Path, outdir: &Path, cargo: &Path, tidy_ctx: &Ti if let Err(e) = spellcheck_runner(root_path, &outdir, &cargo, &args, tidy_ctx.is_running_on_ci()) { - rerun_with_bless("spellcheck", "fix typos", bless); + show_bless_help("spellcheck", "fix typos", bless); check.error(e); } } @@ -248,7 +255,7 @@ fn check_js_lint(outdir: &Path, librustdoc_path: &Path, tools_path: &Path, tidy_ } if let Err(e) = rustdoc_js::lint(outdir, librustdoc_path, tools_path, bless) { - rerun_with_bless("js:lint", "apply esplint suggestion", bless); + show_bless_help("js:lint", "apply esplint suggestion", bless); check.error(e); return; } @@ -318,7 +325,7 @@ fn check_python_lint( let res = run_ruff(root_path, outdir, py_path, &cfg_args, &file_args, args); - if res.is_err() && show_diff() && !bless { + if res.is_err() && !bless && show_diff() { eprintln!("\npython linting failed! Printing diff suggestions:"); let diff_res = run_ruff( @@ -331,7 +338,7 @@ fn check_python_lint( ); // `ruff check --diff` will return status 0 if there are no suggestions. if diff_res.is_err() { - rerun_with_bless("py:lint", "apply ruff suggestions", bless); + show_bless_help("py:lint", "apply ruff suggestions", bless); } } if let Err(e) = res { @@ -374,7 +381,7 @@ fn check_python_fmt( &["format".as_ref(), "--diff".as_ref()], ); } - rerun_with_bless("py:fmt", "reformat Python code", bless); + show_bless_help("py:fmt", "reformat Python code", bless); } if let Err(e) = res { @@ -396,7 +403,8 @@ fn check_cpp_fmt( let mut cfg_args_clang_format = cfg_args.clone(); let mut file_args_clang_format = file_args.clone(); let config_path = root_path.join(".clang-format"); - let config_file_arg = format!("file:{}", config_path.display()); + let mut config_file_arg = OsString::from("file:"); + config_file_arg.push(&config_path); cfg_args_clang_format.extend(&["--style".as_ref(), config_file_arg.as_ref()]); if bless { eprintln!("formatting C++ files"); @@ -424,7 +432,7 @@ fn check_cpp_fmt( let args = merge_args(&cfg_args_clang_format, &file_args_clang_format); let res = py_runner(py_path, false, None, "clang-format", &args); - if res.is_err() && show_diff() && !bless { + if res.is_err() && !bless && show_diff() { eprintln!("\nclang-format linting failed! Printing diff suggestions:"); let mut cfg_args_diff = cfg_args.clone(); @@ -455,7 +463,7 @@ fn check_cpp_fmt( ); } } - rerun_with_bless("cpp:fmt", "reformat C++ code", bless); + show_bless_help("cpp:fmt", "reformat C++ code", bless); } if let Err(e) = res { From 1db5d7741dc9c2163ab44a361464a705cbb667e1 Mon Sep 17 00:00:00 2001 From: Shunpoco Date: Mon, 9 Mar 2026 21:37:06 +0000 Subject: [PATCH 03/14] address review: use Option for functions which already handle errors --- src/tools/tidy/src/extra_checks/mod.rs | 33 +++++++++----------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/tools/tidy/src/extra_checks/mod.rs b/src/tools/tidy/src/extra_checks/mod.rs index a1fe9f3b77630..4ba2da7b5d3f7 100644 --- a/src/tools/tidy/src/extra_checks/mod.rs +++ b/src/tools/tidy/src/extra_checks/mod.rs @@ -114,10 +114,11 @@ pub fn check( if python_lint || python_fmt || cpp_fmt { // Since python lint, format and cpp format share python env, we need to ensure python env is installed before running those checks. - match py_prepare(root_path, outdir, &tidy_ctx) { - Ok(p) => py_path = Some(p), - Err(_) => return, + let p = py_prepare(root_path, outdir, &tidy_ctx); + if p.is_none() { + return; } + py_path = p; } if python_lint { @@ -156,7 +157,7 @@ pub fn check( if js_lint || js_typecheck { // Since js lint and format share node env, we need to ensure node env is installed before running those checks. - if js_prepare(root_path, outdir, npm, &tidy_ctx).is_err() { + if js_prepare(root_path, outdir, npm, &tidy_ctx).is_none() { return; } } @@ -170,14 +171,7 @@ pub fn check( } } -// It is used by prepare functions because they handle errors themselves, so the caller doesn't need to handle errors. -struct ErrorGuaranteed(()); - -fn py_prepare( - root_path: &Path, - outdir: &Path, - tidy_ctx: &TidyCtx, -) -> Result { +fn py_prepare(root_path: &Path, outdir: &Path, tidy_ctx: &TidyCtx) -> Option { let mut check = tidy_ctx.start_check("extra_checks:py_prepare"); let venv_path = outdir.join("venv"); @@ -185,28 +179,23 @@ fn py_prepare( reqs_path.extend(PIP_REQ_PATH); match get_or_create_venv(&venv_path, &reqs_path) { - Ok(p) => Ok(p), + Ok(p) => Some(p), Err(e) => { check.error(e); - Err(ErrorGuaranteed(())) + None } } } -fn js_prepare( - root_path: &Path, - outdir: &Path, - npm: &Path, - tidy_ctx: &TidyCtx, -) -> Result<(), ErrorGuaranteed> { +fn js_prepare(root_path: &Path, outdir: &Path, npm: &Path, tidy_ctx: &TidyCtx) -> Option<()> { let mut check = tidy_ctx.start_check("extra_checks:js_prepare"); if let Err(e) = rustdoc_js::npm_install(root_path, outdir, npm) { check.error(e.to_string()); - return Err(ErrorGuaranteed(())); + return None; } - Ok(()) + Some(()) } fn show_bless_help(mode: &str, action: &str, bless: bool) { From b707e7ae52065f659f08fe6fd5858623b83da5e4 Mon Sep 17 00:00:00 2001 From: Daria Sukhonina Date: Fri, 6 Mar 2026 15:58:10 +0300 Subject: [PATCH 04/14] Remove `FromCycleError` trait before code formatting Currently `QueryVTable`'s `value_from_cycle_error` function pointer uses the `FromCycleError` trait to call query cycle handling code and to construct an erroneous query output value. This trick however relies too heavily on trait impl specialization and makes those impls inconsistent (which is bad AFAIK). Instead this commit directly modifies `value_from_cycle_error` function pointer upon vtable initialization and gets rid of `FromCycleError`. --- .../rustc_query_impl/src/from_cycle_error.rs | 117 +++++++----------- compiler/rustc_query_impl/src/lib.rs | 5 +- compiler/rustc_query_impl/src/plumbing.rs | 6 +- 3 files changed, 51 insertions(+), 77 deletions(-) diff --git a/compiler/rustc_query_impl/src/from_cycle_error.rs b/compiler/rustc_query_impl/src/from_cycle_error.rs index eb6942ba491ff..a8df8b23441cc 100644 --- a/compiler/rustc_query_impl/src/from_cycle_error.rs +++ b/compiler/rustc_query_impl/src/from_cycle_error.rs @@ -1,5 +1,6 @@ use std::collections::VecDeque; use std::fmt::Write; +use std::iter; use std::ops::ControlFlow; use rustc_data_structures::fx::FxHashSet; @@ -9,55 +10,56 @@ use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_middle::dep_graph::DepKind; use rustc_middle::query::CycleError; +use rustc_middle::query::erase::erase_val; use rustc_middle::query::plumbing::CyclePlaceholder; -use rustc_middle::ty::{self, Representability, Ty, TyCtxt}; +use rustc_middle::queries::QueryVTables; +use rustc_middle::ty::layout::{LayoutError, TyAndLayout}; +use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_span::def_id::LocalDefId; use rustc_span::{ErrorGuaranteed, Span}; use crate::job::report_cycle; -pub(crate) trait FromCycleError<'tcx>: Sized { - /// Try to produce a `Self` value that represents an error form (e.g. `TyKind::Error`). - /// - /// Note: the default impl calls `raise_fatal`, ending compilation immediately! Only a few - /// types override this with a non-fatal impl. - fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle_error: CycleError, guar: ErrorGuaranteed) -> Self; +pub(crate) fn specialize_query_vtables<'tcx>(vtables: &mut QueryVTables<'tcx>) { + vtables.type_of.value_from_cycle_error = + |tcx, _, guar| erase_val(ty::EarlyBinder::bind(Ty::new_error(tcx, guar))); + + vtables.type_of_opaque_hir_typeck.value_from_cycle_error = + |tcx, _, guar| erase_val(ty::EarlyBinder::bind(Ty::new_error(tcx, guar))); + + vtables.erase_and_anonymize_regions_ty.value_from_cycle_error = + |tcx, _, guar| erase_val(Ty::new_error(tcx, guar)); + + vtables.type_of_opaque.value_from_cycle_error = + |_, _, guar| erase_val(Err(CyclePlaceholder(guar))); + + vtables.fn_sig.value_from_cycle_error = |tcx, cycle, guar| erase_val(fn_sig(tcx, cycle, guar)); + + vtables.check_representability.value_from_cycle_error = + |tcx, cycle, guar| check_representability(tcx, cycle, guar); + + vtables.check_representability_adt_ty.value_from_cycle_error = + |tcx, cycle, guar| check_representability(tcx, cycle, guar); + + vtables.variances_of.value_from_cycle_error = + |tcx, cycle, guar| erase_val(variances_of(tcx, cycle, guar)); + + vtables.layout_of.value_from_cycle_error = + |tcx, cycle, guar| erase_val(layout_of(tcx, cycle, guar)); } -impl<'tcx, T> FromCycleError<'tcx> for T { - default fn from_cycle_error( - tcx: TyCtxt<'tcx>, - cycle_error: CycleError, - _guar: ErrorGuaranteed, - ) -> T { + pub(crate) fn default<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError, query_name: &str) -> ! { let Some(guar) = tcx.sess.dcx().has_errors() else { bug!( - "<{} as FromCycleError>::from_cycle_error called without errors: {:#?}", - std::any::type_name::(), + "`from_cycle_error_default` on query `{query_name}` called without errors: {:#?}", cycle_error.cycle, ); }; - guar.raise_fatal(); - } -} - -impl<'tcx> FromCycleError<'tcx> for Ty<'_> { - fn from_cycle_error(tcx: TyCtxt<'tcx>, _: CycleError, guar: ErrorGuaranteed) -> Self { - // SAFETY: This is never called when `Self` is not `Ty<'tcx>`. - // FIXME: Represent the above fact in the trait system somehow. - unsafe { std::mem::transmute::, Ty<'_>>(Ty::new_error(tcx, guar)) } - } -} - -impl<'tcx> FromCycleError<'tcx> for Result>, CyclePlaceholder> { - fn from_cycle_error(_tcx: TyCtxt<'tcx>, _: CycleError, guar: ErrorGuaranteed) -> Self { - Err(CyclePlaceholder(guar)) + guar.raise_fatal() } -} -impl<'tcx> FromCycleError<'tcx> for ty::Binder<'_, ty::FnSig<'_>> { - fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle_error: CycleError, guar: ErrorGuaranteed) -> Self { + fn fn_sig<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError, guar: ErrorGuaranteed) -> ty::EarlyBinder<'tcx, ty::PolyFnSig<'tcx>> { let err = Ty::new_error(tcx, guar); let arity = if let Some(info) = cycle_error.cycle.get(0) @@ -72,26 +74,20 @@ impl<'tcx> FromCycleError<'tcx> for ty::Binder<'_, ty::FnSig<'_>> { unreachable!() }; - let fn_sig = ty::Binder::dummy(tcx.mk_fn_sig( + ty::EarlyBinder::bind(ty::Binder::dummy(tcx.mk_fn_sig( std::iter::repeat_n(err, arity), err, false, rustc_hir::Safety::Safe, rustc_abi::ExternAbi::Rust, - )); - - // SAFETY: This is never called when `Self` is not `ty::Binder<'tcx, ty::FnSig<'tcx>>`. - // FIXME: Represent the above fact in the trait system somehow. - unsafe { std::mem::transmute::, ty::Binder<'_, ty::FnSig<'_>>>(fn_sig) } + ))) } -} -impl<'tcx> FromCycleError<'tcx> for Representability { - fn from_cycle_error( + fn check_representability<'tcx>( tcx: TyCtxt<'tcx>, cycle_error: CycleError, _guar: ErrorGuaranteed, - ) -> Self { + ) -> ! { let mut item_and_field_ids = Vec::new(); let mut representable_ids = FxHashSet::default(); for info in &cycle_error.cycle { @@ -120,28 +116,14 @@ impl<'tcx> FromCycleError<'tcx> for Representability { // We used to continue here, but the cycle error printed next is actually less useful than // the error produced by `recursive_type_error`. let guar = recursive_type_error(tcx, item_and_field_ids, &representable_ids); - guar.raise_fatal(); + guar.raise_fatal() } -} -impl<'tcx> FromCycleError<'tcx> for ty::EarlyBinder<'_, Ty<'_>> { - fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle_error: CycleError, guar: ErrorGuaranteed) -> Self { - ty::EarlyBinder::bind(Ty::from_cycle_error(tcx, cycle_error, guar)) - } -} - -impl<'tcx> FromCycleError<'tcx> for ty::EarlyBinder<'_, ty::Binder<'_, ty::FnSig<'_>>> { - fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle_error: CycleError, guar: ErrorGuaranteed) -> Self { - ty::EarlyBinder::bind(ty::Binder::from_cycle_error(tcx, cycle_error, guar)) - } -} - -impl<'tcx> FromCycleError<'tcx> for &[ty::Variance] { - fn from_cycle_error( + fn variances_of<'tcx>( tcx: TyCtxt<'tcx>, cycle_error: CycleError, _guar: ErrorGuaranteed, - ) -> Self { + ) -> &'tcx [ty::Variance] { search_for_cycle_permutation( &cycle_error.cycle, |cycle| { @@ -150,7 +132,7 @@ impl<'tcx> FromCycleError<'tcx> for &[ty::Variance] { && let Some(def_id) = info.frame.def_id { let n = tcx.generics_of(def_id).own_params.len(); - ControlFlow::Break(vec![ty::Bivariant; n].leak()) + ControlFlow::Break(tcx.arena.alloc_from_iter(iter::repeat_n(ty::Bivariant, n))) } else { ControlFlow::Continue(()) } @@ -163,7 +145,6 @@ impl<'tcx> FromCycleError<'tcx> for &[ty::Variance] { }, ) } -} // Take a cycle of `Q` and try `try_cycle` on every permutation, falling back to `otherwise`. fn search_for_cycle_permutation( @@ -184,12 +165,11 @@ fn search_for_cycle_permutation( otherwise() } -impl<'tcx, T> FromCycleError<'tcx> for Result> { - fn from_cycle_error( + fn layout_of<'tcx>( tcx: TyCtxt<'tcx>, cycle_error: CycleError, _guar: ErrorGuaranteed, - ) -> Self { + ) -> Result, &'tcx ty::layout::LayoutError<'tcx>> { let diag = search_for_cycle_permutation( &cycle_error.cycle, |cycle| { @@ -267,13 +247,8 @@ impl<'tcx, T> FromCycleError<'tcx> for Result ); let guar = diag.emit(); - - // tcx.arena.alloc cannot be used because we are not allowed to use &'tcx LayoutError under - // min_specialization. Since this is an error path anyways, leaking doesn't matter (and really, - // tcx.arena.alloc is pretty much equal to leaking). - Err(Box::leak(Box::new(ty::layout::LayoutError::Cycle(guar)))) + Err(tcx.arena.alloc(LayoutError::Cycle(guar))) } -} // item_and_field_ids should form a cycle where each field contains the // type in the next element in the list diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index d92d80dbfb860..6482384f99ea3 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -18,7 +18,6 @@ use rustc_middle::ty::TyCtxt; use rustc_span::Span; pub use crate::dep_kind_vtables::make_dep_kind_vtables; -use crate::from_cycle_error::FromCycleError; pub use crate::job::{QueryJobMap, break_query_cycles, print_query_stack}; use crate::profiling_support::QueryKeyStringCache; @@ -52,9 +51,11 @@ pub fn query_system<'tcx>( on_disk_cache: Option, incremental: bool, ) -> QuerySystem<'tcx> { + let mut query_vtables = make_query_vtables(incremental); + from_cycle_error::specialize_query_vtables(&mut query_vtables); QuerySystem { arenas: Default::default(), - query_vtables: make_query_vtables(incremental), + query_vtables, on_disk_cache, local_providers, extern_providers, diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index f4649b2403a6b..558ecdda5c4b0 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -467,10 +467,8 @@ macro_rules! define_queries { #[cfg(not($cache_on_disk))] is_loadable_from_disk_fn: |_tcx, _key, _index| false, - value_from_cycle_error: |tcx, cycle, guar| { - let result: queries::$name::Value<'tcx> = - FromCycleError::from_cycle_error(tcx, cycle, guar); - erase::erase_val(result) + value_from_cycle_error: |tcx, cycle, _| { + $crate::from_cycle_error::default(tcx, cycle, stringify!($name)) }, #[cfg($no_hash)] From 94187453541be9f80889f0fe9cfa5318c242229d Mon Sep 17 00:00:00 2001 From: Daria Sukhonina Date: Fri, 6 Mar 2026 16:00:20 +0300 Subject: [PATCH 05/14] Run code formatter --- .../rustc_query_impl/src/from_cycle_error.rs | 339 +++++++++--------- 1 file changed, 171 insertions(+), 168 deletions(-) diff --git a/compiler/rustc_query_impl/src/from_cycle_error.rs b/compiler/rustc_query_impl/src/from_cycle_error.rs index a8df8b23441cc..2599c2fde5d08 100644 --- a/compiler/rustc_query_impl/src/from_cycle_error.rs +++ b/compiler/rustc_query_impl/src/from_cycle_error.rs @@ -9,10 +9,10 @@ use rustc_errors::{Applicability, MultiSpan, pluralize, struct_span_code_err}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_middle::dep_graph::DepKind; +use rustc_middle::queries::QueryVTables; use rustc_middle::query::CycleError; use rustc_middle::query::erase::erase_val; use rustc_middle::query::plumbing::CyclePlaceholder; -use rustc_middle::queries::QueryVTables; use rustc_middle::ty::layout::{LayoutError, TyAndLayout}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; @@ -49,102 +49,106 @@ pub(crate) fn specialize_query_vtables<'tcx>(vtables: &mut QueryVTables<'tcx>) { |tcx, cycle, guar| erase_val(layout_of(tcx, cycle, guar)); } - pub(crate) fn default<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError, query_name: &str) -> ! { - let Some(guar) = tcx.sess.dcx().has_errors() else { - bug!( - "`from_cycle_error_default` on query `{query_name}` called without errors: {:#?}", - cycle_error.cycle, - ); - }; - guar.raise_fatal() - } +pub(crate) fn default<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError, query_name: &str) -> ! { + let Some(guar) = tcx.sess.dcx().has_errors() else { + bug!( + "`from_cycle_error_default` on query `{query_name}` called without errors: {:#?}", + cycle_error.cycle, + ); + }; + guar.raise_fatal() +} - fn fn_sig<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError, guar: ErrorGuaranteed) -> ty::EarlyBinder<'tcx, ty::PolyFnSig<'tcx>> { - let err = Ty::new_error(tcx, guar); +fn fn_sig<'tcx>( + tcx: TyCtxt<'tcx>, + cycle_error: CycleError, + guar: ErrorGuaranteed, +) -> ty::EarlyBinder<'tcx, ty::PolyFnSig<'tcx>> { + let err = Ty::new_error(tcx, guar); - let arity = if let Some(info) = cycle_error.cycle.get(0) - && info.frame.dep_kind == DepKind::fn_sig - && let Some(def_id) = info.frame.def_id - && let Some(node) = tcx.hir_get_if_local(def_id) - && let Some(sig) = node.fn_sig() - { - sig.decl.inputs.len() - } else { - tcx.dcx().abort_if_errors(); - unreachable!() - }; + let arity = if let Some(info) = cycle_error.cycle.get(0) + && info.frame.dep_kind == DepKind::fn_sig + && let Some(def_id) = info.frame.def_id + && let Some(node) = tcx.hir_get_if_local(def_id) + && let Some(sig) = node.fn_sig() + { + sig.decl.inputs.len() + } else { + tcx.dcx().abort_if_errors(); + unreachable!() + }; - ty::EarlyBinder::bind(ty::Binder::dummy(tcx.mk_fn_sig( - std::iter::repeat_n(err, arity), - err, - false, - rustc_hir::Safety::Safe, - rustc_abi::ExternAbi::Rust, - ))) - } + ty::EarlyBinder::bind(ty::Binder::dummy(tcx.mk_fn_sig( + std::iter::repeat_n(err, arity), + err, + false, + rustc_hir::Safety::Safe, + rustc_abi::ExternAbi::Rust, + ))) +} - fn check_representability<'tcx>( - tcx: TyCtxt<'tcx>, - cycle_error: CycleError, - _guar: ErrorGuaranteed, - ) -> ! { - let mut item_and_field_ids = Vec::new(); - let mut representable_ids = FxHashSet::default(); - for info in &cycle_error.cycle { - if info.frame.dep_kind == DepKind::check_representability - && let Some(field_id) = info.frame.def_id - && let Some(field_id) = field_id.as_local() - && let Some(DefKind::Field) = info.frame.info.def_kind - { - let parent_id = tcx.parent(field_id.to_def_id()); - let item_id = match tcx.def_kind(parent_id) { - DefKind::Variant => tcx.parent(parent_id), - _ => parent_id, - }; - item_and_field_ids.push((item_id.expect_local(), field_id)); - } +fn check_representability<'tcx>( + tcx: TyCtxt<'tcx>, + cycle_error: CycleError, + _guar: ErrorGuaranteed, +) -> ! { + let mut item_and_field_ids = Vec::new(); + let mut representable_ids = FxHashSet::default(); + for info in &cycle_error.cycle { + if info.frame.dep_kind == DepKind::check_representability + && let Some(field_id) = info.frame.def_id + && let Some(field_id) = field_id.as_local() + && let Some(DefKind::Field) = info.frame.info.def_kind + { + let parent_id = tcx.parent(field_id.to_def_id()); + let item_id = match tcx.def_kind(parent_id) { + DefKind::Variant => tcx.parent(parent_id), + _ => parent_id, + }; + item_and_field_ids.push((item_id.expect_local(), field_id)); } - for info in &cycle_error.cycle { - if info.frame.dep_kind == DepKind::check_representability_adt_ty - && let Some(def_id) = info.frame.def_id_for_ty_in_cycle - && let Some(def_id) = def_id.as_local() - && !item_and_field_ids.iter().any(|&(id, _)| id == def_id) - { - representable_ids.insert(def_id); - } + } + for info in &cycle_error.cycle { + if info.frame.dep_kind == DepKind::check_representability_adt_ty + && let Some(def_id) = info.frame.def_id_for_ty_in_cycle + && let Some(def_id) = def_id.as_local() + && !item_and_field_ids.iter().any(|&(id, _)| id == def_id) + { + representable_ids.insert(def_id); } - // We used to continue here, but the cycle error printed next is actually less useful than - // the error produced by `recursive_type_error`. - let guar = recursive_type_error(tcx, item_and_field_ids, &representable_ids); - guar.raise_fatal() } + // We used to continue here, but the cycle error printed next is actually less useful than + // the error produced by `recursive_type_error`. + let guar = recursive_type_error(tcx, item_and_field_ids, &representable_ids); + guar.raise_fatal() +} - fn variances_of<'tcx>( - tcx: TyCtxt<'tcx>, - cycle_error: CycleError, - _guar: ErrorGuaranteed, - ) -> &'tcx [ty::Variance] { - search_for_cycle_permutation( - &cycle_error.cycle, - |cycle| { - if let Some(info) = cycle.get(0) - && info.frame.dep_kind == DepKind::variances_of - && let Some(def_id) = info.frame.def_id - { - let n = tcx.generics_of(def_id).own_params.len(); - ControlFlow::Break(tcx.arena.alloc_from_iter(iter::repeat_n(ty::Bivariant, n))) - } else { - ControlFlow::Continue(()) - } - }, - || { - span_bug!( - cycle_error.usage.as_ref().unwrap().0, - "only `variances_of` returns `&[ty::Variance]`" - ) - }, - ) - } +fn variances_of<'tcx>( + tcx: TyCtxt<'tcx>, + cycle_error: CycleError, + _guar: ErrorGuaranteed, +) -> &'tcx [ty::Variance] { + search_for_cycle_permutation( + &cycle_error.cycle, + |cycle| { + if let Some(info) = cycle.get(0) + && info.frame.dep_kind == DepKind::variances_of + && let Some(def_id) = info.frame.def_id + { + let n = tcx.generics_of(def_id).own_params.len(); + ControlFlow::Break(tcx.arena.alloc_from_iter(iter::repeat_n(ty::Bivariant, n))) + } else { + ControlFlow::Continue(()) + } + }, + || { + span_bug!( + cycle_error.usage.as_ref().unwrap().0, + "only `variances_of` returns `&[ty::Variance]`" + ) + }, + ) +} // Take a cycle of `Q` and try `try_cycle` on every permutation, falling back to `otherwise`. fn search_for_cycle_permutation( @@ -165,90 +169,89 @@ fn search_for_cycle_permutation( otherwise() } - fn layout_of<'tcx>( - tcx: TyCtxt<'tcx>, - cycle_error: CycleError, - _guar: ErrorGuaranteed, - ) -> Result, &'tcx ty::layout::LayoutError<'tcx>> { - let diag = search_for_cycle_permutation( - &cycle_error.cycle, - |cycle| { - if cycle[0].frame.dep_kind == DepKind::layout_of - && let Some(def_id) = cycle[0].frame.def_id_for_ty_in_cycle - && let Some(def_id) = def_id.as_local() - && let def_kind = tcx.def_kind(def_id) - && matches!(def_kind, DefKind::Closure) - && let Some(coroutine_kind) = tcx.coroutine_kind(def_id) - { - // FIXME: `def_span` for an fn-like coroutine will point to the fn's body - // due to interactions between the desugaring into a closure expr and the - // def_span code. I'm not motivated to fix it, because I tried and it was - // not working, so just hack around it by grabbing the parent fn's span. - let span = if coroutine_kind.is_fn_like() { - tcx.def_span(tcx.local_parent(def_id)) - } else { - tcx.def_span(def_id) +fn layout_of<'tcx>( + tcx: TyCtxt<'tcx>, + cycle_error: CycleError, + _guar: ErrorGuaranteed, +) -> Result, &'tcx ty::layout::LayoutError<'tcx>> { + let diag = search_for_cycle_permutation( + &cycle_error.cycle, + |cycle| { + if cycle[0].frame.dep_kind == DepKind::layout_of + && let Some(def_id) = cycle[0].frame.def_id_for_ty_in_cycle + && let Some(def_id) = def_id.as_local() + && let def_kind = tcx.def_kind(def_id) + && matches!(def_kind, DefKind::Closure) + && let Some(coroutine_kind) = tcx.coroutine_kind(def_id) + { + // FIXME: `def_span` for an fn-like coroutine will point to the fn's body + // due to interactions between the desugaring into a closure expr and the + // def_span code. I'm not motivated to fix it, because I tried and it was + // not working, so just hack around it by grabbing the parent fn's span. + let span = if coroutine_kind.is_fn_like() { + tcx.def_span(tcx.local_parent(def_id)) + } else { + tcx.def_span(def_id) + }; + let mut diag = struct_span_code_err!( + tcx.sess.dcx(), + span, + E0733, + "recursion in {} {} requires boxing", + tcx.def_kind_descr_article(def_kind, def_id.to_def_id()), + tcx.def_kind_descr(def_kind, def_id.to_def_id()), + ); + for (i, info) in cycle.iter().enumerate() { + if info.frame.dep_kind != DepKind::layout_of { + continue; + } + let Some(frame_def_id) = info.frame.def_id_for_ty_in_cycle else { + continue; }; - let mut diag = struct_span_code_err!( - tcx.sess.dcx(), - span, - E0733, - "recursion in {} {} requires boxing", - tcx.def_kind_descr_article(def_kind, def_id.to_def_id()), - tcx.def_kind_descr(def_kind, def_id.to_def_id()), - ); - for (i, info) in cycle.iter().enumerate() { - if info.frame.dep_kind != DepKind::layout_of { - continue; - } - let Some(frame_def_id) = info.frame.def_id_for_ty_in_cycle else { - continue; - }; - let Some(frame_coroutine_kind) = tcx.coroutine_kind(frame_def_id) else { - continue; - }; - let frame_span = - info.frame.info.default_span(cycle[(i + 1) % cycle.len()].span); - if frame_span.is_dummy() { - continue; - } - if i == 0 { - diag.span_label(frame_span, "recursive call here"); - } else { - let coroutine_span: Span = if frame_coroutine_kind.is_fn_like() { - tcx.def_span(tcx.parent(frame_def_id)) - } else { - tcx.def_span(frame_def_id) - }; - let mut multispan = MultiSpan::from_span(coroutine_span); - multispan - .push_span_label(frame_span, "...leading to this recursive call"); - diag.span_note( - multispan, - format!("which leads to this {}", tcx.def_descr(frame_def_id)), - ); - } + let Some(frame_coroutine_kind) = tcx.coroutine_kind(frame_def_id) else { + continue; + }; + let frame_span = + info.frame.info.default_span(cycle[(i + 1) % cycle.len()].span); + if frame_span.is_dummy() { + continue; } - // FIXME: We could report a structured suggestion if we had - // enough info here... Maybe we can use a hacky HIR walker. - if matches!( - coroutine_kind, - hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _) - ) { - diag.note("a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future"); + if i == 0 { + diag.span_label(frame_span, "recursive call here"); + } else { + let coroutine_span: Span = if frame_coroutine_kind.is_fn_like() { + tcx.def_span(tcx.parent(frame_def_id)) + } else { + tcx.def_span(frame_def_id) + }; + let mut multispan = MultiSpan::from_span(coroutine_span); + multispan.push_span_label(frame_span, "...leading to this recursive call"); + diag.span_note( + multispan, + format!("which leads to this {}", tcx.def_descr(frame_def_id)), + ); } - - ControlFlow::Break(diag) - } else { - ControlFlow::Continue(()) } - }, - || report_cycle(tcx.sess, &cycle_error), - ); + // FIXME: We could report a structured suggestion if we had + // enough info here... Maybe we can use a hacky HIR walker. + if matches!( + coroutine_kind, + hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _) + ) { + diag.note("a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future"); + } - let guar = diag.emit(); - Err(tcx.arena.alloc(LayoutError::Cycle(guar))) - } + ControlFlow::Break(diag) + } else { + ControlFlow::Continue(()) + } + }, + || report_cycle(tcx.sess, &cycle_error), + ); + + let guar = diag.emit(); + Err(tcx.arena.alloc(LayoutError::Cycle(guar))) +} // item_and_field_ids should form a cycle where each field contains the // type in the next element in the list From 916d760c47119535dc692c4df14a3b7808c8e67f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 10 Mar 2026 17:14:01 +0100 Subject: [PATCH 06/14] Replace `TyCtxt::node_lint` call with `TyCtxt::emit_node_lint` in `rustc_codegen_ssa` --- compiler/rustc_codegen_ssa/src/mir/block.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index cf643931717be..bf91d6d93883b 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -1019,10 +1019,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { if let Some(hir_id) = terminator.source_info.scope.lint_root(&self.mir.source_scopes) { - let msg = "tail calling a function marked with `#[track_caller]` has no special effect"; - bx.tcx().node_lint(TAIL_CALL_TRACK_CALLER, hir_id, |d| { - _ = d.primary_message(msg).span(fn_span) - }); + bx.tcx().emit_node_lint(TAIL_CALL_TRACK_CALLER, hir_id, rustc_errors::DiagDecorator(|d| { + _ = d.primary_message("tail calling a function marked with `#[track_caller]` has no special effect").span(fn_span) + })); } let instance = ty::Instance::resolve_for_fn_ptr( From 944d70ffa19c9812ef68fa16fd7bae03cae72d60 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 10 Mar 2026 17:25:18 +0100 Subject: [PATCH 07/14] Replace `TyCtxt::node_lint` call with `TyCtxt::emit_node_lint` in `rustc_hir_typeck` --- compiler/rustc_hir_typeck/src/method/confirm.rs | 12 +++++++++--- tests/ui/imports/ambiguous-trait-in-scope.stderr | 14 +++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 608bc7dffd9c0..b90d5b40bec6d 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -736,12 +736,18 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { let trait_name = self.tcx.item_name(pick.item.container_id(self.tcx)); let import_span = self.tcx.hir_span_if_local(pick.import_ids[0].to_def_id()).unwrap(); - self.tcx.node_lint(AMBIGUOUS_GLOB_IMPORTED_TRAITS, segment.hir_id, |diag| { - diag.primary_message(format!("Use of ambiguously glob imported trait `{trait_name}`")) + self.tcx.emit_node_lint( + AMBIGUOUS_GLOB_IMPORTED_TRAITS, + segment.hir_id, + rustc_errors::DiagDecorator(|diag| { + diag.primary_message(format!( + "Use of ambiguously glob imported trait `{trait_name}`" + )) .span(segment.ident.span) .span_label(import_span, format!("`{trait_name}` imported ambiguously here")) .help(format!("Import `{trait_name}` explicitly")); - }); + }), + ); } fn upcast( diff --git a/tests/ui/imports/ambiguous-trait-in-scope.stderr b/tests/ui/imports/ambiguous-trait-in-scope.stderr index cac1f4bb73fb1..9360e104bf24f 100644 --- a/tests/ui/imports/ambiguous-trait-in-scope.stderr +++ b/tests/ui/imports/ambiguous-trait-in-scope.stderr @@ -7,9 +7,9 @@ LL | use m2::*; LL | 0u8.method1(); | ^^^^^^^ | + = help: Import `Trait` explicitly = 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 #147992 - = help: Import `Trait` explicitly = note: `#[warn(ambiguous_glob_imported_traits)]` (part of `#[warn(future_incompatible)]`) on by default error[E0599]: no method named `method2` found for type `u8` in the current scope @@ -49,9 +49,9 @@ LL | use m2::*; LL | 0u8.method2(); | ^^^^^^^ | + = help: Import `Trait` explicitly = 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 #147992 - = help: Import `Trait` explicitly warning: Use of ambiguously glob imported trait `Trait` --> $DIR/ambiguous-trait-in-scope.rs:49:9 @@ -62,9 +62,9 @@ LL | use m2_reexport::*; LL | 0u8.method1(); | ^^^^^^^ | + = help: Import `Trait` explicitly = 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 #147992 - = help: Import `Trait` explicitly error[E0599]: no method named `method2` found for type `u8` in the current scope --> $DIR/ambiguous-trait-in-scope.rs:51:9 @@ -88,9 +88,9 @@ LL | use ambig_reexport::*; LL | 0u8.method1(); | ^^^^^^^ | + = help: Import `Trait` explicitly = 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 #147992 - = help: Import `Trait` explicitly error[E0599]: no method named `method2` found for type `u8` in the current scope --> $DIR/ambiguous-trait-in-scope.rs:58:9 @@ -115,9 +115,9 @@ LL | use external::m2::*; LL | 0u8.method1(); | ^^^^^^^ | + = help: Import `Trait` explicitly = 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 #147992 - = help: Import `Trait` explicitly error[E0599]: no method named `method2` found for type `u8` in the current scope --> $DIR/ambiguous-trait-in-scope.rs:66:9 @@ -142,9 +142,9 @@ LL | use external::m2_reexport::*; LL | 0u8.method1(); | ^^^^^^^ | + = help: Import `Trait` explicitly = 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 #147992 - = help: Import `Trait` explicitly error[E0599]: no method named `method2` found for type `u8` in the current scope --> $DIR/ambiguous-trait-in-scope.rs:74:9 @@ -168,9 +168,9 @@ LL | use external::ambig_reexport::*; LL | 0u8.method1(); | ^^^^^^^ | + = help: Import `Trait` explicitly = 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 #147992 - = help: Import `Trait` explicitly error[E0599]: no method named `method2` found for type `u8` in the current scope --> $DIR/ambiguous-trait-in-scope.rs:81:9 From c653287dfae2e41a01cab0d5ff16d257f7b43a14 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 10 Mar 2026 17:28:14 +0100 Subject: [PATCH 08/14] Replace `TyCtxt::node_lint` call with `TyCtxt::emit_node_lint` in `librustdoc` --- src/librustdoc/core.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index bb41758c7a2e5..0813816b470ac 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -400,16 +400,16 @@ pub(crate) fn run_global_ctxt( {}/rustdoc/how-to-write-documentation.html", crate::DOC_RUST_LANG_ORG_VERSION ); - tcx.node_lint( + tcx.emit_node_lint( crate::lint::MISSING_CRATE_LEVEL_DOCS, DocContext::as_local_hir_id(tcx, krate.module.item_id).unwrap(), - |lint| { + rustc_errors::DiagDecorator(|lint| { if let Some(local_def_id) = krate.module.item_id.as_local_def_id() { lint.span(tcx.def_span(local_def_id)); } lint.primary_message("no documentation found for this crate's top-level module"); lint.help(help); - }, + }), ); } From ff67fd035af41dad9606339f8b6e9d8d029d9759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 10 Mar 2026 16:59:52 +0000 Subject: [PATCH 09/14] Add test for #109804 Close #109804. --- .../suggest-remove-reference-in-where-clause.rs | 4 ++++ ...uggest-remove-reference-in-where-clause.stderr | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/ui/traits/suggest-remove-reference-in-where-clause.rs create mode 100644 tests/ui/traits/suggest-remove-reference-in-where-clause.stderr diff --git a/tests/ui/traits/suggest-remove-reference-in-where-clause.rs b/tests/ui/traits/suggest-remove-reference-in-where-clause.rs new file mode 100644 index 0000000000000..8e73e04e032f3 --- /dev/null +++ b/tests/ui/traits/suggest-remove-reference-in-where-clause.rs @@ -0,0 +1,4 @@ +use std::borrow::Borrow; +pub const F: for<'a> fn(&'a &'static String) -> &'a str = <&'static String as Borrow>::borrow; +//~^ ERROR E0277 +fn main() {} diff --git a/tests/ui/traits/suggest-remove-reference-in-where-clause.stderr b/tests/ui/traits/suggest-remove-reference-in-where-clause.stderr new file mode 100644 index 0000000000000..e7e2da92ee02c --- /dev/null +++ b/tests/ui/traits/suggest-remove-reference-in-where-clause.stderr @@ -0,0 +1,15 @@ +error[E0277]: the trait bound `&'static String: Borrow` is not satisfied + --> $DIR/suggest-remove-reference-in-where-clause.rs:2:60 + | +LL | pub const F: for<'a> fn(&'a &'static String) -> &'a str = <&'static String as Borrow>::borrow; + | ^^^^^^^^^^^^^^^ the trait `Borrow` is not implemented for `&'static String` + | +help: consider removing the leading `&`-reference + | +LL - pub const F: for<'a> fn(&'a &'static String) -> &'a str = <&'static String as Borrow>::borrow; +LL + pub const F: for<'a> fn(&'a &'static String) -> &'a str = >::borrow; + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. From 18ebaa9111b46a43477d5e747d859cffc436b70f Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 11 Mar 2026 02:45:19 +0900 Subject: [PATCH 10/14] add a regression test for issue 153599 --- .../stability-implications-non-local-defid.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/ui/delegation/generics/stability-implications-non-local-defid.rs diff --git a/tests/ui/delegation/generics/stability-implications-non-local-defid.rs b/tests/ui/delegation/generics/stability-implications-non-local-defid.rs new file mode 100644 index 0000000000000..f8b7874f28068 --- /dev/null +++ b/tests/ui/delegation/generics/stability-implications-non-local-defid.rs @@ -0,0 +1,21 @@ +//@ check-pass + +#![feature(fn_delegation)] +#![allow(incomplete_features)] +#![feature(staged_api)] +#![unstable(feature = "foo", issue = "none")] + +pub mod m { + #[unstable(feature = "foo", issue = "none")] + pub struct W { + pub inner: std::iter::Map, + } + + #[unstable(feature = "foo", issue = "none")] + impl B> Iterator for W { + type Item = B; + reuse Iterator::{next, fold} { self.inner } + } +} + +fn main() {} From d65ddf6dbfcea96052e18a421e8e54b182e0ea9d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 10 Mar 2026 17:28:47 +0100 Subject: [PATCH 11/14] Remove `TyCtxt::node_lint` method --- compiler/rustc_middle/src/lint.rs | 1 - compiler/rustc_middle/src/ty/context.rs | 16 +--------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 1c37dd0f82f42..c1496436f20f8 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -487,7 +487,6 @@ pub fn lint_level( /// for example: /// /// - [`TyCtxt::emit_node_span_lint`] -/// - [`TyCtxt::node_lint`] /// - `LintContext::opt_span_lint` /// /// This function will replace `lint_level` once all its callers have been replaced diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index a99e685c1308e..11f2d575a6598 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -55,7 +55,7 @@ use crate::dep_graph::dep_node::make_metadata; use crate::dep_graph::{DepGraph, DepKindVTable, DepNodeIndex}; use crate::ich::StableHashingContext; use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarKind}; -use crate::lint::{diag_lint_level, lint_level}; +use crate::lint::diag_lint_level; use crate::metadata::ModChild; use crate::middle::codegen_fn_attrs::{CodegenFnAttrs, TargetFeature}; use crate::middle::resolve_bound_vars; @@ -2585,20 +2585,6 @@ impl<'tcx> TyCtxt<'tcx> { diag_lint_level(self.sess, lint, level, None, decorator); } - /// Emit a lint at the appropriate level for a hir node. - /// - /// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature - #[track_caller] - pub fn node_lint( - self, - lint: &'static Lint, - id: HirId, - decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), - ) { - let level = self.lint_level_at_node(lint, id); - lint_level(self.sess, lint, level, None, decorate); - } - pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx [TraitCandidate<'tcx>]> { let map = self.in_scope_traits_map(id.owner)?; let candidates = map.get(&id.local_id)?; From 2765e4a61c88379535cf92699258f4769aa9c1b1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 10 Mar 2026 17:30:18 +0100 Subject: [PATCH 12/14] Remove `rustc_middle::lint_level` function --- compiler/rustc_lint/src/context.rs | 2 +- compiler/rustc_middle/src/lint.rs | 188 ----------------------------- 2 files changed, 1 insertion(+), 189 deletions(-) diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index d7a0a02f085a5..ecf71f93cf5ea 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -514,7 +514,7 @@ pub trait LintContext { // set the span in their `decorate` function (preferably using set_span). /// Emit a lint at the appropriate level, with an optional associated span. /// - /// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature + /// [`diag_lint_level`]: rustc_middle::lint::diag_lint_level#decorate-signature #[track_caller] fn opt_span_diag_lint>( &self, diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index c1496436f20f8..f302f18f3b47e 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -293,194 +293,6 @@ fn explain_lint_level_source( } } -/// The innermost function for emitting lints. -/// -/// If you are looking to implement a lint, look for higher level functions, -/// for example: -/// - [`TyCtxt::emit_node_span_lint`] -/// - [`TyCtxt::node_lint`] -/// - `LintContext::opt_span_lint` -/// -/// ## `decorate` -/// -/// It is not intended to call `emit`/`cancel` on the `Diag` passed in the `decorate` callback. -#[track_caller] -pub fn lint_level( - sess: &Session, - lint: &'static Lint, - level: LevelAndSource, - span: Option, - decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), -) { - // Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to - // the "real" work. - #[track_caller] - fn lint_level_impl( - sess: &Session, - lint: &'static Lint, - level: LevelAndSource, - span: Option, - decorate: Box FnOnce(&'b mut Diag<'a, ()>)>, - ) { - let LevelAndSource { level, lint_id, src } = level; - - // Check for future incompatibility lints and issue a stronger warning. - let future_incompatible = lint.future_incompatible; - - let has_future_breakage = future_incompatible.map_or( - // Default allow lints trigger too often for testing. - sess.opts.unstable_opts.future_incompat_test && lint.default_level != Level::Allow, - |incompat| incompat.report_in_deps, - ); - - // Convert lint level to error level. - let err_level = match level { - Level::Allow => { - if has_future_breakage { - rustc_errors::Level::Allow - } else { - return; - } - } - Level::Expect => { - // This case is special as we actually allow the lint itself in this context, but - // we can't return early like in the case for `Level::Allow` because we still - // need the lint diagnostic to be emitted to `rustc_error::DiagCtxtInner`. - // - // We can also not mark the lint expectation as fulfilled here right away, as it - // can still be cancelled in the decorate function. All of this means that we simply - // create a `Diag` and continue as we would for warnings. - rustc_errors::Level::Expect - } - Level::ForceWarn => rustc_errors::Level::ForceWarning, - Level::Warn => rustc_errors::Level::Warning, - Level::Deny | Level::Forbid => rustc_errors::Level::Error, - }; - let mut err = Diag::new(sess.dcx(), err_level, ""); - if let Some(span) = span { - err.span(span); - } - if let Some(lint_id) = lint_id { - err.lint_id(lint_id); - } - - // If this code originates in a foreign macro, aka something that this crate - // did not itself author, then it's likely that there's nothing this crate - // can do about it. We probably want to skip the lint entirely. - if err.span.primary_spans().iter().any(|s| s.in_external_macro(sess.source_map())) { - // Any suggestions made here are likely to be incorrect, so anything we - // emit shouldn't be automatically fixed by rustfix. - err.disable_suggestions(); - - // If this is a future incompatible that is not an edition fixing lint - // it'll become a hard error, so we have to emit *something*. Also, - // if this lint occurs in the expansion of a macro from an external crate, - // allow individual lints to opt-out from being reported. - let incompatible = future_incompatible.is_some_and(|f| f.reason.edition().is_none()); - - // In rustc, for the find_attr macro, we want to always emit this. - // This completely circumvents normal lint checking, which usually doesn't happen for macros from other crates. - // However, we kind of want that when using find_attr from another rustc crate. So we cheat a little. - let is_in_find_attr = sess.enable_internal_lints() - && err.span.primary_spans().iter().any(|s| { - s.source_callee().is_some_and( - |i| matches!(i.kind, ExpnKind::Macro(_, name) if name.as_str() == "find_attr") - ) - }); - - if !incompatible && !lint.report_in_external_macro && !is_in_find_attr { - err.cancel(); - - // Don't continue further, since we don't want to have - // `diag_span_note_once` called for a diagnostic that isn't emitted. - return; - } - } - - err.is_lint(lint.name_lower(), has_future_breakage); - - // Lint diagnostics that are covered by the expect level will not be emitted outside - // the compiler. It is therefore not necessary to add any information for the user. - // This will therefore directly call the decorate function which will in turn emit - // the diagnostic. - if let Level::Expect = level { - decorate(&mut err); - err.emit(); - return; - } - - if let Some(future_incompatible) = future_incompatible { - let explanation = match future_incompatible.reason { - FutureIncompatibilityReason::FutureReleaseError(_) => { - "this was previously accepted by the compiler but is being phased out; \ - it will become a hard error in a future release!" - .to_owned() - } - FutureIncompatibilityReason::FutureReleaseSemanticsChange(_) => { - "this will change its meaning in a future release!".to_owned() - } - FutureIncompatibilityReason::EditionError(EditionFcw { edition, .. }) => { - let current_edition = sess.edition(); - format!( - "this is accepted in the current edition (Rust {current_edition}) but is a hard error in Rust {edition}!" - ) - } - FutureIncompatibilityReason::EditionSemanticsChange(EditionFcw { - edition, .. - }) => { - format!("this changes meaning in Rust {edition}") - } - FutureIncompatibilityReason::EditionAndFutureReleaseError(EditionFcw { - edition, - .. - }) => { - format!( - "this was previously accepted by the compiler but is being phased out; \ - it will become a hard error in Rust {edition} and in a future release in all editions!" - ) - } - FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange( - EditionFcw { edition, .. }, - ) => { - format!( - "this changes meaning in Rust {edition} and in a future release in all editions!" - ) - } - FutureIncompatibilityReason::Custom(reason, _) => reason.to_owned(), - FutureIncompatibilityReason::Unreachable => unreachable!(), - }; - - if future_incompatible.explain_reason { - err.warn(explanation); - } - - let citation = - format!("for more information, see {}", future_incompatible.reason.reference()); - err.note(citation); - } - - // Finally, run `decorate`. `decorate` can call `trimmed_path_str` (directly or indirectly), - // so we need to make sure when we do call `decorate` that the diagnostic is eventually - // emitted or we'll get a `must_produce_diag` ICE. - // - // When is a diagnostic *eventually* emitted? Well, that is determined by 2 factors: - // 1. If the corresponding `rustc_errors::Level` is beyond warning, i.e. `ForceWarning(_)` - // or `Error`, then the diagnostic will be emitted regardless of CLI options. - // 2. If the corresponding `rustc_errors::Level` is warning, then that can be affected by - // `-A warnings` or `--cap-lints=xxx` on the command line. In which case, the diagnostic - // will be emitted if `can_emit_warnings` is true. - let skip = err_level == rustc_errors::Level::Warning && !sess.dcx().can_emit_warnings(); - - if !skip { - decorate(&mut err); - } - - explain_lint_level_source(sess, lint, level, src, &mut err); - err.emit() - } - lint_level_impl(sess, lint, level, span, Box::new(decorate)) -} - /// The innermost function for emitting lints implementing the [`trait@Diagnostic`] trait. /// /// If you are looking to implement a lint, look for higher level functions, From 3c3a35213c508eeb7f5e121ad299a135122733ed Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Sat, 7 Mar 2026 13:04:19 -0800 Subject: [PATCH 13/14] tests/ui/binop: add annotations for reference rules --- tests/ui/binop/augmented-assignment.rs | 1 + tests/ui/binop/binary-minus-without-space.rs | 3 + tests/ui/binop/binop-consume-args.rs | 1 + tests/ui/binop/binop-consume-args.stderr | 80 ++++++++++---------- tests/ui/binop/binop-move-semantics.rs | 1 + tests/ui/binop/binop-move-semantics.stderr | 26 +++---- tests/ui/binop/operator-overloading.rs | 3 + 7 files changed, 62 insertions(+), 53 deletions(-) diff --git a/tests/ui/binop/augmented-assignment.rs b/tests/ui/binop/augmented-assignment.rs index 755ecb466ceb7..a8de7ae1d3fc8 100644 --- a/tests/ui/binop/augmented-assignment.rs +++ b/tests/ui/binop/augmented-assignment.rs @@ -1,4 +1,5 @@ //@ run-pass +//@ reference: expr.arith-logic.behavior #![allow(unused_imports)] #![deny(unused_assignments)] diff --git a/tests/ui/binop/binary-minus-without-space.rs b/tests/ui/binop/binary-minus-without-space.rs index c80c0c88fcbc4..64243ebbb94eb 100644 --- a/tests/ui/binop/binary-minus-without-space.rs +++ b/tests/ui/binop/binary-minus-without-space.rs @@ -1,4 +1,7 @@ //@ run-pass +//@ reference: expr.arith-logic.syntax +//@ reference: patterns.literal.syntax +//@ reference: patterns.literal.intro // Check that issue #954 stays fixed diff --git a/tests/ui/binop/binop-consume-args.rs b/tests/ui/binop/binop-consume-args.rs index 8d6c725d75603..1bd803ce4c8f0 100644 --- a/tests/ui/binop/binop-consume-args.rs +++ b/tests/ui/binop/binop-consume-args.rs @@ -1,3 +1,4 @@ +//@ reference: expr.arith-logic.behavior // Test that binary operators consume their arguments use std::ops::{Add, Sub, Mul, Div, Rem, BitAnd, BitXor, BitOr, Shl, Shr}; diff --git a/tests/ui/binop/binop-consume-args.stderr b/tests/ui/binop/binop-consume-args.stderr index d9d92a44766db..2b2bb10620498 100644 --- a/tests/ui/binop/binop-consume-args.stderr +++ b/tests/ui/binop/binop-consume-args.stderr @@ -1,5 +1,5 @@ error[E0382]: use of moved value: `lhs` - --> $DIR/binop-consume-args.rs:7:10 + --> $DIR/binop-consume-args.rs:8:10 | LL | fn add, B>(lhs: A, rhs: B) { | --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait @@ -9,7 +9,7 @@ LL | drop(lhs); | ^^^ value used here after move | help: if `A` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:5:8 + --> $DIR/binop-consume-args.rs:6:8 | LL | fn add, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -23,7 +23,7 @@ LL | fn add + Copy, B>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `rhs` - --> $DIR/binop-consume-args.rs:8:10 + --> $DIR/binop-consume-args.rs:9:10 | LL | fn add, B>(lhs: A, rhs: B) { | --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait @@ -34,7 +34,7 @@ LL | drop(rhs); | ^^^ value used here after move | help: if `B` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:5:30 + --> $DIR/binop-consume-args.rs:6:30 | LL | fn add, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -46,7 +46,7 @@ LL | fn add, B: Copy>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `lhs` - --> $DIR/binop-consume-args.rs:13:10 + --> $DIR/binop-consume-args.rs:14:10 | LL | fn sub, B>(lhs: A, rhs: B) { | --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait @@ -56,7 +56,7 @@ LL | drop(lhs); | ^^^ value used here after move | help: if `A` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:11:8 + --> $DIR/binop-consume-args.rs:12:8 | LL | fn sub, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -70,7 +70,7 @@ LL | fn sub + Copy, B>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `rhs` - --> $DIR/binop-consume-args.rs:14:10 + --> $DIR/binop-consume-args.rs:15:10 | LL | fn sub, B>(lhs: A, rhs: B) { | --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait @@ -81,7 +81,7 @@ LL | drop(rhs); | ^^^ value used here after move | help: if `B` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:11:30 + --> $DIR/binop-consume-args.rs:12:30 | LL | fn sub, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -93,7 +93,7 @@ LL | fn sub, B: Copy>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `lhs` - --> $DIR/binop-consume-args.rs:19:10 + --> $DIR/binop-consume-args.rs:20:10 | LL | fn mul, B>(lhs: A, rhs: B) { | --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait @@ -103,7 +103,7 @@ LL | drop(lhs); | ^^^ value used here after move | help: if `A` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:17:8 + --> $DIR/binop-consume-args.rs:18:8 | LL | fn mul, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -117,7 +117,7 @@ LL | fn mul + Copy, B>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `rhs` - --> $DIR/binop-consume-args.rs:20:10 + --> $DIR/binop-consume-args.rs:21:10 | LL | fn mul, B>(lhs: A, rhs: B) { | --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait @@ -128,7 +128,7 @@ LL | drop(rhs); | ^^^ value used here after move | help: if `B` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:17:30 + --> $DIR/binop-consume-args.rs:18:30 | LL | fn mul, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -140,7 +140,7 @@ LL | fn mul, B: Copy>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `lhs` - --> $DIR/binop-consume-args.rs:25:10 + --> $DIR/binop-consume-args.rs:26:10 | LL | fn div, B>(lhs: A, rhs: B) { | --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait @@ -150,7 +150,7 @@ LL | drop(lhs); | ^^^ value used here after move | help: if `A` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:23:8 + --> $DIR/binop-consume-args.rs:24:8 | LL | fn div, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -164,7 +164,7 @@ LL | fn div + Copy, B>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `rhs` - --> $DIR/binop-consume-args.rs:26:10 + --> $DIR/binop-consume-args.rs:27:10 | LL | fn div, B>(lhs: A, rhs: B) { | --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait @@ -175,7 +175,7 @@ LL | drop(rhs); | ^^^ value used here after move | help: if `B` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:23:30 + --> $DIR/binop-consume-args.rs:24:30 | LL | fn div, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -187,7 +187,7 @@ LL | fn div, B: Copy>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `lhs` - --> $DIR/binop-consume-args.rs:31:10 + --> $DIR/binop-consume-args.rs:32:10 | LL | fn rem, B>(lhs: A, rhs: B) { | --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait @@ -197,7 +197,7 @@ LL | drop(lhs); | ^^^ value used here after move | help: if `A` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:29:8 + --> $DIR/binop-consume-args.rs:30:8 | LL | fn rem, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -211,7 +211,7 @@ LL | fn rem + Copy, B>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `rhs` - --> $DIR/binop-consume-args.rs:32:10 + --> $DIR/binop-consume-args.rs:33:10 | LL | fn rem, B>(lhs: A, rhs: B) { | --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait @@ -222,7 +222,7 @@ LL | drop(rhs); | ^^^ value used here after move | help: if `B` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:29:30 + --> $DIR/binop-consume-args.rs:30:30 | LL | fn rem, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -234,7 +234,7 @@ LL | fn rem, B: Copy>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `lhs` - --> $DIR/binop-consume-args.rs:37:10 + --> $DIR/binop-consume-args.rs:38:10 | LL | fn bitand, B>(lhs: A, rhs: B) { | --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait @@ -244,7 +244,7 @@ LL | drop(lhs); | ^^^ value used here after move | help: if `A` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:35:11 + --> $DIR/binop-consume-args.rs:36:11 | LL | fn bitand, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -258,7 +258,7 @@ LL | fn bitand + Copy, B>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `rhs` - --> $DIR/binop-consume-args.rs:38:10 + --> $DIR/binop-consume-args.rs:39:10 | LL | fn bitand, B>(lhs: A, rhs: B) { | --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait @@ -269,7 +269,7 @@ LL | drop(rhs); | ^^^ value used here after move | help: if `B` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:35:36 + --> $DIR/binop-consume-args.rs:36:36 | LL | fn bitand, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -281,7 +281,7 @@ LL | fn bitand, B: Copy>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `lhs` - --> $DIR/binop-consume-args.rs:43:10 + --> $DIR/binop-consume-args.rs:44:10 | LL | fn bitor, B>(lhs: A, rhs: B) { | --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait @@ -291,7 +291,7 @@ LL | drop(lhs); | ^^^ value used here after move | help: if `A` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:41:10 + --> $DIR/binop-consume-args.rs:42:10 | LL | fn bitor, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -305,7 +305,7 @@ LL | fn bitor + Copy, B>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `rhs` - --> $DIR/binop-consume-args.rs:44:10 + --> $DIR/binop-consume-args.rs:45:10 | LL | fn bitor, B>(lhs: A, rhs: B) { | --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait @@ -316,7 +316,7 @@ LL | drop(rhs); | ^^^ value used here after move | help: if `B` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:41:34 + --> $DIR/binop-consume-args.rs:42:34 | LL | fn bitor, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -328,7 +328,7 @@ LL | fn bitor, B: Copy>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `lhs` - --> $DIR/binop-consume-args.rs:49:10 + --> $DIR/binop-consume-args.rs:50:10 | LL | fn bitxor, B>(lhs: A, rhs: B) { | --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait @@ -338,7 +338,7 @@ LL | drop(lhs); | ^^^ value used here after move | help: if `A` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:47:11 + --> $DIR/binop-consume-args.rs:48:11 | LL | fn bitxor, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -352,7 +352,7 @@ LL | fn bitxor + Copy, B>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `rhs` - --> $DIR/binop-consume-args.rs:50:10 + --> $DIR/binop-consume-args.rs:51:10 | LL | fn bitxor, B>(lhs: A, rhs: B) { | --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait @@ -363,7 +363,7 @@ LL | drop(rhs); | ^^^ value used here after move | help: if `B` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:47:36 + --> $DIR/binop-consume-args.rs:48:36 | LL | fn bitxor, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -375,7 +375,7 @@ LL | fn bitxor, B: Copy>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `lhs` - --> $DIR/binop-consume-args.rs:55:10 + --> $DIR/binop-consume-args.rs:56:10 | LL | fn shl, B>(lhs: A, rhs: B) { | --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait @@ -385,7 +385,7 @@ LL | drop(lhs); | ^^^ value used here after move | help: if `A` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:53:8 + --> $DIR/binop-consume-args.rs:54:8 | LL | fn shl, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -399,7 +399,7 @@ LL | fn shl + Copy, B>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `rhs` - --> $DIR/binop-consume-args.rs:56:10 + --> $DIR/binop-consume-args.rs:57:10 | LL | fn shl, B>(lhs: A, rhs: B) { | --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait @@ -410,7 +410,7 @@ LL | drop(rhs); | ^^^ value used here after move | help: if `B` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:53:30 + --> $DIR/binop-consume-args.rs:54:30 | LL | fn shl, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -422,7 +422,7 @@ LL | fn shl, B: Copy>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `lhs` - --> $DIR/binop-consume-args.rs:61:10 + --> $DIR/binop-consume-args.rs:62:10 | LL | fn shr, B>(lhs: A, rhs: B) { | --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait @@ -432,7 +432,7 @@ LL | drop(lhs); | ^^^ value used here after move | help: if `A` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:59:8 + --> $DIR/binop-consume-args.rs:60:8 | LL | fn shr, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` @@ -446,7 +446,7 @@ LL | fn shr + Copy, B>(lhs: A, rhs: B) { | ++++++ error[E0382]: use of moved value: `rhs` - --> $DIR/binop-consume-args.rs:62:10 + --> $DIR/binop-consume-args.rs:63:10 | LL | fn shr, B>(lhs: A, rhs: B) { | --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait @@ -457,7 +457,7 @@ LL | drop(rhs); | ^^^ value used here after move | help: if `B` implemented `Clone`, you could clone the value - --> $DIR/binop-consume-args.rs:59:30 + --> $DIR/binop-consume-args.rs:60:30 | LL | fn shr, B>(lhs: A, rhs: B) { | ^ consider constraining this type parameter with `Clone` diff --git a/tests/ui/binop/binop-move-semantics.rs b/tests/ui/binop/binop-move-semantics.rs index b5133ea7c92a0..c49613c02d501 100644 --- a/tests/ui/binop/binop-move-semantics.rs +++ b/tests/ui/binop/binop-move-semantics.rs @@ -1,3 +1,4 @@ +//@ reference: expr.arith-logic.behavior // Test that move restrictions are enforced on overloaded binary operations use std::ops::Add; diff --git a/tests/ui/binop/binop-move-semantics.stderr b/tests/ui/binop/binop-move-semantics.stderr index 2e661c44abd1a..029a94a49452a 100644 --- a/tests/ui/binop/binop-move-semantics.stderr +++ b/tests/ui/binop/binop-move-semantics.stderr @@ -1,5 +1,5 @@ error[E0382]: use of moved value: `x` - --> $DIR/binop-move-semantics.rs:8:5 + --> $DIR/binop-move-semantics.rs:9:5 | LL | fn double_move>(x: T) { | - move occurs because `x` has type `T`, which does not implement the `Copy` trait @@ -12,7 +12,7 @@ LL | | x; | `x` moved due to usage in operator | help: if `T` implemented `Clone`, you could clone the value - --> $DIR/binop-move-semantics.rs:5:16 + --> $DIR/binop-move-semantics.rs:6:16 | LL | fn double_move>(x: T) { | ^ consider constraining this type parameter with `Clone` @@ -26,7 +26,7 @@ LL | fn double_move + Copy>(x: T) { | ++++++ error[E0382]: borrow of moved value: `x` - --> $DIR/binop-move-semantics.rs:14:5 + --> $DIR/binop-move-semantics.rs:15:5 | LL | fn move_then_borrow + Clone>(x: T) { | - move occurs because `x` has type `T`, which does not implement the `Copy` trait @@ -46,7 +46,7 @@ LL | fn move_then_borrow + Clone + Copy>(x: T) { | ++++++ error[E0505]: cannot move out of `x` because it is borrowed - --> $DIR/binop-move-semantics.rs:21:5 + --> $DIR/binop-move-semantics.rs:22:5 | LL | fn move_borrowed>(x: T, mut y: T) { | - binding `x` declared here @@ -60,7 +60,7 @@ LL | use_mut(n); use_imm(m); | - borrow later used here | help: if `T` implemented `Clone`, you could clone the value - --> $DIR/binop-move-semantics.rs:17:18 + --> $DIR/binop-move-semantics.rs:18:18 | LL | fn move_borrowed>(x: T, mut y: T) { | ^ consider constraining this type parameter with `Clone` @@ -68,7 +68,7 @@ LL | let m = &x; | - you could clone this value error[E0505]: cannot move out of `y` because it is borrowed - --> $DIR/binop-move-semantics.rs:23:5 + --> $DIR/binop-move-semantics.rs:24:5 | LL | fn move_borrowed>(x: T, mut y: T) { | ----- binding `y` declared here @@ -82,7 +82,7 @@ LL | use_mut(n); use_imm(m); | - borrow later used here | help: if `T` implemented `Clone`, you could clone the value - --> $DIR/binop-move-semantics.rs:17:18 + --> $DIR/binop-move-semantics.rs:18:18 | LL | fn move_borrowed>(x: T, mut y: T) { | ^ consider constraining this type parameter with `Clone` @@ -91,7 +91,7 @@ LL | let n = &mut y; | - you could clone this value error[E0507]: cannot move out of `*m` which is behind a mutable reference - --> $DIR/binop-move-semantics.rs:30:5 + --> $DIR/binop-move-semantics.rs:31:5 | LL | *m | -^ @@ -105,7 +105,7 @@ LL | | *n; note: calling this operator moves the left-hand side --> $SRC_DIR/core/src/ops/arith.rs:LL:COL help: if `T` implemented `Clone`, you could clone the value - --> $DIR/binop-move-semantics.rs:26:24 + --> $DIR/binop-move-semantics.rs:27:24 | LL | fn illegal_dereference>(mut x: T, y: T) { | ^ consider constraining this type parameter with `Clone` @@ -114,13 +114,13 @@ LL | *m | -- you could clone this value error[E0507]: cannot move out of `*n` which is behind a shared reference - --> $DIR/binop-move-semantics.rs:32:5 + --> $DIR/binop-move-semantics.rs:33:5 | LL | *n; | ^^ move occurs because `*n` has type `T`, which does not implement the `Copy` trait | help: if `T` implemented `Clone`, you could clone the value - --> $DIR/binop-move-semantics.rs:26:24 + --> $DIR/binop-move-semantics.rs:27:24 | LL | fn illegal_dereference>(mut x: T, y: T) { | ^ consider constraining this type parameter with `Clone` @@ -129,7 +129,7 @@ LL | *n; | -- you could clone this value error[E0502]: cannot borrow `f` as immutable because it is also borrowed as mutable - --> $DIR/binop-move-semantics.rs:54:5 + --> $DIR/binop-move-semantics.rs:55:5 | LL | &mut f | ------ @@ -144,7 +144,7 @@ LL | | &f; | immutable borrow occurs here error[E0502]: cannot borrow `f` as mutable because it is also borrowed as immutable - --> $DIR/binop-move-semantics.rs:62:5 + --> $DIR/binop-move-semantics.rs:63:5 | LL | &f | -- diff --git a/tests/ui/binop/operator-overloading.rs b/tests/ui/binop/operator-overloading.rs index 7f29856194e09..76a9ed079a099 100644 --- a/tests/ui/binop/operator-overloading.rs +++ b/tests/ui/binop/operator-overloading.rs @@ -1,4 +1,7 @@ //@ run-pass +//@ reference: expr.arith-logic.behavior +//@ reference: expr.array.index.trait +//@ reference: expr.negate.results #![allow(unused_variables)] use std::cmp; From c12ab08c14b1f607c4799893bcb2752c6fed34b4 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 10 Mar 2026 16:12:05 +1100 Subject: [PATCH 14/14] Move `Spanned`. It's defined in `rustc_span::source_map` which doesn't make any sense because it has nothing to do with source maps. This commit moves it to the crate root, a more sensible spot for something this basic. --- compiler/rustc_ast/src/ast.rs | 5 +++-- compiler/rustc_ast/src/mut_visit.rs | 3 +-- compiler/rustc_ast/src/visit.rs | 3 +-- compiler/rustc_ast_lowering/src/expr.rs | 3 +-- compiler/rustc_ast_lowering/src/pat.rs | 3 +-- compiler/rustc_ast_passes/src/feature_gate.rs | 3 +-- compiler/rustc_ast_pretty/src/pprust/state.rs | 6 ++++-- compiler/rustc_borrowck/src/diagnostics/mod.rs | 3 +-- compiler/rustc_borrowck/src/type_check/mod.rs | 3 +-- .../src/deriving/generic/ty.rs | 3 +-- compiler/rustc_codegen_cranelift/src/abi/mod.rs | 2 +- compiler/rustc_codegen_cranelift/src/common.rs | 3 +-- .../rustc_codegen_cranelift/src/intrinsics/mod.rs | 3 +-- compiler/rustc_codegen_gcc/src/context.rs | 3 +-- compiler/rustc_codegen_llvm/src/context.rs | 3 +-- compiler/rustc_codegen_ssa/src/mir/block.rs | 3 +-- compiler/rustc_const_eval/src/interpret/step.rs | 2 +- compiler/rustc_errors/src/diagnostic.rs | 3 +-- compiler/rustc_expand/src/build.rs | 3 +-- compiler/rustc_hir/src/hir.rs | 3 +-- compiler/rustc_hir_analysis/src/check/check.rs | 2 +- compiler/rustc_hir_analysis/src/check/region.rs | 8 ++++---- compiler/rustc_hir_pretty/src/lib.rs | 4 ++-- compiler/rustc_hir_typeck/src/errors.rs | 3 +-- compiler/rustc_hir_typeck/src/expr.rs | 3 +-- .../rustc_hir_typeck/src/fn_ctxt/suggestions.rs | 3 +-- compiler/rustc_hir_typeck/src/op.rs | 3 +-- compiler/rustc_lint/src/builtin.rs | 3 +-- compiler/rustc_lint/src/invalid_from_utf8.rs | 3 +-- compiler/rustc_lint/src/unused.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 3 +-- compiler/rustc_middle/src/mir/syntax.rs | 3 +-- compiler/rustc_middle/src/queries.rs | 3 +-- compiler/rustc_middle/src/query/erase.rs | 3 +-- compiler/rustc_middle/src/query/on_disk_cache.rs | 3 +-- compiler/rustc_middle/src/ty/codec.rs | 3 +-- compiler/rustc_middle/src/ty/structural_impls.rs | 2 +- .../src/builder/custom/parse/instruction.rs | 3 +-- .../rustc_mir_build/src/builder/expr/as_rvalue.rs | 3 +-- compiler/rustc_mir_build/src/builder/expr/into.rs | 3 +-- compiler/rustc_mir_build/src/builder/expr/stmt.rs | 2 +- .../rustc_mir_build/src/builder/matches/test.rs | 3 +-- compiler/rustc_mir_build/src/builder/scope.rs | 3 +-- compiler/rustc_mir_transform/src/coroutine.rs | 3 +-- .../rustc_mir_transform/src/elaborate_drop.rs | 3 +-- .../src/function_item_references.rs | 3 +-- compiler/rustc_mir_transform/src/inline.rs | 2 +- compiler/rustc_mir_transform/src/lib.rs | 3 +-- .../rustc_mir_transform/src/mentioned_items.rs | 2 +- .../rustc_mir_transform/src/promote_consts.rs | 3 +-- compiler/rustc_mir_transform/src/shim.rs | 3 +-- compiler/rustc_monomorphize/src/collector.rs | 3 +-- .../src/mono_checks/move_check.rs | 3 +-- compiler/rustc_parse/src/parser/diagnostics.rs | 3 +-- compiler/rustc_parse/src/parser/expr.rs | 9 ++++----- compiler/rustc_parse/src/parser/item.rs | 4 ++-- compiler/rustc_parse/src/parser/pat.rs | 3 +-- compiler/rustc_passes/src/abi_test.rs | 3 +-- compiler/rustc_passes/src/layout_test.rs | 3 +-- compiler/rustc_resolve/src/diagnostics.rs | 6 ++++-- compiler/rustc_resolve/src/errors.rs | 3 +-- compiler/rustc_resolve/src/late.rs | 3 +-- compiler/rustc_span/src/lib.rs | 14 ++++++++++++++ compiler/rustc_span/src/source_map.rs | 15 --------------- .../clippy/clippy_lints/src/bool_comparison.rs | 3 +-- .../clippy_lints/src/casts/manual_dangling_ptr.rs | 2 +- .../src/floating_point_arithmetic/custom_abs.rs | 2 +- .../src/floating_point_arithmetic/expm1.rs | 2 +- .../src/floating_point_arithmetic/hypot.rs | 2 +- .../src/floating_point_arithmetic/ln1p.rs | 2 +- .../src/floating_point_arithmetic/log_division.rs | 2 +- .../src/floating_point_arithmetic/mul_add.rs | 2 +- .../src/floating_point_arithmetic/powi.rs | 2 +- .../src/floating_point_arithmetic/radians.rs | 2 +- src/tools/clippy/clippy_lints/src/len_zero.rs | 3 +-- .../clippy_lints/src/loops/manual_slice_fill.rs | 3 +-- src/tools/clippy/clippy_lints/src/loops/utils.rs | 2 +- src/tools/clippy/clippy_lints/src/manual_strip.rs | 3 +-- .../src/matches/match_like_matches.rs | 2 +- .../case_sensitive_file_extension_comparisons.rs | 2 +- .../clippy/clippy_lints/src/methods/get_first.rs | 2 +- .../clippy_lints/src/methods/get_last_with_len.rs | 2 +- .../clippy_lints/src/methods/manual_contains.rs | 2 +- .../clippy_lints/src/methods/open_options.rs | 2 +- .../clippy_lints/src/methods/suspicious_splitn.rs | 2 +- .../src/methods/vec_resize_to_zero.rs | 3 +-- .../src/missing_asserts_for_indexing.rs | 3 +-- .../src/operators/const_comparisons.rs | 3 +-- .../src/operators/float_equality_without_abs.rs | 2 +- .../clippy_lints/src/operators/manual_div_ceil.rs | 2 +- src/tools/clippy/clippy_lints/src/precedence.rs | 2 +- src/tools/clippy/clippy_lints/src/ranges.rs | 3 +-- src/tools/clippy/clippy_lints/src/strings.rs | 2 +- .../src/suspicious_operation_groupings.rs | 2 +- src/tools/clippy/clippy_lints/src/swap.rs | 3 +-- .../src/lint_without_lint_pass.rs | 3 +-- src/tools/rustfmt/src/patterns.rs | 2 +- src/tools/rustfmt/src/spanned.rs | 4 ++-- tests/ui-fulldeps/pprust-expr-roundtrip.rs | 3 +-- 99 files changed, 128 insertions(+), 183 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 5258f179d95d2..74cc1ec17e6f0 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -30,8 +30,9 @@ use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::tagged_ptr::Tag; use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable}; pub use rustc_span::AttrId; -use rustc_span::source_map::{Spanned, respan}; -use rustc_span::{ByteSymbol, DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, sym}; +use rustc_span::{ + ByteSymbol, DUMMY_SP, ErrorGuaranteed, Ident, Span, Spanned, Symbol, kw, respan, sym, +}; use thin_vec::{ThinVec, thin_vec}; use crate::attr::data_structures::CfgEntry; diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index be8e1d22c9dbf..881b6ff107b56 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -11,8 +11,7 @@ use std::ops::DerefMut; use std::panic; use rustc_data_structures::flat_map_in_place::FlatMapInPlace; -use rustc_span::source_map::Spanned; -use rustc_span::{Ident, Span, Symbol}; +use rustc_span::{Ident, Span, Spanned, Symbol}; use smallvec::{SmallVec, smallvec}; use thin_vec::ThinVec; diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index c3c1c518d8495..bdf290f9a9e63 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -15,8 +15,7 @@ pub use rustc_ast_ir::visit::VisitorResult; pub use rustc_ast_ir::{try_visit, visit_opt, walk_list, walk_visitable_list}; -use rustc_span::source_map::Spanned; -use rustc_span::{Ident, Span, Symbol}; +use rustc_span::{Ident, Span, Spanned, Symbol}; use thin_vec::ThinVec; use crate::ast::*; diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 4a2992038003c..305df40651969 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -13,8 +13,7 @@ use rustc_hir::{HirId, Target, find_attr}; use rustc_middle::span_bug; use rustc_middle::ty::TyCtxt; use rustc_session::errors::report_lit_error; -use rustc_span::source_map::{Spanned, respan}; -use rustc_span::{ByteSymbol, DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym}; +use rustc_span::{ByteSymbol, DUMMY_SP, DesugaringKind, Ident, Span, Spanned, Symbol, respan, sym}; use thin_vec::{ThinVec, thin_vec}; use visit::{Visitor, walk_expr}; diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index e066bce95158d..c1c13977e1037 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -6,8 +6,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::definitions::DefPathData; use rustc_hir::{self as hir, LangItem, Target}; use rustc_middle::span_bug; -use rustc_span::source_map::{Spanned, respan}; -use rustc_span::{DesugaringKind, Ident, Span}; +use rustc_span::{DesugaringKind, Ident, Span, Spanned, respan}; use super::errors::{ ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding, diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 72679d7456659..ea8521a831400 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -7,8 +7,7 @@ use rustc_hir::Attribute; use rustc_hir::attrs::AttributeKind; use rustc_session::Session; use rustc_session::parse::{feature_err, feature_warn}; -use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, Span, Symbol, sym}; +use rustc_span::{DUMMY_SP, Span, Spanned, Symbol, sym}; use thin_vec::ThinVec; use crate::errors; diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index c85d6f454321e..4ba5dc541342a 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -20,9 +20,11 @@ use rustc_ast::{ RangeEnd, RangeSyntax, Safety, SelfKind, Term, attr, }; use rustc_span::edition::Edition; -use rustc_span::source_map::{SourceMap, Spanned}; +use rustc_span::source_map::SourceMap; use rustc_span::symbol::IdentPrinter; -use rustc_span::{BytePos, CharPos, DUMMY_SP, FileName, Ident, Pos, Span, Symbol, kw, sym}; +use rustc_span::{ + BytePos, CharPos, DUMMY_SP, FileName, Ident, Pos, Span, Spanned, Symbol, kw, sym, +}; use crate::pp::Breaks::{Consistent, Inconsistent}; use crate::pp::{self, BoxMarker, Breaks}; diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index af8f723ff378d..cb11d35c44b66 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -23,8 +23,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult, MoveOutIndex}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym}; +use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Spanned, Symbol, sym}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::error_reporting::traits::call_kind::{CallDesugaringKind, call_kind}; use rustc_trait_selection::infer::InferCtxtExt; diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 29d38af472c22..9aa8f7a2067a5 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -32,8 +32,7 @@ use rustc_middle::ty::{ use rustc_mir_dataflow::move_paths::MoveData; use rustc_mir_dataflow::points::DenseLocationMap; use rustc_span::def_id::CRATE_DEF_ID; -use rustc_span::source_map::Spanned; -use rustc_span::{Span, sym}; +use rustc_span::{Span, Spanned, sym}; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints; use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput}; diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs index 1458553d4925e..e7972c5436e13 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs @@ -4,8 +4,7 @@ pub(crate) use Ty::*; use rustc_ast::{self as ast, Expr, GenericArg, GenericParamKind, Generics, SelfKind, TyKind}; use rustc_expand::base::ExtCtxt; -use rustc_span::source_map::respan; -use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw}; +use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, respan}; use thin_vec::ThinVec; /// A path, e.g., `::std::option::Option::` (global). Has support diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs index 97a19b8976d3a..13f5ad5157cef 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs @@ -20,7 +20,7 @@ use rustc_middle::ty::TypeVisitableExt; use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_session::Session; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use rustc_target::callconv::{FnAbi, PassMode}; use rustc_target::spec::Arch; use smallvec::{SmallVec, smallvec}; diff --git a/compiler/rustc_codegen_cranelift/src/common.rs b/compiler/rustc_codegen_cranelift/src/common.rs index b11f42408f58b..b22afca847aa9 100644 --- a/compiler/rustc_codegen_cranelift/src/common.rs +++ b/compiler/rustc_codegen_cranelift/src/common.rs @@ -6,8 +6,7 @@ use rustc_middle::ty::TypeFoldable; use rustc_middle::ty::layout::{ self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, }; -use rustc_span::Symbol; -use rustc_span::source_map::Spanned; +use rustc_span::{Spanned, Symbol}; use rustc_target::callconv::FnAbi; use rustc_target::spec::{Arch, HasTargetSpec, Target}; diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs index ab9a11305baa3..da8569dac7468 100644 --- a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs @@ -24,8 +24,7 @@ use rustc_middle::ty; use rustc_middle::ty::GenericArgsRef; use rustc_middle::ty::layout::ValidityRequirement; use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths}; -use rustc_span::source_map::Spanned; -use rustc_span::{Symbol, sym}; +use rustc_span::{Spanned, Symbol, sym}; use rustc_target::spec::PanicStrategy; pub(crate) use self::llvm::codegen_llvm_intrinsic_call; diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs index ada3d73f612e4..5423ee5390fe5 100644 --- a/compiler/rustc_codegen_gcc/src/context.rs +++ b/compiler/rustc_codegen_gcc/src/context.rs @@ -21,8 +21,7 @@ use rustc_middle::ty::{self, ExistentialTraitRef, Instance, Ty, TyCtxt}; use rustc_session::Session; #[cfg(feature = "master")] use rustc_session::config::DebugInfo; -use rustc_span::source_map::respan; -use rustc_span::{DUMMY_SP, Span}; +use rustc_span::{DUMMY_SP, Span, respan}; use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, TlsModel, X86Abi}; #[cfg(feature = "master")] diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 2760683dad9d1..28aa12cc83dc5 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -25,8 +25,7 @@ use rustc_session::Session; use rustc_session::config::{ BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, FunctionReturn, PAuthKey, PacRet, }; -use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, Span, Symbol}; +use rustc_span::{DUMMY_SP, Span, Spanned, Symbol}; use rustc_symbol_mangling::mangle_internal_symbol; use rustc_target::spec::{ Abi, Arch, Env, HasTargetSpec, Os, RelocModel, SmallDataThresholdSupport, Target, TlsModel, diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index cf643931717be..d4c10689f65ca 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -12,8 +12,7 @@ use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths}; use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt}; use rustc_middle::{bug, span_bug}; use rustc_session::config::OptLevel; -use rustc_span::Span; -use rustc_span::source_map::Spanned; +use rustc_span::{Span, Spanned}; use rustc_target::callconv::{ArgAbi, ArgAttributes, CastTarget, FnAbi, PassMode}; use tracing::{debug, info}; diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index 083fd97aec4dc..2dee1157e2a12 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -10,7 +10,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_index::IndexSlice; use rustc_middle::ty::{self, Instance, Ty}; use rustc_middle::{bug, mir, span_bug}; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use rustc_target::callconv::FnAbi; use tracing::field::Empty; use tracing::{info, instrument, trace}; diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 631ed54cc024b..2764a009237ba 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -11,8 +11,7 @@ use rustc_data_structures::sync::DynSend; use rustc_error_messages::{DiagArgMap, DiagArgName, DiagArgValue, IntoDiagArg}; use rustc_lint_defs::{Applicability, LintExpectationId}; use rustc_macros::{Decodable, Encodable}; -use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, Span, Symbol}; +use rustc_span::{DUMMY_SP, Span, Spanned, Symbol}; use tracing::debug; use crate::{ diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 19a2d65762e86..3680f24707df0 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -5,8 +5,7 @@ use rustc_ast::{ self as ast, AnonConst, AttrItem, AttrVec, BlockCheckMode, Expr, LocalKind, MatchKind, MgcaDisambiguation, PatKind, UnOp, attr, token, tokenstream, }; -use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; +use rustc_span::{DUMMY_SP, Ident, Span, Spanned, Symbol, kw, sym}; use thin_vec::{ThinVec, thin_vec}; use crate::base::ExtCtxt; diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 45a363b97722a..7cce0eda4dda7 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -23,9 +23,8 @@ use rustc_error_messages::{DiagArgValue, IntoDiagArg}; use rustc_index::IndexVec; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Spanned; use rustc_span::{ - BytePos, DUMMY_SP, DesugaringKind, ErrorGuaranteed, Ident, Span, Symbol, kw, sym, + BytePos, DUMMY_SP, DesugaringKind, ErrorGuaranteed, Ident, Span, Spanned, Symbol, kw, sym, }; use rustc_target::asm::InlineAsmRegOrRegClass; use smallvec::SmallVec; diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 4157b110fbf6e..83b4833b51b03 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -24,7 +24,7 @@ use rustc_middle::ty::{ TypeVisitable, TypeVisitableExt, fold_regions, }; use rustc_session::lint::builtin::UNINHABITED_STATIC; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use rustc_target::spec::{AbiMap, AbiMapping}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::traits; diff --git a/compiler/rustc_hir_analysis/src/check/region.rs b/compiler/rustc_hir_analysis/src/check/region.rs index 0c611e6c4c9e6..8865638e3af2f 100644 --- a/compiler/rustc_hir_analysis/src/check/region.rs +++ b/compiler/rustc_hir_analysis/src/check/region.rs @@ -18,7 +18,7 @@ use rustc_index::Idx; use rustc_middle::middle::region::*; use rustc_middle::ty::TyCtxt; use rustc_session::lint; -use rustc_span::source_map; +use rustc_span::Spanned; use tracing::debug; #[derive(Debug, Copy, Clone)] @@ -181,7 +181,7 @@ fn resolve_cond<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, cond: &'tcx hi // operands will be terminated). Any temporaries that would need to be dropped will be // dropped before we leave this operator's scope; terminating them here would be redundant. hir::ExprKind::Binary( - source_map::Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. }, + Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. }, _, _, ) => false, @@ -264,7 +264,7 @@ fn resolve_expr<'tcx>( // scopes, meaning that temporaries cannot outlive them. // This ensures fixed size stacks. hir::ExprKind::Binary( - source_map::Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. }, + Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. }, left, right, ) => { @@ -293,7 +293,7 @@ fn resolve_expr<'tcx>( // This is purely an optimization to reduce the number of // terminating scopes. hir::ExprKind::Binary( - source_map::Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. }, + Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. }, .., ) => false, // otherwise: mark it as terminating diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index e806d72d3dd23..82540a9327410 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -23,8 +23,8 @@ use rustc_hir::{ GenericParam, GenericParamKind, HirId, ImplicitSelfKind, LifetimeParamKind, Node, PatKind, PreciseCapturingArg, RangeEnd, Term, TyFieldPath, TyPatKind, }; -use rustc_span::source_map::{SourceMap, Spanned}; -use rustc_span::{DUMMY_SP, FileName, Ident, Span, Symbol, kw, sym}; +use rustc_span::source_map::SourceMap; +use rustc_span::{DUMMY_SP, FileName, Ident, Span, Spanned, Symbol, kw, sym}; pub fn id_to_string(cx: &dyn rustc_hir::intravisit::HirTyCtxt<'_>, hir_id: HirId) -> String { to_string(&cx, |s| s.print_node(cx.hir_node(hir_id))) diff --git a/compiler/rustc_hir_typeck/src/errors.rs b/compiler/rustc_hir_typeck/src/errors.rs index 5c6a66403019c..6eef156846972 100644 --- a/compiler/rustc_hir_typeck/src/errors.rs +++ b/compiler/rustc_hir_typeck/src/errors.rs @@ -14,8 +14,7 @@ use rustc_hir::ExprKind; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_middle::ty::{self, Ty}; use rustc_span::edition::{Edition, LATEST_STABLE_EDITION}; -use rustc_span::source_map::Spanned; -use rustc_span::{Ident, Span, Symbol}; +use rustc_span::{Ident, Span, Spanned, Symbol}; use crate::FnCtxt; diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 2de101a1e4522..e35129f583517 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -34,8 +34,7 @@ use rustc_session::errors::ExprParenthesesNeeded; use rustc_session::parse::feature_err; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::hygiene::DesugaringKind; -use rustc_span::source_map::Spanned; -use rustc_span::{Ident, Span, Symbol, kw, sym}; +use rustc_span::{Ident, Span, Spanned, Symbol, kw, sym}; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::{self, ObligationCauseCode, ObligationCtxt}; use tracing::{debug, instrument, trace}; diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 801f5acf9d2f3..a2f4c57bd442c 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -23,8 +23,7 @@ use rustc_middle::ty::{ suggest_constraining_type_params, }; use rustc_session::errors::ExprParenthesesNeeded; -use rustc_span::source_map::Spanned; -use rustc_span::{ExpnKind, Ident, MacroKind, Span, Symbol, sym}; +use rustc_span::{ExpnKind, Ident, MacroKind, Span, Spanned, Symbol, sym}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::error_reporting::traits::DefIdOrName; use rustc_trait_selection::infer::InferCtxtExt; diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index 4b325a7ad14a1..cf61728f7c2a3 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -13,8 +13,7 @@ use rustc_middle::ty::adjustment::{ use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt}; use rustc_session::errors::ExprParenthesesNeeded; -use rustc_span::source_map::Spanned; -use rustc_span::{Span, Symbol, sym}; +use rustc_span::{Span, Spanned, Symbol, sym}; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::{FulfillmentError, Obligation, ObligationCtxt}; use tracing::debug; diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 54c8c75b88fcb..af590d98c301c 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -39,8 +39,7 @@ pub use rustc_session::lint::builtin::*; use rustc_session::lint::fcw; use rustc_session::{declare_lint, declare_lint_pass, impl_lint_pass}; use rustc_span::edition::Edition; -use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, Ident, InnerSpan, Span, Symbol, kw, sym}; +use rustc_span::{DUMMY_SP, Ident, InnerSpan, Span, Spanned, Symbol, kw, sym}; use rustc_target::asm::InlineAsmArch; use rustc_trait_selection::infer::{InferCtxtExt, TyCtxtInferExt}; use rustc_trait_selection::traits; diff --git a/compiler/rustc_lint/src/invalid_from_utf8.rs b/compiler/rustc_lint/src/invalid_from_utf8.rs index 41b670c92c4c5..f095d0a6a2f40 100644 --- a/compiler/rustc_lint/src/invalid_from_utf8.rs +++ b/compiler/rustc_lint/src/invalid_from_utf8.rs @@ -3,8 +3,7 @@ use std::str::Utf8Error; use rustc_ast::LitKind; use rustc_hir::{Expr, ExprKind}; use rustc_session::{declare_lint, declare_lint_pass}; -use rustc_span::source_map::Spanned; -use rustc_span::sym; +use rustc_span::{Spanned, sym}; use crate::lints::InvalidFromUtf8Diag; use crate::{LateContext, LateLintPass, LintContext}; diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 03a566efc8a54..2864cf9032a1c 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -600,7 +600,7 @@ impl UnusedDelimLint for UnusedParens { && !value.span.from_expansion() && (ctx != UnusedDelimsCtx::LetScrutineeExpr || !matches!(inner.kind, ast::ExprKind::Binary( - rustc_span::source_map::Spanned { node, .. }, + rustc_span::Spanned { node, .. }, _, _, ) if node.is_lazy())) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 8ac532ff4863d..2dd205e8468da 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -24,8 +24,7 @@ use rustc_index::bit_set::DenseBitSet; use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable}; use rustc_serialize::{Decodable, Encodable}; -use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, Span, Symbol}; +use rustc_span::{DUMMY_SP, Span, Spanned, Symbol}; use tracing::{debug, trace}; pub use self::query::*; diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index c3da2f0394852..455089f285d17 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -11,8 +11,7 @@ use rustc_hir::def_id::DefId; use rustc_index::IndexVec; use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Spanned; -use rustc_span::{Span, Symbol}; +use rustc_span::{Span, Spanned, Symbol}; use rustc_target::asm::InlineAsmRegOrRegClass; use smallvec::SmallVec; diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index 2636fc7024ca3..c20a389f56b97 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -96,8 +96,7 @@ use rustc_session::cstore::{ }; use rustc_session::lint::LintExpectationId; use rustc_span::def_id::LOCAL_CRATE; -use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, LocalExpnId, Span, Symbol}; +use rustc_span::{DUMMY_SP, LocalExpnId, Span, Spanned, Symbol}; use rustc_target::spec::PanicStrategy; use crate::infer::canonical::{self, Canonical}; diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index 4d4833b4943e4..a02f6f89b9b90 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -10,8 +10,7 @@ use std::intrinsics::transmute_unchecked; use std::mem::MaybeUninit; use rustc_ast::tokenstream::TokenStream; -use rustc_span::ErrorGuaranteed; -use rustc_span::source_map::Spanned; +use rustc_span::{ErrorGuaranteed, Spanned}; use crate::mir::interpret::EvalToValTreeResult; use crate::mir::mono::{MonoItem, NormalizationErrorInMono}; diff --git a/compiler/rustc_middle/src/query/on_disk_cache.rs b/compiler/rustc_middle/src/query/on_disk_cache.rs index 8db48fc2f9956..6968e5b7d6d81 100644 --- a/compiler/rustc_middle/src/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/query/on_disk_cache.rs @@ -17,10 +17,9 @@ use rustc_session::Session; use rustc_span::hygiene::{ ExpnId, HygieneDecodeContext, HygieneEncodeContext, SyntaxContext, SyntaxContextKey, }; -use rustc_span::source_map::Spanned; use rustc_span::{ BlobDecoder, BytePos, ByteSymbol, CachingSourceMapView, ExpnData, ExpnHash, RelativeBytePos, - SourceFile, Span, SpanDecoder, SpanEncoder, StableSourceFileId, Symbol, + SourceFile, Span, SpanDecoder, SpanEncoder, Spanned, StableSourceFileId, Symbol, }; use crate::dep_graph::{DepNodeIndex, QuerySideEffect, SerializedDepNodeIndex}; diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index d1987f51f6e01..6652c5a758daa 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -15,8 +15,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::LocalDefId; use rustc_middle::ty::Const; use rustc_serialize::{Decodable, Encodable}; -use rustc_span::source_map::Spanned; -use rustc_span::{Span, SpanDecoder, SpanEncoder}; +use rustc_span::{Span, SpanDecoder, SpanEncoder, Spanned}; use crate::arena::ArenaAllocatable; use crate::infer::canonical::{CanonicalVarKind, CanonicalVarKinds}; diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 04985dd3acde5..68e43bbbea205 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -8,7 +8,7 @@ use std::fmt::{self, Debug}; use rustc_abi::TyAndLayout; use rustc_hir::def::Namespace; use rustc_hir::def_id::LocalDefId; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use rustc_type_ir::{ConstKind, TypeFolder, VisitorResult, try_visit}; use super::{GenericArg, GenericArgKind, Pattern, Region}; diff --git a/compiler/rustc_mir_build/src/builder/custom/parse/instruction.rs b/compiler/rustc_mir_build/src/builder/custom/parse/instruction.rs index 13082d408ec08..a47a2e08c9f4b 100644 --- a/compiler/rustc_mir_build/src/builder/custom/parse/instruction.rs +++ b/compiler/rustc_mir_build/src/builder/custom/parse/instruction.rs @@ -4,8 +4,7 @@ use rustc_middle::mir::*; use rustc_middle::thir::*; use rustc_middle::ty; use rustc_middle::ty::cast::mir_cast_kind; -use rustc_span::Span; -use rustc_span::source_map::Spanned; +use rustc_span::{Span, Spanned}; use super::{PResult, ParseCtxt, parse_by_kind}; use crate::builder::custom::ParseError; diff --git a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs index 0f206c1f01ecc..a1b41510f1e1c 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs @@ -11,8 +11,7 @@ use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::cast::{CastTy, mir_cast_kind}; use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::{self, Ty, UpvarArgs}; -use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, Span}; +use rustc_span::{DUMMY_SP, Span, Spanned}; use tracing::debug; use crate::builder::expr::as_place::PlaceBase; diff --git a/compiler/rustc_mir_build/src/builder/expr/into.rs b/compiler/rustc_mir_build/src/builder/expr/into.rs index 24d184121ffd0..446b2939e3705 100644 --- a/compiler/rustc_mir_build/src/builder/expr/into.rs +++ b/compiler/rustc_mir_build/src/builder/expr/into.rs @@ -10,8 +10,7 @@ use rustc_middle::mir::*; use rustc_middle::span_bug; use rustc_middle::thir::*; use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty}; -use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, sym}; +use rustc_span::{DUMMY_SP, Spanned, sym}; use rustc_trait_selection::infer::InferCtxtExt; use tracing::{debug, instrument}; diff --git a/compiler/rustc_mir_build/src/builder/expr/stmt.rs b/compiler/rustc_mir_build/src/builder/expr/stmt.rs index 3d603afbaa4a7..99e16d182a97d 100644 --- a/compiler/rustc_mir_build/src/builder/expr/stmt.rs +++ b/compiler/rustc_mir_build/src/builder/expr/stmt.rs @@ -2,7 +2,7 @@ use rustc_middle::middle::region::{self, TempLifetime}; use rustc_middle::mir::*; use rustc_middle::span_bug; use rustc_middle::thir::*; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use tracing::debug; use crate::builder::scope::{BreakableTarget, LintLevel}; diff --git a/compiler/rustc_mir_build/src/builder/matches/test.rs b/compiler/rustc_mir_build/src/builder/matches/test.rs index 5c3173a7b1488..d8911870d3ad4 100644 --- a/compiler/rustc_mir_build/src/builder/matches/test.rs +++ b/compiler/rustc_mir_build/src/builder/matches/test.rs @@ -14,8 +14,7 @@ use rustc_middle::mir::*; use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::{self, GenericArg, Ty, TyCtxt}; use rustc_span::def_id::DefId; -use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, Span, Symbol, sym}; +use rustc_span::{DUMMY_SP, Span, Spanned, Symbol, sym}; use tracing::{debug, instrument}; use crate::builder::Builder; diff --git a/compiler/rustc_mir_build/src/builder/scope.rs b/compiler/rustc_mir_build/src/builder/scope.rs index b10df60e0f75b..91610e768d012 100644 --- a/compiler/rustc_mir_build/src/builder/scope.rs +++ b/compiler/rustc_mir_build/src/builder/scope.rs @@ -94,8 +94,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, ValTree}; use rustc_middle::{bug, span_bug}; use rustc_pattern_analysis::rustc::RustcPatCtxt; use rustc_session::lint::Level; -use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, Span}; +use rustc_span::{DUMMY_SP, Span, Spanned}; use tracing::{debug, instrument}; use super::matches::BuiltMatchTree; diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index c83b10a5e583a..332196e3afee7 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -83,8 +83,7 @@ use rustc_mir_dataflow::{ Analysis, Results, ResultsCursor, ResultsVisitor, visit_reachable_results, }; use rustc_span::def_id::{DefId, LocalDefId}; -use rustc_span::source_map::dummy_spanned; -use rustc_span::{DUMMY_SP, Span}; +use rustc_span::{DUMMY_SP, Span, dummy_spanned}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::infer::TyCtxtInferExt as _; use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode, ObligationCtxt}; diff --git a/compiler/rustc_mir_transform/src/elaborate_drop.rs b/compiler/rustc_mir_transform/src/elaborate_drop.rs index e17629215b796..1fe745a5d5197 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drop.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drop.rs @@ -9,8 +9,7 @@ use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::{self, GenericArg, GenericArgsRef, Ty, TyCtxt}; use rustc_middle::{bug, span_bug, traits}; -use rustc_span::DUMMY_SP; -use rustc_span::source_map::{Spanned, dummy_spanned}; +use rustc_span::{DUMMY_SP, Spanned, dummy_spanned}; use tracing::{debug, instrument}; use crate::patch::MirPatch; diff --git a/compiler/rustc_mir_transform/src/function_item_references.rs b/compiler/rustc_mir_transform/src/function_item_references.rs index 2ae8f43cf6c81..0216e0d4cfbc5 100644 --- a/compiler/rustc_mir_transform/src/function_item_references.rs +++ b/compiler/rustc_mir_transform/src/function_item_references.rs @@ -5,8 +5,7 @@ use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::*; use rustc_middle::ty::{self, EarlyBinder, GenericArgsRef, Ty, TyCtxt}; use rustc_session::lint::builtin::FUNCTION_ITEM_REFERENCES; -use rustc_span::source_map::Spanned; -use rustc_span::{Span, sym}; +use rustc_span::{Span, Spanned, sym}; use crate::errors; diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 9069f279e9811..afcea3236dbda 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -15,7 +15,7 @@ use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt, TypeFlags, TypeVisitableExt}; use rustc_session::config::{DebugInfo, OptLevel}; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use tracing::{debug, instrument, trace, trace_span}; use crate::cost_checker::{CostChecker, is_call_like}; diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 6bf4221d9ab78..094aae499c4b4 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -27,8 +27,7 @@ use rustc_middle::mir::{ use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt}; use rustc_middle::util::Providers; use rustc_middle::{bug, query, span_bug}; -use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, sym}; +use rustc_span::{DUMMY_SP, Spanned, sym}; use tracing::debug; #[macro_use] diff --git a/compiler/rustc_mir_transform/src/mentioned_items.rs b/compiler/rustc_mir_transform/src/mentioned_items.rs index a9f2c32171c39..c98ca2f4da52d 100644 --- a/compiler/rustc_mir_transform/src/mentioned_items.rs +++ b/compiler/rustc_mir_transform/src/mentioned_items.rs @@ -3,7 +3,7 @@ use rustc_middle::mir::{self, Location, MentionedItem}; use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::{self, TyCtxt}; use rustc_session::Session; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; pub(super) struct MentionedItems; diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index 3f5a630a21749..a47b3ce64ed23 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -23,8 +23,7 @@ use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Vis use rustc_middle::mir::*; use rustc_middle::ty::{self, GenericArgs, List, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::{bug, mir, span_bug}; -use rustc_span::Span; -use rustc_span::source_map::Spanned; +use rustc_span::{Span, Spanned}; use tracing::{debug, instrument}; /// A `MirPass` for promotion. diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 1abbfed1a8222..4fd0629befecf 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -12,8 +12,7 @@ use rustc_middle::ty::{ self, CoroutineArgs, CoroutineArgsExt, EarlyBinder, GenericArgs, Ty, TyCtxt, }; use rustc_middle::{bug, span_bug}; -use rustc_span::source_map::{Spanned, dummy_spanned}; -use rustc_span::{DUMMY_SP, Span}; +use rustc_span::{DUMMY_SP, Span, Spanned, dummy_spanned}; use tracing::{debug, instrument}; use crate::deref_separator::deref_finder; diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 3aa55cc8eb9fb..e56c6dc32ff17 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -236,8 +236,7 @@ use rustc_middle::ty::{ use rustc_middle::util::Providers; use rustc_middle::{bug, span_bug}; use rustc_session::config::{DebugInfo, EntryFnType}; -use rustc_span::source_map::{Spanned, dummy_spanned, respan}; -use rustc_span::{DUMMY_SP, Span}; +use rustc_span::{DUMMY_SP, Span, Spanned, dummy_spanned, respan}; use tracing::{debug, instrument, trace}; use crate::collector::autodiff::collect_autodiff_fn; diff --git a/compiler/rustc_monomorphize/src/mono_checks/move_check.rs b/compiler/rustc_monomorphize/src/mono_checks/move_check.rs index a8f3104c0d98d..a24b0443d39c9 100644 --- a/compiler/rustc_monomorphize/src/mono_checks/move_check.rs +++ b/compiler/rustc_monomorphize/src/mono_checks/move_check.rs @@ -6,8 +6,7 @@ use rustc_middle::mir::visit::Visitor as MirVisitor; use rustc_middle::mir::{self, Location, traversal}; use rustc_middle::ty::{self, AssocTag, Instance, Ty, TyCtxt, TypeFoldable}; use rustc_session::lint::builtin::LARGE_ASSIGNMENTS; -use rustc_span::source_map::Spanned; -use rustc_span::{Ident, Span, sym}; +use rustc_span::{Ident, Span, Spanned, sym}; use tracing::{debug, trace}; use crate::errors::LargeAssignmentsLint; diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 284e651d94ad0..47ac91feefd4b 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -16,9 +16,8 @@ use rustc_errors::{ pluralize, }; use rustc_session::errors::ExprParenthesesNeeded; -use rustc_span::source_map::Spanned; use rustc_span::symbol::used_keywords; -use rustc_span::{BytePos, DUMMY_SP, Ident, Span, SpanSnippetError, Symbol, kw, sym}; +use rustc_span::{BytePos, DUMMY_SP, Ident, Span, SpanSnippetError, Spanned, Symbol, kw, sym}; use thin_vec::{ThinVec, thin_vec}; use tracing::{debug, trace}; diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 4297086983b40..adfc68f4bb22a 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -25,8 +25,7 @@ use rustc_session::errors::{ExprParenthesesNeeded, report_lit_error}; use rustc_session::lint::BuiltinLintDiag; use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP; use rustc_span::edition::Edition; -use rustc_span::source_map::{self, Spanned}; -use rustc_span::{BytePos, ErrorGuaranteed, Ident, Pos, Span, Symbol, kw, sym}; +use rustc_span::{BytePos, ErrorGuaranteed, Ident, Pos, Span, Spanned, Symbol, kw, respan, sym}; use thin_vec::{ThinVec, thin_vec}; use tracing::instrument; @@ -296,12 +295,12 @@ impl<'a> Parser<'a> { let span = self.mk_expr_sp(&lhs, lhs_span, op_span, rhs.span); lhs = match op { AssocOp::Binary(ast_op) => { - let binary = self.mk_binary(source_map::respan(cur_op_span, ast_op), lhs, rhs); + let binary = self.mk_binary(respan(cur_op_span, ast_op), lhs, rhs); self.mk_expr(span, binary) } AssocOp::Assign => self.mk_expr(span, ExprKind::Assign(lhs, rhs, cur_op_span)), AssocOp::AssignOp(aop) => { - let aopexpr = self.mk_assign_op(source_map::respan(cur_op_span, aop), lhs, rhs); + let aopexpr = self.mk_assign_op(respan(cur_op_span, aop), lhs, rhs); self.mk_expr(span, aopexpr) } AssocOp::Cast | AssocOp::Range(_) => { @@ -409,7 +408,7 @@ impl<'a> Parser<'a> { } _ => return None, }; - Some(source_map::respan(span, op)) + Some(respan(span, op)) } /// Checks if this expression is a successfully parsed statement. diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index db5be5feaeb6e..0f4927432f6fa 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -13,7 +13,7 @@ use rustc_errors::{Applicability, PResult, StashKey, msg, struct_span_code_err}; use rustc_session::lint::builtin::VARARGS_WITHOUT_PATTERN; use rustc_span::edit_distance::edit_distance; use rustc_span::edition::Edition; -use rustc_span::{DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, source_map, sym}; +use rustc_span::{DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, respan, sym}; use thin_vec::{ThinVec, thin_vec}; use tracing::debug; @@ -3557,7 +3557,7 @@ impl<'a> Parser<'a> { _ => return Ok(None), }; - let eself = source_map::respan(eself_lo.to(eself_hi), eself); + let eself = respan(eself_lo.to(eself_hi), eself); Ok(Some(Param::from_self(AttrVec::default(), eself, eself_ident))) } diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 528b69abbf1aa..7ee7781f6be0a 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -12,8 +12,7 @@ use rustc_ast::{ use rustc_ast_pretty::pprust; use rustc_errors::{Applicability, Diag, DiagArgValue, PResult, StashKey}; use rustc_session::errors::ExprParenthesesNeeded; -use rustc_span::source_map::{Spanned, respan}; -use rustc_span::{BytePos, ErrorGuaranteed, Ident, Span, kw, sym}; +use rustc_span::{BytePos, ErrorGuaranteed, Ident, Span, Spanned, kw, respan, sym}; use thin_vec::{ThinVec, thin_vec}; use super::{ForceCollect, Parser, PathStyle, Restrictions, Trailing, UsePreAttrPos}; diff --git a/compiler/rustc_passes/src/abi_test.rs b/compiler/rustc_passes/src/abi_test.rs index 3da0978e5ff86..7d1ee1ffbc364 100644 --- a/compiler/rustc_passes/src/abi_test.rs +++ b/compiler/rustc_passes/src/abi_test.rs @@ -5,8 +5,7 @@ use rustc_hir::find_attr; use rustc_middle::span_bug; use rustc_middle::ty::layout::{FnAbiError, LayoutError}; use rustc_middle::ty::{self, GenericArgs, Instance, Ty, TyCtxt}; -use rustc_span::Span; -use rustc_span::source_map::Spanned; +use rustc_span::{Span, Spanned}; use rustc_target::callconv::FnAbi; use super::layout_test::ensure_wf; diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs index 68834cf7d55af..f4f5ae6c1683f 100644 --- a/compiler/rustc_passes/src/layout_test.rs +++ b/compiler/rustc_passes/src/layout_test.rs @@ -6,8 +6,7 @@ use rustc_hir::find_attr; use rustc_middle::span_bug; use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers}; use rustc_middle::ty::{self, Ty, TyCtxt}; -use rustc_span::Span; -use rustc_span::source_map::Spanned; +use rustc_span::{Span, Spanned}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::infer::TyCtxtInferExt; use rustc_trait_selection::traits; diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 1b1198af41c0e..12cc5649c41dd 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -32,8 +32,10 @@ use rustc_session::utils::was_invoked_from_cargo; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::edition::Edition; use rustc_span::hygiene::MacroKind; -use rustc_span::source_map::{SourceMap, Spanned}; -use rustc_span::{BytePos, Ident, RemapPathScopeComponents, Span, Symbol, SyntaxContext, kw, sym}; +use rustc_span::source_map::SourceMap; +use rustc_span::{ + BytePos, Ident, RemapPathScopeComponents, Span, Spanned, Symbol, SyntaxContext, kw, sym, +}; use thin_vec::{ThinVec, thin_vec}; use tracing::{debug, instrument}; diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index 63ffdbc37f7d1..7ab85e5a205f8 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -5,8 +5,7 @@ use rustc_errors::{ EmissionGuarantee, IntoDiagArg, Level, MultiSpan, Subdiagnostic, msg, }; use rustc_macros::{Diagnostic, Subdiagnostic}; -use rustc_span::source_map::Spanned; -use rustc_span::{Ident, Span, Symbol}; +use rustc_span::{Ident, Span, Spanned, Symbol}; use crate::Res; use crate::late::PatternSource; diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 1e2daff6d97cb..453fe9d7a8e0e 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -37,8 +37,7 @@ use rustc_middle::{bug, span_bug}; use rustc_session::config::{CrateType, ResolveDocLinks}; use rustc_session::lint; use rustc_session::parse::feature_err; -use rustc_span::source_map::{Spanned, respan}; -use rustc_span::{BytePos, DUMMY_SP, Ident, Span, Symbol, kw, sym}; +use rustc_span::{BytePos, DUMMY_SP, Ident, Span, Spanned, Symbol, kw, respan, sym}; use smallvec::{SmallVec, smallvec}; use thin_vec::ThinVec; use tracing::{debug, instrument, trace}; diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index a1d43d9863849..d7d2ecb5bbe79 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -90,6 +90,20 @@ use sha2::Sha256; #[cfg(test)] mod tests; +#[derive(Clone, Encodable, Decodable, Debug, Copy, PartialEq, Hash, HashStable_Generic)] +pub struct Spanned { + pub node: T, + pub span: Span, +} + +pub fn respan(sp: Span, t: T) -> Spanned { + Spanned { node: t, span: sp } +} + +pub fn dummy_spanned(t: T) -> Spanned { + respan(DUMMY_SP, t) +} + /// Per-session global variables: this struct is stored in thread-local storage /// in such a way that it is accessible without any kind of handle to all /// threads within the compilation session, but is not accessible outside the diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 35694be9e492b..ec335e7b43390 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -15,7 +15,6 @@ use std::{fs, path}; use rustc_data_structures::sync::{IntoDynSyncSend, MappedReadGuard, ReadGuard, RwLock}; use rustc_data_structures::unhash::UnhashMap; -use rustc_macros::{Decodable, Encodable}; use tracing::{debug, instrument, trace}; use crate::*; @@ -74,20 +73,6 @@ mod monotonic { impl !DerefMut for MonotonicVec {} } -#[derive(Clone, Encodable, Decodable, Debug, Copy, PartialEq, Hash, HashStable_Generic)] -pub struct Spanned { - pub node: T, - pub span: Span, -} - -pub fn respan(sp: Span, t: T) -> Spanned { - Spanned { node: t, span: sp } -} - -pub fn dummy_spanned(t: T) -> Spanned { - respan(DUMMY_SP, t) -} - // _____________________________________________________________________________ // SourceFile, MultiByteChar, FileName, FileLines // diff --git a/src/tools/clippy/clippy_lints/src/bool_comparison.rs b/src/tools/clippy/clippy_lints/src/bool_comparison.rs index 722095909a6fe..feeefefc3b8f1 100644 --- a/src/tools/clippy/clippy_lints/src/bool_comparison.rs +++ b/src/tools/clippy/clippy_lints/src/bool_comparison.rs @@ -6,8 +6,7 @@ use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; -use rustc_span::Span; -use rustc_span::source_map::Spanned; +use rustc_span::{Span, Spanned}; declare_clippy_lint! { /// ### What it does diff --git a/src/tools/clippy/clippy_lints/src/casts/manual_dangling_ptr.rs b/src/tools/clippy/clippy_lints/src/casts/manual_dangling_ptr.rs index 56779e8ce3d95..55b0945f0962b 100644 --- a/src/tools/clippy/clippy_lints/src/casts/manual_dangling_ptr.rs +++ b/src/tools/clippy/clippy_lints/src/casts/manual_dangling_ptr.rs @@ -6,7 +6,7 @@ use rustc_ast::LitKind; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, GenericArg, Mutability, QPath, Ty, TyKind}; use rustc_lint::LateContext; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::MANUAL_DANGLING_PTR; diff --git a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/custom_abs.rs b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/custom_abs.rs index d12a32e158814..6578cf20e6378 100644 --- a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/custom_abs.rs +++ b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/custom_abs.rs @@ -7,7 +7,7 @@ use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; use rustc_lint::LateContext; use rustc_span::SyntaxContext; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::SUBOPTIMAL_FLOPS; diff --git a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/expm1.rs b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/expm1.rs index 9a4c975693087..bf376a51fec93 100644 --- a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/expm1.rs +++ b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/expm1.rs @@ -6,7 +6,7 @@ use clippy_utils::sym; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::IMPRECISE_FLOPS; diff --git a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/hypot.rs b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/hypot.rs index 49f8ba4bf8256..8d3bd8084db8f 100644 --- a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/hypot.rs +++ b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/hypot.rs @@ -6,7 +6,7 @@ use clippy_utils::{eq_expr_value, sym}; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment}; use rustc_lint::LateContext; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::IMPRECISE_FLOPS; diff --git a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/ln1p.rs b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/ln1p.rs index 4c9aa96b5042a..f37737c71aee1 100644 --- a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/ln1p.rs +++ b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/ln1p.rs @@ -4,7 +4,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::IMPRECISE_FLOPS; diff --git a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/log_division.rs b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/log_division.rs index e3419ffad72a5..947935369de16 100644 --- a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/log_division.rs +++ b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/log_division.rs @@ -4,7 +4,7 @@ use clippy_utils::{eq_expr_value, sym}; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment}; use rustc_lint::LateContext; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::SUBOPTIMAL_FLOPS; diff --git a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/mul_add.rs b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/mul_add.rs index e0a6498f62fd4..888d5b7b762a0 100644 --- a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/mul_add.rs +++ b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/mul_add.rs @@ -5,7 +5,7 @@ use rustc_ast::AssignOpKind; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment}; use rustc_lint::LateContext; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::SUBOPTIMAL_FLOPS; diff --git a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/powi.rs b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/powi.rs index a61a2a82c0237..b0b65b357d7ab 100644 --- a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/powi.rs +++ b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/powi.rs @@ -6,7 +6,7 @@ use clippy_utils::{get_parent_expr, sym}; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment}; use rustc_lint::LateContext; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::SUBOPTIMAL_FLOPS; diff --git a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/radians.rs b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/radians.rs index 2021f00a97e8d..8480626133fdd 100644 --- a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/radians.rs +++ b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic/radians.rs @@ -6,7 +6,7 @@ use rustc_ast::ast; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use std::f32::consts as f32_consts; use std::f64::consts as f64_consts; diff --git a/src/tools/clippy/clippy_lints/src/len_zero.rs b/src/tools/clippy/clippy_lints/src/len_zero.rs index d683abd3d33b3..f906bba423b35 100644 --- a/src/tools/clippy/clippy_lints/src/len_zero.rs +++ b/src/tools/clippy/clippy_lints/src/len_zero.rs @@ -13,8 +13,7 @@ use rustc_hir::{BinOpKind, Expr, ExprKind, PatExprKind, PatKind, RustcVersion, S use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, Ty}; use rustc_session::impl_lint_pass; -use rustc_span::source_map::Spanned; -use rustc_span::{Span, Symbol}; +use rustc_span::{Span, Spanned, Symbol}; declare_clippy_lint! { /// ### What it does diff --git a/src/tools/clippy/clippy_lints/src/loops/manual_slice_fill.rs b/src/tools/clippy/clippy_lints/src/loops/manual_slice_fill.rs index a2ff60a3d8ac8..5d09f755bcd15 100644 --- a/src/tools/clippy/clippy_lints/src/loops/manual_slice_fill.rs +++ b/src/tools/clippy/clippy_lints/src/loops/manual_slice_fill.rs @@ -13,8 +13,7 @@ use rustc_hir::QPath::Resolved; use rustc_hir::def::Res; use rustc_hir::{Expr, ExprKind, Pat}; use rustc_lint::LateContext; -use rustc_span::source_map::Spanned; -use rustc_span::sym; +use rustc_span::{Spanned, sym}; use super::MANUAL_SLICE_FILL; diff --git a/src/tools/clippy/clippy_lints/src/loops/utils.rs b/src/tools/clippy/clippy_lints/src/loops/utils.rs index 2c37e2679d972..86f4e606a176a 100644 --- a/src/tools/clippy/clippy_lints/src/loops/utils.rs +++ b/src/tools/clippy/clippy_lints/src/loops/utils.rs @@ -8,7 +8,7 @@ use rustc_hir::{AssignOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, LetSt use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Ty}; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use rustc_span::symbol::{Symbol, sym}; #[derive(Debug, PartialEq, Eq)] diff --git a/src/tools/clippy/clippy_lints/src/manual_strip.rs b/src/tools/clippy/clippy_lints/src/manual_strip.rs index 5261632445969..e0a60e3747a0f 100644 --- a/src/tools/clippy/clippy_lints/src/manual_strip.rs +++ b/src/tools/clippy/clippy_lints/src/manual_strip.rs @@ -15,8 +15,7 @@ use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, Node, PatKind}; use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty; use rustc_session::impl_lint_pass; -use rustc_span::source_map::Spanned; -use rustc_span::{Symbol, SyntaxContext}; +use rustc_span::{Spanned, Symbol, SyntaxContext}; use std::iter; declare_clippy_lint! { diff --git a/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs b/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs index 347560b14eeac..3a16c2ed8790b 100644 --- a/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs +++ b/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs @@ -10,7 +10,7 @@ use rustc_errors::Applicability; use rustc_hir::{Arm, BorrowKind, Expr, ExprKind, Pat, PatKind, QPath}; use rustc_lint::{LateContext, LintContext}; use rustc_middle::ty; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::MATCH_LIKE_MATCHES_MACRO; diff --git a/src/tools/clippy/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs b/src/tools/clippy/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs index b4b10e972f6d4..23a0046dec766 100644 --- a/src/tools/clippy/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs +++ b/src/tools/clippy/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs @@ -8,7 +8,7 @@ use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, LangItem}; use rustc_lint::LateContext; use rustc_span::Span; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS; diff --git a/src/tools/clippy/clippy_lints/src/methods/get_first.rs b/src/tools/clippy/clippy_lints/src/methods/get_first.rs index 414c4e0cd381f..cb5d1ec374fce 100644 --- a/src/tools/clippy/clippy_lints/src/methods/get_first.rs +++ b/src/tools/clippy/clippy_lints/src/methods/get_first.rs @@ -7,7 +7,7 @@ use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::GET_FIRST; diff --git a/src/tools/clippy/clippy_lints/src/methods/get_last_with_len.rs b/src/tools/clippy/clippy_lints/src/methods/get_last_with_len.rs index 171079f52d9a5..14e40328a4168 100644 --- a/src/tools/clippy/clippy_lints/src/methods/get_last_with_len.rs +++ b/src/tools/clippy/clippy_lints/src/methods/get_last_with_len.rs @@ -5,7 +5,7 @@ use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::GET_LAST_WITH_LEN; diff --git a/src/tools/clippy/clippy_lints/src/methods/manual_contains.rs b/src/tools/clippy/clippy_lints/src/methods/manual_contains.rs index d2906b2776f8c..f1d399e1bbd2f 100644 --- a/src/tools/clippy/clippy_lints/src/methods/manual_contains.rs +++ b/src/tools/clippy/clippy_lints/src/methods/manual_contains.rs @@ -9,7 +9,7 @@ use rustc_hir::def::Res; use rustc_hir::{BinOpKind, Body, Expr, ExprKind, HirId, QPath}; use rustc_lint::LateContext; use rustc_middle::ty; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::MANUAL_CONTAINS; diff --git a/src/tools/clippy/clippy_lints/src/methods/open_options.rs b/src/tools/clippy/clippy_lints/src/methods/open_options.rs index 1b520a9edb566..042558d645e65 100644 --- a/src/tools/clippy/clippy_lints/src/methods/open_options.rs +++ b/src/tools/clippy/clippy_lints/src/methods/open_options.rs @@ -8,7 +8,7 @@ use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::Ty; use rustc_span::Span; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::{NONSENSICAL_OPEN_OPTIONS, SUSPICIOUS_OPEN_OPTIONS}; diff --git a/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs b/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs index be1481ebb996e..98b7834178f24 100644 --- a/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs +++ b/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs @@ -3,7 +3,7 @@ use rustc_ast::LitKind; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; use rustc_span::Symbol; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::SUSPICIOUS_SPLITN; diff --git a/src/tools/clippy/clippy_lints/src/methods/vec_resize_to_zero.rs b/src/tools/clippy/clippy_lints/src/methods/vec_resize_to_zero.rs index 5debaab2067bd..8979f9973d6f6 100644 --- a/src/tools/clippy/clippy_lints/src/methods/vec_resize_to_zero.rs +++ b/src/tools/clippy/clippy_lints/src/methods/vec_resize_to_zero.rs @@ -5,8 +5,7 @@ use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; -use rustc_span::source_map::Spanned; -use rustc_span::{Span, sym}; +use rustc_span::{Span, Spanned, sym}; use super::VEC_RESIZE_TO_ZERO; diff --git a/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs b/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs index 2773f537efc65..b5becbdeb30d9 100644 --- a/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs +++ b/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs @@ -15,8 +15,7 @@ use rustc_errors::{Applicability, Diag}; use rustc_hir::{Block, Body, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; -use rustc_span::source_map::Spanned; -use rustc_span::{Span, Symbol, sym}; +use rustc_span::{Span, Spanned, Symbol, sym}; declare_clippy_lint! { /// ### What it does diff --git a/src/tools/clippy/clippy_lints/src/operators/const_comparisons.rs b/src/tools/clippy/clippy_lints/src/operators/const_comparisons.rs index 56001a185771a..e5a5b46b7b2e4 100644 --- a/src/tools/clippy/clippy_lints/src/operators/const_comparisons.rs +++ b/src/tools/clippy/clippy_lints/src/operators/const_comparisons.rs @@ -7,8 +7,7 @@ use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::layout::HasTyCtxt; use rustc_middle::ty::{Ty, TypeckResults}; -use rustc_span::Span; -use rustc_span::source_map::Spanned; +use rustc_span::{Span, Spanned}; use clippy_utils::SpanlessEq; use clippy_utils::diagnostics::span_lint_and_note; diff --git a/src/tools/clippy/clippy_lints/src/operators/float_equality_without_abs.rs b/src/tools/clippy/clippy_lints/src/operators/float_equality_without_abs.rs index 97b3c0d02e84e..6c6221525b578 100644 --- a/src/tools/clippy/clippy_lints/src/operators/float_equality_without_abs.rs +++ b/src/tools/clippy/clippy_lints/src/operators/float_equality_without_abs.rs @@ -6,7 +6,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::FLOAT_EQUALITY_WITHOUT_ABS; diff --git a/src/tools/clippy/clippy_lints/src/operators/manual_div_ceil.rs b/src/tools/clippy/clippy_lints/src/operators/manual_div_ceil.rs index 6751532ecbc78..a0f61f6d36c4e 100644 --- a/src/tools/clippy/clippy_lints/src/operators/manual_div_ceil.rs +++ b/src/tools/clippy/clippy_lints/src/operators/manual_div_ceil.rs @@ -9,7 +9,7 @@ use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use super::MANUAL_DIV_CEIL; diff --git a/src/tools/clippy/clippy_lints/src/precedence.rs b/src/tools/clippy/clippy_lints/src/precedence.rs index 034fe8edc715d..1f0371c782000 100644 --- a/src/tools/clippy/clippy_lints/src/precedence.rs +++ b/src/tools/clippy/clippy_lints/src/precedence.rs @@ -5,7 +5,7 @@ use rustc_ast::ast::{BinOpKind, Expr, ExprKind}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass, Lint}; use rustc_session::declare_lint_pass; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; declare_clippy_lint! { /// ### What it does diff --git a/src/tools/clippy/clippy_lints/src/ranges.rs b/src/tools/clippy/clippy_lints/src/ranges.rs index 61087ad884577..39019c646bd5a 100644 --- a/src/tools/clippy/clippy_lints/src/ranges.rs +++ b/src/tools/clippy/clippy_lints/src/ranges.rs @@ -14,8 +14,7 @@ use rustc_hir::{BinOpKind, Expr, ExprKind, HirId, LangItem, Node}; use rustc_lint::{LateContext, LateLintPass, Lint}; use rustc_middle::ty::{self, ClauseKind, GenericArgKind, PredicatePolarity, Ty}; use rustc_session::impl_lint_pass; -use rustc_span::source_map::Spanned; -use rustc_span::{DesugaringKind, Span}; +use rustc_span::{DesugaringKind, Span, Spanned}; use std::cmp::Ordering; declare_clippy_lint! { diff --git a/src/tools/clippy/clippy_lints/src/strings.rs b/src/tools/clippy/clippy_lints/src/strings.rs index ab11c37b5041d..61b5842ea542a 100644 --- a/src/tools/clippy/clippy_lints/src/strings.rs +++ b/src/tools/clippy/clippy_lints/src/strings.rs @@ -11,7 +11,7 @@ use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, LangItem, Node}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::ty; use rustc_session::declare_lint_pass; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; declare_clippy_lint! { /// ### What it does diff --git a/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs b/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs index 9fa4d2c142b5b..44e35b8dc71b0 100644 --- a/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs +++ b/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs @@ -8,7 +8,7 @@ use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::declare_lint_pass; use rustc_span::Span; -use rustc_span::source_map::Spanned; +use rustc_span::Spanned; use rustc_span::symbol::Ident; declare_clippy_lint! { diff --git a/src/tools/clippy/clippy_lints/src/swap.rs b/src/tools/clippy/clippy_lints/src/swap.rs index 0c78ed84adc4a..01482b2475f7c 100644 --- a/src/tools/clippy/clippy_lints/src/swap.rs +++ b/src/tools/clippy/clippy_lints/src/swap.rs @@ -14,9 +14,8 @@ use rustc_hir::{AssignOpKind, Block, Expr, ExprKind, LetStmt, PatKind, QPath, St use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::ty; use rustc_session::declare_lint_pass; -use rustc_span::source_map::Spanned; use rustc_span::symbol::Ident; -use rustc_span::{Span, SyntaxContext}; +use rustc_span::{Span, Spanned, SyntaxContext}; declare_clippy_lint! { /// ### What it does diff --git a/src/tools/clippy/clippy_lints_internal/src/lint_without_lint_pass.rs b/src/tools/clippy/clippy_lints_internal/src/lint_without_lint_pass.rs index f56b6f31550ba..cab1422c3000a 100644 --- a/src/tools/clippy/clippy_lints_internal/src/lint_without_lint_pass.rs +++ b/src/tools/clippy/clippy_lints_internal/src/lint_without_lint_pass.rs @@ -12,9 +12,8 @@ use rustc_hir::{ExprKind, HirId, Item, MutTy, Mutability, Path, TyKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::Span; -use rustc_span::source_map::Spanned; use rustc_span::symbol::Symbol; +use rustc_span::{Span, Spanned}; declare_tool_lint! { /// ### What it does diff --git a/src/tools/rustfmt/src/patterns.rs b/src/tools/rustfmt/src/patterns.rs index df2a8dc5c6fde..0a9ff4771b0e0 100644 --- a/src/tools/rustfmt/src/patterns.rs +++ b/src/tools/rustfmt/src/patterns.rs @@ -361,7 +361,7 @@ pub(crate) fn rewrite_range_pat( shape: Shape, lhs: &Option>, rhs: &Option>, - end_kind: &rustc_span::source_map::Spanned, + end_kind: &rustc_span::Spanned, span: Span, ) -> RewriteResult { let infix = match end_kind.node { diff --git a/src/tools/rustfmt/src/spanned.rs b/src/tools/rustfmt/src/spanned.rs index 020651e2daace..143fb1dea2223 100644 --- a/src/tools/rustfmt/src/spanned.rs +++ b/src/tools/rustfmt/src/spanned.rs @@ -1,7 +1,7 @@ use std::cmp::max; use rustc_ast::ast; -use rustc_span::{Span, source_map}; +use rustc_span::Span; use crate::macros::MacroArg; use crate::patterns::RangeOperand; @@ -18,7 +18,7 @@ impl Spanned for Box { } } -impl Spanned for source_map::Spanned { +impl Spanned for rustc_span::Spanned { fn span(&self) -> Span { self.span } diff --git a/tests/ui-fulldeps/pprust-expr-roundtrip.rs b/tests/ui-fulldeps/pprust-expr-roundtrip.rs index 8d7425186680a..84f9a09990fdd 100644 --- a/tests/ui-fulldeps/pprust-expr-roundtrip.rs +++ b/tests/ui-fulldeps/pprust-expr-roundtrip.rs @@ -38,9 +38,8 @@ use rustc_ast::mut_visit::MutVisitor; use rustc_ast::*; use rustc_ast_pretty::pprust; use rustc_session::parse::ParseSess; -use rustc_span::source_map::Spanned; use rustc_span::symbol::Ident; -use rustc_span::DUMMY_SP; +use rustc_span::{DUMMY_SP, Spanned}; use thin_vec::{thin_vec, ThinVec}; // Helper functions for building exprs