From 0e079046f75822c4ca5b443b03063c4ae8872df1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 18 Feb 2021 17:29:44 +0100 Subject: [PATCH 01/22] Prevent to compute Item attributes twice --- src/librustdoc/clean/inline.rs | 11 ++++++----- src/librustdoc/clean/types.rs | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index cdff37cbd51f4..97d561561dcef 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -416,7 +416,10 @@ crate fn build_impl( debug!("build_impl: impl {:?} for {:?}", trait_.def_id(), for_.def_id()); - let mut item = clean::Item::from_def_id_and_parts( + let attrs = box merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs); + debug!("merged_attrs={:?}", attrs); + + ret.push(clean::Item::from_def_id_and_attrs_and_parts( did, None, clean::ImplItem(clean::Impl { @@ -430,11 +433,9 @@ crate fn build_impl( synthetic: false, blanket_impl: None, }), + attrs, cx, - ); - item.attrs = box merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs); - debug!("merged_attrs={:?}", item.attrs); - ret.push(item); + )); } fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet) -> clean::Module { diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 754f1c2eeeb21..42096140e9d7c 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -140,6 +140,22 @@ impl Item { name: Option, kind: ItemKind, cx: &DocContext<'_>, + ) -> Item { + Self::from_def_id_and_attrs_and_parts( + def_id, + name, + kind, + box cx.tcx.get_attrs(def_id).clean(cx), + cx, + ) + } + + pub fn from_def_id_and_attrs_and_parts( + def_id: DefId, + name: Option, + kind: ItemKind, + attrs: Box, + cx: &DocContext<'_>, ) -> Item { debug!("name={:?}, def_id={:?}", name, def_id); @@ -157,7 +173,7 @@ impl Item { kind: box kind, name, source: source.clean(cx), - attrs: box cx.tcx.get_attrs(def_id).clean(cx), + attrs, visibility: cx.tcx.visibility(def_id).clean(cx), } } From 3ed189e8af09c60aa9410193dacc7c9f11144344 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Thu, 18 Feb 2021 20:21:18 +0100 Subject: [PATCH 02/22] Cleanup `PpMode` and friends --- compiler/rustc_driver/src/pretty.rs | 38 ++++---- compiler/rustc_interface/src/passes.rs | 2 +- compiler/rustc_session/src/config.rs | 117 ++++++++++++++----------- 3 files changed, 83 insertions(+), 74 deletions(-) diff --git a/compiler/rustc_driver/src/pretty.rs b/compiler/rustc_driver/src/pretty.rs index 17d2b3386f5fe..00e4cc46c33e4 100644 --- a/compiler/rustc_driver/src/pretty.rs +++ b/compiler/rustc_driver/src/pretty.rs @@ -9,7 +9,7 @@ use rustc_hir_pretty as pprust_hir; use rustc_middle::hir::map as hir_map; use rustc_middle::ty::{self, TyCtxt}; use rustc_mir::util::{write_mir_graphviz, write_mir_pretty}; -use rustc_session::config::{Input, PpMode, PpSourceMode}; +use rustc_session::config::{Input, PpHirMode, PpMode, PpSourceMode}; use rustc_session::Session; use rustc_span::symbol::Ident; use rustc_span::FileName; @@ -42,43 +42,41 @@ where F: FnOnce(&dyn PrinterSupport) -> A, { match *ppmode { - PpmNormal | PpmEveryBodyLoops | PpmExpanded => { + Normal | EveryBodyLoops | Expanded => { let annotation = NoAnn { sess, tcx }; f(&annotation) } - PpmIdentified | PpmExpandedIdentified => { + Identified | ExpandedIdentified => { let annotation = IdentifiedAnnotation { sess, tcx }; f(&annotation) } - PpmExpandedHygiene => { + ExpandedHygiene => { let annotation = HygieneAnnotation { sess }; f(&annotation) } - _ => panic!("Should use call_with_pp_support_hir"), } } -fn call_with_pp_support_hir(ppmode: &PpSourceMode, tcx: TyCtxt<'_>, f: F) -> A +fn call_with_pp_support_hir(ppmode: &PpHirMode, tcx: TyCtxt<'_>, f: F) -> A where F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate<'_>) -> A, { match *ppmode { - PpmNormal => { + PpHirMode::Normal => { let annotation = NoAnn { sess: tcx.sess, tcx: Some(tcx) }; f(&annotation, tcx.hir().krate()) } - PpmIdentified => { + PpHirMode::Identified => { let annotation = IdentifiedAnnotation { sess: tcx.sess, tcx: Some(tcx) }; f(&annotation, tcx.hir().krate()) } - PpmTyped => { + PpHirMode::Typed => { abort_on_err(tcx.analysis(LOCAL_CRATE), tcx.sess); let annotation = TypedAnnotation { tcx, maybe_typeck_results: Cell::new(None) }; tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate())) } - _ => panic!("Should use call_with_pp_support"), } } @@ -395,7 +393,7 @@ pub fn print_after_parsing( let mut out = String::new(); - if let PpmSource(s) = ppm { + if let Source(s) = ppm { // Silently ignores an identified node. let out = &mut out; call_with_pp_support(&s, sess, None, move |annotation| { @@ -436,7 +434,7 @@ pub fn print_after_hir_lowering<'tcx>( let mut out = String::new(); match ppm { - PpmSource(s) => { + Source(s) => { // Silently ignores an identified node. let out = &mut out; call_with_pp_support(&s, tcx.sess, Some(tcx), move |annotation| { @@ -455,20 +453,20 @@ pub fn print_after_hir_lowering<'tcx>( }) } - PpmHir(s) => { + Hir(s) => { let out = &mut out; call_with_pp_support_hir(&s, tcx, move |annotation, krate| { - debug!("pretty printing source code {:?}", s); + debug!("pretty printing HIR {:?}", s); let sess = annotation.sess(); let sm = sess.source_map(); *out = pprust_hir::print_crate(sm, krate, src_name, src, annotation.pp_ann()) }) } - PpmHirTree(s) => { + HirTree => { let out = &mut out; - call_with_pp_support_hir(&s, tcx, move |_annotation, krate| { - debug!("pretty printing source code {:?}", s); + call_with_pp_support_hir(&PpHirMode::Normal, tcx, move |_annotation, krate| { + debug!("pretty printing HIR tree"); *out = format!("{:#?}", krate); }); } @@ -493,9 +491,9 @@ fn print_with_analysis( tcx.analysis(LOCAL_CRATE)?; match ppm { - PpmMir | PpmMirCFG => match ppm { - PpmMir => write_mir_pretty(tcx, None, &mut out), - PpmMirCFG => write_mir_graphviz(tcx, None, &mut out), + Mir | MirCFG => match ppm { + Mir => write_mir_pretty(tcx, None, &mut out), + MirCFG => write_mir_graphviz(tcx, None, &mut out), _ => unreachable!(), }, _ => unreachable!(), diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 544da4cd9aa7d..06a7d1aeb4d8c 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -348,7 +348,7 @@ fn configure_and_expand_inner<'a>( rustc_builtin_macros::test_harness::inject(&sess, &mut resolver, &mut krate) }); - if let Some(PpMode::PpmSource(PpSourceMode::PpmEveryBodyLoops)) = sess.opts.pretty { + if let Some(PpMode::Source(PpSourceMode::EveryBodyLoops)) = sess.opts.pretty { tracing::debug!("replacing bodies with loop {{}}"); util::ReplaceBodyWithLoop::new(&mut resolver).visit_crate(&mut krate); } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 4533b37f10b42..35854b2088639 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2068,40 +2068,21 @@ fn parse_pretty( debugging_opts: &DebuggingOptions, efmt: ErrorOutputType, ) -> Option { - let pretty = if debugging_opts.unstable_options { - matches.opt_default("pretty", "normal").map(|a| { - // stable pretty-print variants only - parse_pretty_inner(efmt, &a, false) - }) - } else { - None - }; - - return if pretty.is_none() { - debugging_opts.unpretty.as_ref().map(|a| { - // extended with unstable pretty-print variants - parse_pretty_inner(efmt, &a, true) - }) - } else { - pretty - }; - fn parse_pretty_inner(efmt: ErrorOutputType, name: &str, extended: bool) -> PpMode { use PpMode::*; - use PpSourceMode::*; let first = match (name, extended) { - ("normal", _) => PpmSource(PpmNormal), - ("identified", _) => PpmSource(PpmIdentified), - ("everybody_loops", true) => PpmSource(PpmEveryBodyLoops), - ("expanded", _) => PpmSource(PpmExpanded), - ("expanded,identified", _) => PpmSource(PpmExpandedIdentified), - ("expanded,hygiene", _) => PpmSource(PpmExpandedHygiene), - ("hir", true) => PpmHir(PpmNormal), - ("hir,identified", true) => PpmHir(PpmIdentified), - ("hir,typed", true) => PpmHir(PpmTyped), - ("hir-tree", true) => PpmHirTree(PpmNormal), - ("mir", true) => PpmMir, - ("mir-cfg", true) => PpmMirCFG, + ("normal", _) => Source(PpSourceMode::Normal), + ("identified", _) => Source(PpSourceMode::Identified), + ("everybody_loops", true) => Source(PpSourceMode::EveryBodyLoops), + ("expanded", _) => Source(PpSourceMode::Expanded), + ("expanded,identified", _) => Source(PpSourceMode::ExpandedIdentified), + ("expanded,hygiene", _) => Source(PpSourceMode::ExpandedHygiene), + ("hir", true) => Hir(PpHirMode::Normal), + ("hir,identified", true) => Hir(PpHirMode::Identified), + ("hir,typed", true) => Hir(PpHirMode::Typed), + ("hir-tree", true) => HirTree, + ("mir", true) => Mir, + ("mir-cfg", true) => MirCFG, _ => { if extended { early_error( @@ -2130,6 +2111,18 @@ fn parse_pretty( tracing::debug!("got unpretty option: {:?}", first); first } + + if debugging_opts.unstable_options { + if let Some(a) = matches.opt_default("pretty", "normal") { + // stable pretty-print variants only + return Some(parse_pretty_inner(efmt, &a, false)); + } + } + + debugging_opts.unpretty.as_ref().map(|a| { + // extended with unstable pretty-print variants + parse_pretty_inner(efmt, &a, true) + }) } pub fn make_crate_type_option() -> RustcOptGroup { @@ -2237,22 +2230,43 @@ impl fmt::Display for CrateType { #[derive(Copy, Clone, PartialEq, Debug)] pub enum PpSourceMode { - PpmNormal, - PpmEveryBodyLoops, - PpmExpanded, - PpmIdentified, - PpmExpandedIdentified, - PpmExpandedHygiene, - PpmTyped, + /// `--pretty=normal` + Normal, + /// `-Zunpretty=everybody_loops` + EveryBodyLoops, + /// `--pretty=expanded` + Expanded, + /// `--pretty=identified` + Identified, + /// `--pretty=expanded,identified` + ExpandedIdentified, + /// `--pretty=expanded,hygiene` + ExpandedHygiene, +} + +#[derive(Copy, Clone, PartialEq, Debug)] +pub enum PpHirMode { + /// `-Zunpretty=hir` + Normal, + /// `-Zunpretty=hir,identified` + Identified, + /// `-Zunpretty=hir,typed` + Typed, } #[derive(Copy, Clone, PartialEq, Debug)] pub enum PpMode { - PpmSource(PpSourceMode), - PpmHir(PpSourceMode), - PpmHirTree(PpSourceMode), - PpmMir, - PpmMirCFG, + /// Options that print the source code, i.e. + /// `--pretty` and `-Zunpretty=everybody_loops` + Source(PpSourceMode), + /// Options that print the HIR, i.e. `-Zunpretty=hir` + Hir(PpHirMode), + /// `-Zunpretty=hir-tree` + HirTree, + /// `-Zunpretty=mir` + Mir, + /// `-Zunpretty=mir-cfg` + MirCFG, } impl PpMode { @@ -2260,22 +2274,19 @@ impl PpMode { use PpMode::*; use PpSourceMode::*; match *self { - PpmSource(PpmNormal | PpmIdentified) => false, + Source(Normal | Identified) => false, - PpmSource( - PpmExpanded | PpmEveryBodyLoops | PpmExpandedIdentified | PpmExpandedHygiene, - ) - | PpmHir(_) - | PpmHirTree(_) - | PpmMir - | PpmMirCFG => true, - PpmSource(PpmTyped) => panic!("invalid state"), + Source(Expanded | EveryBodyLoops | ExpandedIdentified | ExpandedHygiene) + | Hir(_) + | HirTree + | Mir + | MirCFG => true, } } pub fn needs_analysis(&self) -> bool { use PpMode::*; - matches!(*self, PpmMir | PpmMirCFG) + matches!(*self, Mir | MirCFG) } } From dd3772e4f01a9cab1d967c1b80c9c7cbe6014592 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Fri, 19 Feb 2021 19:08:12 +0100 Subject: [PATCH 03/22] A few more code cleanups --- compiler/rustc_driver/src/pretty.rs | 52 ++++++++++------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_driver/src/pretty.rs b/compiler/rustc_driver/src/pretty.rs index 00e4cc46c33e4..1dcc4d147acf2 100644 --- a/compiler/rustc_driver/src/pretty.rs +++ b/compiler/rustc_driver/src/pretty.rs @@ -391,16 +391,13 @@ pub fn print_after_parsing( ) { let (src, src_name) = get_source(input, sess); - let mut out = String::new(); - - if let Source(s) = ppm { + let out = if let Source(s) = ppm { // Silently ignores an identified node. - let out = &mut out; call_with_pp_support(&s, sess, None, move |annotation| { debug!("pretty printing source code {:?}", s); let sess = annotation.sess(); let parse = &sess.parse_sess; - *out = pprust::print_crate( + pprust::print_crate( sess.source_map(), krate, src_name, @@ -411,7 +408,7 @@ pub fn print_after_parsing( ) }) } else { - unreachable!(); + unreachable!() }; write_or_print(&out, ofile); @@ -431,17 +428,14 @@ pub fn print_after_hir_lowering<'tcx>( let (src, src_name) = get_source(input, tcx.sess); - let mut out = String::new(); - - match ppm { + let out = match ppm { Source(s) => { // Silently ignores an identified node. - let out = &mut out; call_with_pp_support(&s, tcx.sess, Some(tcx), move |annotation| { debug!("pretty printing source code {:?}", s); let sess = annotation.sess(); let parse = &sess.parse_sess; - *out = pprust::print_crate( + pprust::print_crate( sess.source_map(), krate, src_name, @@ -453,26 +447,20 @@ pub fn print_after_hir_lowering<'tcx>( }) } - Hir(s) => { - let out = &mut out; - call_with_pp_support_hir(&s, tcx, move |annotation, krate| { - debug!("pretty printing HIR {:?}", s); - let sess = annotation.sess(); - let sm = sess.source_map(); - *out = pprust_hir::print_crate(sm, krate, src_name, src, annotation.pp_ann()) - }) - } + Hir(s) => call_with_pp_support_hir(&s, tcx, move |annotation, krate| { + debug!("pretty printing HIR {:?}", s); + let sess = annotation.sess(); + let sm = sess.source_map(); + pprust_hir::print_crate(sm, krate, src_name, src, annotation.pp_ann()) + }), - HirTree => { - let out = &mut out; - call_with_pp_support_hir(&PpHirMode::Normal, tcx, move |_annotation, krate| { - debug!("pretty printing HIR tree"); - *out = format!("{:#?}", krate); - }); - } + HirTree => call_with_pp_support_hir(&PpHirMode::Normal, tcx, move |_annotation, krate| { + debug!("pretty printing HIR tree"); + format!("{:#?}", krate) + }), _ => unreachable!(), - } + }; write_or_print(&out, ofile); } @@ -491,14 +479,10 @@ fn print_with_analysis( tcx.analysis(LOCAL_CRATE)?; match ppm { - Mir | MirCFG => match ppm { - Mir => write_mir_pretty(tcx, None, &mut out), - MirCFG => write_mir_graphviz(tcx, None, &mut out), - _ => unreachable!(), - }, + Mir => write_mir_pretty(tcx, None, &mut out).unwrap(), + MirCFG => write_mir_graphviz(tcx, None, &mut out).unwrap(), _ => unreachable!(), } - .unwrap(); let out = std::str::from_utf8(&out).unwrap(); write_or_print(out, ofile); From 7ad4b7a62f887bd9f5c1e2cf3fbfc0c3619ffac2 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Fri, 19 Feb 2021 18:26:19 -0800 Subject: [PATCH 04/22] Replace normalize.css 3.0.0 with unminified version. This is in preparation to upgrade to 8.0.1, so the next commit can contain more meaningful diffs. --- src/librustdoc/html/static/normalize.css | 425 ++++++++++++++++++++++- 1 file changed, 423 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/normalize.css b/src/librustdoc/html/static/normalize.css index 0e0426279183f..196d223f12c36 100644 --- a/src/librustdoc/html/static/normalize.css +++ b/src/librustdoc/html/static/normalize.css @@ -1,2 +1,423 @@ -/* ignore-tidy-linelength */ -/*! normalize.css v3.0.0 | MIT License | git.io/normalize */html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}h1{font-size:2em;margin:.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:bold}table{border-collapse:collapse;border-spacing:0}td,th{padding:0} +/*! normalize.css v3.0.0 | MIT License | git.io/normalize */ + +/** + * 1. Set default font family to sans-serif. + * 2. Prevent iOS text size adjust after orientation change, without disabling + * user zoom. + */ + +html { + font-family: sans-serif; /* 1 */ + -ms-text-size-adjust: 100%; /* 2 */ + -webkit-text-size-adjust: 100%; /* 2 */ +} + +/** + * Remove default margin. + */ + +body { + margin: 0; +} + +/* HTML5 display definitions + ========================================================================== */ + +/** + * Correct `block` display not defined in IE 8/9. + */ + +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +main, +nav, +section, +summary { + display: block; +} + +/** + * 1. Correct `inline-block` display not defined in IE 8/9. + * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera. + */ + +audio, +canvas, +progress, +video { + display: inline-block; /* 1 */ + vertical-align: baseline; /* 2 */ +} + +/** + * Prevent modern browsers from displaying `audio` without controls. + * Remove excess height in iOS 5 devices. + */ + +audio:not([controls]) { + display: none; + height: 0; +} + +/** + * Address `[hidden]` styling not present in IE 8/9. + * Hide the `template` element in IE, Safari, and Firefox < 22. + */ + +[hidden], +template { + display: none; +} + +/* Links + ========================================================================== */ + +/** + * Remove the gray background color from active links in IE 10. + */ + +a { + background: transparent; +} + +/** + * Improve readability when focused and also mouse hovered in all browsers. + */ + +a:active, +a:hover { + outline: 0; +} + +/* Text-level semantics + ========================================================================== */ + +/** + * Address styling not present in IE 8/9, Safari 5, and Chrome. + */ + +abbr[title] { + border-bottom: 1px dotted; +} + +/** + * Address style set to `bolder` in Firefox 4+, Safari 5, and Chrome. + */ + +b, +strong { + font-weight: bold; +} + +/** + * Address styling not present in Safari 5 and Chrome. + */ + +dfn { + font-style: italic; +} + +/** + * Address variable `h1` font-size and margin within `section` and `article` + * contexts in Firefox 4+, Safari 5, and Chrome. + */ + +h1 { + font-size: 2em; + margin: 0.67em 0; +} + +/** + * Address styling not present in IE 8/9. + */ + +mark { + background: #ff0; + color: #000; +} + +/** + * Address inconsistent and variable font size in all browsers. + */ + +small { + font-size: 80%; +} + +/** + * Prevent `sub` and `sup` affecting `line-height` in all browsers. + */ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sup { + top: -0.5em; +} + +sub { + bottom: -0.25em; +} + +/* Embedded content + ========================================================================== */ + +/** + * Remove border when inside `a` element in IE 8/9. + */ + +img { + border: 0; +} + +/** + * Correct overflow displayed oddly in IE 9. + */ + +svg:not(:root) { + overflow: hidden; +} + +/* Grouping content + ========================================================================== */ + +/** + * Address margin not present in IE 8/9 and Safari 5. + */ + +figure { + margin: 1em 40px; +} + +/** + * Address differences between Firefox and other browsers. + */ + +hr { + -moz-box-sizing: content-box; + box-sizing: content-box; + height: 0; +} + +/** + * Contain overflow in all browsers. + */ + +pre { + overflow: auto; +} + +/** + * Address odd `em`-unit font size rendering in all browsers. + */ + +code, +kbd, +pre, +samp { + font-family: monospace, monospace; + font-size: 1em; +} + +/* Forms + ========================================================================== */ + +/** + * Known limitation: by default, Chrome and Safari on OS X allow very limited + * styling of `select`, unless a `border` property is set. + */ + +/** + * 1. Correct color not being inherited. + * Known issue: affects color of disabled elements. + * 2. Correct font properties not being inherited. + * 3. Address margins set differently in Firefox 4+, Safari 5, and Chrome. + */ + +button, +input, +optgroup, +select, +textarea { + color: inherit; /* 1 */ + font: inherit; /* 2 */ + margin: 0; /* 3 */ +} + +/** + * Address `overflow` set to `hidden` in IE 8/9/10. + */ + +button { + overflow: visible; +} + +/** + * Address inconsistent `text-transform` inheritance for `button` and `select`. + * All other form control elements do not inherit `text-transform` values. + * Correct `button` style inheritance in Firefox, IE 8+, and Opera + * Correct `select` style inheritance in Firefox. + */ + +button, +select { + text-transform: none; +} + +/** + * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` + * and `video` controls. + * 2. Correct inability to style clickable `input` types in iOS. + * 3. Improve usability and consistency of cursor style between image-type + * `input` and others. + */ + +button, +html input[type="button"], /* 1 */ +input[type="reset"], +input[type="submit"] { + -webkit-appearance: button; /* 2 */ + cursor: pointer; /* 3 */ +} + +/** + * Re-set default cursor for disabled elements. + */ + +button[disabled], +html input[disabled] { + cursor: default; +} + +/** + * Remove inner padding and border in Firefox 4+. + */ + +button::-moz-focus-inner, +input::-moz-focus-inner { + border: 0; + padding: 0; +} + +/** + * Address Firefox 4+ setting `line-height` on `input` using `!important` in + * the UA stylesheet. + */ + +input { + line-height: normal; +} + +/** + * It's recommended that you don't attempt to style these elements. + * Firefox's implementation doesn't respect box-sizing, padding, or width. + * + * 1. Address box sizing set to `content-box` in IE 8/9/10. + * 2. Remove excess padding in IE 8/9/10. + */ + +input[type="checkbox"], +input[type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ +} + +/** + * Fix the cursor style for Chrome's increment/decrement buttons. For certain + * `font-size` values of the `input`, it causes the cursor style of the + * decrement button to change from `default` to `text`. + */ + +input[type="number"]::-webkit-inner-spin-button, +input[type="number"]::-webkit-outer-spin-button { + height: auto; +} + +/** + * 1. Address `appearance` set to `searchfield` in Safari 5 and Chrome. + * 2. Address `box-sizing` set to `border-box` in Safari 5 and Chrome + * (include `-moz` to future-proof). + */ + +input[type="search"] { + -webkit-appearance: textfield; /* 1 */ + -moz-box-sizing: content-box; + -webkit-box-sizing: content-box; /* 2 */ + box-sizing: content-box; +} + +/** + * Remove inner padding and search cancel button in Safari and Chrome on OS X. + * Safari (but not Chrome) clips the cancel button when the search input has + * padding (and `textfield` appearance). + */ + +input[type="search"]::-webkit-search-cancel-button, +input[type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} + +/** + * Define consistent border, margin, and padding. + */ + +fieldset { + border: 1px solid #c0c0c0; + margin: 0 2px; + padding: 0.35em 0.625em 0.75em; +} + +/** + * 1. Correct `color` not being inherited in IE 8/9. + * 2. Remove padding so people aren't caught out if they zero out fieldsets. + */ + +legend { + border: 0; /* 1 */ + padding: 0; /* 2 */ +} + +/** + * Remove default vertical scrollbar in IE 8/9. + */ + +textarea { + overflow: auto; +} + +/** + * Don't inherit the `font-weight` (applied by a rule above). + * NOTE: the default cannot safely be changed in Chrome and Safari on OS X. + */ + +optgroup { + font-weight: bold; +} + +/* Tables + ========================================================================== */ + +/** + * Remove most spacing between table cells. + */ + +table { + border-collapse: collapse; + border-spacing: 0; +} + +td, +th { + padding: 0; +} From 9bbd48256d2371e1052941595f3e9a08193aa352 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Fri, 19 Feb 2021 18:28:53 -0800 Subject: [PATCH 05/22] Update normalize.css to 8.0.1 From https://github.com/necolas/normalize.css/releases/tag/8.0.1. --- src/librustdoc/html/static/normalize.css | 390 +++++++++-------------- 1 file changed, 158 insertions(+), 232 deletions(-) diff --git a/src/librustdoc/html/static/normalize.css b/src/librustdoc/html/static/normalize.css index 196d223f12c36..192eb9ce43389 100644 --- a/src/librustdoc/html/static/normalize.css +++ b/src/librustdoc/html/static/normalize.css @@ -1,149 +1,116 @@ -/*! normalize.css v3.0.0 | MIT License | git.io/normalize */ +/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */ + +/* Document + ========================================================================== */ /** - * 1. Set default font family to sans-serif. - * 2. Prevent iOS text size adjust after orientation change, without disabling - * user zoom. + * 1. Correct the line height in all browsers. + * 2. Prevent adjustments of font size after orientation changes in iOS. */ html { - font-family: sans-serif; /* 1 */ - -ms-text-size-adjust: 100%; /* 2 */ + line-height: 1.15; /* 1 */ -webkit-text-size-adjust: 100%; /* 2 */ } -/** - * Remove default margin. - */ - -body { - margin: 0; -} - -/* HTML5 display definitions +/* Sections ========================================================================== */ /** - * Correct `block` display not defined in IE 8/9. - */ - -article, -aside, -details, -figcaption, -figure, -footer, -header, -hgroup, -main, -nav, -section, -summary { - display: block; -} - -/** - * 1. Correct `inline-block` display not defined in IE 8/9. - * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera. + * Remove the margin in all browsers. */ -audio, -canvas, -progress, -video { - display: inline-block; /* 1 */ - vertical-align: baseline; /* 2 */ +body { + margin: 0; } /** - * Prevent modern browsers from displaying `audio` without controls. - * Remove excess height in iOS 5 devices. + * Render the `main` element consistently in IE. */ -audio:not([controls]) { - display: none; - height: 0; +main { + display: block; } /** - * Address `[hidden]` styling not present in IE 8/9. - * Hide the `template` element in IE, Safari, and Firefox < 22. + * Correct the font size and margin on `h1` elements within `section` and + * `article` contexts in Chrome, Firefox, and Safari. */ -[hidden], -template { - display: none; +h1 { + font-size: 2em; + margin: 0.67em 0; } -/* Links +/* Grouping content ========================================================================== */ /** - * Remove the gray background color from active links in IE 10. + * 1. Add the correct box sizing in Firefox. + * 2. Show the overflow in Edge and IE. */ -a { - background: transparent; +hr { + box-sizing: content-box; /* 1 */ + height: 0; /* 1 */ + overflow: visible; /* 2 */ } /** - * Improve readability when focused and also mouse hovered in all browsers. + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. */ -a:active, -a:hover { - outline: 0; +pre { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ } /* Text-level semantics ========================================================================== */ /** - * Address styling not present in IE 8/9, Safari 5, and Chrome. - */ - -abbr[title] { - border-bottom: 1px dotted; -} - -/** - * Address style set to `bolder` in Firefox 4+, Safari 5, and Chrome. + * Remove the gray background on active links in IE 10. */ -b, -strong { - font-weight: bold; +a { + background-color: transparent; } /** - * Address styling not present in Safari 5 and Chrome. + * 1. Remove the bottom border in Chrome 57- + * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari. */ -dfn { - font-style: italic; +abbr[title] { + border-bottom: none; /* 1 */ + text-decoration: underline; /* 2 */ + text-decoration: underline dotted; /* 2 */ } /** - * Address variable `h1` font-size and margin within `section` and `article` - * contexts in Firefox 4+, Safari 5, and Chrome. + * Add the correct font weight in Chrome, Edge, and Safari. */ -h1 { - font-size: 2em; - margin: 0.67em 0; +b, +strong { + font-weight: bolder; } /** - * Address styling not present in IE 8/9. + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. */ -mark { - background: #ff0; - color: #000; +code, +kbd, +samp { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ } /** - * Address inconsistent and variable font size in all browsers. + * Add the correct font size in all browsers. */ small { @@ -151,7 +118,8 @@ small { } /** - * Prevent `sub` and `sup` affecting `line-height` in all browsers. + * Prevent `sub` and `sup` elements from affecting the line height in + * all browsers. */ sub, @@ -162,262 +130,220 @@ sup { vertical-align: baseline; } -sup { - top: -0.5em; -} - sub { bottom: -0.25em; } +sup { + top: -0.5em; +} + /* Embedded content ========================================================================== */ /** - * Remove border when inside `a` element in IE 8/9. + * Remove the border on images inside links in IE 10. */ img { - border: 0; -} - -/** - * Correct overflow displayed oddly in IE 9. - */ - -svg:not(:root) { - overflow: hidden; + border-style: none; } -/* Grouping content +/* Forms ========================================================================== */ /** - * Address margin not present in IE 8/9 and Safari 5. + * 1. Change the font styles in all browsers. + * 2. Remove the margin in Firefox and Safari. */ -figure { - margin: 1em 40px; -} - -/** - * Address differences between Firefox and other browsers. - */ - -hr { - -moz-box-sizing: content-box; - box-sizing: content-box; - height: 0; +button, +input, +optgroup, +select, +textarea { + font-family: inherit; /* 1 */ + font-size: 100%; /* 1 */ + line-height: 1.15; /* 1 */ + margin: 0; /* 2 */ } /** - * Contain overflow in all browsers. + * Show the overflow in IE. + * 1. Show the overflow in Edge. */ -pre { - overflow: auto; +button, +input { /* 1 */ + overflow: visible; } /** - * Address odd `em`-unit font size rendering in all browsers. + * Remove the inheritance of text transform in Edge, Firefox, and IE. + * 1. Remove the inheritance of text transform in Firefox. */ -code, -kbd, -pre, -samp { - font-family: monospace, monospace; - font-size: 1em; +button, +select { /* 1 */ + text-transform: none; } -/* Forms - ========================================================================== */ - -/** - * Known limitation: by default, Chrome and Safari on OS X allow very limited - * styling of `select`, unless a `border` property is set. - */ - /** - * 1. Correct color not being inherited. - * Known issue: affects color of disabled elements. - * 2. Correct font properties not being inherited. - * 3. Address margins set differently in Firefox 4+, Safari 5, and Chrome. + * Correct the inability to style clickable types in iOS and Safari. */ button, -input, -optgroup, -select, -textarea { - color: inherit; /* 1 */ - font: inherit; /* 2 */ - margin: 0; /* 3 */ +[type="button"], +[type="reset"], +[type="submit"] { + -webkit-appearance: button; } /** - * Address `overflow` set to `hidden` in IE 8/9/10. + * Remove the inner border and padding in Firefox. */ -button { - overflow: visible; +button::-moz-focus-inner, +[type="button"]::-moz-focus-inner, +[type="reset"]::-moz-focus-inner, +[type="submit"]::-moz-focus-inner { + border-style: none; + padding: 0; } /** - * Address inconsistent `text-transform` inheritance for `button` and `select`. - * All other form control elements do not inherit `text-transform` values. - * Correct `button` style inheritance in Firefox, IE 8+, and Opera - * Correct `select` style inheritance in Firefox. + * Restore the focus styles unset by the previous rule. */ -button, -select { - text-transform: none; +button:-moz-focusring, +[type="button"]:-moz-focusring, +[type="reset"]:-moz-focusring, +[type="submit"]:-moz-focusring { + outline: 1px dotted ButtonText; } /** - * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` - * and `video` controls. - * 2. Correct inability to style clickable `input` types in iOS. - * 3. Improve usability and consistency of cursor style between image-type - * `input` and others. + * Correct the padding in Firefox. */ -button, -html input[type="button"], /* 1 */ -input[type="reset"], -input[type="submit"] { - -webkit-appearance: button; /* 2 */ - cursor: pointer; /* 3 */ +fieldset { + padding: 0.35em 0.75em 0.625em; } /** - * Re-set default cursor for disabled elements. + * 1. Correct the text wrapping in Edge and IE. + * 2. Correct the color inheritance from `fieldset` elements in IE. + * 3. Remove the padding so developers are not caught out when they zero out + * `fieldset` elements in all browsers. */ -button[disabled], -html input[disabled] { - cursor: default; +legend { + box-sizing: border-box; /* 1 */ + color: inherit; /* 2 */ + display: table; /* 1 */ + max-width: 100%; /* 1 */ + padding: 0; /* 3 */ + white-space: normal; /* 1 */ } /** - * Remove inner padding and border in Firefox 4+. + * Add the correct vertical alignment in Chrome, Firefox, and Opera. */ -button::-moz-focus-inner, -input::-moz-focus-inner { - border: 0; - padding: 0; +progress { + vertical-align: baseline; } /** - * Address Firefox 4+ setting `line-height` on `input` using `!important` in - * the UA stylesheet. + * Remove the default vertical scrollbar in IE 10+. */ -input { - line-height: normal; +textarea { + overflow: auto; } /** - * It's recommended that you don't attempt to style these elements. - * Firefox's implementation doesn't respect box-sizing, padding, or width. - * - * 1. Address box sizing set to `content-box` in IE 8/9/10. - * 2. Remove excess padding in IE 8/9/10. + * 1. Add the correct box sizing in IE 10. + * 2. Remove the padding in IE 10. */ -input[type="checkbox"], -input[type="radio"] { +[type="checkbox"], +[type="radio"] { box-sizing: border-box; /* 1 */ padding: 0; /* 2 */ } /** - * Fix the cursor style for Chrome's increment/decrement buttons. For certain - * `font-size` values of the `input`, it causes the cursor style of the - * decrement button to change from `default` to `text`. + * Correct the cursor style of increment and decrement buttons in Chrome. */ -input[type="number"]::-webkit-inner-spin-button, -input[type="number"]::-webkit-outer-spin-button { +[type="number"]::-webkit-inner-spin-button, +[type="number"]::-webkit-outer-spin-button { height: auto; } /** - * 1. Address `appearance` set to `searchfield` in Safari 5 and Chrome. - * 2. Address `box-sizing` set to `border-box` in Safari 5 and Chrome - * (include `-moz` to future-proof). + * 1. Correct the odd appearance in Chrome and Safari. + * 2. Correct the outline style in Safari. */ -input[type="search"] { +[type="search"] { -webkit-appearance: textfield; /* 1 */ - -moz-box-sizing: content-box; - -webkit-box-sizing: content-box; /* 2 */ - box-sizing: content-box; + outline-offset: -2px; /* 2 */ } /** - * Remove inner padding and search cancel button in Safari and Chrome on OS X. - * Safari (but not Chrome) clips the cancel button when the search input has - * padding (and `textfield` appearance). + * Remove the inner padding in Chrome and Safari on macOS. */ -input[type="search"]::-webkit-search-cancel-button, -input[type="search"]::-webkit-search-decoration { +[type="search"]::-webkit-search-decoration { -webkit-appearance: none; } /** - * Define consistent border, margin, and padding. + * 1. Correct the inability to style clickable types in iOS and Safari. + * 2. Change font properties to `inherit` in Safari. */ -fieldset { - border: 1px solid #c0c0c0; - margin: 0 2px; - padding: 0.35em 0.625em 0.75em; +::-webkit-file-upload-button { + -webkit-appearance: button; /* 1 */ + font: inherit; /* 2 */ } -/** - * 1. Correct `color` not being inherited in IE 8/9. - * 2. Remove padding so people aren't caught out if they zero out fieldsets. - */ - -legend { - border: 0; /* 1 */ - padding: 0; /* 2 */ -} +/* Interactive + ========================================================================== */ -/** - * Remove default vertical scrollbar in IE 8/9. +/* + * Add the correct display in Edge, IE 10+, and Firefox. */ -textarea { - overflow: auto; +details { + display: block; } -/** - * Don't inherit the `font-weight` (applied by a rule above). - * NOTE: the default cannot safely be changed in Chrome and Safari on OS X. +/* + * Add the correct display in all browsers. */ -optgroup { - font-weight: bold; +summary { + display: list-item; } -/* Tables +/* Misc ========================================================================== */ /** - * Remove most spacing between table cells. + * Add the correct display in IE 10+. */ -table { - border-collapse: collapse; - border-spacing: 0; +template { + display: none; } -td, -th { - padding: 0; +/** + * Add the correct display in IE 10. + */ + +[hidden] { + display: none; } From 7acb10514bace3f7fa66d8b7f3ed09932d44de7d Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Fri, 19 Feb 2021 18:47:00 -0800 Subject: [PATCH 06/22] Re-minify normalize.css. This bypasses tidy's complaints about tab indent. Also, this lets us remove comments while keeping the MIT license comment. --- src/librustdoc/html/static/normalize.css | 351 +---------------------- 1 file changed, 2 insertions(+), 349 deletions(-) diff --git a/src/librustdoc/html/static/normalize.css b/src/librustdoc/html/static/normalize.css index 192eb9ce43389..da9a75e3e85e9 100644 --- a/src/librustdoc/html/static/normalize.css +++ b/src/librustdoc/html/static/normalize.css @@ -1,349 +1,2 @@ -/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */ - -/* Document - ========================================================================== */ - -/** - * 1. Correct the line height in all browsers. - * 2. Prevent adjustments of font size after orientation changes in iOS. - */ - -html { - line-height: 1.15; /* 1 */ - -webkit-text-size-adjust: 100%; /* 2 */ -} - -/* Sections - ========================================================================== */ - -/** - * Remove the margin in all browsers. - */ - -body { - margin: 0; -} - -/** - * Render the `main` element consistently in IE. - */ - -main { - display: block; -} - -/** - * Correct the font size and margin on `h1` elements within `section` and - * `article` contexts in Chrome, Firefox, and Safari. - */ - -h1 { - font-size: 2em; - margin: 0.67em 0; -} - -/* Grouping content - ========================================================================== */ - -/** - * 1. Add the correct box sizing in Firefox. - * 2. Show the overflow in Edge and IE. - */ - -hr { - box-sizing: content-box; /* 1 */ - height: 0; /* 1 */ - overflow: visible; /* 2 */ -} - -/** - * 1. Correct the inheritance and scaling of font size in all browsers. - * 2. Correct the odd `em` font sizing in all browsers. - */ - -pre { - font-family: monospace, monospace; /* 1 */ - font-size: 1em; /* 2 */ -} - -/* Text-level semantics - ========================================================================== */ - -/** - * Remove the gray background on active links in IE 10. - */ - -a { - background-color: transparent; -} - -/** - * 1. Remove the bottom border in Chrome 57- - * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari. - */ - -abbr[title] { - border-bottom: none; /* 1 */ - text-decoration: underline; /* 2 */ - text-decoration: underline dotted; /* 2 */ -} - -/** - * Add the correct font weight in Chrome, Edge, and Safari. - */ - -b, -strong { - font-weight: bolder; -} - -/** - * 1. Correct the inheritance and scaling of font size in all browsers. - * 2. Correct the odd `em` font sizing in all browsers. - */ - -code, -kbd, -samp { - font-family: monospace, monospace; /* 1 */ - font-size: 1em; /* 2 */ -} - -/** - * Add the correct font size in all browsers. - */ - -small { - font-size: 80%; -} - -/** - * Prevent `sub` and `sup` elements from affecting the line height in - * all browsers. - */ - -sub, -sup { - font-size: 75%; - line-height: 0; - position: relative; - vertical-align: baseline; -} - -sub { - bottom: -0.25em; -} - -sup { - top: -0.5em; -} - -/* Embedded content - ========================================================================== */ - -/** - * Remove the border on images inside links in IE 10. - */ - -img { - border-style: none; -} - -/* Forms - ========================================================================== */ - -/** - * 1. Change the font styles in all browsers. - * 2. Remove the margin in Firefox and Safari. - */ - -button, -input, -optgroup, -select, -textarea { - font-family: inherit; /* 1 */ - font-size: 100%; /* 1 */ - line-height: 1.15; /* 1 */ - margin: 0; /* 2 */ -} - -/** - * Show the overflow in IE. - * 1. Show the overflow in Edge. - */ - -button, -input { /* 1 */ - overflow: visible; -} - -/** - * Remove the inheritance of text transform in Edge, Firefox, and IE. - * 1. Remove the inheritance of text transform in Firefox. - */ - -button, -select { /* 1 */ - text-transform: none; -} - -/** - * Correct the inability to style clickable types in iOS and Safari. - */ - -button, -[type="button"], -[type="reset"], -[type="submit"] { - -webkit-appearance: button; -} - -/** - * Remove the inner border and padding in Firefox. - */ - -button::-moz-focus-inner, -[type="button"]::-moz-focus-inner, -[type="reset"]::-moz-focus-inner, -[type="submit"]::-moz-focus-inner { - border-style: none; - padding: 0; -} - -/** - * Restore the focus styles unset by the previous rule. - */ - -button:-moz-focusring, -[type="button"]:-moz-focusring, -[type="reset"]:-moz-focusring, -[type="submit"]:-moz-focusring { - outline: 1px dotted ButtonText; -} - -/** - * Correct the padding in Firefox. - */ - -fieldset { - padding: 0.35em 0.75em 0.625em; -} - -/** - * 1. Correct the text wrapping in Edge and IE. - * 2. Correct the color inheritance from `fieldset` elements in IE. - * 3. Remove the padding so developers are not caught out when they zero out - * `fieldset` elements in all browsers. - */ - -legend { - box-sizing: border-box; /* 1 */ - color: inherit; /* 2 */ - display: table; /* 1 */ - max-width: 100%; /* 1 */ - padding: 0; /* 3 */ - white-space: normal; /* 1 */ -} - -/** - * Add the correct vertical alignment in Chrome, Firefox, and Opera. - */ - -progress { - vertical-align: baseline; -} - -/** - * Remove the default vertical scrollbar in IE 10+. - */ - -textarea { - overflow: auto; -} - -/** - * 1. Add the correct box sizing in IE 10. - * 2. Remove the padding in IE 10. - */ - -[type="checkbox"], -[type="radio"] { - box-sizing: border-box; /* 1 */ - padding: 0; /* 2 */ -} - -/** - * Correct the cursor style of increment and decrement buttons in Chrome. - */ - -[type="number"]::-webkit-inner-spin-button, -[type="number"]::-webkit-outer-spin-button { - height: auto; -} - -/** - * 1. Correct the odd appearance in Chrome and Safari. - * 2. Correct the outline style in Safari. - */ - -[type="search"] { - -webkit-appearance: textfield; /* 1 */ - outline-offset: -2px; /* 2 */ -} - -/** - * Remove the inner padding in Chrome and Safari on macOS. - */ - -[type="search"]::-webkit-search-decoration { - -webkit-appearance: none; -} - -/** - * 1. Correct the inability to style clickable types in iOS and Safari. - * 2. Change font properties to `inherit` in Safari. - */ - -::-webkit-file-upload-button { - -webkit-appearance: button; /* 1 */ - font: inherit; /* 2 */ -} - -/* Interactive - ========================================================================== */ - -/* - * Add the correct display in Edge, IE 10+, and Firefox. - */ - -details { - display: block; -} - -/* - * Add the correct display in all browsers. - */ - -summary { - display: list-item; -} - -/* Misc - ========================================================================== */ - -/** - * Add the correct display in IE 10+. - */ - -template { - display: none; -} - -/** - * Add the correct display in IE 10. - */ - -[hidden] { - display: none; -} +/* ignore-tidy-linelength */ +/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:block}h1{font-size:2em;margin:.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:.35em .75em .625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none} From 10f234240dd9e790cc222570d99d7a320fa88d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sat, 20 Feb 2021 10:51:26 +0100 Subject: [PATCH 07/22] Remove some P-s --- compiler/rustc_ast/src/ast.rs | 4 ++-- compiler/rustc_builtin_macros/src/global_asm.rs | 2 +- .../rustc_builtin_macros/src/standard_library_imports.rs | 5 ++--- compiler/rustc_parse/src/parser/item.rs | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 3550055ac10d3..7d75a6c2d6b8a 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2695,7 +2695,7 @@ pub enum ItemKind { /// A use declaration item (`use`). /// /// E.g., `use foo;`, `use foo::bar;` or `use foo::bar as FooBar;`. - Use(P), + Use(UseTree), /// A static item (`static`). /// /// E.g., `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";`. @@ -2719,7 +2719,7 @@ pub enum ItemKind { /// E.g., `extern {}` or `extern "C" {}`. ForeignMod(ForeignMod), /// Module-level inline assembly (from `global_asm!()`). - GlobalAsm(P), + GlobalAsm(GlobalAsm), /// A type alias (`type`). /// /// E.g., `type Foo = Bar;`. diff --git a/compiler/rustc_builtin_macros/src/global_asm.rs b/compiler/rustc_builtin_macros/src/global_asm.rs index 3689e33be6f0f..76d874529270e 100644 --- a/compiler/rustc_builtin_macros/src/global_asm.rs +++ b/compiler/rustc_builtin_macros/src/global_asm.rs @@ -28,7 +28,7 @@ pub fn expand_global_asm<'cx>( ident: Ident::invalid(), attrs: Vec::new(), id: ast::DUMMY_NODE_ID, - kind: ast::ItemKind::GlobalAsm(P(global_asm)), + kind: ast::ItemKind::GlobalAsm(global_asm), vis: ast::Visibility { span: sp.shrink_to_lo(), kind: ast::VisibilityKind::Inherited, diff --git a/compiler/rustc_builtin_macros/src/standard_library_imports.rs b/compiler/rustc_builtin_macros/src/standard_library_imports.rs index 3a81d076dc52f..f446e6be84ca4 100644 --- a/compiler/rustc_builtin_macros/src/standard_library_imports.rs +++ b/compiler/rustc_builtin_macros/src/standard_library_imports.rs @@ -1,5 +1,4 @@ use rustc_ast as ast; -use rustc_ast::ptr::P; use rustc_expand::base::{ExtCtxt, ResolverExpand}; use rustc_expand::expand::ExpansionConfig; use rustc_session::Session; @@ -72,11 +71,11 @@ pub fn inject( span, Ident::invalid(), vec![cx.attribute(cx.meta_word(span, sym::prelude_import))], - ast::ItemKind::Use(P(ast::UseTree { + ast::ItemKind::Use(ast::UseTree { prefix: cx.path(span, import_path), kind: ast::UseTreeKind::Glob, span, - })), + }), ); krate.items.insert(0, use_item); diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 0f907859a19a6..98800bac27be1 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -225,7 +225,7 @@ impl<'a> Parser<'a> { return Err(e); } - (Ident::invalid(), ItemKind::Use(P(tree))) + (Ident::invalid(), ItemKind::Use(tree)) } else if self.check_fn_front_matter() { // FUNCTION ITEM let (ident, sig, generics, body) = self.parse_fn(attrs, req_name, lo)?; From fece59b56cbeda4faa7c148ad58569c2bd52a52d Mon Sep 17 00:00:00 2001 From: 0yoyoyo <60439919+0yoyoyo@users.noreply.github.com> Date: Sun, 21 Feb 2021 18:29:14 +0900 Subject: [PATCH 08/22] Change `find_anon_type` method to function --- .../nice_region_error/different_lifetimes.rs | 5 +- .../nice_region_error/find_anon_type.rs | 114 +++++++++--------- .../error_reporting/nice_region_error/mod.rs | 2 +- .../nice_region_error/named_anon_conflict.rs | 3 +- 4 files changed, 61 insertions(+), 63 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs index cdd68d83f22b1..1b35c4032f44c 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -1,6 +1,7 @@ //! Error Reporting for Anonymous Region Lifetime Errors //! where both the regions are anonymous. +use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type; use crate::infer::error_reporting::nice_region_error::util::AnonymousParamInfo; use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::infer::lexical_region_resolve::RegionResolutionError; @@ -66,9 +67,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { let scope_def_id_sub = anon_reg_sub.def_id; let bregion_sub = anon_reg_sub.boundregion; - let ty_sup = self.find_anon_type(sup, &bregion_sup)?; + let ty_sup = find_anon_type(self.tcx(), sup, &bregion_sup)?; - let ty_sub = self.find_anon_type(sub, &bregion_sub)?; + let ty_sub = find_anon_type(self.tcx(), sub, &bregion_sub)?; debug!( "try_report_anon_anon_conflict: found_param1={:?} sup={:?} br1={:?}", diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs index b014b9832e783..ffdaedf8666c3 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -1,4 +1,3 @@ -use crate::infer::error_reporting::nice_region_error::NiceRegionError; use rustc_hir as hir; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::Node; @@ -6,67 +5,64 @@ use rustc_middle::hir::map::Map; use rustc_middle::middle::resolve_lifetime as rl; use rustc_middle::ty::{self, Region, TyCtxt}; -impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { - /// This function calls the `visit_ty` method for the parameters - /// corresponding to the anonymous regions. The `nested_visitor.found_type` - /// contains the anonymous type. - /// - /// # Arguments - /// region - the anonymous region corresponding to the anon_anon conflict - /// br - the bound region corresponding to the above region which is of type `BrAnon(_)` - /// - /// # Example - /// ``` - /// fn foo(x: &mut Vec<&u8>, y: &u8) - /// { x.push(y); } - /// ``` - /// The function returns the nested type corresponding to the anonymous region - /// for e.g., `&u8` and Vec<`&u8`. - pub(super) fn find_anon_type( - &self, - region: Region<'tcx>, - br: &ty::BoundRegionKind, - ) -> Option<(&hir::Ty<'tcx>, &hir::FnDecl<'tcx>)> { - if let Some(anon_reg) = self.tcx().is_suitable_region(region) { - let hir_id = self.tcx().hir().local_def_id_to_hir_id(anon_reg.def_id); - let fndecl = match self.tcx().hir().get(hir_id) { - Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. }) - | Node::TraitItem(&hir::TraitItem { - kind: hir::TraitItemKind::Fn(ref m, ..), - .. - }) - | Node::ImplItem(&hir::ImplItem { - kind: hir::ImplItemKind::Fn(ref m, ..), .. - }) => &m.decl, - _ => return None, - }; +/// This function calls the `visit_ty` method for the parameters +/// corresponding to the anonymous regions. The `nested_visitor.found_type` +/// contains the anonymous type. +/// +/// # Arguments +/// region - the anonymous region corresponding to the anon_anon conflict +/// br - the bound region corresponding to the above region which is of type `BrAnon(_)` +/// +/// # Example +/// ``` +/// fn foo(x: &mut Vec<&u8>, y: &u8) +/// { x.push(y); } +/// ``` +/// The function returns the nested type corresponding to the anonymous region +/// for e.g., `&u8` and Vec<`&u8`. +pub(crate) fn find_anon_type( + tcx: TyCtxt<'tcx>, + region: Region<'tcx>, + br: &ty::BoundRegionKind, +) -> Option<(&'tcx hir::Ty<'tcx>, &'tcx hir::FnDecl<'tcx>)> { + if let Some(anon_reg) = tcx.is_suitable_region(region) { + let hir_id = tcx.hir().local_def_id_to_hir_id(anon_reg.def_id); + let fndecl = match tcx.hir().get(hir_id) { + Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. }) + | Node::TraitItem(&hir::TraitItem { + kind: hir::TraitItemKind::Fn(ref m, ..), .. + }) + | Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(ref m, ..), .. }) => { + &m.decl + } + _ => return None, + }; - fndecl - .inputs - .iter() - .find_map(|arg| self.find_component_for_bound_region(arg, br)) - .map(|ty| (ty, &**fndecl)) - } else { - None - } + fndecl + .inputs + .iter() + .find_map(|arg| find_component_for_bound_region(tcx, arg, br)) + .map(|ty| (ty, &**fndecl)) + } else { + None } +} - // This method creates a FindNestedTypeVisitor which returns the type corresponding - // to the anonymous region. - fn find_component_for_bound_region( - &self, - arg: &'tcx hir::Ty<'tcx>, - br: &ty::BoundRegionKind, - ) -> Option<&'tcx hir::Ty<'tcx>> { - let mut nested_visitor = FindNestedTypeVisitor { - tcx: self.tcx(), - bound_region: *br, - found_type: None, - current_index: ty::INNERMOST, - }; - nested_visitor.visit_ty(arg); - nested_visitor.found_type - } +// This method creates a FindNestedTypeVisitor which returns the type corresponding +// to the anonymous region. +fn find_component_for_bound_region( + tcx: TyCtxt<'tcx>, + arg: &'tcx hir::Ty<'tcx>, + br: &ty::BoundRegionKind, +) -> Option<&'tcx hir::Ty<'tcx>> { + let mut nested_visitor = FindNestedTypeVisitor { + tcx, + bound_region: *br, + found_type: None, + current_index: ty::INNERMOST, + }; + nested_visitor.visit_ty(arg); + nested_visitor.found_type } // The FindNestedTypeVisitor captures the corresponding `hir::Ty` of the diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs index 0599c78ebfd07..8b2d17ac29b69 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs @@ -5,8 +5,8 @@ use rustc_errors::{DiagnosticBuilder, ErrorReported}; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::source_map::Span; +pub mod find_anon_type; mod different_lifetimes; -mod find_anon_type; mod named_anon_conflict; mod placeholder_error; mod static_impl_trait; diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs index 2f622231a081e..2f3c0d6957a61 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs @@ -1,5 +1,6 @@ //! Error Reporting for Anonymous Region Lifetime Errors //! where one region is named and the other is anonymous. +use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type; use crate::infer::error_reporting::nice_region_error::NiceRegionError; use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir::intravisit::Visitor; @@ -74,7 +75,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { return None; } - if let Some((_, fndecl)) = self.find_anon_type(anon, &br) { + if let Some((_, fndecl)) = find_anon_type(self.tcx(), anon, &br) { if self.is_self_anon(is_first, scope_def_id) { return None; } From 17176ccd78033b0b73f12b0d67e28edb1b002104 Mon Sep 17 00:00:00 2001 From: 0yoyoyo <60439919+0yoyoyo@users.noreply.github.com> Date: Sun, 21 Feb 2021 18:38:20 +0900 Subject: [PATCH 09/22] Add indication of anonymous lifetime position --- .../src/infer/error_reporting/mod.rs | 10 ++++- ...issing-lifetimes-in-signature-2.nll.stderr | 6 +-- .../missing-lifetimes-in-signature-2.stderr | 6 +-- .../missing-lifetimes-in-signature.nll.stderr | 41 ++++++++----------- .../missing-lifetimes-in-signature.stderr | 30 ++++++-------- 5 files changed, 43 insertions(+), 50 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 9e55f7e558999..f4eb861d61dae 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -50,6 +50,7 @@ use super::region_constraints::GenericKind; use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs}; use crate::infer; +use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type; use crate::traits::error_reporting::report_object_safety_error; use crate::traits::{ IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode, @@ -179,7 +180,14 @@ fn msg_span_from_early_bound_and_free_regions( } ty::ReFree(ref fr) => match fr.bound_region { ty::BrAnon(idx) => { - (format!("the anonymous lifetime #{} defined on", idx + 1), tcx.hir().span(node)) + if let Some((ty, _)) = find_anon_type(tcx, region, &fr.bound_region) { + ("the anonymous lifetime defined on".to_string(), ty.span) + } else { + ( + format!("the anonymous lifetime #{} defined on", idx + 1), + tcx.hir().span(node), + ) + } } _ => ( format!("the lifetime `{}` as defined on", region), diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr index b359826cb4ae4..7e07a5775bb12 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr @@ -7,11 +7,11 @@ LL | | t.test(); LL | | }); | |______^ | -note: the parameter type `T` must be valid for the anonymous lifetime #2 defined on the function body at 19:1... - --> $DIR/missing-lifetimes-in-signature-2.rs:19:1 +note: the parameter type `T` must be valid for the anonymous lifetime defined on the function body at 19:24... + --> $DIR/missing-lifetimes-in-signature-2.rs:19:24 | LL | fn func(foo: &Foo, t: T) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr index c7def9b668d9c..4e7d52978400f 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr @@ -6,11 +6,11 @@ LL | fn func(foo: &Foo, t: T) { LL | foo.bar(move |_| { | ^^^ | -note: the parameter type `T` must be valid for the anonymous lifetime #2 defined on the function body at 19:1... - --> $DIR/missing-lifetimes-in-signature-2.rs:19:1 +note: the parameter type `T` must be valid for the anonymous lifetime defined on the function body at 19:24... + --> $DIR/missing-lifetimes-in-signature-2.rs:19:24 | LL | fn func(foo: &Foo, t: T) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature-2.rs:20:13: 23:6]` will meet its required lifetime bounds --> $DIR/missing-lifetimes-in-signature-2.rs:20:9 | diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr index 1bfcdab5d860d..b509610b89e26 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr @@ -25,14 +25,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ | ^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the function body at 25:1... - --> $DIR/missing-lifetimes-in-signature.rs:25:1 - | -LL | / fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ -LL | | -LL | | where -LL | | G: Get - | |_____________^ +note: the parameter type `G` must be valid for the anonymous lifetime defined on the function body at 25:26... + --> $DIR/missing-lifetimes-in-signature.rs:25:26 + | +LL | fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ error[E0311]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:47:45 @@ -40,14 +37,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ | ^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the function body at 47:1... - --> $DIR/missing-lifetimes-in-signature.rs:47:1 +note: the parameter type `G` must be valid for the anonymous lifetime defined on the function body at 47:34... + --> $DIR/missing-lifetimes-in-signature.rs:47:34 | -LL | / fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ -LL | | -LL | | where -LL | | G: Get - | |_____________^ +LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ error[E0311]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:59:58 @@ -55,11 +49,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn qux<'b, G: Get + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { | ^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the method body at 59:5... - --> $DIR/missing-lifetimes-in-signature.rs:59:5 +note: the parameter type `G` must be valid for the anonymous lifetime defined on the method body at 59:47... + --> $DIR/missing-lifetimes-in-signature.rs:59:47 | LL | fn qux<'b, G: Get + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ error[E0311]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:68:45 @@ -67,14 +61,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a | ^^^^^^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the function body at 68:1... - --> $DIR/missing-lifetimes-in-signature.rs:68:1 +note: the parameter type `G` must be valid for the anonymous lifetime defined on the function body at 68:34... + --> $DIR/missing-lifetimes-in-signature.rs:68:34 | -LL | / fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a -LL | | -LL | | where -LL | | G: Get - | |_____________^ +LL | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a + | ^^^^^^ error[E0621]: explicit lifetime required in the type of `dest` --> $DIR/missing-lifetimes-in-signature.rs:73:5 diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr index 69e95efa72d50..789fff7acc29b 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr @@ -33,14 +33,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ | ^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the function body at 25:1... - --> $DIR/missing-lifetimes-in-signature.rs:25:1 - | -LL | / fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ -LL | | -LL | | where -LL | | G: Get - | |_____________^ +note: the parameter type `G` must be valid for the anonymous lifetime defined on the function body at 25:26... + --> $DIR/missing-lifetimes-in-signature.rs:25:26 + | +LL | fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:30:5: 32:6]` will meet its required lifetime bounds --> $DIR/missing-lifetimes-in-signature.rs:25:37 | @@ -57,14 +54,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ | ^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the function body at 47:1... - --> $DIR/missing-lifetimes-in-signature.rs:47:1 +note: the parameter type `G` must be valid for the anonymous lifetime defined on the function body at 47:34... + --> $DIR/missing-lifetimes-in-signature.rs:47:34 | -LL | / fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ -LL | | -LL | | where -LL | | G: Get - | |_____________^ +LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:52:5: 54:6]` will meet its required lifetime bounds --> $DIR/missing-lifetimes-in-signature.rs:47:45 | @@ -81,11 +75,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn qux<'b, G: Get + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { | ^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the method body at 59:5... - --> $DIR/missing-lifetimes-in-signature.rs:59:5 +note: the parameter type `G` must be valid for the anonymous lifetime defined on the method body at 59:47... + --> $DIR/missing-lifetimes-in-signature.rs:59:47 | LL | fn qux<'b, G: Get + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:61:9: 63:10]` will meet its required lifetime bounds --> $DIR/missing-lifetimes-in-signature.rs:59:58 | From ce1a521012017a352dc15ef1036b3dc56fa676ca Mon Sep 17 00:00:00 2001 From: 0yoyoyo <60439919+0yoyoyo@users.noreply.github.com> Date: Sun, 21 Feb 2021 22:51:49 +0900 Subject: [PATCH 10/22] Apply tidy check --- .../src/infer/error_reporting/nice_region_error/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs index 8b2d17ac29b69..e20436690b3aa 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs @@ -5,8 +5,8 @@ use rustc_errors::{DiagnosticBuilder, ErrorReported}; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::source_map::Span; -pub mod find_anon_type; mod different_lifetimes; +pub mod find_anon_type; mod named_anon_conflict; mod placeholder_error; mod static_impl_trait; From b9449a387360356a937ede125b55a37cb85538f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Sun, 21 Feb 2021 00:00:00 +0000 Subject: [PATCH 11/22] Add option enabling MIR inlining independently of mir-opt-level --- compiler/rustc_interface/src/tests.rs | 1 + compiler/rustc_mir/src/transform/inline.rs | 32 +++++++++++++--------- compiler/rustc_mir/src/transform/mod.rs | 3 +- compiler/rustc_session/src/options.rs | 2 ++ 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index f9c3406d3b335..3ee58e001640a 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -556,6 +556,7 @@ fn test_debugging_options_tracking_hash() { tracked!(function_sections, Some(false)); tracked!(human_readable_cgu_names, true); tracked!(inline_in_all_cgus, Some(true)); + tracked!(inline_mir, Some(true)); tracked!(inline_mir_threshold, 123); tracked!(inline_mir_hint_threshold, 123); tracked!(insert_sideeffect, true); diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index f4f69fc8ac62b..3f8c9272b26a4 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -37,21 +37,27 @@ struct CallSite<'tcx> { source_info: SourceInfo, } +/// Returns true if MIR inlining is enabled in the current compilation session. +crate fn is_enabled(tcx: TyCtxt<'_>) -> bool { + if tcx.sess.opts.debugging_opts.instrument_coverage { + // Since `Inline` happens after `InstrumentCoverage`, the function-specific coverage + // counters can be invalidated, such as by merging coverage counter statements from + // a pre-inlined function into a different function. This kind of change is invalid, + // so inlining must be skipped. Note: This check is performed here so inlining can + // be disabled without preventing other optimizations (regardless of `mir_opt_level`). + return false; + } + + if let Some(enabled) = tcx.sess.opts.debugging_opts.inline_mir { + return enabled; + } + + tcx.sess.opts.debugging_opts.mir_opt_level >= 2 +} + impl<'tcx> MirPass<'tcx> for Inline { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - // If you change this optimization level, also change the level in - // `mir_drops_elaborated_and_const_checked` for the call to `mir_inliner_callees`. - // Otherwise you will get an ICE about stolen MIR. - if tcx.sess.opts.debugging_opts.mir_opt_level < 2 { - return; - } - - if tcx.sess.opts.debugging_opts.instrument_coverage { - // Since `Inline` happens after `InstrumentCoverage`, the function-specific coverage - // counters can be invalidated, such as by merging coverage counter statements from - // a pre-inlined function into a different function. This kind of change is invalid, - // so inlining must be skipped. Note: This check is performed here so inlining can - // be disabled without preventing other optimizations (regardless of `mir_opt_level`). + if !is_enabled(tcx) { return; } diff --git a/compiler/rustc_mir/src/transform/mod.rs b/compiler/rustc_mir/src/transform/mod.rs index 2786127513d38..9a8935916fb18 100644 --- a/compiler/rustc_mir/src/transform/mod.rs +++ b/compiler/rustc_mir/src/transform/mod.rs @@ -427,8 +427,7 @@ fn mir_drops_elaborated_and_const_checked<'tcx>( let def = ty::WithOptConstParam::unknown(did); // Do not compute the mir call graph without said call graph actually being used. - // Keep this in sync with the mir inliner's optimization level. - if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 { + if inline::is_enabled(tcx) { let _ = tcx.mir_inliner_callees(ty::InstanceDef::Item(def)); } } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index baa0502521da7..2a792c35842f6 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -956,6 +956,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, (default: no)"), incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED], "verify incr. comp. hashes of green query instances (default: no)"), + inline_mir: Option = (None, parse_opt_bool, [TRACKED], + "enable MIR inlining (default: no)"), inline_mir_threshold: usize = (50, parse_uint, [TRACKED], "a default MIR inlining threshold (default: 50)"), inline_mir_hint_threshold: usize = (100, parse_uint, [TRACKED], From 5c546be880c2d918f34c3e9123f380bdbd1b84a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Sun, 21 Feb 2021 00:00:00 +0000 Subject: [PATCH 12/22] Use optional values for inlining thresholds Turn inlining threshold into optional values to make it possible to configure different defaults depending on the current mir-opt-level. --- compiler/rustc_interface/src/tests.rs | 4 ++-- compiler/rustc_mir/src/transform/inline.rs | 4 ++-- compiler/rustc_session/src/options.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 3ee58e001640a..6ea2d1d0c6e42 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -557,8 +557,8 @@ fn test_debugging_options_tracking_hash() { tracked!(human_readable_cgu_names, true); tracked!(inline_in_all_cgus, Some(true)); tracked!(inline_mir, Some(true)); - tracked!(inline_mir_threshold, 123); - tracked!(inline_mir_hint_threshold, 123); + tracked!(inline_mir_threshold, Some(123)); + tracked!(inline_mir_hint_threshold, Some(123)); tracked!(insert_sideeffect, true); tracked!(instrument_coverage, true); tracked!(instrument_mcount, true); diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index 3f8c9272b26a4..da41e91e69bdd 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -316,9 +316,9 @@ impl Inliner<'tcx> { } let mut threshold = if hinted { - self.tcx.sess.opts.debugging_opts.inline_mir_hint_threshold + self.tcx.sess.opts.debugging_opts.inline_mir_hint_threshold.unwrap_or(100) } else { - self.tcx.sess.opts.debugging_opts.inline_mir_threshold + self.tcx.sess.opts.debugging_opts.inline_mir_threshold.unwrap_or(50) }; if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) { diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 2a792c35842f6..4e3d12555e782 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -958,9 +958,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "verify incr. comp. hashes of green query instances (default: no)"), inline_mir: Option = (None, parse_opt_bool, [TRACKED], "enable MIR inlining (default: no)"), - inline_mir_threshold: usize = (50, parse_uint, [TRACKED], + inline_mir_threshold: Option = (None, parse_opt_uint, [TRACKED], "a default MIR inlining threshold (default: 50)"), - inline_mir_hint_threshold: usize = (100, parse_uint, [TRACKED], + inline_mir_hint_threshold: Option = (None, parse_opt_uint, [TRACKED], "inlining threshold for functions with inline hint (default: 100)"), inline_in_all_cgus: Option = (None, parse_opt_bool, [TRACKED], "control whether `#[inline]` functions are in all CGUs"), From 5f7d6631f94db4bcc0498568d00f24b0bb9a382e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 22 Feb 2021 12:02:37 +0200 Subject: [PATCH 13/22] :arrow_up: rust-analyzer --- src/tools/rust-analyzer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer b/src/tools/rust-analyzer index 7435b9e98c928..14de9e54a6d9e 160000 --- a/src/tools/rust-analyzer +++ b/src/tools/rust-analyzer @@ -1 +1 @@ -Subproject commit 7435b9e98c9280043605748c11a1f450669e04d6 +Subproject commit 14de9e54a6d9ef070399b34a11634294a8cc3ca5 From 75d1e303af04758c26e1aee63f2f0afd53dfd6f8 Mon Sep 17 00:00:00 2001 From: 0yoyoyo <60439919+0yoyoyo@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:39:06 +0900 Subject: [PATCH 14/22] Update test cases --- src/test/ui/issues/issue-16683.stderr | 6 ++--- src/test/ui/issues/issue-17740.stderr | 12 +++++----- src/test/ui/issues/issue-17758.stderr | 6 ++--- src/test/ui/issues/issue-17905-2.stderr | 12 +++++----- .../ui/issues/issue-20831-debruijn.stderr | 6 ++--- src/test/ui/issues/issue-27942.stderr | 12 +++++----- src/test/ui/nll/issue-52742.stderr | 6 ++--- src/test/ui/nll/issue-55394.stderr | 6 ++--- .../ui/nll/type-alias-free-regions.stderr | 12 +++++----- .../regions-infer-paramd-indirect.stderr | 6 ++--- .../ui/ufcs/ufcs-explicit-self-bad.stderr | 24 +++++++++---------- 11 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/test/ui/issues/issue-16683.stderr b/src/test/ui/issues/issue-16683.stderr index 6efc12df8fa2c..35bcf286c440f 100644 --- a/src/test/ui/issues/issue-16683.stderr +++ b/src/test/ui/issues/issue-16683.stderr @@ -4,11 +4,11 @@ error[E0495]: cannot infer an appropriate lifetime for autoref due to conflictin LL | self.a(); | ^ | -note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 3:5... - --> $DIR/issue-16683.rs:3:5 +note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 3:10... + --> $DIR/issue-16683.rs:3:10 | LL | fn b(&self) { - | ^^^^^^^^^^^ + | ^^^^^ note: ...so that reference does not outlive borrowed content --> $DIR/issue-16683.rs:4:9 | diff --git a/src/test/ui/issues/issue-17740.stderr b/src/test/ui/issues/issue-17740.stderr index 9fe80232a1421..995f5f1fc3de3 100644 --- a/src/test/ui/issues/issue-17740.stderr +++ b/src/test/ui/issues/issue-17740.stderr @@ -6,11 +6,11 @@ LL | fn bar(self: &mut Foo) { | = note: expected struct `Foo<'a>` found struct `Foo<'_>` -note: the anonymous lifetime #2 defined on the method body at 6:5... - --> $DIR/issue-17740.rs:6:5 +note: the anonymous lifetime defined on the method body at 6:23... + --> $DIR/issue-17740.rs:6:23 | LL | fn bar(self: &mut Foo) { - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 5:7 --> $DIR/issue-17740.rs:5:7 | @@ -30,11 +30,11 @@ note: the lifetime `'a` as defined on the impl at 5:7... | LL | impl <'a> Foo<'a>{ | ^^ -note: ...does not necessarily outlive the anonymous lifetime #2 defined on the method body at 6:5 - --> $DIR/issue-17740.rs:6:5 +note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 6:23 + --> $DIR/issue-17740.rs:6:23 | LL | fn bar(self: &mut Foo) { - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-17758.stderr b/src/test/ui/issues/issue-17758.stderr index f82e0f53a23df..846e8939b53b8 100644 --- a/src/test/ui/issues/issue-17758.stderr +++ b/src/test/ui/issues/issue-17758.stderr @@ -4,11 +4,11 @@ error[E0495]: cannot infer an appropriate lifetime for autoref due to conflictin LL | self.foo(); | ^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 6:5... - --> $DIR/issue-17758.rs:6:5 +note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 6:12... + --> $DIR/issue-17758.rs:6:12 | LL | fn bar(&self) { - | ^^^^^^^^^^^^^ + | ^^^^^ note: ...so that reference does not outlive borrowed content --> $DIR/issue-17758.rs:7:9 | diff --git a/src/test/ui/issues/issue-17905-2.stderr b/src/test/ui/issues/issue-17905-2.stderr index c762a4ab496c9..3c27f7058591c 100644 --- a/src/test/ui/issues/issue-17905-2.stderr +++ b/src/test/ui/issues/issue-17905-2.stderr @@ -6,11 +6,11 @@ LL | fn say(self: &Pair<&str, isize>) { | = note: expected struct `Pair<&str, _>` found struct `Pair<&str, _>` -note: the anonymous lifetime #2 defined on the method body at 8:5... - --> $DIR/issue-17905-2.rs:8:5 +note: the anonymous lifetime defined on the method body at 8:24... + --> $DIR/issue-17905-2.rs:8:24 | LL | fn say(self: &Pair<&str, isize>) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^ note: ...does not necessarily outlive the lifetime `'_` as defined on the impl at 5:5 --> $DIR/issue-17905-2.rs:5:5 | @@ -30,11 +30,11 @@ note: the lifetime `'_` as defined on the impl at 5:5... | LL | &str, | ^ -note: ...does not necessarily outlive the anonymous lifetime #2 defined on the method body at 8:5 - --> $DIR/issue-17905-2.rs:8:5 +note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 8:24 + --> $DIR/issue-17905-2.rs:8:24 | LL | fn say(self: &Pair<&str, isize>) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-20831-debruijn.stderr b/src/test/ui/issues/issue-20831-debruijn.stderr index bcfb6b70b2e5f..e68482d1caf69 100644 --- a/src/test/ui/issues/issue-20831-debruijn.stderr +++ b/src/test/ui/issues/issue-20831-debruijn.stderr @@ -4,11 +4,11 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` d LL | fn subscribe(&mut self, t : Box::Output> + 'a>) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the method body at 28:5... - --> $DIR/issue-20831-debruijn.rs:28:5 +note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 28:58... + --> $DIR/issue-20831-debruijn.rs:28:58 | LL | fn subscribe(&mut self, t : Box::Output> + 'a>) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...but the lifetime must also be valid for the lifetime `'a` as defined on the impl at 26:6... --> $DIR/issue-20831-debruijn.rs:26:6 | diff --git a/src/test/ui/issues/issue-27942.stderr b/src/test/ui/issues/issue-27942.stderr index 6ce0fa37a8840..80eecb42d1cef 100644 --- a/src/test/ui/issues/issue-27942.stderr +++ b/src/test/ui/issues/issue-27942.stderr @@ -6,11 +6,11 @@ LL | fn select(&self) -> BufferViewHandle; | = note: expected type `Resources<'_>` found type `Resources<'a>` -note: the anonymous lifetime #1 defined on the method body at 5:5... - --> $DIR/issue-27942.rs:5:5 +note: the anonymous lifetime defined on the method body at 5:15... + --> $DIR/issue-27942.rs:5:15 | LL | fn select(&self) -> BufferViewHandle; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^ note: ...does not necessarily outlive the lifetime `'a` as defined on the trait at 3:18 --> $DIR/issue-27942.rs:3:18 | @@ -30,11 +30,11 @@ note: the lifetime `'a` as defined on the trait at 3:18... | LL | pub trait Buffer<'a, R: Resources<'a>> { | ^^ -note: ...does not necessarily outlive the anonymous lifetime #1 defined on the method body at 5:5 - --> $DIR/issue-27942.rs:5:5 +note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 5:15 + --> $DIR/issue-27942.rs:5:15 | LL | fn select(&self) -> BufferViewHandle; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/issue-52742.stderr b/src/test/ui/nll/issue-52742.stderr index 7631ca61e5e15..23bb12f942075 100644 --- a/src/test/ui/nll/issue-52742.stderr +++ b/src/test/ui/nll/issue-52742.stderr @@ -9,11 +9,11 @@ note: ...the reference is valid for the lifetime `'_` as defined on the impl at | LL | impl Foo<'_, '_> { | ^^ -note: ...but the borrowed content is only valid for the anonymous lifetime #2 defined on the method body at 13:5 - --> $DIR/issue-52742.rs:13:5 +note: ...but the borrowed content is only valid for the anonymous lifetime defined on the method body at 13:31 + --> $DIR/issue-52742.rs:13:31 | LL | fn take_bar(&mut self, b: Bar<'_>) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/nll/issue-55394.stderr b/src/test/ui/nll/issue-55394.stderr index e24ef176db01e..36721f923f7da 100644 --- a/src/test/ui/nll/issue-55394.stderr +++ b/src/test/ui/nll/issue-55394.stderr @@ -4,11 +4,11 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'s` d LL | Foo { bar } | ^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 8:5... - --> $DIR/issue-55394.rs:8:5 +note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 8:17... + --> $DIR/issue-55394.rs:8:17 | LL | fn new(bar: &mut Bar) -> Self { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^ note: ...so that reference does not outlive borrowed content --> $DIR/issue-55394.rs:9:15 | diff --git a/src/test/ui/nll/type-alias-free-regions.stderr b/src/test/ui/nll/type-alias-free-regions.stderr index 38e3e05d1cbb7..6498ecfbe6f9b 100644 --- a/src/test/ui/nll/type-alias-free-regions.stderr +++ b/src/test/ui/nll/type-alias-free-regions.stderr @@ -4,11 +4,11 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` d LL | C { f: b } | ^ | -note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 16:5... - --> $DIR/type-alias-free-regions.rs:16:5 +note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 16:24... + --> $DIR/type-alias-free-regions.rs:16:24 | LL | fn from_box(b: Box) -> Self { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ note: ...so that the expression is assignable --> $DIR/type-alias-free-regions.rs:17:16 | @@ -35,11 +35,11 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | C { f: Box::new(b.0) } | ^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 26:5... - --> $DIR/type-alias-free-regions.rs:26:5 +note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 26:23... + --> $DIR/type-alias-free-regions.rs:26:23 | LL | fn from_tuple(b: (B,)) -> Self { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ note: ...so that the expression is assignable --> $DIR/type-alias-free-regions.rs:27:25 | diff --git a/src/test/ui/regions/regions-infer-paramd-indirect.stderr b/src/test/ui/regions/regions-infer-paramd-indirect.stderr index 620b25c9e0555..95eb4d1f75b72 100644 --- a/src/test/ui/regions/regions-infer-paramd-indirect.stderr +++ b/src/test/ui/regions/regions-infer-paramd-indirect.stderr @@ -6,11 +6,11 @@ LL | self.f = b; | = note: expected struct `Box>` found struct `Box>` -note: the anonymous lifetime #2 defined on the method body at 21:5... - --> $DIR/regions-infer-paramd-indirect.rs:21:5 +note: the anonymous lifetime defined on the method body at 21:36... + --> $DIR/regions-infer-paramd-indirect.rs:21:36 | LL | fn set_f_bad(&mut self, b: Box) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 16:6 --> $DIR/regions-infer-paramd-indirect.rs:16:6 | diff --git a/src/test/ui/ufcs/ufcs-explicit-self-bad.stderr b/src/test/ui/ufcs/ufcs-explicit-self-bad.stderr index d7c4817357190..133ecab2296b7 100644 --- a/src/test/ui/ufcs/ufcs-explicit-self-bad.stderr +++ b/src/test/ui/ufcs/ufcs-explicit-self-bad.stderr @@ -33,11 +33,11 @@ LL | fn dummy2(self: &Bar) {} | = note: expected reference `&'a Bar` found reference `&Bar` -note: the anonymous lifetime #1 defined on the method body at 37:5... - --> $DIR/ufcs-explicit-self-bad.rs:37:5 +note: the anonymous lifetime defined on the method body at 37:21... + --> $DIR/ufcs-explicit-self-bad.rs:37:21 | LL | fn dummy2(self: &Bar) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 35:6 --> $DIR/ufcs-explicit-self-bad.rs:35:6 | @@ -57,11 +57,11 @@ note: the lifetime `'a` as defined on the impl at 35:6... | LL | impl<'a, T> SomeTrait for &'a Bar { | ^^ -note: ...does not necessarily outlive the anonymous lifetime #1 defined on the method body at 37:5 - --> $DIR/ufcs-explicit-self-bad.rs:37:5 +note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 37:21 + --> $DIR/ufcs-explicit-self-bad.rs:37:21 | LL | fn dummy2(self: &Bar) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ error[E0308]: mismatched `self` parameter type --> $DIR/ufcs-explicit-self-bad.rs:39:21 @@ -71,11 +71,11 @@ LL | fn dummy3(self: &&Bar) {} | = note: expected reference `&'a Bar` found reference `&Bar` -note: the anonymous lifetime #2 defined on the method body at 39:5... - --> $DIR/ufcs-explicit-self-bad.rs:39:5 +note: the anonymous lifetime defined on the method body at 39:22... + --> $DIR/ufcs-explicit-self-bad.rs:39:22 | LL | fn dummy3(self: &&Bar) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 35:6 --> $DIR/ufcs-explicit-self-bad.rs:35:6 | @@ -95,11 +95,11 @@ note: the lifetime `'a` as defined on the impl at 35:6... | LL | impl<'a, T> SomeTrait for &'a Bar { | ^^ -note: ...does not necessarily outlive the anonymous lifetime #2 defined on the method body at 39:5 - --> $DIR/ufcs-explicit-self-bad.rs:39:5 +note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 39:22 + --> $DIR/ufcs-explicit-self-bad.rs:39:22 | LL | fn dummy3(self: &&Bar) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ error: aborting due to 7 previous errors From 24c23f54045549dd7499bac8d35b74f282cacb3a Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 22 Feb 2021 18:17:58 +0200 Subject: [PATCH 15/22] Test hexagon-enum only when llvm target is present See https://github.com/rust-lang/rust/pull/82379#issuecomment-783439754 --- src/test/ui/layout/hexagon-enum.rs | 1 + src/test/ui/layout/hexagon-enum.stderr | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/ui/layout/hexagon-enum.rs b/src/test/ui/layout/hexagon-enum.rs index 4bcfa58f7cf15..8c6c97206649c 100644 --- a/src/test/ui/layout/hexagon-enum.rs +++ b/src/test/ui/layout/hexagon-enum.rs @@ -1,4 +1,5 @@ // compile-flags: --target hexagon-unknown-linux-musl +// needs-llvm-components: hexagon // // Verify that the hexagon targets implement the repr(C) for enums correctly. // diff --git a/src/test/ui/layout/hexagon-enum.stderr b/src/test/ui/layout/hexagon-enum.stderr index 390eff6e5b957..d4676a5afb25e 100644 --- a/src/test/ui/layout/hexagon-enum.stderr +++ b/src/test/ui/layout/hexagon-enum.stderr @@ -81,7 +81,7 @@ error: layout_of(A) = Layout { raw: 1, }, } - --> $DIR/hexagon-enum.rs:15:1 + --> $DIR/hexagon-enum.rs:16:1 | LL | enum A { Apple } | ^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ error: layout_of(B) = Layout { raw: 1, }, } - --> $DIR/hexagon-enum.rs:19:1 + --> $DIR/hexagon-enum.rs:20:1 | LL | enum B { Banana = 255, } | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -257,7 +257,7 @@ error: layout_of(C) = Layout { raw: 2, }, } - --> $DIR/hexagon-enum.rs:23:1 + --> $DIR/hexagon-enum.rs:24:1 | LL | enum C { Chaenomeles = 256, } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -345,7 +345,7 @@ error: layout_of(P) = Layout { raw: 4, }, } - --> $DIR/hexagon-enum.rs:27:1 + --> $DIR/hexagon-enum.rs:28:1 | LL | enum P { Peach = 0x1000_0000isize, } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -433,7 +433,7 @@ error: layout_of(T) = Layout { raw: 4, }, } - --> $DIR/hexagon-enum.rs:33:1 + --> $DIR/hexagon-enum.rs:34:1 | LL | enum T { Tangerine = TANGERINE as isize } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From c02d21033d3603f1dac3bfd6062c37f69a1681cd Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 23 Feb 2021 00:07:36 +0300 Subject: [PATCH 16/22] Add tests --- .../ui/proc-macro/auxiliary/test-macros.rs | 22 +++++++++++---- .../derive-helper-legacy-spurious.rs | 13 +++++++++ .../derive-helper-legacy-spurious.stderr | 28 +++++++++++++++++++ .../ui/proc-macro/inert-attribute-order.rs | 23 +++++++++++++++ .../proc-macro/inert-attribute-order.stdout | 7 +++++ 5 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 src/test/ui/proc-macro/derive-helper-legacy-spurious.rs create mode 100644 src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr create mode 100644 src/test/ui/proc-macro/inert-attribute-order.rs create mode 100644 src/test/ui/proc-macro/inert-attribute-order.stdout diff --git a/src/test/ui/proc-macro/auxiliary/test-macros.rs b/src/test/ui/proc-macro/auxiliary/test-macros.rs index 57a7ffa39ef00..a7ed4bc88250d 100644 --- a/src/test/ui/proc-macro/auxiliary/test-macros.rs +++ b/src/test/ui/proc-macro/auxiliary/test-macros.rs @@ -7,7 +7,7 @@ #![crate_type = "proc-macro"] extern crate proc_macro; -use proc_macro::TokenStream; +use proc_macro::{TokenStream, TokenTree}; // Macro that return empty token stream. @@ -80,6 +80,10 @@ pub fn recollect_derive(input: TokenStream) -> TokenStream { // Macros that print their input in the original and re-collected forms (if they differ). fn print_helper(input: TokenStream, kind: &str) -> TokenStream { + print_helper_ext(input, kind, true) +} + +fn print_helper_ext(input: TokenStream, kind: &str, debug: bool) -> TokenStream { let input_display = format!("{}", input); let input_debug = format!("{:#?}", input); let recollected = input.into_iter().collect(); @@ -89,9 +93,11 @@ fn print_helper(input: TokenStream, kind: &str) -> TokenStream { if recollected_display != input_display { println!("PRINT-{} RE-COLLECTED (DISPLAY): {}", kind, recollected_display); } - println!("PRINT-{} INPUT (DEBUG): {}", kind, input_debug); - if recollected_debug != input_debug { - println!("PRINT-{} RE-COLLECTED (DEBUG): {}", kind, recollected_debug); + if debug { + println!("PRINT-{} INPUT (DEBUG): {}", kind, input_debug); + if recollected_debug != input_debug { + println!("PRINT-{} RE-COLLECTED (DEBUG): {}", kind, recollected_debug); + } } recollected } @@ -108,8 +114,12 @@ pub fn print_bang_consume(input: TokenStream) -> TokenStream { } #[proc_macro_attribute] -pub fn print_attr(_: TokenStream, input: TokenStream) -> TokenStream { - print_helper(input, "ATTR") +pub fn print_attr(args: TokenStream, input: TokenStream) -> TokenStream { + let debug = match &args.into_iter().collect::>()[..] { + [TokenTree::Ident(ident)] if ident.to_string() == "nodebug" => false, + _ => true, + }; + print_helper_ext(input, "ATTR", debug) } #[proc_macro_attribute] diff --git a/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs b/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs new file mode 100644 index 0000000000000..8180aab0caa13 --- /dev/null +++ b/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs @@ -0,0 +1,13 @@ +// aux-build:test-macros.rs + +#![dummy] //~ ERROR cannot find attribute `dummy` in this scope + +#[macro_use] +extern crate test_macros; + +#[derive(Empty)] //~ ERROR cannot determine resolution for the attribute macro `derive` +#[empty_helper] //~ WARN derive helper attribute is used before it is introduced + //~| WARN this was previously accepted +struct Foo {} + +fn main() {} diff --git a/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr b/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr new file mode 100644 index 0000000000000..96754fed9933c --- /dev/null +++ b/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr @@ -0,0 +1,28 @@ +error: cannot find attribute `dummy` in this scope + --> $DIR/derive-helper-legacy-spurious.rs:3:4 + | +LL | #![dummy] + | ^^^^^ + +error: cannot determine resolution for the attribute macro `derive` + --> $DIR/derive-helper-legacy-spurious.rs:8:3 + | +LL | #[derive(Empty)] + | ^^^^^^ + | + = note: import resolution is stuck, try simplifying macro imports + +warning: derive helper attribute is used before it is introduced + --> $DIR/derive-helper-legacy-spurious.rs:9:3 + | +LL | #[derive(Empty)] + | ----- the attribute is introduced here +LL | #[empty_helper] + | ^^^^^^^^^^^^ + | + = note: `#[warn(legacy_derive_helpers)]` on by default + = 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 #79202 + +error: aborting due to 2 previous errors; 1 warning emitted + diff --git a/src/test/ui/proc-macro/inert-attribute-order.rs b/src/test/ui/proc-macro/inert-attribute-order.rs new file mode 100644 index 0000000000000..f807967564116 --- /dev/null +++ b/src/test/ui/proc-macro/inert-attribute-order.rs @@ -0,0 +1,23 @@ +// Order of inert attributes, both built-in and custom is preserved during expansion. + +// check-pass +// compile-flags: -Z span-debug +// aux-build:test-macros.rs + +#![no_std] // Don't load unnecessary hygiene information from std +extern crate std; + +#[macro_use] +extern crate test_macros; + +/// 1 +#[rustfmt::attr2] +#[doc = "3"] +#[print_attr(nodebug)] +#[doc = "4"] +#[rustfmt::attr5] +/// 6 +#[print_attr(nodebug)] +struct S; + +fn main() {} diff --git a/src/test/ui/proc-macro/inert-attribute-order.stdout b/src/test/ui/proc-macro/inert-attribute-order.stdout new file mode 100644 index 0000000000000..7c0620b50b30f --- /dev/null +++ b/src/test/ui/proc-macro/inert-attribute-order.stdout @@ -0,0 +1,7 @@ +PRINT-ATTR INPUT (DISPLAY): /// 1 +#[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] /// 6 +#[print_attr(nodebug)] #[rustfmt :: attr2] struct S ; +PRINT-ATTR RE-COLLECTED (DISPLAY): #[doc = " 1"] #[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] #[doc = " 6"] +#[print_attr(nodebug)] #[rustfmt :: attr2] struct S ; +PRINT-ATTR INPUT (DISPLAY): #[doc = " 1"] #[doc = "3"] #[doc = "4"] #[doc = " 6"] #[rustfmt :: attr2] +#[rustfmt :: attr5] struct S ; From fc9d578bc5ada5162f49ed02a547cf87f2456a93 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 23 Feb 2021 00:54:09 +0300 Subject: [PATCH 17/22] expand: Preserve order of inert attributes during expansion --- compiler/rustc_expand/src/expand.rs | 23 ++++--- .../derive-helper-legacy-spurious.rs | 3 +- .../derive-helper-legacy-spurious.stderr | 10 +-- .../proc-macro/inert-attribute-order.stdout | 12 ++-- .../proc-macro/issue-75930-derive-cfg.stdout | 64 +++++++++---------- 5 files changed, 55 insertions(+), 57 deletions(-) diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 5a4737842f0af..10c19ea105e4a 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -301,6 +301,8 @@ pub enum InvocationKind { }, Attr { attr: ast::Attribute, + // Re-insertion position for inert attributes. + pos: usize, item: Annotatable, // Required for resolving derive helper attributes. derives: Vec, @@ -690,7 +692,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { } _ => unreachable!(), }, - InvocationKind::Attr { attr, mut item, derives } => match ext { + InvocationKind::Attr { attr, pos, mut item, derives } => match ext { SyntaxExtensionKind::Attr(expander) => { self.gate_proc_macro_input(&item); self.gate_proc_macro_attr_item(span, &item); @@ -721,7 +723,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { ExpandResult::Retry(item) => { // Reassemble the original invocation for retrying. return ExpandResult::Retry(Invocation { - kind: InvocationKind::Attr { attr, item, derives }, + kind: InvocationKind::Attr { attr, pos, item, derives }, ..invoc }); } @@ -739,7 +741,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { if *mark_used { self.cx.sess.mark_attr_used(&attr); } - item.visit_attrs(|attrs| attrs.push(attr)); + item.visit_attrs(|attrs| attrs.insert(pos, attr)); fragment_kind.expect_from_annotatables(iter::once(item)) } _ => unreachable!(), @@ -1000,17 +1002,20 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { fn collect_attr( &mut self, - (attr, derives): (ast::Attribute, Vec), + (attr, pos, derives): (ast::Attribute, usize, Vec), item: Annotatable, kind: AstFragmentKind, ) -> AstFragment { - self.collect(kind, InvocationKind::Attr { attr, item, derives }) + self.collect(kind, InvocationKind::Attr { attr, pos, item, derives }) } /// If `item` is an attribute invocation, remove the attribute and return it together with - /// derives following it. We have to collect the derives in order to resolve legacy derive - /// helpers (helpers written before derives that introduce them). - fn take_first_attr(&mut self, item: &mut impl HasAttrs) -> Option<(ast::Attribute, Vec)> { + /// its position and derives following it. We have to collect the derives in order to resolve + /// legacy derive helpers (helpers written before derives that introduce them). + fn take_first_attr( + &mut self, + item: &mut impl HasAttrs, + ) -> Option<(ast::Attribute, usize, Vec)> { let mut attr = None; item.visit_attrs(|attrs| { @@ -1033,7 +1038,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { }) .collect(); - (attr, following_derives) + (attr, attr_pos, following_derives) }) }); diff --git a/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs b/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs index 8180aab0caa13..4a7e48eed46c3 100644 --- a/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs +++ b/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs @@ -6,8 +6,7 @@ extern crate test_macros; #[derive(Empty)] //~ ERROR cannot determine resolution for the attribute macro `derive` -#[empty_helper] //~ WARN derive helper attribute is used before it is introduced - //~| WARN this was previously accepted +#[empty_helper] //~ ERROR cannot find attribute `empty_helper` in this scope struct Foo {} fn main() {} diff --git a/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr b/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr index 96754fed9933c..fd1ed8a3d0ff3 100644 --- a/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr +++ b/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr @@ -12,17 +12,11 @@ LL | #[derive(Empty)] | = note: import resolution is stuck, try simplifying macro imports -warning: derive helper attribute is used before it is introduced +error: cannot find attribute `empty_helper` in this scope --> $DIR/derive-helper-legacy-spurious.rs:9:3 | -LL | #[derive(Empty)] - | ----- the attribute is introduced here LL | #[empty_helper] | ^^^^^^^^^^^^ - | - = note: `#[warn(legacy_derive_helpers)]` on by default - = 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 #79202 -error: aborting due to 2 previous errors; 1 warning emitted +error: aborting due to 3 previous errors diff --git a/src/test/ui/proc-macro/inert-attribute-order.stdout b/src/test/ui/proc-macro/inert-attribute-order.stdout index 7c0620b50b30f..cc215545952df 100644 --- a/src/test/ui/proc-macro/inert-attribute-order.stdout +++ b/src/test/ui/proc-macro/inert-attribute-order.stdout @@ -1,7 +1,7 @@ PRINT-ATTR INPUT (DISPLAY): /// 1 -#[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] /// 6 -#[print_attr(nodebug)] #[rustfmt :: attr2] struct S ; -PRINT-ATTR RE-COLLECTED (DISPLAY): #[doc = " 1"] #[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] #[doc = " 6"] -#[print_attr(nodebug)] #[rustfmt :: attr2] struct S ; -PRINT-ATTR INPUT (DISPLAY): #[doc = " 1"] #[doc = "3"] #[doc = "4"] #[doc = " 6"] #[rustfmt :: attr2] -#[rustfmt :: attr5] struct S ; +#[rustfmt :: attr2] #[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] /// 6 +#[print_attr(nodebug)] struct S ; +PRINT-ATTR RE-COLLECTED (DISPLAY): #[doc = " 1"] #[rustfmt :: attr2] #[doc = "3"] #[doc = "4"] +#[rustfmt :: attr5] #[doc = " 6"] #[print_attr(nodebug)] struct S ; +PRINT-ATTR INPUT (DISPLAY): #[doc = " 1"] #[rustfmt :: attr2] #[doc = "3"] #[doc = "4"] +#[rustfmt :: attr5] #[doc = " 6"] struct S ; diff --git a/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout b/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout index 19aa4dfb60e36..15e63c20eb9bc 100644 --- a/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout +++ b/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout @@ -1,4 +1,4 @@ -PRINT-ATTR INPUT (DISPLAY): #[allow(dead_code)] #[derive(Print)] #[print_helper(b)] #[print_helper(a)] +PRINT-ATTR INPUT (DISPLAY): #[print_helper(a)] #[allow(dead_code)] #[derive(Print)] #[print_helper(b)] struct Foo < #[cfg(FALSE)] A, B > { #[cfg(FALSE)] first : String, #[cfg_attr(FALSE, deny(warnings))] second : @@ -23,6 +23,31 @@ struct Foo < #[cfg(FALSE)] A, B > }], #[print_helper(d)] fourth : B } PRINT-ATTR INPUT (DEBUG): TokenStream [ + Punct { + ch: '#', + spacing: Alone, + span: $DIR/issue-75930-derive-cfg.rs:16:1: 16:2 (#0), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "print_helper", + span: $DIR/issue-75930-derive-cfg.rs:16:3: 16:15 (#0), + }, + Group { + delimiter: Parenthesis, + stream: TokenStream [ + Ident { + ident: "a", + span: $DIR/issue-75930-derive-cfg.rs:16:16: 16:17 (#0), + }, + ], + span: $DIR/issue-75930-derive-cfg.rs:16:15: 16:18 (#0), + }, + ], + span: $DIR/issue-75930-derive-cfg.rs:16:2: 16:19 (#0), + }, Punct { ch: '#', spacing: Alone, @@ -98,31 +123,6 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ ], span: $DIR/issue-75930-derive-cfg.rs:21:2: 21:19 (#0), }, - Punct { - ch: '#', - spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:16:1: 16:2 (#0), - }, - Group { - delimiter: Bracket, - stream: TokenStream [ - Ident { - ident: "print_helper", - span: $DIR/issue-75930-derive-cfg.rs:16:3: 16:15 (#0), - }, - Group { - delimiter: Parenthesis, - stream: TokenStream [ - Ident { - ident: "a", - span: $DIR/issue-75930-derive-cfg.rs:16:16: 16:17 (#0), - }, - ], - span: $DIR/issue-75930-derive-cfg.rs:16:15: 16:18 (#0), - }, - ], - span: $DIR/issue-75930-derive-cfg.rs:16:2: 16:19 (#0), - }, Ident { ident: "struct", span: $DIR/issue-75930-derive-cfg.rs:22:1: 22:7 (#0), @@ -1194,7 +1194,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ span: $DIR/issue-75930-derive-cfg.rs:22:32: 65:2 (#0), }, ] -PRINT-DERIVE INPUT (DISPLAY): #[allow(dead_code)] #[print_helper(b)] #[print_helper(a)] struct Foo < B > +PRINT-DERIVE INPUT (DISPLAY): #[print_helper(a)] #[allow(dead_code)] #[print_helper(b)] struct Foo < B > { second : bool, third : [u8 ; @@ -1217,14 +1217,14 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ delimiter: Bracket, stream: TokenStream [ Ident { - ident: "allow", + ident: "print_helper", span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { - ident: "dead_code", + ident: "a", span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0), }, ], @@ -1242,14 +1242,14 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ delimiter: Bracket, stream: TokenStream [ Ident { - ident: "print_helper", + ident: "allow", span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { - ident: "b", + ident: "dead_code", span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0), }, ], @@ -1274,7 +1274,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ delimiter: Parenthesis, stream: TokenStream [ Ident { - ident: "a", + ident: "b", span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0), }, ], From e8dcc02dc5bb8ee26c22d67efa4ede281927e5cb Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 22 Feb 2021 14:42:59 -0800 Subject: [PATCH 18/22] Add a `size()` function to WASI's `MetadataExt`. WASI's `filestat` type includes a size field, so expose it in `MetadataExt` via a `size()` function, similar to the corresponding Unix function. --- library/std/src/sys/wasi/ext/fs.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/std/src/sys/wasi/ext/fs.rs b/library/std/src/sys/wasi/ext/fs.rs index a8da003d550ac..1dc7983f18831 100644 --- a/library/std/src/sys/wasi/ext/fs.rs +++ b/library/std/src/sys/wasi/ext/fs.rs @@ -397,6 +397,8 @@ pub trait MetadataExt { fn ino(&self) -> u64; /// Returns the `st_nlink` field of the internal `filestat_t` fn nlink(&self) -> u64; + /// Returns the `st_size` field of the internal `filestat_t` + fn size(&self) -> u64; /// Returns the `st_atim` field of the internal `filestat_t` fn atim(&self) -> u64; /// Returns the `st_mtim` field of the internal `filestat_t` @@ -415,6 +417,9 @@ impl MetadataExt for fs::Metadata { fn nlink(&self) -> u64 { self.as_inner().as_wasi().nlink } + fn size(&self) -> u64 { + self.as_inner().as_wasi().size + } fn atim(&self) -> u64 { self.as_inner().as_wasi().atim } From fa74d489a227054f20b0ffdda85e864e53cc7617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Sun, 21 Feb 2021 13:29:43 +0300 Subject: [PATCH 19/22] Improve error msgs when found type is deref of expected This improves help messages in two cases: - When expected type is `T` and found type is `&T`, we now look through blocks and suggest dereferencing the expression of the block, rather than the whole block. - In the above case, if the expression is an `&`, we not suggest removing the `&` instead of adding `*`. Both of these are demonstrated in the regression test. Before this patch the first error in the test would be: error[E0308]: `if` and `else` have incompatible types --> test.rs:8:9 | 5 | / if true { 6 | | a | | - expected because of this 7 | | } else { 8 | | b | | ^ expected `usize`, found `&usize` 9 | | }; | |_____- `if` and `else` have incompatible types | help: consider dereferencing the borrow | 7 | } else *{ 8 | b 9 | }; | Now: error[E0308]: `if` and `else` have incompatible types --> test.rs:8:9 | 5 | / if true { 6 | | a | | - expected because of this 7 | | } else { 8 | | b | | ^ | | | | | expected `usize`, found `&usize` | | help: consider dereferencing the borrow: `*b` 9 | | }; | |_____- `if` and `else` have incompatible types The second error: error[E0308]: `if` and `else` have incompatible types --> test.rs:14:9 | 11 | / if true { 12 | | 1 | | - expected because of this 13 | | } else { 14 | | &1 | | ^^ expected integer, found `&{integer}` 15 | | }; | |_____- `if` and `else` have incompatible types | help: consider dereferencing the borrow | 13 | } else *{ 14 | &1 15 | }; | now: error[E0308]: `if` and `else` have incompatible types --> test.rs:14:9 | 11 | / if true { 12 | | 1 | | - expected because of this 13 | | } else { 14 | | &1 | | ^- | | || | | |help: consider removing the `&`: `1` | | expected integer, found `&{integer}` 15 | | }; | |_____- `if` and `else` have incompatible types Fixes #82361 --- compiler/rustc_hir/src/hir.rs | 8 ++++ compiler/rustc_typeck/src/check/demand.rs | 28 +++++++++++-- src/test/ui/suggestions/issue-82361.fixed | 24 +++++++++++ src/test/ui/suggestions/issue-82361.rs | 24 +++++++++++ src/test/ui/suggestions/issue-82361.stderr | 48 ++++++++++++++++++++++ 5 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/suggestions/issue-82361.fixed create mode 100644 src/test/ui/suggestions/issue-82361.rs create mode 100644 src/test/ui/suggestions/issue-82361.stderr diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 2fef7c2cc087d..f4402843afcbe 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1577,6 +1577,14 @@ impl Expr<'_> { expr } + pub fn peel_blocks(&self) -> &Self { + let mut expr = self; + while let ExprKind::Block(Block { expr: Some(inner), .. }, _) = &expr.kind { + expr = inner; + } + expr + } + pub fn can_have_side_effects(&self) -> bool { match self.peel_drop_temps().kind { ExprKind::Path(_) | ExprKind::Lit(_) => false, diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index 8d2004a543b7b..39b973ed371ae 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -616,10 +616,30 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } _ if sp == expr.span && !is_macro => { if let Some(steps) = self.deref_steps(checked_ty, expected) { + let expr = expr.peel_blocks(); + if steps == 1 { - // For a suggestion to make sense, the type would need to be `Copy`. - if self.infcx.type_is_copy_modulo_regions(self.param_env, expected, sp) { - if let Ok(code) = sm.span_to_snippet(sp) { + if let hir::ExprKind::AddrOf(_, mutbl, inner) = expr.kind { + // If the expression has `&`, removing it would fix the error + let prefix_span = expr.span.with_hi(inner.span.lo()); + let message = match mutbl { + hir::Mutability::Not => "consider removing the `&`", + hir::Mutability::Mut => "consider removing the `&mut`", + }; + let suggestion = String::new(); + return Some(( + prefix_span, + message, + suggestion, + Applicability::MachineApplicable, + )); + } else if self.infcx.type_is_copy_modulo_regions( + self.param_env, + expected, + sp, + ) { + // For this suggestion to make sense, the type would need to be `Copy`. + if let Ok(code) = sm.span_to_snippet(expr.span) { let message = if checked_ty.is_region_ptr() { "consider dereferencing the borrow" } else { @@ -631,7 +651,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { format!("*{}", code) }; return Some(( - sp, + expr.span, message, suggestion, Applicability::MachineApplicable, diff --git a/src/test/ui/suggestions/issue-82361.fixed b/src/test/ui/suggestions/issue-82361.fixed new file mode 100644 index 0000000000000..d72de982bf98a --- /dev/null +++ b/src/test/ui/suggestions/issue-82361.fixed @@ -0,0 +1,24 @@ +// run-rustfix + +fn main() { + let a: usize = 123; + let b: &usize = &a; + + if true { + a + } else { + *b //~ ERROR `if` and `else` have incompatible types [E0308] + }; + + if true { + 1 + } else { + 1 //~ ERROR `if` and `else` have incompatible types [E0308] + }; + + if true { + 1 + } else { + 1 //~ ERROR `if` and `else` have incompatible types [E0308] + }; +} diff --git a/src/test/ui/suggestions/issue-82361.rs b/src/test/ui/suggestions/issue-82361.rs new file mode 100644 index 0000000000000..c068f6d22b476 --- /dev/null +++ b/src/test/ui/suggestions/issue-82361.rs @@ -0,0 +1,24 @@ +// run-rustfix + +fn main() { + let a: usize = 123; + let b: &usize = &a; + + if true { + a + } else { + b //~ ERROR `if` and `else` have incompatible types [E0308] + }; + + if true { + 1 + } else { + &1 //~ ERROR `if` and `else` have incompatible types [E0308] + }; + + if true { + 1 + } else { + &mut 1 //~ ERROR `if` and `else` have incompatible types [E0308] + }; +} diff --git a/src/test/ui/suggestions/issue-82361.stderr b/src/test/ui/suggestions/issue-82361.stderr new file mode 100644 index 0000000000000..c19d59ccd4c66 --- /dev/null +++ b/src/test/ui/suggestions/issue-82361.stderr @@ -0,0 +1,48 @@ +error[E0308]: `if` and `else` have incompatible types + --> $DIR/issue-82361.rs:10:9 + | +LL | / if true { +LL | | a + | | - expected because of this +LL | | } else { +LL | | b + | | ^ + | | | + | | expected `usize`, found `&usize` + | | help: consider dereferencing the borrow: `*b` +LL | | }; + | |_____- `if` and `else` have incompatible types + +error[E0308]: `if` and `else` have incompatible types + --> $DIR/issue-82361.rs:16:9 + | +LL | / if true { +LL | | 1 + | | - expected because of this +LL | | } else { +LL | | &1 + | | -^ + | | | + | | expected integer, found `&{integer}` + | | help: consider removing the `&` +LL | | }; + | |_____- `if` and `else` have incompatible types + +error[E0308]: `if` and `else` have incompatible types + --> $DIR/issue-82361.rs:22:9 + | +LL | / if true { +LL | | 1 + | | - expected because of this +LL | | } else { +LL | | &mut 1 + | | -----^ + | | | + | | expected integer, found `&mut {integer}` + | | help: consider removing the `&mut` +LL | | }; + | |_____- `if` and `else` have incompatible types + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. From 132ec261b0d215f77b71eeee3d814cd304fc1a29 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 22 Feb 2021 14:21:43 -0800 Subject: [PATCH 20/22] Enable API documentation for `std::os::wasi`. This adds API documentation support for `std::os::wasi` modeled after how `std::os::unix` works, so that WASI can be documented [here] along with the other platforms. [here]: https://doc.rust-lang.org/stable/std/os/index.html Two changes of particular interest: - This changes the `AsRawFd` for `io::Stdin` for WASI to return `libc::STDIN_FILENO` instead of `sys::stdio::Stdin.as_raw_fd()` (and similar for `Stdout` and `Stderr`), which matches how the `unix` version works. `STDIN_FILENO` etc. may not always be explicitly reserved at the WASI level, but as long as we have Rust's `std` and `libc`, I think it's reasonable to guarantee that we'll always use `libc::STDIN_FILENO` for stdin. - This duplicates the `osstr2str` utility function, rather than trying to share it across all the configurations that need it. --- library/std/src/os/mod.rs | 3 +++ library/std/src/sys/mod.rs | 30 +++++++++++++++++++++++++---- library/std/src/sys/wasi/ext/fs.rs | 25 +++++++++++++++--------- library/std/src/sys/wasi/ext/io.rs | 12 ++++++------ library/std/src/sys/wasi/ext/mod.rs | 28 +++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 19 deletions(-) diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index f61e402e37027..fad5886def700 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -22,6 +22,9 @@ pub use crate::sys::windows_ext as windows; #[doc(cfg(target_os = "linux"))] pub mod linux; +#[cfg(doc)] +pub use crate::sys::wasi_ext as wasi; + // If we're not documenting libstd then we just expose the main modules as we otherwise would. #[cfg(not(doc))] diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs index d48d9cb0efce0..d3f53801d2d0f 100644 --- a/library/std/src/sys/mod.rs +++ b/library/std/src/sys/mod.rs @@ -61,9 +61,9 @@ cfg_if::cfg_if! { #[stable(feature = "rust1", since = "1.0.0")] pub use self::ext as unix_ext; } else if #[cfg(any(target_os = "hermit", - target_arch = "wasm32", + all(target_arch = "wasm32", not(target_os = "wasi")), all(target_vendor = "fortanix", target_env = "sgx")))] { - // On wasm right now the module below doesn't compile + // On non-WASI wasm right now the module below doesn't compile // (missing things in `libc` which is empty) so just omit everything // with an empty module #[unstable(issue = "none", feature = "std_internals")] @@ -85,9 +85,9 @@ cfg_if::cfg_if! { #[stable(feature = "rust1", since = "1.0.0")] pub use self::ext as windows_ext; } else if #[cfg(any(target_os = "hermit", - target_arch = "wasm32", + all(target_arch = "wasm32", not(target_os = "wasi")), all(target_vendor = "fortanix", target_env = "sgx")))] { - // On wasm right now the shim below doesn't compile, so + // On non-WASI wasm right now the shim below doesn't compile, so // just omit it #[unstable(issue = "none", feature = "std_internals")] #[allow(missing_docs)] @@ -106,3 +106,25 @@ cfg_if::cfg_if! { pub mod windows_ext; } } + +#[cfg(doc)] +cfg_if::cfg_if! { + if #[cfg(target_os = "wasi")] { + // On WASI we'll document what's already available + #[stable(feature = "rust1", since = "1.0.0")] + pub use self::ext as wasi_ext; + } else if #[cfg(any(target_os = "hermit", + target_arch = "wasm32", + all(target_vendor = "fortanix", target_env = "sgx")))] { + // On non-WASI wasm right now the module below doesn't compile + // (missing things in `libc` which is empty) so just omit everything + // with an empty module + #[unstable(issue = "none", feature = "std_internals")] + #[allow(missing_docs)] + pub mod wasi_ext {} + } else { + // On other platforms like Windows document the bare bones of WASI + #[path = "wasi/ext/mod.rs"] + pub mod wasi_ext; + } +} diff --git a/library/std/src/sys/wasi/ext/fs.rs b/library/std/src/sys/wasi/ext/fs.rs index a8da003d550ac..66b6caf25127d 100644 --- a/library/std/src/sys/wasi/ext/fs.rs +++ b/library/std/src/sys/wasi/ext/fs.rs @@ -3,11 +3,14 @@ #![deny(unsafe_op_in_unsafe_fn)] #![unstable(feature = "wasi_ext", issue = "none")] +use crate::ffi::OsStr; use crate::fs::{self, File, Metadata, OpenOptions}; use crate::io::{self, IoSlice, IoSliceMut}; use crate::path::{Path, PathBuf}; -use crate::sys::fs::osstr2str; use crate::sys_common::{AsInner, AsInnerMut, FromInner}; +// Used for `File::read` on intra-doc links +#[allow(unused_imports)] +use io::{Read, Write}; /// WASI-specific extensions to [`File`]. pub trait FileExt { @@ -54,11 +57,11 @@ pub trait FileExt { /// # Errors /// /// If this function encounters an error of the kind - /// [`ErrorKind::Interrupted`] then the error is ignored and the operation + /// [`io::ErrorKind::Interrupted`] then the error is ignored and the operation /// will continue. /// /// If this function encounters an "end of file" before completely filling - /// the buffer, it returns an error of the kind [`ErrorKind::UnexpectedEof`]. + /// the buffer, it returns an error of the kind [`io::ErrorKind::UnexpectedEof`]. /// The contents of `buf` are unspecified in this case. /// /// If any other read error is encountered then this function immediately @@ -131,16 +134,16 @@ pub trait FileExt { /// The current file cursor is not affected by this function. /// /// This method will continuously call [`write_at`] until there is no more data - /// to be written or an error of non-[`ErrorKind::Interrupted`] kind is + /// to be written or an error of non-[`io::ErrorKind::Interrupted`] kind is /// returned. This method will not return until the entire buffer has been /// successfully written or such an error occurs. The first error that is - /// not of [`ErrorKind::Interrupted`] kind generated from this method will be + /// not of [`io::ErrorKind::Interrupted`] kind generated from this method will be /// returned. /// /// # Errors /// /// This function will return the first error of - /// non-[`ErrorKind::Interrupted`] kind that [`write_at`] returns. + /// non-[`io::ErrorKind::Interrupted`] kind that [`write_at`] returns. /// /// [`write_at`]: FileExt::write_at #[stable(feature = "rw_exact_all_at", since = "1.33.0")] @@ -426,7 +429,7 @@ impl MetadataExt for fs::Metadata { } } -/// WASI-specific extensions for [`FileType`]. +/// WASI-specific extensions for [`fs::FileType`]. /// /// Adds support for special WASI file types such as block/character devices, /// pipes, and sockets. @@ -517,8 +520,12 @@ pub fn symlink, U: AsRef>( /// Create a symbolic link. /// -/// This is a convenience API similar to [`std::os::unix::fs::symlink`] and -/// [`std::os::windows::fs::symlink_file`] and [`symlink_dir`](std::os::windows::fs::symlink_dir). +/// This is a convenience API similar to `std::os::unix::fs::symlink` and +/// `std::os::windows::fs::symlink_file` and `std::os::windows::fs::symlink_dir`. pub fn symlink_path, U: AsRef>(old_path: P, new_path: U) -> io::Result<()> { crate::sys::fs::symlink(old_path.as_ref(), new_path.as_ref()) } + +fn osstr2str(f: &OsStr) -> io::Result<&str> { + f.to_str().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "input must be utf-8")) +} diff --git a/library/std/src/sys/wasi/ext/io.rs b/library/std/src/sys/wasi/ext/io.rs index 81413f39dc1cd..d0edfa9f35f90 100644 --- a/library/std/src/sys/wasi/ext/io.rs +++ b/library/std/src/sys/wasi/ext/io.rs @@ -145,36 +145,36 @@ impl IntoRawFd for fs::File { impl AsRawFd for io::Stdin { fn as_raw_fd(&self) -> RawFd { - sys::stdio::Stdin.as_raw_fd() + libc::STDIN_FILENO } } impl AsRawFd for io::Stdout { fn as_raw_fd(&self) -> RawFd { - sys::stdio::Stdout.as_raw_fd() + libc::STDOUT_FILENO } } impl AsRawFd for io::Stderr { fn as_raw_fd(&self) -> RawFd { - sys::stdio::Stderr.as_raw_fd() + libc::STDERR_FILENO } } impl<'a> AsRawFd for io::StdinLock<'a> { fn as_raw_fd(&self) -> RawFd { - sys::stdio::Stdin.as_raw_fd() + libc::STDIN_FILENO } } impl<'a> AsRawFd for io::StdoutLock<'a> { fn as_raw_fd(&self) -> RawFd { - sys::stdio::Stdout.as_raw_fd() + libc::STDOUT_FILENO } } impl<'a> AsRawFd for io::StderrLock<'a> { fn as_raw_fd(&self) -> RawFd { - sys::stdio::Stderr.as_raw_fd() + libc::STDERR_FILENO } } diff --git a/library/std/src/sys/wasi/ext/mod.rs b/library/std/src/sys/wasi/ext/mod.rs index 1cda30edcad0a..8a83b24700391 100644 --- a/library/std/src/sys/wasi/ext/mod.rs +++ b/library/std/src/sys/wasi/ext/mod.rs @@ -1,4 +1,32 @@ +//! Platform-specific extensions to `std` for WASI. +//! +//! Provides access to platform-level information on WASI, and exposes +//! WASI-specific functions that would otherwise be inappropriate as +//! part of the core `std` library. +//! +//! It exposes more ways to deal with platform-specific strings (`OsStr`, +//! `OsString`), allows to set permissions more granularly, extract low-level +//! file descriptors from files and sockets, and has platform-specific helpers +//! for spawning processes. +//! +//! # Examples +//! +//! ```no_run +//! use std::fs::File; +//! use std::os::wasi::prelude::*; +//! +//! fn main() -> std::io::Result<()> { +//! let f = File::create("foo.txt")?; +//! let fd = f.as_raw_fd(); +//! +//! // use fd with native WASI bindings +//! +//! Ok(()) +//! } +//! ``` + #![deny(unsafe_op_in_unsafe_fn)] +#![doc(cfg(target_os = "wasi"))] pub mod ffi; pub mod fs; From a6eb836ff0e2dff4397468d1bcca787436489efb Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Wed, 30 Dec 2020 23:33:38 +0100 Subject: [PATCH 21/22] Use #[doc = include_str!()] in std --- library/core/src/macros/mod.rs | 2 +- library/std/src/lib.rs | 1 - library/std/src/macros.rs | 2 +- library/std/src/os/raw/mod.rs | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 41ea2760ec570..9a54921f07b49 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -1,4 +1,4 @@ -#[doc(include = "panic.md")] +#[doc = include_str!("panic.md")] #[macro_export] #[rustc_builtin_macro = "core_panic"] #[allow_internal_unstable(edition_panic)] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 588bffb57c9c5..32aca8c83924d 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -264,7 +264,6 @@ #![feature(exhaustive_patterns)] #![feature(extend_one)] #![feature(extended_key_value_attributes)] -#![feature(external_doc)] #![feature(fn_traits)] #![feature(format_args_nl)] #![feature(gen_future)] diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs index c0750f8c0d1b0..b729349cf530f 100644 --- a/library/std/src/macros.rs +++ b/library/std/src/macros.rs @@ -4,7 +4,7 @@ //! library. Each macro is available for use when linking against the standard //! library. -#[doc(include = "../../core/src/macros/panic.md")] +#[doc = include_str!("../../core/src/macros/panic.md")] #[macro_export] #[rustc_builtin_macro = "std_panic"] #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/std/src/os/raw/mod.rs b/library/std/src/os/raw/mod.rs index 22c98d7ade992..50464a050c706 100644 --- a/library/std/src/os/raw/mod.rs +++ b/library/std/src/os/raw/mod.rs @@ -18,7 +18,7 @@ macro_rules! type_alias_no_nz { $Docfile:tt, $Alias:ident = $Real:ty; $( $Cfg:tt )* } => { - #[doc(include = $Docfile)] + #[doc = include_str!($Docfile)] $( $Cfg )* #[stable(feature = "raw_os", since = "1.1.0")] pub type $Alias = $Real; From df78eea3430c41049ae051fd64558ab0a20fa9b2 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 21 Feb 2021 16:32:38 +0300 Subject: [PATCH 22/22] expand: Resolve and expand inner attributes on out-of-line modules --- compiler/rustc_ast/src/ast.rs | 2 +- compiler/rustc_expand/src/expand.rs | 56 ++++++++++---- compiler/rustc_expand/src/module.rs | 54 +++++++++---- .../inner-cfg-non-inline-mod.rs | 7 ++ .../module_with_cfg.rs | 3 + .../proc-macro/inner-attr-non-inline-mod.rs | 17 +++++ .../inner-attr-non-inline-mod.stderr | 39 ++++++++++ .../inner-attr-non-inline-mod.stdout | 76 +++++++++++++++++++ src/test/ui/proc-macro/module_with_attrs.rs | 4 + 9 files changed, 226 insertions(+), 32 deletions(-) create mode 100644 src/test/ui/conditional-compilation/inner-cfg-non-inline-mod.rs create mode 100644 src/test/ui/conditional-compilation/module_with_cfg.rs create mode 100644 src/test/ui/proc-macro/inner-attr-non-inline-mod.rs create mode 100644 src/test/ui/proc-macro/inner-attr-non-inline-mod.stderr create mode 100644 src/test/ui/proc-macro/inner-attr-non-inline-mod.stdout create mode 100644 src/test/ui/proc-macro/module_with_attrs.rs diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 1d2f1f694cf5b..2c17f07acc0a1 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2299,7 +2299,7 @@ impl FnRetTy { } } -#[derive(Clone, PartialEq, Encodable, Decodable, Debug)] +#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)] pub enum Inline { Yes, No, diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 5a4737842f0af..115b947f41b9b 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1278,16 +1278,24 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { let pushed = &mut false; // Record `parse_external_mod` pushing so we can pop. let dir = Directory { ownership: orig_ownership, path: module.directory }; let Directory { ownership, path } = match mod_kind { - ModKind::Loaded(_, Inline::Yes, _) => { - // Inline `mod foo { ... }`, but we still need to push directories. + ModKind::Loaded(_, inline, inner_span) => { + // Inline `mod foo { ... }` or previously loaded `mod foo;`, + // we still need to push directories. + let dir = push_directory( + &self.cx.sess, + ident, + &attrs, + dir, + *inline, + *inner_span, + span, + ); item.attrs = attrs; - push_directory(&self.cx.sess, ident, &item.attrs, dir) - } - ModKind::Loaded(_, Inline::No, _) => { - panic!("`mod` item is loaded from a file for the second time") + dir } ModKind::Unloaded => { // We have an outline `mod foo;` so we need to parse the file. + let old_attrs_len = attrs.len(); let (items, inner_span, dir) = parse_external_mod(&self.cx.sess, ident, span, dir, &mut attrs, pushed); @@ -1299,16 +1307,34 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { *mod_kind = ModKind::Loaded(krate.items, Inline::No, inner_span); item.attrs = krate.attrs; - // File can have inline attributes, e.g., `#![cfg(...)]` & co. => Reconfigure. - item = match self.configure(item) { - Some(node) => node, - None => { - if *pushed { - sess.included_mod_stack.borrow_mut().pop(); - } - return Default::default(); + + if item.attrs.len() > old_attrs_len { + // If we loaded an out-of-line module and added some inner attributes, + // then we need to re-configure it and re-collect attributes for + // resolution and expansion. + let file_path = if *pushed { + sess.included_mod_stack.borrow_mut().pop() + } else { + None + }; + + item = configure!(self, item); + + if let Some(attr) = self.take_first_attr(&mut item) { + return self + .collect_attr( + attr, + Annotatable::Item(item), + AstFragmentKind::Items, + ) + .make_items(); } - }; + + if let Some(file_path) = file_path { + sess.included_mod_stack.borrow_mut().push(file_path); + } + } + dir } }; diff --git a/compiler/rustc_expand/src/module.rs b/compiler/rustc_expand/src/module.rs index 076d3b02be93f..57275baad3a66 100644 --- a/compiler/rustc_expand/src/module.rs +++ b/compiler/rustc_expand/src/module.rs @@ -1,5 +1,5 @@ use rustc_ast::ptr::P; -use rustc_ast::{token, Attribute, Item}; +use rustc_ast::{token, Attribute, Inline, Item}; use rustc_errors::{struct_span_err, PResult}; use rustc_parse::new_parser_from_file; use rustc_session::parse::ParseSess; @@ -103,25 +103,47 @@ crate fn push_directory( id: Ident, attrs: &[Attribute], Directory { mut ownership, mut path }: Directory, + inline: Inline, + inner_span: Span, + span: Span, // The span to blame on errors. ) -> Directory { - if let Some(filename) = sess.first_attr_value_str_by_name(attrs, sym::path) { - path.push(&*filename.as_str()); - ownership = DirectoryOwnership::Owned { relative: None }; - } else { - // We have to push on the current module name in the case of relative - // paths in order to ensure that any additional module paths from inline - // `mod x { ... }` come after the relative extension. - // - // For example, a `mod z { ... }` inside `x/y.rs` should set the current - // directory path to `/x/y/z`, not `/x/z` with a relative offset of `y`. - if let DirectoryOwnership::Owned { relative } = &mut ownership { - if let Some(ident) = relative.take() { - // Remove the relative offset. - path.push(&*ident.as_str()); + match inline { + Inline::Yes => { + if let Some(filename) = sess.first_attr_value_str_by_name(attrs, sym::path) { + path.push(&*filename.as_str()); + ownership = DirectoryOwnership::Owned { relative: None }; + } else { + // We have to push on the current module name in the case of relative + // paths in order to ensure that any additional module paths from inline + // `mod x { ... }` come after the relative extension. + // + // For example, a `mod z { ... }` inside `x/y.rs` should set the current + // directory path to `/x/y/z`, not `/x/z` with a relative offset of `y`. + if let DirectoryOwnership::Owned { relative } = &mut ownership { + if let Some(ident) = relative.take() { + // Remove the relative offset. + path.push(&*ident.as_str()); + } + } + path.push(&*id.as_str()); + } + } + Inline::No => { + // FIXME: This is a subset of `parse_external_mod` without actual parsing, + // check whether the logic for unloaded, loaded and inline modules can be unified. + if let Ok(mp) = submod_path(sess, id, span, &attrs, ownership, &path) { + ownership = mp.ownership; } + + // Extract the directory path for submodules of the module. + path = match sess.source_map().span_to_unmapped_path(inner_span) { + FileName::Real(name) => name.into_local_path(), + other => PathBuf::from(other.to_string()), + }; + path.pop(); } - path.push(&*id.as_str()); } + Directory { ownership, path } } diff --git a/src/test/ui/conditional-compilation/inner-cfg-non-inline-mod.rs b/src/test/ui/conditional-compilation/inner-cfg-non-inline-mod.rs new file mode 100644 index 0000000000000..af5a6462e8a75 --- /dev/null +++ b/src/test/ui/conditional-compilation/inner-cfg-non-inline-mod.rs @@ -0,0 +1,7 @@ +// check-pass + +mod module_with_cfg; + +mod module_with_cfg {} // Ok, the module above is configured away by an inner attribute. + +fn main() {} diff --git a/src/test/ui/conditional-compilation/module_with_cfg.rs b/src/test/ui/conditional-compilation/module_with_cfg.rs new file mode 100644 index 0000000000000..56c4baadf22b4 --- /dev/null +++ b/src/test/ui/conditional-compilation/module_with_cfg.rs @@ -0,0 +1,3 @@ +// ignore-test + +#![cfg_attr(all(), cfg(FALSE))] diff --git a/src/test/ui/proc-macro/inner-attr-non-inline-mod.rs b/src/test/ui/proc-macro/inner-attr-non-inline-mod.rs new file mode 100644 index 0000000000000..6b6f9f0e785ca --- /dev/null +++ b/src/test/ui/proc-macro/inner-attr-non-inline-mod.rs @@ -0,0 +1,17 @@ +// compile-flags: -Z span-debug +// error-pattern:custom inner attributes are unstable +// error-pattern:inner macro attributes are unstable +// aux-build:test-macros.rs + +#![no_std] // Don't load unnecessary hygiene information from std +extern crate std; + +#[macro_use] +extern crate test_macros; + +#[deny(unused_attributes)] +mod module_with_attrs; +//~^ ERROR non-inline modules in proc macro input are unstable +//~| ERROR custom inner attributes are unstable + +fn main() {} diff --git a/src/test/ui/proc-macro/inner-attr-non-inline-mod.stderr b/src/test/ui/proc-macro/inner-attr-non-inline-mod.stderr new file mode 100644 index 0000000000000..41f0b6d2f0714 --- /dev/null +++ b/src/test/ui/proc-macro/inner-attr-non-inline-mod.stderr @@ -0,0 +1,39 @@ +error[E0658]: custom inner attributes are unstable + --> $DIR/module_with_attrs.rs:3:4 + | +LL | #![rustfmt::skip] + | ^^^^^^^^^^^^^ + | + = note: see issue #54726 for more information + = help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable + +error[E0658]: inner macro attributes are unstable + --> $DIR/module_with_attrs.rs:4:4 + | +LL | #![print_attr] + | ^^^^^^^^^^ + | + = note: see issue #54726 for more information + = help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable + +error[E0658]: non-inline modules in proc macro input are unstable + --> $DIR/inner-attr-non-inline-mod.rs:13:1 + | +LL | mod module_with_attrs; + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #54727 for more information + = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable + +error[E0658]: custom inner attributes are unstable + --> $DIR/inner-attr-non-inline-mod.rs:13:1 + | +LL | mod module_with_attrs; + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #54726 for more information + = help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/proc-macro/inner-attr-non-inline-mod.stdout b/src/test/ui/proc-macro/inner-attr-non-inline-mod.stdout new file mode 100644 index 0000000000000..3fb13a1f6cc0e --- /dev/null +++ b/src/test/ui/proc-macro/inner-attr-non-inline-mod.stdout @@ -0,0 +1,76 @@ +PRINT-ATTR INPUT (DISPLAY): #[deny(unused_attributes)] mod module_with_attrs { # ! [rustfmt :: skip] } +PRINT-ATTR INPUT (DEBUG): TokenStream [ + Punct { + ch: '#', + spacing: Alone, + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "deny", + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + Group { + delimiter: Parenthesis, + stream: TokenStream [ + Ident { + ident: "unused_attributes", + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + ], + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + ], + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + Ident { + ident: "mod", + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + Ident { + ident: "module_with_attrs", + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + Group { + delimiter: Brace, + stream: TokenStream [ + Punct { + ch: '#', + spacing: Joint, + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + Punct { + ch: '!', + spacing: Alone, + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "rustfmt", + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + Punct { + ch: ':', + spacing: Joint, + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + Punct { + ch: ':', + spacing: Alone, + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + Ident { + ident: "skip", + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + ], + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, + ], + span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0), + }, +] diff --git a/src/test/ui/proc-macro/module_with_attrs.rs b/src/test/ui/proc-macro/module_with_attrs.rs new file mode 100644 index 0000000000000..63e66a62ac380 --- /dev/null +++ b/src/test/ui/proc-macro/module_with_attrs.rs @@ -0,0 +1,4 @@ +// ignore-test + +#![rustfmt::skip] +#![print_attr]